arduino-audio-tools
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Synthesizer Class Reference

A simple Synthesizer which can generate sound having multiple keys pressed. The main purpose of this class is managing the synthezizer channels. More...

#include <Synthesizer.h>

Inheritance diagram for Synthesizer:
SoundGenerator< int16_t >

Classes

struct  KeyParameter
 

Public Member Functions

 Synthesizer ()
 
 Synthesizer (AbstractSynthesizerChannel *ch)
 
 Synthesizer (Synthesizer const &)=delete
 
virtual ~Synthesizer ()
 
virtual AudioInfo audioInfo ()
 Provides the AudioInfo.
 
virtual bool begin ()
 Starts the processing.
 
bool begin (AudioInfo config)
 Starts the processing with the provided AudioInfo.
 
virtual AudioInfo defaultConfig ()
 Provides the default configuration.
 
virtual void end ()
 
virtual void end (bool allow_rampdown)
 
virtual bool isActive ()
 Checks if the begin method has been called - after end() isActive is false.
 
void keyOff (int note)
 
void keyOn (int note, float tgt=0)
 
Synthesizeroperator= (Synthesizer const &)=delete
 
virtual size_t readBytes (uint8_t *data, size_t len)
 Provides the data as byte array with the requested number of channels.
 
int16_t readSample () override
 Provides mixed samples of all channels.
 
virtual size_t readSamples (int16_t *data, size_t len)
 
virtual void restart ()
 Restarts the generator, e.g. after a play time has been defined and reached.
 
virtual void setAudioInfo (AudioInfo info)
 Defines/updates the AudioInfo.
 
virtual void setFrequency (float frequency)
 Abstract method: not implemented! Just provides an error message...
 
void setKeys (AudioActions &actions, SynthesizerKey *p_keys, AudioActions::ActiveLogic activeValue)
 Assigns pins to notes - the last SynthesizerKey is marked with an entry containing the note <= 0.
 
void setMidiName (const char *name)
 Defines the midi name.
 
virtual void setPlayTime (uint32_t playMs, uint8_t upPercent=20, uint8_t downPercent=30)
 Defines the play time in ms and the ramp up and ramp down time in percent.
 
virtual void setRampTimes (uint32_t playMs, uint32_t upMs=5, uint32_t downMs=5)
 

Protected Member Functions

int16_t applyRamp (int16_t sample)
 
AbstractSynthesizerChannelgetFreeChannel ()
 
AbstractSynthesizerChannelgetNoteChannel (int note)
 
size_t readBytesFrames (uint8_t *buffer, size_t lengthBytes, int frames, int channels)
 
size_t readBytesFromBuffer (uint8_t *buffer, size_t lengthBytes, int frame_size, int channels)
 
void recalculatePlayTime ()
 

Static Protected Member Functions

static void callbackKeyOff (bool active, int pin, void *ref)
 
static void callbackKeyOn (bool active, int pin, void *ref)
 

Protected Attributes

bool active
 
bool activeWarningIssued
 
AudioInfo cfg
 
Vector< AbstractSynthesizerChannel * > channels
 
uint32_t currentSample
 
AbstractSynthesizerChanneldefaultChannel
 
uint32_t downMs
 
uint8_t downPercent
 
uint32_t downSamples
 
float factor
 
AudioInfo info
 
const char * midi_name = "Synthesizer"
 
uint32_t playMs
 
uint32_t playSamples
 
float rampDownDec
 
float rampUpInc
 
RingBuffer< uint8_t > ring_buffer
 
uint32_t upMs
 
uint8_t upPercent
 
uint32_t upSamples
 

Detailed Description

A simple Synthesizer which can generate sound having multiple keys pressed. The main purpose of this class is managing the synthezizer channels.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ Synthesizer() [1/3]

Synthesizer ( )
inline

◆ Synthesizer() [2/3]

◆ Synthesizer() [3/3]

Synthesizer ( Synthesizer const &  )
delete

◆ ~Synthesizer()

virtual ~Synthesizer ( )
inlinevirtual

Member Function Documentation

◆ applyRamp()

int16_t applyRamp ( int16_t  sample)
inlineprotectedinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlinevirtualinherited

Provides the AudioInfo.

◆ begin() [1/2]

virtual bool begin ( )
inlinevirtualinherited

Starts the processing.

◆ begin() [2/2]

bool begin ( AudioInfo  info)
inlinevirtual

Starts the processing with the provided AudioInfo.

Reimplemented from SoundGenerator< int16_t >.

◆ callbackKeyOff()

static void callbackKeyOff ( bool  active,
int  pin,
void *  ref 
)
inlinestaticprotected

◆ callbackKeyOn()

static void callbackKeyOn ( bool  active,
int  pin,
void *  ref 
)
inlinestaticprotected

