Use the new filepool API
This commit is contained in:
parent
62b68b2af3
commit
f5ac778c16
2 changed files with 24 additions and 9 deletions
|
|
@ -357,19 +357,15 @@ const WavetableMulti* WavetablePool::createFileWave(FilePool& filePool, const st
|
||||||
if (const WavetableMulti* wave = getFileWave(filename))
|
if (const WavetableMulti* wave = getFileWave(filename))
|
||||||
return wave;
|
return wave;
|
||||||
|
|
||||||
if (!filePool.preloadFile(filename, 0))
|
auto fileHandle = filePool.loadFile(filename);
|
||||||
|
if (!fileHandle)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
FilePromisePtr fp = filePool.getFilePromise(filename);
|
|
||||||
if (!fp)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
fp->waitCompletion();
|
if (fileHandle->information.numChannels > 1)
|
||||||
if (fp->dataStatus == FilePromise::DataStatus::Error)
|
DBG("[sfizz] Only the first channel of " << filename << " will be used to create the wavetable");
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// use 1 channel only, maybe warn if file has more channels
|
auto audioData = fileHandle->preloadedData->getConstSpan(0);
|
||||||
auto audioData = fp->fileData.getSpan(0);
|
|
||||||
size_t fftSize = audioData.size();
|
size_t fftSize = audioData.size();
|
||||||
size_t specSize = fftSize / 2 + 1;
|
size_t specSize = fftSize / 2 + 1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,8 +193,27 @@ private:
|
||||||
struct WavetablePool {
|
struct WavetablePool {
|
||||||
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);
|
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);
|
const WavetableMulti* createFileWave(FilePool& filePool, const std::string& filename);
|
||||||
|
/**
|
||||||
|
* @brief Removes all the stored file waves from the wavetable pool.
|
||||||
|
*/
|
||||||
void clearFileWaves();
|
void clearFileWaves();
|
||||||
|
|
||||||
static const WavetableMulti* getWaveSin();
|
static const WavetableMulti* getWaveSin();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue