From f5ac778c163b1d0ced8c119b9bd02945528aa64d Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sat, 28 Mar 2020 19:46:23 +0100 Subject: [PATCH] Use the new filepool API --- src/sfizz/Wavetables.cpp | 14 +++++--------- src/sfizz/Wavetables.h | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/sfizz/Wavetables.cpp b/src/sfizz/Wavetables.cpp index 9576af8a..dd962083 100644 --- a/src/sfizz/Wavetables.cpp +++ b/src/sfizz/Wavetables.cpp @@ -357,19 +357,15 @@ const WavetableMulti* WavetablePool::createFileWave(FilePool& filePool, const st if (const WavetableMulti* wave = getFileWave(filename)) return wave; - if (!filePool.preloadFile(filename, 0)) + auto fileHandle = filePool.loadFile(filename); + if (!fileHandle) return nullptr; - FilePromisePtr fp = filePool.getFilePromise(filename); - if (!fp) - return nullptr; - fp->waitCompletion(); - if (fp->dataStatus == FilePromise::DataStatus::Error) - return nullptr; + if (fileHandle->information.numChannels > 1) + DBG("[sfizz] Only the first channel of " << filename << " will be used to create the wavetable"); - // use 1 channel only, maybe warn if file has more channels - auto audioData = fp->fileData.getSpan(0); + auto audioData = fileHandle->preloadedData->getConstSpan(0); size_t fftSize = audioData.size(); size_t specSize = fftSize / 2 + 1; diff --git a/src/sfizz/Wavetables.h b/src/sfizz/Wavetables.h index 30640e16..f3ebd692 100644 --- a/src/sfizz/Wavetables.h +++ b/src/sfizz/Wavetables.h @@ -193,8 +193,27 @@ private: struct WavetablePool { WavetablePool(); + /** + * @brief Get a file wave. Return a silent table if the wave does not exist yet. + * Use createFileWave to preload file waves before calling this function. + * This function is real-time safe. + * + * @param filename the name of the file wave + * @return the wavetable, or a silent table + */ const WavetableMulti* getFileWave(const std::string& filename); + /** + * @brief Load a file wave from the filepool and use it to create a wavetable. + * This function is not real-time safe. + * + * @param filePool the file pool to use to load the file + * @param filename the file name to load + * @return the wavetable + */ const WavetableMulti* createFileWave(FilePool& filePool, const std::string& filename); + /** + * @brief Removes all the stored file waves from the wavetable pool. + */ void clearFileWaves(); static const WavetableMulti* getWaveSin();