Generates tones with smooth transitions using Tone Buffers. More...

#include <ToneGenerator.h>

Public Types

enum class  Voice { XX , MAX }
 
enum class  ToneEffect { XX }
 

Public Member Functions

 ~ToneGenerator ()
 
bool begin (unsigned sampleRate)
 Initialise the tone generator and I2S. More...
 
void end ()
 Stop playback and un-initialise I2S. More...
 
bool start ()
 Start tone playback. More...
 
void stop ()
 Stop tone playback and release any memory allocated for buffers. More...
 
bool isStarted ()
 
ToneBuffercreateTone (Voice voice, unsigned frequency, ToneEffect effect, unsigned repeatCount=0)
 Create a tone and queue it. More...
 
void queueTone (Voice voice, unsigned frequency)
 Create a tone with appropriate filtering. More...
 
void submitPending ()
 Submit queued tone buffers for playback. More...
 

Static Public Member Functions

static String getVoiceName (Voice voice)
 
static String getEffectName (ToneEffect effect)
 

Detailed Description

Generates tones with smooth transitions using Tone Buffers.

Note
During tone playback, a single active ToneBuffer feeds the I2S with samples. When a new tone is prepared via queueTone(), a ToneBuffer is added to the pending queue. If transitioning between tone and silence then additional fade in/out buffers are queued to implement low-pass filtering on these relatively abrupt transitions and thus reduce clicking. Calling submitPending() appends the pending queue onto the transition queue. The transition to the new tone (or silence) is made within i2sWrite(), at which point buffers are released back to the avail queue.

Member Enumeration Documentation

◆ ToneEffect

Enumerator
XX 

◆ Voice

enum ToneGenerator::Voice
strong
Enumerator
XX 
MAX 

Constructor & Destructor Documentation

◆ ~ToneGenerator()

ToneGenerator::~ToneGenerator ( )
inline

Member Function Documentation

◆ begin()

bool ToneGenerator::begin ( unsigned  sampleRate)

Initialise the tone generator and I2S.

Parameters
sampleRate
Return values
booltrue on success

◆ createTone()

ToneBuffer* ToneGenerator::createTone ( Voice  voice,
unsigned  frequency,
ToneEffect  effect,
unsigned  repeatCount = 0 
)

Create a tone and queue it.

Parameters
voiceVoice to use for tone
frequencyFrequency in Hz
effect
repeatCountSpecify non-zero to repeat this tone a specific number of times
Return values
ToneBuffer*The queued buffer, nullptr on error

◆ end()

void ToneGenerator::end ( )

Stop playback and un-initialise I2S.

Note
Releases all allocated memory

◆ getEffectName()

static String ToneGenerator::getEffectName ( ToneEffect  effect)
static

◆ getVoiceName()

static String ToneGenerator::getVoiceName ( Voice  voice)
static

◆ isStarted()

bool ToneGenerator::isStarted ( )
inline

◆ queueTone()

void ToneGenerator::queueTone ( Voice  voice,
unsigned  frequency 
)

Create a tone with appropriate filtering.

Parameters
voiceVoice to use for tone @frequency Frequency in Hz @

◆ start()

bool ToneGenerator::start ( )

Start tone playback.

◆ stop()

void ToneGenerator::stop ( )

Stop tone playback and release any memory allocated for buffers.

Note
Leaves I2S initialised. Call start() to resume.

◆ submitPending()

void ToneGenerator::submitPending ( )
inline

Submit queued tone buffers for playback.


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