AudioDataLib
A C++ library of classes supporting a variety of audio-data tasks.
Loading...
Searching...
No Matches
AudioDataLib::SampleBasedSynth Class Reference

This class knows how to synthesize real-time sound as a function of MIDI messages and WaveTableData. More...

#include <SampleBasedSynth.h>

Inheritance diagram for AudioDataLib::SampleBasedSynth:
AudioDataLib::MidiSynth AudioDataLib::MidiMsgDestination

Public Member Functions

 SampleBasedSynth ()
 
virtual ~SampleBasedSynth ()
 
virtual bool ReceiveMessage (double deltaTimeSeconds, const uint8_t *message, uint64_t messageSize, Error &error) override
 
virtual SynthModuleGetRootModule (uint16_t channel) override
 
virtual bool Process (Error &error) override
 
virtual bool Initialize (Error &error) override
 
bool SetChannelInstrument (uint8_t channel, uint8_t instrument, Error &error)
 
bool GetChannelInstrument (uint8_t channel, uint8_t &instrument) const
 
void SetWaveTableData (std::shared_ptr< WaveTableData > &waveTableData)
 
std::shared_ptr< WaveTableDataGetWaveTableData ()
 
void Clear ()
 
void SetReverbEnabled (bool reverbEnabled)
 
bool GetReverbEnabled ()
 
- Public Member Functions inherited from AudioDataLib::MidiSynth
 MidiSynth ()
 
virtual ~MidiSynth ()
 
void SetAudioStream (std::shared_ptr< AudioStream > audioStream)
 
std::shared_ptr< AudioStreamGetAudioStream ()
 
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 Finalize (Error &error)
 

Additional Inherited Members

- Static Public Member Functions inherited from AudioDataLib::MidiSynth
static double MidiPitchToFrequency (uint8_t pitchValue)
 
static double MidiVelocityToAmplitude (uint8_t velocityValue)
 
- Protected Attributes inherited from AudioDataLib::MidiSynth
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.
 

Detailed Description

This class knows how to synthesize real-time sound as a function of MIDI messages and WaveTableData.

Constructor & Destructor Documentation

◆ SampleBasedSynth()

SampleBasedSynth::SampleBasedSynth ( )

◆ ~SampleBasedSynth()

SampleBasedSynth::~SampleBasedSynth ( )
virtual

Member Function Documentation

◆ Clear()

void SampleBasedSynth::Clear ( )

◆ GetChannelInstrument()

bool SampleBasedSynth::GetChannelInstrument ( uint8_t channel,
uint8_t & instrument ) const

◆ GetReverbEnabled()

bool AudioDataLib::SampleBasedSynth::GetReverbEnabled ( )
inline

◆ GetRootModule()

SynthModule * SampleBasedSynth::GetRootModule ( uint16_t channel)
overridevirtual

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.

Implements AudioDataLib::MidiSynth.

◆ GetWaveTableData()

std::shared_ptr< WaveTableData > AudioDataLib::SampleBasedSynth::GetWaveTableData ( )
inline

◆ Initialize()

bool SampleBasedSynth::Initialize ( Error & error)
overridevirtual

This method will get called by the MidiMsgSource class during its own initialization.

Parameters
[out]errorThis should be populated with error information if false is returned.
Returns
True should be returned on success; false otherwise.

Reimplemented from AudioDataLib::MidiMsgDestination.

◆ Process()

bool SampleBasedSynth::Process ( Error & error)
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::MidiSynth.

◆ ReceiveMessage()

bool SampleBasedSynth::ReceiveMessage ( double deltaTimeSeconds,
const uint8_t * message,
uint64_t messageSize,
Error & error )
overridevirtual

This method will be called when this destination is to receive the given MIDI message. Note that it's important that no heavy processing be done in this method (such as is the mentality when writing an audio callback), because the timing of MIDI message reception and processing can effect the quality of audio playback.

Parameters
[in]deltaTimeSecondsThis is typically, but not always, set to the amount of time (in seconds) between now and the last time the function was called.
[in]messageThis is the payload of the message, which can be decoded using a derivative of the MidiData::Event class.
[in]messageSizeThis is the size of the payload in bytes.
[out]errorThis should be populated with error information if false is returned.
Returns
True should be returned on success; false otherwise.

Reimplemented from AudioDataLib::MidiMsgDestination.

◆ SetChannelInstrument()

bool SampleBasedSynth::SetChannelInstrument ( uint8_t channel,
uint8_t instrument,
Error & error )

◆ SetReverbEnabled()

void SampleBasedSynth::SetReverbEnabled ( bool reverbEnabled)

◆ SetWaveTableData()

void AudioDataLib::SampleBasedSynth::SetWaveTableData ( std::shared_ptr< WaveTableData > & waveTableData)
inline

The documentation for this class was generated from the following files: