FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
devices::audio Namespace Reference

Defines API for audio tones (square waves) generation and simple melodies playing. More...

Namespaces

namespace  SpecialTone
 This namespace defines special "tones" which have an impact on how to play a melody.
 

Classes

class  AbstractTonePlayer
 This low-level API defines an abstract player of melodies (defined as a sequence of tones and durations). More...
 
class  AsyncTonePlayer
 This API defines a player of melodies, defined as a sequence of tones and durations. More...
 
class  Beat
 This embeds minimum duration (duration of a 32nd note), in milliseconds, for a given tempo (beats per minute). More...
 
class  QTonePlay
 An optimized surrogate to TonePlay structure. More...
 
class  ToneGenerator
 API class for tone generation to a buzzer (or better an amplifier) connected to pin OUTPUT. More...
 
class  TonePlay
 This struct is the unit data manipulated by TonePlayer: it describes one Tone along with its duration in milliseconds. More...
 
class  TonePlayer
 This API defines a player of melodies, defined as a sequence of tones and durations. More...
 

Enumerations

enum class  Duration : uint8_t {
  WHOLE = 32 ,
  HALF = 16 ,
  QUARTER = 8 ,
  EIGHTH = 4 ,
  SIXTEENTH = 2 ,
  SEMI_BREVE = WHOLE ,
  MINIM = HALF ,
  CROTCHET = QUARTER ,
  QUAVER = EIGHTH ,
  SEMI_QUAVER = SIXTEENTH
}
 Possible duration of a note, following music theory. More...
 
enum class  Tone : uint16_t {
  USER0 = 0 ,
  USER1 ,
  USER2 ,
  USER3 ,
  USER4 ,
  USER5 ,
  USER6 ,
  USER7 ,
  SILENCE = USER7 + 1 ,
  REST = SILENCE ,
  C0 = 131 ,
  Cs0 = 139 ,
  Df0 = Cs0 ,
  D0 = 147 ,
  Ds0 = 156 ,
  Ef0 = Ds0 ,
  E0 = 165 ,
  F0 = 175 ,
  Fs0 = 185 ,
  Gf0 = Fs0 ,
  G0 = 196 ,
  Gs0 = 208 ,
  Af0 = Gs0 ,
  A0 = 220 ,
  As0 = 233 ,
  Bf0 = As0 ,
  B0 = 247 ,
  C1 = 262 ,
  Cs1 = 277 ,
  Df1 = Cs1 ,
  D1 = 294 ,
  Ds1 = 311 ,
  Ef1 = Ds1 ,
  E1 = 330 ,
  F1 = 349 ,
  Fs1 = 370 ,
  Gf1 = Fs1 ,
  G1 = 392 ,
  Gs1 = 415 ,
  Af1 = Gs1 ,
  A1 = 440 ,
  As1 = 466 ,
  Bf1 = As1 ,
  B1 = 494 ,
  C2 = 523 ,
  Cs2 = 554 ,
  Df2 = Cs2 ,
  D2 = 587 ,
  Ds2 = 622 ,
  Ef2 = Ds2 ,
  E2 = 659 ,
  F2 = 698 ,
  Fs2 = 740 ,
  Gf2 = Fs2 ,
  G2 = 784 ,
  Gs2 = 831 ,
  Af2 = Gs2 ,
  A2 = 880 ,
  As2 = 932 ,
  Bf2 = As2 ,
  B2 = 988 ,
  C3 = 1046 ,
  Cs3 = 1109 ,
  Df3 = Cs3 ,
  D3 = 1175 ,
  Ds3 = 1245 ,
  Ef3 = Ds3 ,
  E3 = 1319 ,
  F3 = 1397 ,
  Fs3 = 1480 ,
  Gf3 = Fs3 ,
  G3 = 1568 ,
  Gs3 = 1662 ,
  Af3 = Gs3 ,
  A3 = 1760 ,
  As3 = 1865 ,
  Bf3 = As3 ,
  B3 = 1976 ,
  C4 = 2093 ,
  Cs4 = 2217 ,
  Df4 = Cs4 ,
  D4 = 2349 ,
  Ds4 = 2489 ,
  Ef4 = Ds4 ,
  E4 = 2637 ,
  F4 = 2794 ,
  Fs4 = 2960 ,
  Gf4 = Fs4 ,
  G4 = 3136 ,
  Gs4 = 3322 ,
  Af4 = Gs4 ,
  A4 = 3520 ,
  As4 = 3729 ,
  Bf4 = As4 ,
  B4 = 3951
}
 This enum defines all possible audio tones that can be generated. More...
 

Functions

static constexpr Duration dotted (Duration d)
 Transforms a note duration to its dotted value (1.5 times the given duration). More...
 
static constexpr Duration triplet (Duration d)
 Transforms a note duration to allow it to use in a triplet. More...
 

Detailed Description

Defines API for audio tones (square waves) generation and simple melodies playing.

Enumeration Type Documentation

◆ Duration

enum class devices::audio::Duration : uint8_t
strong

Possible duration of a note, following music theory.

The shortest duration supported is the semi-quaver (or sixteenth). Synonyms are also defined when they exist.

The uint8_t value is the multiplier to apply to the duration of a 32th note to get the actual duration (in 4 quarters time signature).

A note duration can be altered by:

  • dotting it (i.e. multiplying the duration by 1.5)
  • making it a note in a triplet (i.e. multiplying the duration by 0.67)
See also
dotted()
triplet()
Enumerator
WHOLE 

Duration of a whole note; 4 times the duration of a quarter.

HALF 

Duration of a half note; 2 times the duration of a quarter.

QUARTER 

Duration of a quarter note; this is actually the duration of one beat.

EIGHTH 

Duration of an eighth note; half the duration of a quarter.

SIXTEENTH 

Duration of a sixteenth note; a quarter the duration of a quarter!

SEMI_BREVE 

Other common name for a whole note.

MINIM 

Other common name for a half note.

CROTCHET 

Other common name for a quarter note.

QUAVER 

Other common name for an eighth note.

SEMI_QUAVER 

Other common name for a sixteenth note.

Definition at line 103 of file tone_player.h.

◆ Tone

enum class devices::audio::Tone : uint16_t
strong

This enum defines all possible audio tones that can be generated.

This also defnes "special" values that are not actual tones but are reserved for user purposes or for silences:

  • USER0 ... USER7: can be used for any purpose defined by the end-developer
  • SILENCE or REST: used to play no tone at all All other tones are named according to their musical note (in English scale), and their octave,. This is similar to the usual Scientific Pitch Notation except for the octave index which is different: in this enum, the standard tuning pitch (440Hz) is A1 instead of A4 in SPN.

Sharps are noted as s between the note and its octave, as in Cs0. Flats are noted as f between the note and its octave, as in Df0.

Please note that each tone can be converted to a uint16_t which is its playing frequency.

Definition at line 56 of file tones.h.

Function Documentation

◆ dotted()

static constexpr Duration devices::audio::dotted ( Duration  d)
staticconstexpr

Transforms a note duration to its dotted value (1.5 times the given duration).

Definition at line 133 of file tone_player.h.

◆ triplet()

static constexpr Duration devices::audio::triplet ( Duration  d)
staticconstexpr

Transforms a note duration to allow it to use in a triplet.

Definition at line 141 of file tone_player.h.