From 9a0abf4a45c516b15d74ab41f8dab8348d6b00c9 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 15 Jun 2016 07:53:25 +0200 Subject: Make sure we abide the samplerate in all input/output engines. --- drumgizmo/input/midifile.cc | 7 ++++++- drumgizmo/input/midifile.h | 1 + drumgizmo/input/test.cc | 21 +++++++++++++-------- drumgizmo/input/test.h | 2 ++ 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'drumgizmo') diff --git a/drumgizmo/input/midifile.cc b/drumgizmo/input/midifile.cc index 27a8e04..6a24a00 100644 --- a/drumgizmo/input/midifile.cc +++ b/drumgizmo/input/midifile.cc @@ -40,7 +40,7 @@ MidifileInputEngine::MidifileInputEngine() , track{-1} // all tracks , loop{false} , offset{0.0} - , samplerate{44100.0} // todo: via ctor arg + , samplerate{44100.0} { } @@ -190,3 +190,8 @@ void MidifileInputEngine::run(size_t pos, size_t len, std::vector& even void MidifileInputEngine::post() { } + +void MidifileInputEngine::setSampleRate(double sample_rate) +{ + this->samplerate = sample_rate; +} diff --git a/drumgizmo/input/midifile.h b/drumgizmo/input/midifile.h index a0e8fa6..518d8d2 100644 --- a/drumgizmo/input/midifile.h +++ b/drumgizmo/input/midifile.h @@ -49,6 +49,7 @@ public: void pre() override; void run(size_t pos, size_t len, std::vector& events) override; void post() override; + void setSampleRate(double sample_rate) override; private: smf_t* smf; diff --git a/drumgizmo/input/test.cc b/drumgizmo/input/test.cc index 4789119..6767769 100644 --- a/drumgizmo/input/test.cc +++ b/drumgizmo/input/test.cc @@ -35,6 +35,7 @@ TestInputEngine::TestInputEngine() , probability{0.1} , instrument{-1} , length{-1} + , sample_rate{44100.0} { } @@ -44,14 +45,14 @@ TestInputEngine::~TestInputEngine() bool TestInputEngine::init(const Instruments& instruments) { - return true; + return true; } void TestInputEngine::setParm(const std::string& parm, const std::string& value) { if(parm == "p") { - probability = atof(value.c_str()); + probability = atof(value.c_str()); } if(parm == "instr") { @@ -65,7 +66,7 @@ void TestInputEngine::setParm(const std::string& parm, const std::string& value) bool TestInputEngine::start() { - return true; + return true; } void TestInputEngine::stop() @@ -78,7 +79,7 @@ void TestInputEngine::pre() void TestInputEngine::run(size_t pos, size_t len, std::vector& events) { - if((float)rand() / (float)RAND_MAX > probability) + if((float)rand() / (float)RAND_MAX > probability) { return; } @@ -87,17 +88,16 @@ void TestInputEngine::run(size_t pos, size_t len, std::vector& events) auto& event = events.back(); event.type = TYPE_ONSET; - if(length != -1 && (int)pos > length * 44100) + if((length != -1) && (pos > std::llround(length * sample_rate))) { event.type = TYPE_STOP; } - else + else { event.type = TYPE_ONSET; } - - if(instrument != -1) + if(instrument != -1) { event.instrument = instrument; } @@ -113,3 +113,8 @@ void TestInputEngine::run(size_t pos, size_t len, std::vector& events) void TestInputEngine::post() { } + +void TestInputEngine::setSampleRate(double sample_rate) +{ + this->sample_rate = sample_rate; +} diff --git a/drumgizmo/input/test.h b/drumgizmo/input/test.h index 1edf386..70936ea 100644 --- a/drumgizmo/input/test.h +++ b/drumgizmo/input/test.h @@ -45,9 +45,11 @@ public: void pre() override; void run(size_t pos, size_t len, std::vector& events) override; void post() override; + void setSampleRate(double sample_rate) override; private: float probability; int instrument; int length; + double sample_rate; }; -- cgit v1.2.3