arduino-audio-tools
|
RTTTL (Ring Tone Text Transfer Language) parser and player stream. More...
#include <RTTTLOutput.h>
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 |
Print * | p_print = nullptr |
void * | reference = nullptr |
RingBuffer< uint8_t > | ring_buffer {0} |
SingleBuffer< uint8_t > | tmp {MAX_SINGLE_CHARS} |
int | tmpPos = 0 |
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
int16_t
).Usage:
setOutput(...)
overload to attach an AudioStream
, AudioOutput
or raw Print
target.begin()
to reset internal parse state (typically called by the surrounding audio pipeline when starting a stream).write(const uint8_t* data, size_t len)
. RTTTLOutput will buffer the incoming bytes and parse the title, defaults and notes. Notes are rendered immediately via play_note()
.RTTTL semantics implemented:
ms_per_whole = 240000.0 / bpm
(i.e. 60s * 4 * 1000 ms / bpm). The duration field in RTTTL (1,2,4,8,16,...) divides the whole-note length.Important implementation notes / expectations:
play_note()
to generate PCM frames.Print
(or derived) pointer; attaching an AudioStream
or AudioOutput
via setOutput
will register for audio format notifications and forward generated bytes to that target.b=0
is parsed, the implementation falls back to a fixed m_msec_semi = 750.0
(legacy/fallback behavior). Consider validating or rejecting b=0
RTTTL if that is undesired.Edge cases & behavior:
write()
appends to an internal ring buffer and parsing continues as bytes arrive. The parser expects the standard RTTTL format: "name:defaults:notes" and will parse title and defaults on first write()
after begin()
.Example RTTTL string: "Entertainer:d=4,o=5,b=120:8d6,8d6,8d6"
Public API (selected):
Note callback details:
setNoteCallback(cb)
to register a callback that will be invoked for every parsed note or rest. The callback signature is void(float frequencyHz, int durationMs, int midiNote)
.play_note()
before audio generation begins. If you require the callback after playback, you should wrap setNoteCallback
and buffer events or change ordering.MusicalNotes
helper doesn't expose a toMidi(...)
helper, the midiNote may be computed using the standard formula: midi = 12*(octave + 1) + semitoneIndex
where semitoneIndex is the note's index within the 12 semitones (C=0, C#=1, ..., B=11).Known limitations:
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, CodecChain, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, RTSPClient< TcpClient, UdpSocket >, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlineoverridevirtualinherited |
provides the actual input AudioInfo
Implements AudioInfoSupport.
Reimplemented in AdapterPrintToAudioOutput, EncodedAudioOutput, and AdapterAudioStreamToAudioOutput.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in PureDataStream, PWMAudioOutput, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, and ResampleStreamT< TInterpolator >.
|
inlineoverridevirtualinherited |
Reimplemented from Print.
Reimplemented in RTSPOutput< Platform >.
|
inlinevirtual |
Reimplemented from AudioOutput.
|
inlineoverridevirtual |
Start the RTTTL stream: we start with parsing the title and defaults.
Reimplemented from AudioOutput.
|
inlinevirtual |
Reimplemented from AudioOutput.
|
inlinevirtualinherited |
Deletes all change notify subscriptions.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlinevirtualinherited |
Reimplemented in RTSPOutput< Platform >, PitchShiftOutput< T, BufferT >, EncodedAudioOutput, and OggContainerOutput.
|
inlinevirtualinherited |
Reimplemented from Print.
|
inline |
Returns the default bpm parsed from the RTTTL string
|
inline |
Returns the default duration parsed from the RTTTL string
|
inline |
Returns the default octave parsed from the RTTTL string
|
inline |
Returns the parsed title of the RTTTL ringtone
|
inlinevirtualinherited |
If true we need to release the related memory in the destructor.
Reimplemented in AdapterPrintToAudioOutput, and AdapterAudioStreamToAudioOutput.
|
inlinevirtualinherited |
Reimplemented in RTSPOutput< Platform >, and EncodedAudioOutput.
|
inlinevirtualinherited |
Removes a target in order not to be notified about audio changes.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlineoverridevirtualinherited |
Defines the input AudioInfo.
Implements AudioInfoSupport.
Reimplemented in ChannelsSelectOutput, AdapterPrintToAudioOutput, MultiOutput, AdapterAudioStreamToAudioOutput, CsvOutput< T >, PWMAudioOutput, and EncodedAudioOutput.
|
inline |
Defines the Generator that is used to generate the sound
|
inline |
Set an optional callback to be invoked for each parsed note/rest. Callback signature: void(float frequencyHz, int durationMs, int midiNote)
|
inline |
Defines/Changes the output target (AudioOutput) and register for audio info
|
inline |
Defines/Changes the output target (AudioStream) and register for audio info
|
inline |
transpose all notes by the specified number of octaves e.g. -2 = 2 octaves down
|
inlineoverridevirtual |
Writes RTTTL data to the parser and plays the notes.
Implements AudioOutput.
|
inlinevirtualinherited |
Writes n 0 values (= silence)
len |