|
AudioDataLib
A C++ library of classes supporting a variety of audio-data tasks.
|
Derivatives of this class know how to synthesize MIDI messages into real-time audio. More...
#include <MidiSynth.h>
Public Member Functions | |
| MidiSynth () | |
| virtual | ~MidiSynth () |
| virtual bool | Process (Error &error) override |
| virtual SynthModule * | GetRootModule (uint16_t channel)=0 |
| void | SetAudioStream (std::shared_ptr< AudioStream > audioStream) |
| std::shared_ptr< AudioStream > | GetAudioStream () |
| void | SetMinMaxLatency (double minLatencySeconds, double maxLatencySeconds) |
| void | GetMinMaxLatency (double &minLatencySeconds, double &maxLatencySeconds) const |
Public Member Functions inherited from AudioDataLib::MidiMsgDestination | |
| MidiMsgDestination () | |
| virtual | ~MidiMsgDestination () |
| virtual bool | ReceiveMessage (double deltaTimeSeconds, const uint8_t *message, uint64_t messageSize, Error &error) |
| virtual bool | Initialize (Error &error) |
| virtual bool | Finalize (Error &error) |
Static Public Member Functions | |
| static double | MidiPitchToFrequency (uint8_t pitchValue) |
| static double | MidiVelocityToAmplitude (uint8_t velocityValue) |
Protected Attributes | |
| std::shared_ptr< AudioStream > * | audioStream |
| double | minLatencySeconds |
| This is the minimum amount of audio (measured in seconds) that should always be buffered at any given time. | |
| double | maxLatencySeconds |
| This is the maximum amount of audio (measured in seconds) that should always be buffered at any given time. | |
Derivatives of this class know how to synthesize MIDI messages into real-time audio.
| MidiSynth::MidiSynth | ( | ) |
|
virtual |
|
inline |
Return a shared pointer to the AudioStream we're trying to continuously feed.
| void MidiSynth::GetMinMaxLatency | ( | double & | minLatencySeconds, |
| double & | maxLatencySeconds ) const |
Get the latency range.
|
pure virtual |
A derived class must impliment this method to provide a SynthModule that can feed the given channel. Note that the term "channel" is overloaded. It can refer to a channel in a stream of audio (e.g., left, right, mono, etc.), as is the case here, or it can mean a MIDI channel, of which there are 16, so don't get them confused. Context usually makes it clear.
Implemented in AudioDataLib::SampleBasedSynth, AudioDataLib::SimpleSynth, and AudioDataLib::SubtractiveSynth.
|
static |
|
static |
|
overridevirtual |
This is where we strike a balance between keeping enough audio data buffered in our audio stream to prevent an audio drop-out while also not buffering too much so as to maintain the lowest possible latency. If we don't feed the audio buffer quick enough, we periodically have to feed silence to the audio stream. If we feed the audio buffer too much, then changes to the audio (such as a note turnning on or off) don't happen soon enough, or as close to when they actually happend as we would like. As far as drop-outs are concerned, this class is really at the mercy of the SynthModule implimentations, which needs to be as quick as they possibly can be.
A derived class might override this to do its own processing, but should call this base-class method as well.
Reimplemented from AudioDataLib::MidiMsgDestination.
Reimplemented in AudioDataLib::SampleBasedSynth.
| void MidiSynth::SetAudioStream | ( | std::shared_ptr< AudioStream > | audioStream | ) |
The goal of this class is to feed the given AudioStream class. Typically this is chosen as a ThreadSafeAudioStream, because, while it is fed on the main thread, it is usually consumed in a time-sensative audio callback running on a dedicated audio thread.
| void MidiSynth::SetMinMaxLatency | ( | double | minLatencySeconds, |
| double | maxLatencySeconds ) |
Set the latency range. The synthesizer tries to keep the amount of audio (measured in seconds) to always be somewhere in this range. You typically want the range to be to be as small as is reasonably possible, both in size and in distance to zero.
|
protected |
|
protected |
This is the maximum amount of audio (measured in seconds) that should always be buffered at any given time.
|
protected |
This is the minimum amount of audio (measured in seconds) that should always be buffered at any given time.