summaryrefslogtreecommitdiff
path: root/src/drumgizmo.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/drumgizmo.cc')
-rw-r--r--src/drumgizmo.cc67
1 files changed, 63 insertions, 4 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index 1abbb10..2370d43 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -36,6 +36,8 @@
#include <hugin.hpp>
+#include <config.h>
+
#include "drumkitparser.h"
#include "audioinputenginemidi.h"
#include "configuration.h"
@@ -55,6 +57,8 @@ bool DrumGizmo::loadkit(std::string file)
{
if(file == "") return 1;
+ printf("loadkit() go\n");
+
DEBUG(drumgizmo, "loadkit(%s)\n", file.c_str());
// Remove all queue AudioFiles from loader before we actually delete them.
@@ -66,12 +70,23 @@ bool DrumGizmo::loadkit(std::string file)
DrumKitParser parser(file, kit);
if(parser.parse()) {
ERR(drumgizmo, "Drumkit parser failed: %s\n", file.c_str());
- return false;
+ printf("loadkit() parser failed\n");
+ return false;
}
loader.loadKit(&kit);
+#ifdef WITH_RESAMPLER
+ unsigned int output_fs = kit.samplerate();
+ if(oe->samplerate() != UNKNOWN_SAMPLERATE) output_fs = oe->samplerate();
+ for(int i = 0; i < MAX_NUM_CHANNELS; i++) {
+ resampler[i].setup(kit.samplerate(), output_fs);
+ }
+#endif/*WITH_RESAMPLER*/
+
+
DEBUG(loadkit, "loadkit: Success\n");
+ printf("loadkit() done\n");
return true;
}
@@ -157,6 +172,7 @@ void DrumGizmo::handleMessage(Message *msg)
bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
{
+ // printf("."); fflush(stdout);
// Handle engine messages, at most one in each iteration:
handleMessages(1);
@@ -239,7 +255,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
} else {
//DEBUG(drumgizmo, "Adding event %d.\n", evs[e].offset);
Event *evt = new EventSample(ch.num, 1.0, af, i->group(), i);
- evt->offset = evs[e].offset + pos;
+ evt->offset = (evs[e].offset + pos) * resampler[0].ratio();
activeevents[ch.num].push_back(evt);
}
j++;
@@ -254,10 +270,11 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
free(evs);
-
//
// Write audio
//
+#ifndef WITH_RESAMPLER
+ // No resampling needed
for(size_t c = 0; c < kit.channels.size(); c++) {
sample_t *buf = samples;
bool internal = false;
@@ -269,9 +286,49 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples)
memset(buf, 0, nsamples * sizeof(sample_t));
getSamples(c, pos, buf, nsamples);
+
if(!internal) oe->run(c, samples, nsamples);
}
}
+#else/*WITH_RESAMPLER*/
+ // Resampling needed
+
+ //
+ // NOTE: Channels must be processed one buffer at a time on all channels in
+ // parallel - NOT all buffers on one channel and then all buffer on the next
+ // one since this would mess up the event queue (it would jump back and forth
+ // in time)
+ //
+
+ // Prepare output buffer
+ for(size_t c = 0; c < kit.channels.size(); c++) {
+ resampler[c].setOutputSamples(resampler_output_buffer[c], nsamples);
+ }
+
+ // Process channel data
+ size_t kitpos = pos * resampler[0].ratio();
+ //printf("ratio: %f\n", resampler[c].ratio());
+ while(resampler[0].getOutputSampleCount() > 0) {
+ for(size_t c = 0; c < kit.channels.size(); c++) {
+ if(resampler[c].getInputSampleCount() == 0) {
+ sample_t *sin = resampler_input_buffer[c];
+ size_t insize = sizeof(resampler_input_buffer[c]) / sizeof(sample_t);
+ memset(resampler_input_buffer[c], 0,
+ sizeof(resampler_input_buffer[c]));
+ getSamples(c, kitpos, sin, insize);
+ kitpos += insize;
+
+ resampler[c].setInputSamples(sin, insize);
+ }
+ resampler[c].process();
+ }
+ }
+
+ // Write output data to output engine.
+ for(size_t c = 0; c < kit.channels.size(); c++) {
+ oe->run(c, resampler_output_buffer[c], nsamples);
+ }
+#endif/*WITH_RESAMPLER*/
ie->post();
oe->post(nsamples);
@@ -300,6 +357,7 @@ void DrumGizmo::run(int endpos)
free(samples);
}
+#undef SSE
#ifdef SSE
#define N 8
@@ -332,7 +390,8 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz)
size_t n = 0;
if(evt->offset > (size_t)pos) n = evt->offset - pos;
size_t end = sz;
- if(evt->t + end - n > af->size) end = af->size - evt->t + n;
+ if((evt->t + end - n) > af->size) end = af->size - evt->t + n;
+ if(end > sz) end = sz;
if(evt->rampdown == NO_RAMPDOWN) {
#ifdef SSE