◆ defaultConfig()

virtual AudioInfo defaultConfig ( )
inlinevirtualinherited

Provides the default configuration.

◆ end() [1/2]

virtual void end ( )
inlinevirtualinherited

◆ end() [2/2]

virtual void end ( bool  allow_rampdown)
inlinevirtualinherited

Ends the processing. If either setPlayTime() or setRampTimes() have been set, then allow_rampdown=true will start a ramp-down instead of stopping immediately.

◆ getFreeChannel()

AbstractSynthesizerChannel * getFreeChannel ( )
inlineprotected

◆ getNoteChannel()

AbstractSynthesizerChannel * getNoteChannel ( int  note)
inlineprotected

◆ isActive()

virtual bool isActive ( )
inlinevirtualinherited

Checks if the begin method has been called - after end() isActive is false.

◆ keyOff()

void keyOff ( int  note)
inline

◆ keyOn()

void keyOn ( int  note,
float  tgt = 0 
)
inline

◆ operator=()

Synthesizer & operator= ( Synthesizer const &  )
delete

◆ readBytes()

virtual size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlinevirtualinherited

Provides the data as byte array with the requested number of channels.

◆ readBytesFrames()

size_t readBytesFrames ( uint8_t *  buffer,
size_t  lengthBytes,
int  frames,
int  channels 
)
inlineprotectedinherited

◆ readBytesFromBuffer()

size_t readBytesFromBuffer ( uint8_t *  buffer,
size_t  lengthBytes,
int  frame_size,
int  channels 
)
inlineprotectedinherited

◆ readSample()

int16_t readSample ( )
inlineoverridevirtual

Provides mixed samples of all channels.

Implements SoundGenerator< int16_t >.

◆ readSamples()

virtual size_t readSamples ( int16_t *  data,
size_t  len 
)
inlinevirtualinherited

Provides the data as T array (interleaved by channel) with the requested number of samples (values, not frames)

◆ recalculatePlayTime()

void recalculatePlayTime ( )
inlineprotectedinherited

◆ restart()

virtual void restart ( )
inlinevirtualinherited

Restarts the generator, e.g. after a play time has been defined and reached.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlinevirtualinherited

Defines/updates the AudioInfo.

◆ setFrequency()

virtual void setFrequency ( float  frequency)
inlinevirtualinherited

Abstract method: not implemented! Just provides an error message...

◆ setKeys()

void setKeys ( AudioActions actions,
SynthesizerKey p_keys,
AudioActions::ActiveLogic  activeValue 
)
inline

Assigns pins to notes - the last SynthesizerKey is marked with an entry containing the note <= 0.

◆ setMidiName()

void setMidiName ( const char *  name)
inline

Defines the midi name.

◆ setPlayTime()

virtual void setPlayTime ( uint32_t  playMs,
uint8_t  upPercent = 20,
uint8_t  downPercent = 30 
)
inlinevirtualinherited

Defines the play time in ms and the ramp up and ramp down time in percent.

◆ setRampTimes()

virtual void setRampTimes ( uint32_t  playMs,
uint32_t  upMs = 5,
uint32_t  downMs = 5 
)
inlinevirtualinherited

Alternative to setPlayTime. It sets ramp-up and ramp-down times in ms instead of percentages. If playMs == 0, it will play indefinitely. restart();begin(); starts the ramp-up and sustain as normal, but it will sustain forever. end(true) triggers a ramp-down then inactive.

Member Data Documentation

◆ active

bool active
protectedinherited

◆ activeWarningIssued

bool activeWarningIssued
protectedinherited

◆ cfg

AudioInfo cfg
protected

◆ channels

Vector<AbstractSynthesizerChannel*> channels
protected

◆ currentSample

uint32_t currentSample
protectedinherited

◆ defaultChannel

AbstractSynthesizerChannel* defaultChannel
protected

◆ downMs

uint32_t downMs
protectedinherited

◆ downPercent

uint8_t downPercent
protectedinherited

◆ downSamples

uint32_t downSamples
protectedinherited

◆ factor

float factor
protectedinherited

◆ info

AudioInfo info
protectedinherited

◆ midi_name

const char* midi_name = "Synthesizer"
protected

◆ playMs

uint32_t playMs
protectedinherited

◆ playSamples

uint32_t playSamples
protectedinherited

◆ rampDownDec

float rampDownDec
protectedinherited

◆ rampUpInc

float rampUpInc
protectedinherited

◆ ring_buffer

RingBuffer<uint8_t> ring_buffer
protectedinherited

◆ upMs

uint32_t upMs
protectedinherited

◆ upPercent

uint8_t upPercent
protectedinherited

◆ upSamples

uint32_t upSamples
protectedinherited

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