Remove all use of nframes_t.
[ardour.git] / libs / ardour / audio_port.cc
1 /*
2     Copyright (C) 2006 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <cassert>
20 #include "ardour/audio_port.h"
21 #include "ardour/audioengine.h"
22 #include "ardour/data_type.h"
23 #include "ardour/audio_buffer.h"
24
25 using namespace ARDOUR;
26 using namespace std;
27
28 framecnt_t AudioPort::_port_offset = 0;
29
30 AudioPort::AudioPort (const std::string& name, Flags flags)
31         : Port (name, DataType::AUDIO, flags)
32         , _buffer (new AudioBuffer (0))
33 {
34         assert (name.find_first_of (':') == string::npos);
35 }
36
37 AudioPort::~AudioPort ()
38 {
39         delete _buffer;
40 }
41
42 void
43 AudioPort::cycle_start (pframes_t nframes)
44 {
45         /* caller must hold process lock */
46
47         /* get_buffer() must only be run on outputs here in cycle_start().
48
49            Inputs must be done in the correct processing order, which
50            requires interleaving with route processing. that will
51            happen when Port::get_buffer() is called.
52         */
53
54         if (sends_output()) {
55
56                 /* Notice that cycle_start() is always run with the *entire* process cycle frame count,
57                    so we do not bother to apply _port_offset here - we always want the address of the
58                    entire JACK port buffer. We are not collecting data here - just noting the
59                    address where we will write data later in the process cycle.
60                 */
61
62                 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes);
63                 _buffer->prepare ();
64         }
65 }
66
67 void
68 AudioPort::cycle_end (pframes_t nframes)
69 {
70         if (sends_output() && !_buffer->written()) {
71                 _buffer->silence (nframes);
72         }
73 }
74
75 void
76 AudioPort::cycle_split ()
77 {
78 }
79
80 AudioBuffer&
81 AudioPort::get_audio_buffer (framecnt_t nframes, framecnt_t offset)
82 {
83         /* caller must hold process lock */
84
85         if (receives_input ()) {
86
87                 /* Get a pointer to the audio data @ offset + _port_offset within the JACK port buffer and store
88                    it in our _buffer member.
89
90                    Note that offset is expected to be zero in almost all cases.
91                 */
92
93                 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset + _port_offset, nframes);
94         }
95
96         /* output ports set their _buffer data information during ::cycle_start()
97          */
98
99         return *_buffer;
100 }
101
102 size_t
103 AudioPort::raw_buffer_size (pframes_t nframes) const
104 {
105         return nframes * sizeof (Sample);
106 }
107