Merge branch 'feature/dynamic-voices' into develop
This commit is contained in:
commit
3810083d7f
4 changed files with 63 additions and 5 deletions
|
|
@ -35,11 +35,9 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
sfz::Synth::Synth()
|
sfz::Synth::Synth(int numVoices)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < config::numVoices; ++i)
|
resetVoices(numVoices);
|
||||||
voices.push_back(std::make_unique<Voice>(midiState));
|
|
||||||
voiceViewArray.reserve(config::numVoices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Synth::callback(absl::string_view header, const std::vector<Opcode>& members)
|
void sfz::Synth::callback(absl::string_view header, const std::vector<Opcode>& members)
|
||||||
|
|
@ -507,3 +505,28 @@ void sfz::Synth::setVolume(float volume) noexcept
|
||||||
{
|
{
|
||||||
this->volume = Default::volumeRange.clamp(volume);
|
this->volume = Default::volumeRange.clamp(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sfz::Synth::getNumVoices() const noexcept
|
||||||
|
{
|
||||||
|
return numVoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sfz::Synth::setNumVoices(int numVoices) noexcept
|
||||||
|
{
|
||||||
|
ASSERT(numVoices > 0);
|
||||||
|
resetVoices(numVoices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sfz::Synth::resetVoices(int numVoices)
|
||||||
|
{
|
||||||
|
AtomicDisabler callbackDisabler{ canEnterCallback };
|
||||||
|
while (inCallback) {
|
||||||
|
std::this_thread::sleep_for(1ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
voices.clear();
|
||||||
|
for (int i = 0; i < numVoices; ++i)
|
||||||
|
voices.push_back(std::make_unique<Voice>(midiState));
|
||||||
|
voiceViewArray.reserve(numVoices);
|
||||||
|
this->numVoices = numVoices;
|
||||||
|
}
|
||||||
|
|
@ -39,7 +39,8 @@ namespace sfz {
|
||||||
|
|
||||||
class Synth : public Parser {
|
class Synth : public Parser {
|
||||||
public:
|
public:
|
||||||
Synth();
|
Synth() {}
|
||||||
|
Synth(int numVoices);
|
||||||
bool loadSfzFile(const fs::path& file) final;
|
bool loadSfzFile(const fs::path& file) final;
|
||||||
int getNumRegions() const noexcept;
|
int getNumRegions() const noexcept;
|
||||||
int getNumGroups() const noexcept;
|
int getNumGroups() const noexcept;
|
||||||
|
|
@ -63,6 +64,8 @@ public:
|
||||||
void tempo(int delay, float secondsPerQuarter) noexcept;
|
void tempo(int delay, float secondsPerQuarter) noexcept;
|
||||||
|
|
||||||
int getNumActiveVoices() const noexcept;
|
int getNumActiveVoices() const noexcept;
|
||||||
|
int getNumVoices() const noexcept;
|
||||||
|
void setNumVoices(int numVoices) noexcept;
|
||||||
void garbageCollect() noexcept;
|
void garbageCollect() noexcept;
|
||||||
protected:
|
protected:
|
||||||
void callback(absl::string_view header, const std::vector<Opcode>& members) final;
|
void callback(absl::string_view header, const std::vector<Opcode>& members) final;
|
||||||
|
|
@ -74,6 +77,7 @@ private:
|
||||||
int numMasters { 0 };
|
int numMasters { 0 };
|
||||||
int numCurves { 0 };
|
int numCurves { 0 };
|
||||||
void clear();
|
void clear();
|
||||||
|
void resetVoices(int numVoices);
|
||||||
void handleGlobalOpcodes(const std::vector<Opcode>& members);
|
void handleGlobalOpcodes(const std::vector<Opcode>& members);
|
||||||
void handleControlOpcodes(const std::vector<Opcode>& members);
|
void handleControlOpcodes(const std::vector<Opcode>& members);
|
||||||
void buildRegion(const std::vector<Opcode>& regionOpcodes);
|
void buildRegion(const std::vector<Opcode>& regionOpcodes);
|
||||||
|
|
@ -107,6 +111,8 @@ private:
|
||||||
std::atomic<bool> canEnterCallback { true };
|
std::atomic<bool> canEnterCallback { true };
|
||||||
std::atomic<bool> inCallback { false };
|
std::atomic<bool> inCallback { false };
|
||||||
|
|
||||||
|
int numVoices { config::numVoices };
|
||||||
|
|
||||||
LEAK_DETECTOR(Synth);
|
LEAK_DETECTOR(Synth);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "Synth.h"
|
#include "Synth.h"
|
||||||
#include "sfizz.h"
|
#include "sfizz.h"
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -122,6 +123,7 @@ void sfizz_render_block(sfizz_synth_t* synth, float** channels, int num_channels
|
||||||
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||||
// Only stereo output is supported for now
|
// Only stereo output is supported for now
|
||||||
ASSERT(num_channels == 2);
|
ASSERT(num_channels == 2);
|
||||||
|
UNUSED(num_channels);
|
||||||
self->renderBlock({{channels[0], channels[1]}, static_cast<size_t>(num_frames)});
|
self->renderBlock({{channels[0], channels[1]}, static_cast<size_t>(num_frames)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,6 +145,18 @@ float sfizz_get_volume(sfizz_synth_t* synth)
|
||||||
return self->getVolume();
|
return self->getVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sfizz_set_num_voices(sfizz_synth_t* synth, int num_voices)
|
||||||
|
{
|
||||||
|
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||||
|
self->setNumVoices(num_voices);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sfizz_get_num_voices(sfizz_synth_t* synth)
|
||||||
|
{
|
||||||
|
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||||
|
return self->getNumVoices();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -232,6 +232,21 @@ void sfizz_set_volume(sfizz_synth_t* synth, float volume);
|
||||||
*/
|
*/
|
||||||
float sfizz_get_volume(sfizz_synth_t* synth);
|
float sfizz_get_volume(sfizz_synth_t* synth);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the number of voices used by the synth
|
||||||
|
*
|
||||||
|
* @param synth
|
||||||
|
* @param num_voices
|
||||||
|
*/
|
||||||
|
void sfizz_set_num_voices(sfizz_synth_t* synth, int num_voices);
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of voices
|
||||||
|
*
|
||||||
|
* @param synth
|
||||||
|
* @return num_voices
|
||||||
|
*/
|
||||||
|
int sfizz_get_num_voices(sfizz_synth_t* synth);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue