Merge remote-tracking branch 'origin/cpp14' into cpp14

This commit is contained in:
paulfd 2019-09-21 10:58:39 +02:00
commit a6c5e1af5d
7 changed files with 22 additions and 17 deletions

View file

@ -4,11 +4,15 @@ project(sfizz VERSION 1.0.0 LANGUAGES CXX)
# Set the highest possible standard
set(CMAKE_CXX_STANDARD 14)
# Enable LTO
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) # To override the policy in abseil and benchmark
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT ANDROID)
add_compile_options(-stdlib=libc++)
# Presumably need the above for linking too, maybe other options missing as well
add_link_options(-stdlib=libc++) # New command on CMake master, not in 3.12 release
else()
else()
add_link_options(-lstdc++fs)
endif()

View file

@ -37,19 +37,22 @@ endif()
set(SFIZZ_SOURCES ${SFIZZ_SOURCES} ${SFIZZ_SIMD_SOURCES})
add_library(sfizz_parser STATIC)
target_sources(sfizz_parser PUBLIC Parser.cpp Opcode.cpp)
target_sources(sfizz_parser PRIVATE Parser.cpp Opcode.cpp)
target_include_directories(sfizz_parser PUBLIC .)
if(UNIX)
target_link_libraries(sfizz_parser PUBLIC stdc++fs)
# target_compile_options(sfizz_parser PUBLIC -fno-rtti -fno-exceptions)
endif(UNIX)
target_link_libraries(sfizz_parser PRIVATE absl::strings)
add_library(sfizz STATIC ${SFIZZ_SOURCES})
target_link_libraries(sfizz PRIVATE sfizz_parser)
target_include_directories(sfizz PUBLIC .)
find_package(Threads REQUIRED)
target_link_libraries(sfizz PRIVATE Threads::Threads)
if(UNIX)
target_link_libraries(sfizz PUBLIC stdc++fs atomic)
target_compile_options(sfizz PRIVATE -fno-rtti -fno-exceptions)
# target_compile_options(sfizz PUBLIC -fno-rtti -fno-exceptions)
endif(UNIX)
target_link_libraries(sfizz PUBLIC absl::strings)
target_link_libraries(sfizz PRIVATE sndfile absl::flat_hash_map)

View file

@ -45,7 +45,7 @@ std::unique_ptr<AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, int numFram
sndFile.readf(tempReadBuffer->channelWriter(0), numFrames);
::readInterleaved<float>(tempReadBuffer->getSpan(0), returnedBuffer->getSpan(0), returnedBuffer->getSpan(1));
}
return std::move(returnedBuffer);
return returnedBuffer;
}
absl::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation(const std::string& filename, uint32_t offset) noexcept

View file

@ -38,11 +38,7 @@
namespace sfz {
class FilePool {
public:
FilePool()
: fileLoadingThread(std::thread(&FilePool::loadingThread, this))
, garbageCollectionThread(std::thread(&FilePool::garbageThread, this))
{
}
FilePool() { }
~FilePool()
{
@ -75,11 +71,11 @@ private:
moodycamel::BlockingReaderWriterQueue<FileLoadingInformation> loadingQueue { config::numVoices };
void loadingThread() noexcept;
void garbageThread() noexcept;
std::thread fileLoadingThread;
std::thread garbageCollectionThread;
bool quitThread { false };
std::thread fileLoadingThread { &FilePool::loadingThread, this };
std::thread garbageCollectionThread { &FilePool::garbageThread, this };
std::vector<std::shared_ptr<AudioBuffer<float>>> fileHandles;
std::mutex fileHandleMutex;
bool quitThread { false };
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
LEAK_DETECTOR(FilePool);
};

View file

@ -356,12 +356,14 @@ void sfz::Synth::noteOn(int delay, int channel, int noteNumber, uint8_t velocity
}
}
void sfz::Synth::noteOff(int delay, int channel, int noteNumber, uint8_t velocity) noexcept
{
ASSERT(noteNumber < 128);
ASSERT(noteNumber >= 0);
auto replacedVelocity = velocity == 0 ? midiState.getNoteVelocity(noteNumber) : velocity;
// FIXME: Some keyboards (e.g. Casio PX5S) can send a real note-off velocity. In this case, do we have a
// way in sfz to specify that a release trigger should NOT use the note-on velocity?
// auto replacedVelocity = (velocity == 0 ? sfz::getNoteVelocity(noteNumber) : velocity);
auto replacedVelocity = midiState.getNoteVelocity(noteNumber);
auto randValue = randNoteDistribution(Random::randomGenerator);
for (auto& voice : voices)
voice->registerNoteOff(delay, channel, noteNumber, replacedVelocity);

View file

@ -365,8 +365,8 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
::add<int>(sourcePosition, indices);
//FIXME : all this casting is driving me crazy
const auto sampleEnd = static_cast<int>(region->trueSampleEnd()) - 1;
if (region->shouldLoop() && static_cast<size_t>(sampleEnd) <= source.getNumFrames()) {
const auto sampleEnd = min(static_cast<int>(region->trueSampleEnd()), static_cast<int>(source.getNumFrames())) - 1;
if (region->shouldLoop() && region->loopRange.getEnd() <= source.getNumFrames()) {
const auto offset = sampleEnd - static_cast<int>(region->loopRange.getStart());
for (auto* index = indices.begin(); index < indices.end(); ++index) {
if (*index > sampleEnd) {

View file

@ -528,7 +528,7 @@ TEST_CASE("[Helpers] Linear Ramp (SIMD)")
std::array<float, 6> output;
std::array<float, 6> expected { v, v + v, v + v + v, v + v + v + v, v + v + v + v + v, v + v + v + v + v + v };
linearRamp<float, true>(absl::MakeSpan(output), start, v);
REQUIRE(output == expected);
REQUIRE(approxEqual<float>(output, expected));
}
TEST_CASE("[Helpers] Linear Ramp (SIMD vs scalar)")