arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RTTTLOutput< T > Class Template Reference

RTTTL (Ring Tone Text Transfer Language) parser and player stream. More...

#include <RTTTLOutput.h>

Inheritance diagram for RTTTLOutput< T >:
AudioOutput Print AudioInfoSupport AudioInfoSource

Public Member Functions

 RTTTLOutput (SoundGenerator< T > &generator)
 
 RTTTLOutput (SoundGenerator< T > &generator, AudioOutput &out)
 
 RTTTLOutput (SoundGenerator< T > &generator, AudioStream &out)
 
 RTTTLOutput (SoundGenerator< T > &generator, Print &out)
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int availableForWrite () override
 
virtual bool begin ()
 
bool begin () override
 Start the RTTTL stream: we start with parsing the title and defaults.
 
virtual bool begin (AudioInfo info)
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
virtual void flush ()
 
int getDefaultBpm () const
 
int getDefaultDuration () const
 
int getDefaultOctave () const
 
const char * getTitle ()
 
virtual bool isDeletable ()
 If true we need to release the related memory in the destructor.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setGenerator (SoundGenerator< T > &generator)
 
void setNoteCallback (std::function< void(float freqHz, int durationMs, int midiNote, void *ref)> cb)
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setOutput (AudioOutput &out)
 
void setOutput (AudioStream &out)
 
void setOutput (Print &out)
 Defines/Changes the output target (Print)
 
void setReference (void *ref)
 Provide reference for callback.
 
void setTransposeOctaves (int8_t octaves)
 
size_t write (const uint8_t *data, size_t len) override
 Writes RTTTL data to the parser and plays the notes.
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 

Protected Member Functions

int find_byte (const uint8_t *haystack, size_t haystack_len, uint8_t needle)
 
char next_char (bool convertToLower=true)
 
void notifyAudioChange (AudioInfo info)
 
void parse_defaults ()
 
void parse_notes ()
 
int parse_num ()
 
void parse_title ()
 
void play_note (float freq, int msec, int midi=-1)
 
float transpose (float frequency, int8_t octaves)
 

Protected Attributes

int _timeout = 10
 
AudioInfo cfg
 
bool is_active = false
 
bool is_notify_active = true
 
bool is_start = true
 
char m_actual = 0
 
int m_bpm = 120
 
int m_duration = 4
 
float m_msec_semi = 750
 
MusicalNotes m_notes
 
int m_octave = 4
 
char m_prec = 0
 
Str m_title {40}
 
int8_t m_tranpose_octaves = 0
 
std::function< void(float, int, int, void *)> noteCallback
 
Vector< AudioInfoSupport * > notify_vector
 
SoundGenerator< T > * p_generator = nullptr
 
Printp_print = nullptr
 
void * reference = nullptr
 
RingBuffer< uint8_t > ring_buffer {0}
 
SingleBuffer< uint8_t > tmp {MAX_SINGLE_CHARS}
 
int tmpPos = 0
 

Detailed Description

template<class T = int16_t>
class audio_tools::RTTTLOutput< T >

RTTTL (Ring Tone Text Transfer Language) parser and player stream.

RTTTLOutput<T> parses RTTTL text provided via its write() method and generates audio by driving a provided SoundGenerator<T>. It writes the generated PCM bytes to a Print-compatible output (typically an AudioStream or AudioOutput that implements Print).

Template parameter T

Usage:

RTTTL semantics implemented:

Important implementation notes / expectations:

Edge cases & behavior:

Example RTTTL string: "Entertainer:d=4,o=5,b=120:8d6,8d6,8d6"

Public API (selected):

Note callback details:

Known limitations:

Author
Phil Schatzmann

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

provides the actual input AudioInfo

Implements AudioInfoSupport.

Reimplemented in AdapterPrintToAudioOutput, EncodedAudioOutput, and AdapterAudioStreamToAudioOutput.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

Reimplemented from Print.

Reimplemented in RTSPOutput< Platform >.

◆ begin() [1/3]

template<class T = int16_t>
virtual bool begin ( )
inlinevirtual

Reimplemented from AudioOutput.

◆ begin() [2/3]

template<class T = int16_t>
bool begin ( )
inlineoverridevirtual

Start the RTTTL stream: we start with parsing the title and defaults.

Returns
True if initialization was successful.

Reimplemented from AudioOutput.

◆ begin() [3/3]

template<class T = int16_t>
virtual bool begin ( AudioInfo  info)
inlinevirtual

Reimplemented from AudioOutput.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

virtual void flush ( )
inlinevirtualinherited

Reimplemented from Print.

◆ getDefaultBpm()

template<class T = int16_t>
int getDefaultBpm ( ) const
inline

Returns the default bpm parsed from the RTTTL string

◆ getDefaultDuration()

template<class T = int16_t>
int getDefaultDuration ( ) const
inline

Returns the default duration parsed from the RTTTL string

◆ getDefaultOctave()

template<class T = int16_t>
int getDefaultOctave ( ) const
inline

Returns the default octave parsed from the RTTTL string

◆ getTitle()

template<class T = int16_t>
const char * getTitle ( )
inline

Returns the parsed title of the RTTTL ringtone

◆ isDeletable()

virtual bool isDeletable ( )
inlinevirtualinherited

If true we need to release the related memory in the destructor.

Reimplemented in AdapterPrintToAudioOutput, and AdapterAudioStreamToAudioOutput.

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setGenerator()

template<class T = int16_t>
void setGenerator ( SoundGenerator< T > &  generator)
inline

Defines the Generator that is used to generate the sound

◆ setNoteCallback()

template<class T = int16_t>
void setNoteCallback ( std::function< void(float freqHz, int durationMs, int midiNote, void *ref)>  cb)
inline

Set an optional callback to be invoked for each parsed note/rest. Callback signature: void(float frequencyHz, int durationMs, int midiNote)

  • frequencyHz: 0.0 for rests
  • durationMs: computed duration in milliseconds
  • midiNote: MIDI note number (0-127)

◆ setOutput() [1/2]

template<class T = int16_t>
void setOutput ( AudioOutput out)
inline

Defines/Changes the output target (AudioOutput) and register for audio info

◆ setOutput() [2/2]

template<class T = int16_t>
void setOutput ( AudioStream out)
inline

Defines/Changes the output target (AudioStream) and register for audio info

◆ setTransposeOctaves()

template<class T = int16_t>
void setTransposeOctaves ( int8_t  octaves)
inline

transpose all notes by the specified number of octaves e.g. -2 = 2 octaves down

◆ write()

template<class T = int16_t>
size_t write ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Writes RTTTL data to the parser and plays the notes.

Implements AudioOutput.

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes n 0 values (= silence)

Parameters
len

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