summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-06-15 07:53:25 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-06-15 07:54:08 +0200
commit9a0abf4a45c516b15d74ab41f8dab8348d6b00c9 (patch)
tree1e915664db627f2dd124ee08a0cebe3d6c306b3c
parent149d86611985b7a382994ac684d555660927e8d2 (diff)
Make sure we abide the samplerate in all input/output engines.
-rw-r--r--drumgizmo/input/midifile.cc7
-rw-r--r--drumgizmo/input/midifile.h1
-rw-r--r--drumgizmo/input/test.cc21
-rw-r--r--drumgizmo/input/test.h2
-rw-r--r--src/audioinputengine.h3
-rw-r--r--src/drumgizmo.cc4
6 files changed, 29 insertions, 9 deletions
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<event_t>& 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<event_t>& 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<event_t>& 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<event_t>& 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<event_t>& 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<event_t>& events) override;
void post() override;
+ void setSampleRate(double sample_rate) override;
private:
float probability;
int instrument;
int length;
+ double sample_rate;
};
diff --git a/src/audioinputengine.h b/src/audioinputengine.h
index bb7131c..72fa57d 100644
--- a/src/audioinputengine.h
+++ b/src/audioinputengine.h
@@ -48,4 +48,7 @@ public:
virtual void pre() = 0;
virtual void run(size_t pos, size_t len, std::vector<event_t>& events) = 0;
virtual void post() = 0;
+
+ //! Reimplement to receive sample rate changes.
+ virtual void setSampleRate(double sample_rate) {}
};
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index e07b7a1..d6dc028 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -426,6 +426,10 @@ void DrumGizmo::setSamplerate(int samplerate)
{
DEBUG(dgeditor, "%s samplerate: %d\n", __PRETTY_FUNCTION__, samplerate);
settings.samplerate.store(samplerate);
+
+ // Notify input engine of the samplerate change.
+ ie.setSampleRate(samplerate);
+
#ifdef WITH_RESAMPLER
resamplers.setup(kit.getSamplerate(), settings.samplerate.load());