No need for AudioBuffers for intermediate buffers
File reading can use dumb buffers
This commit is contained in:
parent
d6c49ef827
commit
b208d8faca
1 changed files with 8 additions and 4 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "FilePool.h"
|
#include "FilePool.h"
|
||||||
|
#include "Buffer.h"
|
||||||
#include "AudioBuffer.h"
|
#include "AudioBuffer.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
|
|
@ -41,10 +42,10 @@ std::unique_ptr<sfz::AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, uint32
|
||||||
if (sndFile.channels() == 1) {
|
if (sndFile.channels() == 1) {
|
||||||
sndFile.readf(baseBuffer->channelWriter(0), numFrames);
|
sndFile.readf(baseBuffer->channelWriter(0), numFrames);
|
||||||
} else if (sndFile.channels() == 2) {
|
} else if (sndFile.channels() == 2) {
|
||||||
auto tempReadBuffer = std::make_unique<sfz::AudioBuffer<T>>(1, 2 * numFrames);
|
auto tempReadBuffer = std::make_unique<sfz::Buffer<T>>(2 * numFrames);
|
||||||
sndFile.readf(tempReadBuffer->channelWriter(0), numFrames);
|
sndFile.readf(tempReadBuffer->data(), numFrames);
|
||||||
auto fileBuffer = std::make_unique<sfz::AudioBuffer<T>>(2, numFrames);
|
auto fileBuffer = std::make_unique<sfz::AudioBuffer<T>>(2, numFrames);
|
||||||
sfz::readInterleaved<T>(tempReadBuffer->getSpan(0), baseBuffer->getSpan(0), baseBuffer->getSpan(1));
|
sfz::readInterleaved<T>(*tempReadBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (factor) {
|
switch (factor) {
|
||||||
|
|
@ -112,7 +113,10 @@ bool sfz::FilePool::preloadFile(const std::string& filename, uint32_t maxOffset)
|
||||||
preloadedFiles[filename].preloadedData = readFromFile<float>(sndFile, framesToLoad, oversamplingFactor);
|
preloadedFiles[filename].preloadedData = readFromFile<float>(sndFile, framesToLoad, oversamplingFactor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
preloadedFiles.insert_or_assign(filename, { readFromFile<float>(sndFile, framesToLoad, oversamplingFactor), static_cast<float>(sndFile.samplerate() * oversamplingFactor) });
|
preloadedFiles.insert_or_assign(filename, {
|
||||||
|
readFromFile<float>(sndFile, framesToLoad, oversamplingFactor),
|
||||||
|
static_cast<float>(sndFile.samplerate() * oversamplingFactor)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue