Use the new filepool API

This commit is contained in:
Paul Ferrand 2020-03-28 19:46:23 +01:00
parent 62b68b2af3
commit f5ac778c16
2 changed files with 24 additions and 9 deletions

View file

@ -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;

View file

@ -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();