X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Faudio_port.cc;h=714be28f3409c4c0ce7fe4006fd7621bdb9598ba;hb=1d210a54f9b1c0da7a196413bd760ff53f198270;hp=99f2b7ecae17993e11674f568a0ca0484595c192;hpb=30ab1fd61569f9d7fb7410d483fa68cbf9865c37;p=ardour.git diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 99f2b7ecae..714be28f34 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -18,52 +18,109 @@ #include #include +#include +#include #include using namespace ARDOUR; using namespace std; -jack_nframes_t AudioPort::_short_over_length = 2; -jack_nframes_t AudioPort::_long_over_length = 10; +AudioPort::AudioPort (const std::string& name, Flags flags, bool external, nframes_t capacity) + : Port (name, flags) + , BaseAudioPort (name, flags) + , PortFacade (name, flags) +{ + if (!external || receives_input()) { + + /* internal-only and input ports need their own buffers. + external output ports use the external port buffer. + */ + + _buffer = new AudioBuffer (capacity); + _own_buffer = true; + } + + if (!external) { + + _ext_port = 0; + set_name (name); + + } else { + + /* make the JackAudioPort create its own buffer. For input, + we will copy from it during cycle_start(). For output, + we will set up our buffer to point to its buffer, which + will in turn be using the JACK port buffer for data. + */ + + _ext_port = new JackAudioPort (name, flags, 0); + + if (sends_output()) { + _buffer = &dynamic_cast(_ext_port)->get_audio_buffer(); + } + + Port::set_name (_ext_port->name()); + } + + reset (); +} -AudioPort::AudioPort(jack_port_t* p) - : Port(p) - , _buffer(0) +AudioPort::~AudioPort() { - DataType dt(_type); - assert(dt == DataType::AUDIO); - - reset(); + if (_ext_port) { + delete _ext_port; + _ext_port = 0; + } } void AudioPort::reset() { - Port::reset(); - if (_flags & JackPortIsOutput) { - if (_buffer.capacity() > 0) { - _buffer.clear(); - } - _silent = true; + BaseAudioPort::reset(); + + if (_ext_port) { + _ext_port->reset (); } - - _metering = 0; - reset_meters (); } + void -AudioPort::cycle_start (jack_nframes_t nframes) +AudioPort::cycle_start (nframes_t nframes, nframes_t offset) { - if (_flags & JackPortIsOutput) { - // FIXME: do nothing, we can cache the value (but capacity needs to be set) - _buffer.set_data((Sample*)jack_port_get_buffer (_port, nframes), nframes); + /* caller must hold process lock */ + + if (_ext_port) { + _ext_port->cycle_start (nframes, offset); + } + + if (_flags & IsInput) { + + if (_ext_port) { + _buffer->read_from (dynamic_cast(_ext_port)->get_audio_buffer(), nframes, offset); + + if (!_connections.empty()) { + (*_mixdown) (_connections, _buffer, nframes, offset, false); + } + + } else { + + if (_connections.empty()) { + _buffer->silence (nframes, offset); + } else { + (*_mixdown) (_connections, _buffer, nframes, offset, true); + } + } + } else { - _buffer.set_data((Sample*)jack_port_get_buffer (_port, nframes), nframes); + + // XXX if we could get the output stage to not purely mix into, but also + // to initially overwrite the buffer, we could avoid this silence step. + + _buffer->silence (nframes, offset); } } void -AudioPort::cycle_end() +AudioPort::cycle_end (nframes_t nframes, nframes_t offset) { - // whatever... }