From 47adc0e3e96b7845f71fc1ce029833908fe8d8dc Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 8 Feb 2021 18:42:44 +0100 Subject: WIP: PoC on stereo map feature. --- src/drumgizmo.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/drumgizmo.cc') diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index ca91c12..a67dace 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -185,6 +185,63 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) // // Write audio // + if(settings.enable_stereo_mode) + { + static sample_t left[4096]; + static sample_t right[4096]; + std::memset(left, 0, sizeof(left)); + std::memset(right, 0, sizeof(right)); + for(size_t c = 0; c < kit.channels.size(); ++c) + { + const auto& channel = kit.channels[c]; + (void)channel; + const auto pan = channel.stereo_panning * 0.5 + 0.5; // -> [0; 1] + const auto scale = channel.stereo_volume; + static sample_t buf[4096]; + std::memset(buf, 0, sizeof(buf)); + getSamples(c, pos, buf, nsamples); + for(auto i = 0u; i < nsamples; ++i) + { + left[i] += buf[i] * pan * scale; + right[i] += buf[i] * (1 - pan) * scale; + } + } + + for(size_t c = 0; c < kit.channels.size(); ++c) + { + sample_t *buf = samples; + bool internal = false; + if(oe.getBuffer(c)) + { + buf = oe.getBuffer(c); + internal = true; + } + + if(buf) + { + if(c == 0) // left channel + { + memcpy(buf, left, nsamples * sizeof(sample_t)); + } + else if(c == 1) // right channel + { + memcpy(buf, right, nsamples * sizeof(sample_t)); + } + else + { + std::memset(buf, 0, nsamples * sizeof(sample_t)); + } + + if(!internal) + { + oe.run(c, samples, nsamples); + } + } + } + + } + else + { if(!enable_resampling || ratio == 1.0) { // No resampling needed @@ -250,6 +307,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) } } } + } ie.post(); oe.post(nsamples); -- cgit v1.2.3