2 Copyright (C) 2006 Paul Davis
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.
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.
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.
20 #include "ardour/audio_port.h"
21 #include "ardour/audioengine.h"
22 #include "ardour/data_type.h"
23 #include "ardour/audio_buffer.h"
25 using namespace ARDOUR;
28 framecnt_t AudioPort::_port_offset = 0;
30 AudioPort::AudioPort (const std::string& name, Flags flags)
31 : Port (name, DataType::AUDIO, flags)
32 , _buffer (new AudioBuffer (0))
34 assert (name.find_first_of (':') == string::npos);
37 AudioPort::~AudioPort ()
43 AudioPort::cycle_start (pframes_t nframes)
45 /* caller must hold process lock */
47 /* get_buffer() must only be run on outputs here in cycle_start().
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.
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.
62 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes);
68 AudioPort::cycle_end (pframes_t nframes)
70 if (sends_output() && !_buffer->written()) {
71 _buffer->silence (nframes);
76 AudioPort::cycle_split ()
81 AudioPort::get_audio_buffer (framecnt_t nframes, framecnt_t offset)
83 /* caller must hold process lock */
85 if (receives_input ()) {
87 /* Get a pointer to the audio data @ offset + _port_offset within the JACK port buffer and store
88 it in our _buffer member.
90 Note that offset is expected to be zero in almost all cases.
93 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset + _port_offset, nframes);
96 /* output ports set their _buffer data information during ::cycle_start()
103 AudioPort::raw_buffer_size (pframes_t nframes) const
105 return nframes * sizeof (Sample);