diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-04-01 15:30:23 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2017-04-01 21:00:39 +0200 |
commit | 9774762dd014bed4f4e3c4ac142a7b9634944fe4 (patch) | |
tree | 684d1587b8a2ac2e1a9b7bd195090743cba4f74b | |
parent | 32ad5ff14a03cdf049903523603c6b7a83dd7a5a (diff) |
Update underrun counter directly in AudioCache.
-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 | ||||
-rw-r--r-- | test/audiocachetest.cc | 6 |
5 files changed, 27 insertions, 37 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; }; diff --git a/test/audiocachetest.cc b/test/audiocachetest.cc index b194b14..ae3e8f2 100644 --- a/test/audiocachetest.cc +++ b/test/audiocachetest.cc @@ -28,6 +28,7 @@ #include <audiofile.h> #include <audiocache.h> +#include <settings.h> #include <unistd.h> #include "drumkit_creator.h" @@ -68,7 +69,8 @@ public: printf("audio_file.load\n"); audio_file.load(4096); - AudioCache audio_cache; + Settings settings; + AudioCache audio_cache(settings); printf("audio_cache.init\n"); audio_cache.init(100); audio_cache.setAsyncMode(threaded); @@ -115,7 +117,7 @@ public: samples = audio_cache.next(id, size); - CPPUNIT_ASSERT_EQUAL(0, (int)audio_cache.getNumberOfUnderruns()); + CPPUNIT_ASSERT_EQUAL(std::size_t(0), settings.number_of_underruns.load()); for(size_t i = 0; (i < size) && (offset < audio_file_ref.size); ++i) { |