diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-05-08 12:15:10 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-05-08 12:17:16 +0200 |
commit | 8ec32c94e0d8161120018170724d64d262bc133d (patch) | |
tree | 62b4a6d97519fdd936ec0c782407ba09a06d52cd /src | |
parent | 32332a63ac9a80750b89452490830e042518797a (diff) |
Make Resamplers container class.
Diffstat (limited to 'src')
-rw-r--r-- | src/chresampler.cc | 18 | ||||
-rw-r--r-- | src/chresampler.h | 62 | ||||
-rw-r--r-- | src/drumgizmo.cc | 28 | ||||
-rw-r--r-- | src/drumgizmo.h | 2 | ||||
-rw-r--r-- | src/drumkitloader.cc | 11 | ||||
-rw-r--r-- | src/drumkitloader.h | 4 |
6 files changed, 77 insertions, 48 deletions
diff --git a/src/chresampler.cc b/src/chresampler.cc index d759d78..c8323de 100644 --- a/src/chresampler.cc +++ b/src/chresampler.cc @@ -104,7 +104,7 @@ CHResampler::~CHResampler() #endif } -void CHResampler::setInputSamples(float* samples, size_t count) +void CHResampler::setInputSamples(float* samples, std::size_t count) { #if defined(USE_ZITA) prv->zita.inp_data = samples; @@ -115,7 +115,7 @@ void CHResampler::setInputSamples(float* samples, size_t count) #endif } -void CHResampler::setOutputSamples(float* samples, size_t count) +void CHResampler::setOutputSamples(float* samples, std::size_t count) { #if defined(USE_ZITA) prv->zita.out_data = samples; @@ -139,7 +139,7 @@ void CHResampler::process() #endif } -size_t CHResampler::getInputSampleCount() const +std::size_t CHResampler::getInputSampleCount() const { #if defined(USE_ZITA) return prv->zita.inp_count; @@ -148,7 +148,7 @@ size_t CHResampler::getInputSampleCount() const #endif } -size_t CHResampler::getOutputSampleCount() const +std::size_t CHResampler::getOutputSampleCount() const { #if defined(USE_ZITA) return prv->zita.out_count; @@ -165,19 +165,19 @@ double CHResampler::getRatio() const #else // Dummy implementation -CHResampler::CHResampler() {} +CHResampler::CHResampler() {} CHResampler::~CHResampler() {} void CHResampler::setup(double, double) {} -void CHResampler::setInputSamples(float*, size_t) {} -void CHResampler::setOutputSamples(float*, size_t) {} +void CHResampler::setInputSamples(float*, std::size_t) {} +void CHResampler::setOutputSamples(float*, std::size_t) {} void CHResampler::process() {} -size_t CHResampler::getInputSampleCount() const +std::size_t CHResampler::getInputSampleCount() const { return 0; } -size_t CHResampler::getOutputSampleCount() const +std::size_t CHResampler::getOutputSampleCount() const { return 0; } diff --git a/src/chresampler.h b/src/chresampler.h index bbe2521..4148aee 100644 --- a/src/chresampler.h +++ b/src/chresampler.h @@ -27,16 +27,14 @@ #pragma once #include <memory> -#include <stdlib.h> #include <config.h> +#include <array> -/** - * Channel resampler class using either zita-resampler or secret rabbit code - * (really!!) depending on the value of the WITH_RESAMPLER macro. - * If WITH_RESAMPLER is unset the resampler is disabled entirely. - * If WITH_RESAMPLER=="zita" zita-resampler will be used. - * If WITH_RESAMPLER=="src" Secret Rabbit Code will be used. - */ +//! Channel resampler class using either zita-resampler or secret rabbit code +//! (really!!) depending on the value of the WITH_RESAMPLER macro. +//! If WITH_RESAMPLER is unset the resampler is disabled entirely. +//! If WITH_RESAMPLER=="zita" zita-resampler will be used. +//! If WITH_RESAMPLER=="src" Secret Rabbit Code will be used. class CHResampler { public: @@ -45,13 +43,13 @@ public: void setup(double input_fs, double output_fs); - void setInputSamples(float* samples, size_t count); - void setOutputSamples(float* samples, size_t count); + void setInputSamples(float* samples, std::size_t count); + void setOutputSamples(float* samples, std::size_t count); void process(); - size_t getInputSampleCount() const; - size_t getOutputSampleCount() const; + std::size_t getInputSampleCount() const; + std::size_t getOutputSampleCount() const; double getRatio() const; @@ -60,7 +58,43 @@ private: class Prv; std::unique_ptr<Prv> prv; - double input_fs{44100}; - double output_fs{44100}; + double input_fs{44100.0}; + double output_fs{44100.0}; #endif /*WITH_RESAMPLER*/ }; + +//! Container class for the resampler array. +class Resamplers +{ +public: + void setup(double input_fs, double output_fs) + { + for(auto& resampler : resamplers) + { + resampler.setup(input_fs, output_fs); + } + } + + bool isActive() const + { + return getRatio() != 1.0; + } + + double getRatio() const + { + return resamplers[0].getRatio(); + } + + + CHResampler& operator[](std::size_t idx) + { + return resamplers[idx]; + } + + std::size_t getOutputSampleCount() const + { + return resamplers[0].getOutputSampleCount(); + } + + std::array<CHResampler, 64> resamplers; +}; diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 893b536..1ccefc5 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -50,7 +50,7 @@ DrumGizmo::DrumGizmo(Settings& settings, AudioOutputEngine *o, AudioInputEngine *i) - : loader(settings, kit, *i, resampler) + : loader(settings, kit, *i, resamplers) , oe(o) , ie(i) , kit() @@ -87,7 +87,7 @@ bool DrumGizmo::init() void DrumGizmo::setFrameSize(size_t framesize) { // If we are resampling override the frame size. - if(resampler[0].getRatio() != 1) + if(resamplers.isActive()) { framesize = RESAMPLER_INPUT_BUFFER; } @@ -154,7 +154,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) ie->run(pos, nsamples, events); - double resample_ratio = resampler[0].getRatio(); + double resample_ratio = resamplers.getRatio(); bool active_events_left = input_processor.process(events, pos, resample_ratio); if(!active_events_left) @@ -168,7 +168,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) // #ifdef WITH_RESAMPLER if((settings.enable_resampling.load() == false) || - (resampler[0].getRatio() == 1.0)) // No resampling needed + (!resamplers.isActive())) // No resampling needed { #endif for(size_t c = 0; c < kit.channels.size(); ++c) @@ -209,27 +209,27 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) // Prepare output buffer for(size_t c = 0; c < kit.channels.size(); ++c) { - resampler[c].setOutputSamples(resampler_output_buffer[c], nsamples); + resamplers[c].setOutputSamples(resampler_output_buffer[c], nsamples); } // Process channel data - size_t kitpos = pos * resampler[0].getRatio(); + size_t kitpos = pos * resamplers.getRatio(); size_t insize = sizeof(resampler_input_buffer[0]) / sizeof(sample_t); - while(resampler[0].getOutputSampleCount() > 0) + while(resamplers.getOutputSampleCount() > 0) { for(size_t c = 0; c < kit.channels.size(); ++c) { - if(resampler[c].getInputSampleCount() == 0) + if(resamplers[c].getInputSampleCount() == 0) { sample_t *sin = resampler_input_buffer[c]; memset(resampler_input_buffer[c], 0, sizeof(resampler_input_buffer[c])); getSamples(c, kitpos, sin, insize); - resampler[c].setInputSamples(sin, insize); + resamplers[c].setInputSamples(sin, insize); } - resampler[c].process(); + resamplers[c].process(); } kitpos += insize; } @@ -413,11 +413,9 @@ void DrumGizmo::setSamplerate(int samplerate) DEBUG(dgeditor, "%s samplerate: %d\n", __PRETTY_FUNCTION__, samplerate); settings.samplerate.store(samplerate); #ifdef WITH_RESAMPLER - for(auto& chresampler: resampler) - { - chresampler.setup(kit.getSamplerate(), settings.samplerate.load()); - } - if(resampler[0].getRatio() != 1) + resamplers.setup(kit.getSamplerate(), settings.samplerate.load()); + + if(resamplers.isActive()) { setFrameSize(RESAMPLER_INPUT_BUFFER); } diff --git a/src/drumgizmo.h b/src/drumgizmo.h index eb89050..e25db2f 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -85,7 +85,7 @@ protected: std::list< Event* > activeevents[MAX_NUM_CHANNELS]; - std::array<CHResampler, MAX_NUM_CHANNELS> resampler; + Resamplers resamplers; sample_t resampler_output_buffer[MAX_NUM_CHANNELS][RESAMPLER_OUTPUT_BUFFER]; sample_t resampler_input_buffer[MAX_NUM_CHANNELS][RESAMPLER_INPUT_BUFFER]; diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index ec86e77..a08fc0a 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -36,12 +36,12 @@ DrumKitLoader::DrumKitLoader(Settings& settings, DrumKit& kit, AudioInputEngine& ie, - std::array<CHResampler, 64>& resampler) + Resamplers& resamplers) : settings(settings) , getter(settings) , kit(kit) , ie(ie) - , resampler(resampler) + , resamplers(resamplers) { run(); run_semaphore.wait(); // Wait for the thread to actually start. @@ -99,10 +99,7 @@ bool DrumKitLoader::loadkit(const std::string& file) loadKit(&kit); #ifdef WITH_RESAMPLER - for(auto& chresampler: resampler) - { - chresampler.setup(kit.getSamplerate(), settings.samplerate.load()); - } + resamplers.setup(kit.getSamplerate(), settings.samplerate.load()); #endif/*WITH_RESAMPLER*/ @@ -234,7 +231,7 @@ void DrumKitLoader::thread_main() } // Note: Remove this line to enable diskstreaming - preload_size = ALL_SAMPLES; + //preload_size = ALL_SAMPLES; audiofile->load(preload_size); } diff --git a/src/drumkitloader.h b/src/drumkitloader.h index 01b4f06..f99f439 100644 --- a/src/drumkitloader.h +++ b/src/drumkitloader.h @@ -51,7 +51,7 @@ class DrumKitLoader public: //! The constrcutor starts the loader thread. DrumKitLoader(Settings& settings, DrumKit& kit, AudioInputEngine& ie, - std::array<CHResampler, 64>& resampler); + Resamplers& resamplers); //! The destructor signals the thread to stop and waits to merge before //! returning (ie. deleting the object will garantuee that the thread has @@ -89,6 +89,6 @@ protected: SettingsGetter getter; DrumKit& kit; AudioInputEngine& ie; - std::array<CHResampler, 64>& resampler; + Resamplers& resamplers; MemChecker memchecker; }; |