diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-01-29 11:41:27 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-01-29 11:41:27 +0100 |
commit | 8faba64d538753d09765f2fe003cc08bc5ff2712 (patch) | |
tree | 97b919714c6251b52ca89047e119e88c72386bc0 | |
parent | 35a301aa644d0be234f2920f447fe1a3b4a42b26 (diff) |
wip 1
-rw-r--r-- | src/audiocache.cc | 16 | ||||
-rw-r--r-- | src/audiocache.h | 6 | ||||
-rw-r--r-- | src/audiofile.cc | 4 | ||||
-rw-r--r-- | src/audiofile.h | 4 | ||||
-rw-r--r-- | src/drumgizmo.cc | 60 |
5 files changed, 45 insertions, 45 deletions
diff --git a/src/audiocache.cc b/src/audiocache.cc index 237a3ff..e098fd0 100644 --- a/src/audiocache.cc +++ b/src/audiocache.cc @@ -62,10 +62,10 @@ void AudioCache::deinit() } // Invariant: initial_samples_needed < preloaded audio data -sample_t* AudioCache::open(AudioFile* file, size_t initial_samples_needed, +sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed, int channel, cacheid_t& id) { - if(!file->isValid()) + if(!file.isValid()) { // File preload not yet ready - skip this sample. id = CACHE_DUMMYID; @@ -87,7 +87,7 @@ sample_t* AudioCache::open(AudioFile* file, size_t initial_samples_needed, // Get the cache_t connected with the registered id. cache_t& c = id_manager.getCache(id); - c.afile = &event_handler.openFile(file->filename); + c.afile = &event_handler.openFile(file.filename); c.channel = channel; // Next call to 'next()' will read from this point. @@ -97,25 +97,25 @@ sample_t* AudioCache::open(AudioFile* file, size_t initial_samples_needed, c.back = nullptr; // This is allocated when needed. // cropped_size is the preload chunk size cropped to sample length. - size_t cropped_size = file->preloadedsize - c.localpos; + size_t cropped_size = file.preloadedsize - c.localpos; cropped_size /= framesize; cropped_size *= framesize; cropped_size += initial_samples_needed; - if(file->preloadedsize == file->size) + if(file.preloadedsize == file.size) { // We have preloaded the entire file, so use it. - cropped_size = file->preloadedsize; + cropped_size = file.preloadedsize; } - c.preloaded_samples = file->data; + c.preloaded_samples = file.data; c.preloaded_samples_size = cropped_size; // Next read from disk will read from this point. c.pos = cropped_size;//c.preloaded_samples_size; // Only load next buffer if there are more data in the file to be loaded... - if(c.pos < file->size) + if(c.pos < file.size) { if(c.back == nullptr) { diff --git a/src/audiocache.h b/src/audiocache.h index 004fcf8..059faa2 100644 --- a/src/audiocache.h +++ b/src/audiocache.h @@ -67,7 +67,7 @@ public: //! \param [out] new_id The newly created cache id. //! \return A pointer to the first buffer containing the //! 'initial_samples_needed' number of samples. - sample_t* open(AudioFile* file, size_t initial_samples_needed, int channel, + sample_t* open(const AudioFile& file, size_t initial_samples_needed, int channel, cacheid_t& new_id); //! Get next buffer. @@ -79,7 +79,7 @@ public: //! \return A pointer to the buffer. sample_t* next(cacheid_t id, size_t &size); - //! Returns if the next chunk of the supplied id has been read from disk. + //! Returns true iff the next chunk of the supplied id has been read from disk. bool isReady(cacheid_t id); //! Unregister cache entry. @@ -105,7 +105,7 @@ public: private: size_t framesize{0}; - sample_t *nodata{nullptr}; + sample_t* nodata{nullptr}; size_t number_of_underruns{0}; AudioCacheIDManager id_manager; diff --git a/src/audiofile.cc b/src/audiofile.cc index e9b5976..b0ad4da 100644 --- a/src/audiofile.cc +++ b/src/audiofile.cc @@ -56,7 +56,7 @@ AudioFile::~AudioFile() unload(); } -bool AudioFile::isValid() +bool AudioFile::isValid() const { return this == magic; } @@ -147,7 +147,7 @@ void AudioFile::load(int num_samples) is_loaded = true; } -bool AudioFile::isLoaded() +bool AudioFile::isLoaded() const { return is_loaded; } diff --git a/src/audiofile.h b/src/audiofile.h index 3ca8b97..eb9440e 100644 --- a/src/audiofile.h +++ b/src/audiofile.h @@ -45,7 +45,7 @@ public: void load(int num_samples = ALL_SAMPLES); void unload(); - bool isLoaded(); + bool isLoaded() const; volatile size_t size{0}; // Full size of the file volatile size_t preloadedsize{0}; // Number of samples preloaded (in data) @@ -53,7 +53,7 @@ public: std::string filename; - bool isValid(); + bool isValid() const; Mutex mutex; diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index a777125..f8f30b8 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -477,59 +477,59 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) typedef float vNsf __attribute__ ((vector_size(sizeof(sample_t)*N))); #endif/*SSE*/ -void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz) +void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) { std::list< Event* >::iterator i = activeevents[ch].begin(); for(; i != activeevents[ch].end(); ++i) { bool removeevent = false; - Event *event = *i; + Event* event = *i; Event::type_t type = event->type(); switch(type) { case Event::sample: { - EventSample *evt = (EventSample *)event; - AudioFile *af = evt->file; + EventSample& evt = *static_cast<EventSample*>(event); + AudioFile& af = *evt.file; - if(!af->isLoaded() || !af->isValid() || (s == nullptr)) + if(!af.isLoaded() || !af.isValid() || (s == nullptr)) { removeevent = true; break; } // Don't handle event now is is scheduled for a future iteration? - if(evt->offset > (pos + sz)) + if(evt.offset > (pos + sz)) { continue; } - if(evt->cache_id == CACHE_NOID) + 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_size = initial_chunksize; + size_t initial_chunksize = (pos + sz) - evt.offset; + evt.buffer = audioCache.open(af, initial_chunksize, + af.filechannel, evt.cache_id); + evt.buffer_size = initial_chunksize; } { - MutexAutolock l(af->mutex); + MutexAutolock l(af.mutex); size_t n = 0; // default start point is 0. // If we are not at offset 0 in current buffer: - if(evt->offset > (size_t)pos) + if(evt.offset > (size_t)pos) { - n = evt->offset - pos; + n = evt.offset - pos; } size_t end = sz; // default end point is the end of the buffer. // Find the end point intra-buffer - if((evt->t + end - n) > af->size) + if((evt.t + end - n) > af.size) { - end = af->size - evt->t + n; + end = af.size - evt.t + n; } // This should not be necessary but make absolutely sure that we do @@ -540,7 +540,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz) } size_t t = 0; // Internal buffer counter - if(evt->rampdown == NO_RAMPDOWN) + if(evt.rampdown == NO_RAMPDOWN) { #ifdef SSE @@ -548,40 +548,40 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz) // Force source addr to be 16 byte aligned... // (might skip 1 or 2 samples) - while((size_t)&evt->buffer[t] % 16) + while((size_t)&evt.buffer[t] % 16) { ++t; } - for(; (n < optend) && (t < evt->buffer_size); n += N) + for(; (n < optend) && (t < evt.buffer_size); n += N) { - *(vNsf*)&(s[n]) += *(vNsf*)&(evt->buffer[t]); + *(vNsf*)&(s[n]) += *(vNsf*)&(evt.buffer[t]); t += N; } #endif - for(; (n < end) && (t < evt->buffer_size); ++n) + for(; (n < end) && (t < evt.buffer_size); ++n) { - s[n] += evt->buffer[t]; + s[n] += evt.buffer[t]; ++t; } } else { // Ramp down in progress. - for(; (n < end) && (t < evt->buffer_size) && evt->rampdown; ++n) + for(; (n < end) && (t < evt.buffer_size) && evt.rampdown; ++n) { - float scale = (float)evt->rampdown/(float)evt->ramp_start; - s[n] += evt->buffer[t] * scale; + float scale = (float)evt.rampdown/(float)evt.ramp_start; + s[n] += evt.buffer[t] * scale; ++t; - evt->rampdown--; + evt.rampdown--; } } // Add internal buffer counter to "global" event counter. - evt->t += evt->buffer_size; + evt.t += evt.buffer_size; - if((evt->t < af->size) && (evt->rampdown != 0)) + if((evt.t < af.size) && (evt.rampdown != 0)) { - evt->buffer = audioCache.next(evt->cache_id, evt->buffer_size); + evt.buffer = audioCache.next(evt.cache_id, evt.buffer_size); } else { @@ -590,7 +590,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t *s, size_t sz) if(removeevent) { - audioCache.close(evt->cache_id); + audioCache.close(evt.cache_id); } } } |