X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Faudio_port.cc;h=a75f7d7a09163058b624bcaf6788763b687331ac;hb=325671e20afa56f5c796d14ce9bb76146a232f0b;hp=55d65d850d6a69ebf564998bb644ff136ae78282;hpb=d6637dad5a239d74038fdf9e5800e5108ba0c44f;p=ardour.git diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 55d65d850d..a75f7d7a09 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 Paul Davis + Copyright (C) 2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,126 +17,89 @@ */ #include -#include -#include -#include -#include +#include "ardour/audio_port.h" +#include "ardour/audioengine.h" +#include "ardour/data_type.h" +#include "ardour/audio_buffer.h" using namespace ARDOUR; using namespace std; -AudioPort::AudioPort (const std::string& name, Flags flags, bool ext, nframes_t capacity) - : Port (name, DataType::AUDIO, flags, ext) - , _has_been_mixed_down (false) - , _buffer (0) +AudioPort::AudioPort (const std::string& name, Flags flags) + : Port (name, DataType::AUDIO, flags) + , _buffer (new AudioBuffer (0)) { assert (name.find_first_of (':') == string::npos); - - if (external ()) { - - /* external ports use the external port buffer */ - _buffer = new AudioBuffer (0); - - } else { - - /* internal ports need their own buffers */ - _buffer = new AudioBuffer (capacity); - - } - } -AudioPort::~AudioPort() +AudioPort::~AudioPort () { delete _buffer; } void -AudioPort::cycle_start (nframes_t nframes, nframes_t offset) +AudioPort::cycle_start (nframes_t nframes) { /* caller must hold process lock */ - _has_been_mixed_down = false; + /* get_buffer() must only be run on outputs here in cycle_start(). - if (external ()) { - /* external ports use JACK's memory */ - _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes + offset); - } -} + Inputs must be done in the correct processing order, which + requires interleaving with route processing. that will + happen when Port::get_buffer() is called. + */ -AudioBuffer & -AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset) -{ - /* caller must hold process lock */ + if (sends_output()) { - if (_has_been_mixed_down) { - return *_buffer; - } + /* Notice that cycle_start() is always run with the *entire* process cycle frame count, + so we do not bother to apply _port_offset here - we always want the address of the + entire JACK port buffer. We are not collecting data here - just noting the + address where we will write data later in the process cycle. + */ - if (receives_input ()) { - - /* INPUT */ - - /* If we're external (), we have some data in our buffer set up by JACK; - otherwise, we have an undefined buffer. In either case we mix down - our non-JACK inputs; either accumulating into the JACK data or - overwriting the undefined data */ - - mixdown (nframes, offset, !external ()); - - } else { - - /* OUTPUT */ - - if (!external ()) { - /* start internal output buffers with silence */ - _buffer->silence (nframes, offset); - } - - } - - if (nframes) { - _has_been_mixed_down = true; + _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes); + _buffer->prepare (); } - - return *_buffer; } void -AudioPort::cycle_end (nframes_t nframes, nframes_t offset) +AudioPort::cycle_end (nframes_t nframes) { - _has_been_mixed_down = false; + if (sends_output() && !_buffer->written()) { + _buffer->silence (nframes); + } } void -AudioPort::mixdown (nframes_t cnt, nframes_t offset, bool first_overwrite) +AudioPort::cycle_split () { - if (_connections.empty()) { - if (first_overwrite) { - _buffer->silence (cnt, offset); - } - return; - } - - set::const_iterator p = _connections.begin(); +} - if (first_overwrite) { - _buffer->read_from (dynamic_cast(*p)->get_audio_buffer (cnt, offset), cnt, offset); - ++p; - } +AudioBuffer& +AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset) +{ + /* caller must hold process lock */ + + if (receives_input ()) { - for (; p != _connections.end (); ++p) { - _buffer->accumulate_from (dynamic_cast(*p)->get_audio_buffer (cnt, offset), cnt, offset); + /* Get a pointer to the audio data @ offset + _port_offset within the JACK port buffer and store + it in our _buffer member. + + Note that offset is expected to be zero in almost all cases. + */ + + _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset + _port_offset, nframes); } + + /* output ports set their _buffer data information during ::cycle_start() + */ + + return *_buffer; } -void -AudioPort::reset () +size_t +AudioPort::raw_buffer_size(nframes_t nframes) const { - Port::reset (); - - if (_buffer->capacity () != 0) { - _buffer->resize (_engine->frames_per_cycle ()); - _buffer->clear (); - } + return nframes * sizeof(float); } +