Cosmetics
This commit is contained in:
parent
c7850e018f
commit
2a493873ae
4 changed files with 39 additions and 43 deletions
|
|
@ -1 +1,30 @@
|
||||||
#include "FilePool.h"
|
#include "FilePool.h"
|
||||||
|
|
||||||
|
std::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(std::string_view filename)
|
||||||
|
{
|
||||||
|
std::filesystem::path file { rootDirectory / filename };
|
||||||
|
if (!std::filesystem::exists(file))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
SndfileHandle sndFile ( reinterpret_cast<const char*>(file.c_str()) );
|
||||||
|
FileInformation returnedValue;
|
||||||
|
returnedValue.end = static_cast<uint32_t>(sndFile.frames());
|
||||||
|
|
||||||
|
SF_INSTRUMENT instrumentInfo;
|
||||||
|
sndFile.command(SFC_GET_INSTRUMENT, &instrumentInfo, sizeof(instrumentInfo));
|
||||||
|
|
||||||
|
if (instrumentInfo.loop_count == 1)
|
||||||
|
{
|
||||||
|
returnedValue.loopBegin = instrumentInfo.loops[0].start;
|
||||||
|
returnedValue.loopEnd = instrumentInfo.loops[0].end;
|
||||||
|
}
|
||||||
|
auto preloadedSize = std::min(returnedValue.end, static_cast<uint32_t>(config::preloadSize));
|
||||||
|
returnedValue.preloadedData = std::make_shared<StereoBuffer<float>>(preloadedSize);
|
||||||
|
sndFile.readf(tempReadBuffer.data(), preloadedSize);
|
||||||
|
returnedValue.preloadedData->readInterleaved<SIMDConfig::useSIMD>(tempReadBuffer.data(), preloadedSize);
|
||||||
|
preloadedData[filename] = returnedValue.preloadedData;
|
||||||
|
// char buffer [2048] ;
|
||||||
|
// sndFile.command(SFC_GET_LOG_INFO, buffer, sizeof(buffer)) ;
|
||||||
|
// DBG(buffer);
|
||||||
|
return returnedValue;
|
||||||
|
}
|
||||||
|
|
@ -14,10 +14,8 @@ class FilePool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FilePool() = default;
|
FilePool() = default;
|
||||||
void setRootDirectory(const std::filesystem::path& directory)
|
void setRootDirectory(const std::filesystem::path& directory) { rootDirectory = directory; }
|
||||||
{
|
size_t getNumPreloadedSamples() { return preloadedData.size(); }
|
||||||
rootDirectory = directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct FileInformation
|
struct FileInformation
|
||||||
{
|
{
|
||||||
|
|
@ -26,42 +24,11 @@ public:
|
||||||
uint32_t loopEnd { Default::loopRange.getEnd() };
|
uint32_t loopEnd { Default::loopRange.getEnd() };
|
||||||
std::shared_ptr<StereoBuffer<float>> preloadedData;
|
std::shared_ptr<StereoBuffer<float>> preloadedData;
|
||||||
};
|
};
|
||||||
|
std::optional<FileInformation> getFileInformation(std::string_view filename);
|
||||||
std::optional<FileInformation> getFileInformation(std::string_view filename)
|
|
||||||
{
|
|
||||||
std::filesystem::path file { rootDirectory / filename };
|
|
||||||
if (!std::filesystem::exists(file))
|
|
||||||
return {};
|
|
||||||
|
|
||||||
SndfileHandle sndFile ( reinterpret_cast<const char*>(file.c_str()) );
|
|
||||||
FileInformation returnedValue;
|
|
||||||
returnedValue.end = static_cast<uint32_t>(sndFile.frames());
|
|
||||||
|
|
||||||
SF_INSTRUMENT instrumentInfo;
|
|
||||||
sndFile.command(SFC_GET_INSTRUMENT, &instrumentInfo, sizeof(instrumentInfo));
|
|
||||||
|
|
||||||
if (instrumentInfo.loop_count == 1)
|
|
||||||
{
|
|
||||||
returnedValue.loopBegin = instrumentInfo.loops[0].start;
|
|
||||||
returnedValue.loopEnd = instrumentInfo.loops[0].end;
|
|
||||||
}
|
|
||||||
auto preloadedSize = std::min(returnedValue.end, static_cast<uint32_t>(config::preloadSize));
|
|
||||||
returnedValue.preloadedData = std::make_shared<StereoBuffer<float>>(preloadedSize);
|
|
||||||
sndFile.readf(tempReadBuffer.data(), preloadedSize);
|
|
||||||
returnedValue.preloadedData->readInterleaved<SIMDConfig::useSIMD>(tempReadBuffer.data(), preloadedSize);
|
|
||||||
preloadedData[filename] = returnedValue.preloadedData;
|
|
||||||
// char buffer [2048] ;
|
|
||||||
// sndFile.command(SFC_GET_LOG_INFO, buffer, sizeof(buffer)) ;
|
|
||||||
// DBG(buffer);
|
|
||||||
return returnedValue;
|
|
||||||
}
|
|
||||||
size_t getNumPreloadedSamples() { return preloadedData.size(); }
|
|
||||||
private:
|
private:
|
||||||
std::filesystem::path rootDirectory;
|
std::filesystem::path rootDirectory;
|
||||||
Buffer<float> tempReadBuffer { config::preloadSize * 2 };
|
Buffer<float> tempReadBuffer { config::preloadSize * 2 };
|
||||||
// std::map<std::string_view, std::shared_ptr<StereoBuffer<float>>> preloadedData;
|
// std::map<std::string_view, std::shared_ptr<StereoBuffer<float>>> preloadedData;
|
||||||
absl::flat_hash_map<std::string_view, std::shared_ptr<StereoBuffer<float>>> preloadedData;
|
absl::flat_hash_map<std::string_view, std::shared_ptr<StereoBuffer<float>>> preloadedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline FilePool filePool;
|
|
||||||
}
|
}
|
||||||
|
|
@ -47,12 +47,12 @@ void StereoBuffer<float, 16>::fill<true>(float value) noexcept
|
||||||
const __m128 mmValue = _mm_set_ps1(value);
|
const __m128 mmValue = _mm_set_ps1(value);
|
||||||
auto [lBegin, rBegin] = getChannels();
|
auto [lBegin, rBegin] = getChannels();
|
||||||
auto [lEnd, rEnd] = alignedEnds();
|
auto [lEnd, rEnd] = alignedEnds();
|
||||||
auto mmLeft = reinterpret_cast<__m128 *>(lBegin);
|
auto mmLeft = reinterpret_cast<__m128*>(lBegin);
|
||||||
auto mmRight = reinterpret_cast<__m128 *>(rBegin);
|
auto mmRight = reinterpret_cast<__m128*>(rBegin);
|
||||||
while (mmLeft < reinterpret_cast<__m128 *>(lEnd)) // we should only need to test a single channel
|
while (mmLeft < reinterpret_cast<__m128*>(lEnd)) // we should only need to test a single channel
|
||||||
{
|
{
|
||||||
_mm_store_ps(reinterpret_cast<float *>(mmLeft), mmValue);
|
_mm_store_ps(reinterpret_cast<float*>(mmLeft), mmValue);
|
||||||
_mm_store_ps(reinterpret_cast<float *>(mmRight), mmValue);
|
_mm_store_ps(reinterpret_cast<float*>(mmRight), mmValue);
|
||||||
mmLeft++;
|
mmLeft++;
|
||||||
mmRight++;
|
mmRight++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
|
||||||
|
|
||||||
currentRegion++;
|
currentRegion++;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG("Removed " << regions.size() - std::distance(regions.begin(), lastRegion) - 1 << " out of " << regions.size() << " regions.");
|
DBG("Removed " << regions.size() - std::distance(regions.begin(), lastRegion) - 1 << " out of " << regions.size() << " regions.");
|
||||||
regions.resize(std::distance(regions.begin(), lastRegion) + 1);
|
regions.resize(std::distance(regions.begin(), lastRegion) + 1);
|
||||||
return parserReturned;
|
return parserReturned;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue