diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/audiocache.cc | 17 | ||||
-rw-r--r-- | src/audiocache.h | 12 | ||||
-rw-r--r-- | src/drumgizmo.cc | 22 | ||||
-rw-r--r-- | src/drumgizmo.h | 7 |
4 files changed, 23 insertions, 35 deletions
diff --git a/src/audiocache.cc b/src/audiocache.cc index a366423..2deecc9 100644 --- a/src/audiocache.cc +++ b/src/audiocache.cc @@ -37,6 +37,11 @@ #define CHUNKSIZE(x) (x * CHUNK_MULTIPLIER) +AudioCache::AudioCache(Settings& settings) + : settings(settings) +{ +} + AudioCache::~AudioCache() { DEBUG(cache, "~AudioCache() pre\n"); @@ -190,7 +195,7 @@ sample_t* AudioCache::next(cacheid_t id, size_t& size) if(!c.ready) { // Just return silence. - ++number_of_underruns; + settings.number_of_underruns.fetch_add(1); return nodata; } @@ -285,13 +290,3 @@ bool AudioCache::isAsyncMode() const { return event_handler.isThreaded(); } - -size_t AudioCache::getNumberOfUnderruns() const -{ - return number_of_underruns; -} - -void AudioCache::resetNumberOfUnderruns() -{ - number_of_underruns = 0; -} diff --git a/src/audiocache.h b/src/audiocache.h index d0be509..761f2b2 100644 --- a/src/audiocache.h +++ b/src/audiocache.h @@ -36,12 +36,13 @@ #include "audiocachefile.h" #include "audiocacheidmanager.h" #include "audiocacheeventhandler.h" +#include "settings.h" #define CHUNK_MULTIPLIER 16 class AudioCache { public: - AudioCache() = default; + AudioCache(Settings& settings); //! Destroy object and stop thread if needed. ~AudioCache(); @@ -97,18 +98,13 @@ public: void setAsyncMode(bool async); bool isAsyncMode() const; - //! Return the number of chunks that were read too late. - size_t getNumberOfUnderruns() const; - - //! Set underrun counter to 0. - void resetNumberOfUnderruns(); - private: size_t framesize{0}; sample_t* nodata{nullptr}; size_t nodata_framesize{0}; - size_t number_of_underruns{0}; AudioCacheIDManager id_manager; AudioCacheEventHandler event_handler{id_manager}; + + Settings& settings; }; diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 18cbbb7..2b4007d 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -45,14 +45,11 @@ DrumGizmo::DrumGizmo(Settings& settings, : loader(settings, kit, i, resamplers, rand) , oe(o) , ie(i) - , kit() + , audio_cache(settings) , input_processor(settings, kit, activeevents) - , framesize(0) - , freewheel(true) - , events{} , settings(settings) { - audioCache.init(10000); // start thread + audio_cache.init(10000); // start thread events.reserve(1000); loader.init(); } @@ -60,7 +57,7 @@ DrumGizmo::DrumGizmo(Settings& settings, DrumGizmo::~DrumGizmo() { loader.deinit(); - audioCache.deinit(); // stop thread + audio_cache.deinit(); // stop thread } bool DrumGizmo::init() @@ -94,7 +91,7 @@ void DrumGizmo::setFrameSize(size_t framesize) // Update framesize in drumkitloader and cachemanager: loader.setFrameSize(framesize); - audioCache.setFrameSize(framesize); + audio_cache.setFrameSize(framesize); } } @@ -103,7 +100,7 @@ void DrumGizmo::setFreeWheel(bool freewheel) // Freewheel = true means that we are bouncing and therefore running faster // than realtime. this->freewheel = freewheel; - audioCache.setAsyncMode(!freewheel); + audio_cache.setAsyncMode(!freewheel); } void DrumGizmo::setRandomSeed(unsigned int seed) @@ -240,7 +237,6 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) bool removeevent = false; Event* event = *i; - Event::type_t type = event->getType(); switch(type) { case Event::sample: @@ -263,8 +259,8 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) if(evt.cache_id == CACHE_NOID) { size_t initial_chunksize = (pos + sz) - evt.offset; - evt.buffer = audioCache.open(af, initial_chunksize, - af.filechannel, evt.cache_id); + evt.buffer = audio_cache.open(af, initial_chunksize, + af.filechannel, evt.cache_id); evt.buffer_size = initial_chunksize; } @@ -342,7 +338,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) if((evt.t < af.size) && (evt.rampdown != 0)) { - evt.buffer = audioCache.next(evt.cache_id, evt.buffer_size); + evt.buffer = audio_cache.next(evt.cache_id, evt.buffer_size); } else { @@ -351,7 +347,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) if(removeevent) { - audioCache.close(evt.cache_id); + audio_cache.close(evt.cache_id); } } } diff --git a/src/drumgizmo.h b/src/drumgizmo.h index b104772..e74d1b5 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -92,14 +92,15 @@ protected: std::map<std::string, AudioFile *> audiofiles; - AudioCache audioCache; + AudioCache audio_cache; DrumKit kit; InputProcessor input_processor; - size_t framesize; - bool freewheel; + size_t framesize{0}; + bool freewheel{true}; std::vector<event_t> events; Settings& settings; + Random rand; }; |