RTTTLParser Library  1.0
RTTTL String parser and playing controls
RTTTL String format

A RTTTL tune can be divided into 3 parts, which are separated using a colon (':')

Looney:d=4,o=5,b=140:32p,c6,8f6,8e6,8d6,8c6,a.,8c6,8f6,8e6,8d6,8d#6
  • The title
  • Default parameters (duration, pitch and bpm)
  • Song Data

The Title

The title of the song, which can be no more than 10 characters. The name of the example song (above) is 'Looney'.

Default parameters

The default value section is a set of values separated by commas, where each value contains a key and a value separated by an equal ('=') character, which describes certain global defaults for the execution of the ring tone. Possible names are

Id Parameter
d Duration in milliseconds
o Octave
b Beat or Tempo (beats per minute)

If these parameters are not specified, the values "d=4,o=6,b=63" are used.

The duration parameter is specified as a fraction of a full note duration.

# Proportion of full note
1 a full note
2 a half note
4 a quarter note
8 an eighth note
16 a sixteenth note
32 a thirty-second note

The RTTTL format allows octaves starting from the A below middle C and going up four octaves. These octaves are numbered from lowest pitch to highest pitch from 4 to 7.

Oct Frequency
4 Note A is 220Hz
5 Note A is 440Hz
6 Note A is 880Hz
7 Note A is 1760Hz

BPM determines how much time each note or pause can take and is the number of quarter notes in a minute. The BPM values can be one of 25, 28, 31, 35, 40, 45, 50, 56, 63, 70, 80, 90, 100, 112, 125, 140, 160, 180, 200, 225, 250, 285, 320, 355, 400, 450, 500, 565, 635, 715, 800 and 900.

Song data

The last section of the string contains the song data as note specifications separated by a comma. A note is encoded by:

[<duration>]<note>[<scale>][<special-duration>]

Special-duration represents dotted rhythm patterns, formed by appending a period ('.') character to the end of duration-note-octave tuple in the song data. This increases the duration of the note to 1.5 times its normal duration. Many RTTTL strings swap the special-duration and scale fields (ie, the octave value comes after the dot notation). The library recognizes and processes either form.

When the optional values duration and/or _scale are omitted, the default parameters from the default section of the RTTTL string are used instead.

The following notes can be used in a RTTTL string:

Id Note Name
P Pause or rest
C Note C
C# Note C sharp
D Note D
D# Note D sharp
E Note E
F Note F
F# Note F sharp
G Note G
G# Note G sharp
A Note A
A# Note A sharp
H Note H (same as B)

The octave is left out for a rest or pause.

Although not part of the original specification, these additional notes are also present in many RTTTL strings:

Id Note Name
B_ B flat (same as A#)
C_ C flat (same as B)
D_ D flat (same as C#)
E_ E flat (same as D#)
F_ F flat (same as E)
G_ G flat (same as F#)
A_ A flat (same as G#)
H_ H flat (same as B_)

The library will translate these extensions into the equivalent note.

Formal specification

<RTTTL> := <title> ":" [<control-section>] ":" <tone-commands>

<title> := <string:10>

<control-section> := <def-note-duration> "," <def-note-scale> "," <def-beats>
<def-duration> := "d=" <duration>
<def-scale> := "o=" <scale>
<def-beats> := "b=" <beats-per-minute>
; if not specified, defaults are duration=4, scale=6, beats-per-minute=63

<tone-commands> := <note> ["," <tone-commands>]
<note> := [<duration>] <note> [<scale>] [<special-duration>]

<duration> := "1"|"2"|"4"|"8"|"16"|"32"
<scale> := "5"|"6"|"7"|"8"
<beats-per-minute> := "5"|"28"|"31"|"35"|"40"|"45"|"50"|"56"|"63"|"70"|"80"|"90"|"100"|"112"|
                    "125"|"140"|"160"|"180"|"200"|"225"|"250"|"285"|"20"|"355"|"400"|"450"|"500"|
                    "565"|"635"|"715"|"800"|"900"
<note> := "P"|"C"|"C#"|"D"|"D#"|"E"|"F"|"F#"|"G"|"G#"|"A"|"A#"|"H"
<special-duration> := "."