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"
|
||||
|
||||
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:
|
||||
FilePool() = default;
|
||||
void setRootDirectory(const std::filesystem::path& directory)
|
||||
{
|
||||
rootDirectory = directory;
|
||||
}
|
||||
void setRootDirectory(const std::filesystem::path& directory) { rootDirectory = directory; }
|
||||
size_t getNumPreloadedSamples() { return preloadedData.size(); }
|
||||
|
||||
struct FileInformation
|
||||
{
|
||||
|
|
@ -26,42 +24,11 @@ public:
|
|||
uint32_t loopEnd { Default::loopRange.getEnd() };
|
||||
std::shared_ptr<StereoBuffer<float>> preloadedData;
|
||||
};
|
||||
|
||||
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(); }
|
||||
std::optional<FileInformation> getFileInformation(std::string_view filename);
|
||||
private:
|
||||
std::filesystem::path rootDirectory;
|
||||
Buffer<float> tempReadBuffer { config::preloadSize * 2 };
|
||||
// std::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);
|
||||
auto [lBegin, rBegin] = getChannels();
|
||||
auto [lEnd, rEnd] = alignedEnds();
|
||||
auto mmLeft = reinterpret_cast<__m128 *>(lBegin);
|
||||
auto mmRight = reinterpret_cast<__m128 *>(rBegin);
|
||||
while (mmLeft < reinterpret_cast<__m128 *>(lEnd)) // we should only need to test a single channel
|
||||
auto mmLeft = reinterpret_cast<__m128*>(lBegin);
|
||||
auto mmRight = reinterpret_cast<__m128*>(rBegin);
|
||||
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 *>(mmRight), mmValue);
|
||||
_mm_store_ps(reinterpret_cast<float*>(mmLeft), mmValue);
|
||||
_mm_store_ps(reinterpret_cast<float*>(mmRight), mmValue);
|
||||
mmLeft++;
|
||||
mmRight++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue