summaryrefslogtreecommitdiff
path: root/libs/ardour/panner.cc
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-08-12 08:20:24 +0000
committerDavid Robillard <d@drobilla.net>2006-08-12 08:20:24 +0000
commit30ab1fd61569f9d7fb7410d483fa68cbf9865c37 (patch)
tree60cf9b5228a2728cda6608d517528066253d1a17 /libs/ardour/panner.cc
parentcbdf686e391bc2e7b93f37a5d3fa9197cb178078 (diff)
Towards MIDI:
- Converted vector<Sample*> to BufferList and numerous counts from int to ChanCount (and related changes) - Added fancy type-generic iterators to BufferList, PortIterator (see IO::collect_input for a good example of the idea - the same code will work to read all input (of various types in a single IO, eg instruments) without modification no matter how many types we add) - Fixed comparison operator bugs with ChanCount (screwed up metering among other things) - Moved peak metering into it's own object, and moved most of the pan related code out of IO to panner (still a touch more to be done here for MIDI playback) Not directly MIDI related fixes for problems in trunk: - Fixed varispeed gain/pan automation to work properly (was reading the wrong range of automation data, probably causing nasty clicks?) - Fixed crash on varispeed looping (possibly only a 64-bit problem). It still doesn't work, but at least it doesn't die Quite a few things broken, and the new classes are pretty filthy still, but I think the direction is a lot better than all my previous plans... git-svn-id: svn://localhost/ardour2/branches/midi@795 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/panner.cc')
-rw-r--r--libs/ardour/panner.cc155
1 files changed, 143 insertions, 12 deletions
diff --git a/libs/ardour/panner.cc b/libs/ardour/panner.cc
index f866b5ae10..0d15ba84e7 100644
--- a/libs/ardour/panner.cc
+++ b/libs/ardour/panner.cc
@@ -39,6 +39,7 @@
#include <ardour/utils.h>
#include <ardour/mix.h>
+#include <ardour/buffer_set.h>
#include "i18n.h"
@@ -292,8 +293,10 @@ BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt)
}
void
-BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_nframes_t nframes)
+BaseStereoPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, jack_nframes_t nframes)
{
+ assert(obufs.count().get(DataType::AUDIO) == 2);
+
pan_t delta;
Sample* dst;
pan_t pan;
@@ -301,10 +304,12 @@ BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, ja
if (_muted) {
return;
}
+
+ Sample* const src = srcbuf.data(nframes);
/* LEFT */
- dst = obufs[0];
+ dst = obufs.get_audio(0).data(nframes);
if (fabsf ((delta = (left - desired_left))) > 0.002) { // about 1 degree of arc
@@ -354,7 +359,7 @@ BaseStereoPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, ja
/* RIGHT */
- dst = obufs[1];
+ dst = obufs.get_audio(1).data(nframes);
if (fabsf ((delta = (right - desired_right))) > 0.002) { // about 1 degree of arc
@@ -445,19 +450,22 @@ EqualPowerStereoPanner::update ()
}
void
-EqualPowerStereoPanner::distribute_automated (Sample* src, Sample** obufs,
+EqualPowerStereoPanner::distribute_automated (AudioBuffer& srcbuf, BufferSet& obufs,
jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes,
pan_t** buffers)
{
+ assert(obufs.count().get(DataType::AUDIO) == 2);
+
Sample* dst;
pan_t* pbuf;
+ Sample* const src = srcbuf.data(nframes);
/* fetch positional data */
if (!_automation.rt_safe_get_vector (start, end, buffers[0], nframes)) {
/* fallback */
if (!_muted) {
- distribute (src, obufs, 1.0, nframes);
+ distribute (srcbuf, obufs, 1.0, nframes);
}
return;
}
@@ -489,25 +497,25 @@ EqualPowerStereoPanner::distribute_automated (Sample* src, Sample** obufs,
/* LEFT */
- dst = obufs[0];
+ dst = obufs.get_audio(0).data(nframes);
pbuf = buffers[0];
for (jack_nframes_t n = 0; n < nframes; ++n) {
dst[n] += src[n] * pbuf[n];
}
- /* XXX it would be nice to mark the buffer as written to */
+ /* XXX it would be nice to mark the buffer as written to */
/* RIGHT */
- dst = obufs[1];
+ dst = obufs.get_audio(1).data(nframes);
pbuf = buffers[1];
for (jack_nframes_t n = 0; n < nframes; ++n) {
dst[n] += src[n] * pbuf[n];
}
- /* XXX it would be nice to mark the buffer as written to */
+ /* XXX it would be nice to mark the buffer as written to */
}
StreamPanner*
@@ -648,7 +656,7 @@ Multi2dPanner::update ()
}
void
-Multi2dPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_nframes_t nframes)
+Multi2dPanner::distribute (AudioBuffer& srcbuf, BufferSet& obufs, gain_t gain_coeff, jack_nframes_t nframes)
{
Sample* dst;
pan_t pan;
@@ -658,11 +666,13 @@ Multi2dPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_
if (_muted) {
return;
}
+
+ Sample* const src = srcbuf.data(nframes);
for (n = 0, o = parent.outputs.begin(); o != parent.outputs.end(); ++o, ++n) {
- dst = obufs[n];
+ dst = obufs.get_audio(n).data(nframes);
#ifdef CAN_INTERP
if (fabsf ((delta = (left_interp - desired_left))) > 0.002) { // about 1 degree of arc
@@ -719,7 +729,7 @@ Multi2dPanner::distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_
}
void
-Multi2dPanner::distribute_automated (Sample* src, Sample** obufs,
+Multi2dPanner::distribute_automated (AudioBuffer& src, BufferSet& obufs,
jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes,
pan_t** buffers)
{
@@ -1477,3 +1487,124 @@ Panner::set_position (float xpos, float ypos, float zpos, StreamPanner& orig)
}
}
}
+
+void
+Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff)
+{
+ if (outbufs.count().get(DataType::AUDIO) == 0) {
+ // Don't want to lose audio...
+ assert(inbufs.count().get(DataType::AUDIO) == 0);
+ return;
+ }
+
+ // We shouldn't be called in the first place...
+ assert(!bypassed());
+ assert(!empty());
+
+
+ if (outbufs.count().get(DataType::AUDIO) == 1) {
+
+ AudioBuffer& dst = outbufs.get_audio(0);
+
+ if (gain_coeff == 0.0f) {
+
+ /* only one output, and gain was zero, so make it silent */
+
+ dst.silence(offset);
+
+ } else if (gain_coeff == 1.0f){
+
+ /* mix all buffers into the output */
+
+ // copy the first
+ dst.read_from(inbufs.get_audio(0), nframes, offset);
+
+ // accumulate starting with the second
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (++i; i != inbufs.audio_end(); ++i) {
+ dst.accumulate_from(*i, nframes, offset);
+ }
+
+ //audio_output(0)->mark_silence (false); // FIXME
+
+ } else {
+
+ /* mix all buffers into the output, scaling them all by the gain */
+
+ // copy the first
+ dst.read_from(inbufs.get_audio(0), nframes, offset);
+
+ // accumulate (with gain) starting with the second
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (++i; i != inbufs.audio_end(); ++i) {
+ dst.accumulate_with_gain_from(*i, nframes, offset, gain_coeff);
+ }
+
+ //audio_output(0)->mark_silence (false); // FIXME
+ }
+
+ return;
+ }
+
+ // More than 1 output, we should have 1 panner for each input
+ assert(size() == inbufs.count().get(DataType::AUDIO));
+
+ /* the terrible silence ... */
+ for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
+ i->silence(nframes, offset);
+ }
+
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (iterator pan = begin(); pan != end(); ++pan, ++i) {
+ (*pan)->distribute (*i, outbufs, gain_coeff, nframes);
+ }
+}
+
+void
+Panner::distribute_automated (BufferSet& inbufs, BufferSet& outbufs, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset)
+{
+ if (outbufs.count().get(DataType::AUDIO) == 0) {
+ // Don't want to lose audio...
+ assert(inbufs.count().get(DataType::AUDIO) == 0);
+ return;
+ }
+
+ // We shouldn't be called in the first place...
+ assert(!bypassed());
+ assert(!empty());
+
+
+ if (outbufs.count().get(DataType::AUDIO) == 1) {
+
+ AudioBuffer& dst = outbufs.get_audio(0);
+
+ // FIXME: apply gain automation?
+
+ // copy the first
+ dst.read_from(inbufs.get_audio(0), nframes, offset);
+
+ // accumulate starting with the second
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (++i; i != inbufs.audio_end(); ++i) {
+ dst.accumulate_from(*i, nframes, offset);
+ }
+
+ //audio_output(0)->mark_silence (false); // FIXME
+
+ return;
+ }
+
+ // More than 1 output, we should have 1 panner for each input
+ assert(size() == inbufs.count().get(DataType::AUDIO));
+
+ /* the terrible silence ... */
+ for (BufferSet::audio_iterator i = outbufs.audio_begin(); i != outbufs.audio_end(); ++i) {
+ i->silence(nframes, offset);
+ }
+
+ BufferSet::audio_iterator i = inbufs.audio_begin();
+ for (iterator pan = begin(); pan != end(); ++pan, ++i) {
+ (*pan)->distribute_automated (*i, outbufs, start_frame, end_frame, nframes, _session.pan_automation_buffer());
+ }
+}
+