Synthesizer class
-
class Synthesizer
Represents a MIDI synthesizer.
A SoundFont file must be loaded into the synthesizer before any synthesis can happen.
The synthesizer can be controlled either via MIDI messages, or directly by calling dedicated methods.
Construction / Destruction
-
Synthesizer(const SynthesizerSettings &settings)
Constructor.
- Parameters:
settings – The settings of the synthetiser
-
~Synthesizer()
Destructor.
SoundFont file loading methods
-
bool loadSoundFont(const std::filesystem::path &path)
Load a SoundFont file.
- Parameters:
path – Path to the SoundFont file
- Returns:
True if the file was loaded successfully, false otherwise
-
bool loadSoundFont(const char *buffer, size_t size)
Load a SoundFont file from a buffer.
- Parameters:
buffer – The buffer
size – Size of the buffer
- Returns:
True if the file was loaded successfully, false otherwise
-
inline const sf::SoundFont &soundfont() const
Returns the loaded SoundFont file representation.
MIDI & notes
-
bool processMidiMessage(uint8_t channel, uint8_t command, uint8_t data1, uint8_t data2)
Process a MIDI message.
- Parameters:
channel – The channel affected by the message
command – The command to process
data1 – Data associated to the command
data2 – Secondary data associated to the command
-
void noteOn(uint8_t channel, uint8_t key, uint8_t velocity)
Start to press a key.
The key will be pressed until
noteOff()is called.- Parameters:
channel – The channel
key – The key to press
velocity – The velocity of the key press
-
void noteOff(uint8_t channel, uint8_t key)
Release a key.
It is expected that
noteOn()has been called on that channel with that key before.When a key is released, its sound gradually falls off.
- Parameters:
channel – The channel
key – The key to release
-
void allNotesOff(bool immediate)
Release all the keys.
- Parameters:
immediate – If false, the sound of the notes gradually falls off like with
noteOff().
-
void allNotesOff(uint8_t channel, bool immediate)
Release all the keys of a specific channel.
- Parameters:
channel – The channel
immediate – If false, the sound of the notes gradually falls off like with
noteOff().
-
void resetAllControllers()
Reset the value of all the MIDI controllers.
-
void resetControllers(uint8_t channel)
Reset the value of all the MIDI controllers of a specific channel.
- Parameters:
channel – The channel
Audio synthesis
-
void render(float *left, float *right, size_t size)
Render the audio into stereo buffers (left and right)
It is expected that this method is called with buffers of appropriate size each time a MIDI message is processed by
processMidiMessage()or each time a key (or a group of keys) is pressed or released.- Parameters:
left – The left buffer (will be filled)
right – The right buffer (will be filled)
size – Size of the buffers
-
void render(float *buffer, size_t size)
Render the audio into a mono buffer.
It is expected that this method is called with a buffer of appropriate size each time a MIDI message is processed by
processMidiMessage()or each time a key (or a group of keys) is pressed or released.- Parameters:
buffer – The buffer (will be filled)
size – Size of the buffer
-
void setMasterVolume(float volume)
Sets the master volume, in dB.
-
float masterVolume() const
Returns the master volume, in dB.
-
inline uint32_t nbRenderedSamples() const
Returns the number of samples rendered so far.
-
uint16_t nbActiveVoices() const
Returns the number of active voices.
Channels
-
inline size_t nbChannels() const
Returns the number of channels.
-
bool configureChannel(uint8_t channel, uint8_t bank, uint8_t preset)
Assign a preset from the SoundFont file to a channel.
- Parameters:
channel – The number of the channel
bank – The bank of the preset
preset – The number of the preset
-
inline bool configureChannel(uint8_t channel, sf::preset_id_t id)
Assign a preset from the SoundFont file to a channel.
- Parameters:
channel – The number of the channel
id – The id of the preset
-
std::map<sf::preset_id_t, std::string> presetNames()
Retrieves a list of the names of all the presets in thr SoundFont file.
Other methods
-
inline const SynthesizerSettings &settings() const
Returns the settings of the synthesizer.
-
void reset()
Reset the synthesizer (like if no rendering happened, no key was pressed)
-
Synthesizer(const SynthesizerSettings &settings)