/*
- 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
*/
#include <cassert>
-#include <ardour/audio_port.h>
-#include <ardour/audioengine.h>
-#include <ardour/data_type.h>
-#include <ardour/audio_buffer.h>
+#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)
+nframes_t AudioPort::_port_offset = 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)
-{
- /* caller must hold process lock */
-
- _has_been_mixed_down = false;
-
- if (external ()) {
- /* external ports use JACK's memory */
- _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes + offset);
- }
-}
-
-AudioBuffer &
-AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset)
+AudioPort::cycle_start (nframes_t nframes)
{
/* caller must hold process lock */
- if (_has_been_mixed_down) {
- return *_buffer;
- }
+ /* get_buffer() must only be run on outputs here in cycle_start().
- if (receives_input ()) {
+ Inputs must be done in the correct processing order, which
+ requires interleaving with route processing. that will
+ happen when Port::get_buffer() is called.
+ */
- /* INPUT */
+ if (sends_output()) {
- /* 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 {
+ /* 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.
+ */
- /* 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<Port*>::const_iterator p = _connections.begin();
+}
- if (first_overwrite) {
- _buffer->read_from (dynamic_cast<AudioPort*>(*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<AudioPort*>(*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 (Sample);
}
+