Mozzi  version v2.0
sound synthesis library for Arduino
Midi note number to frequency conversions

Useful if you like playing notes in tune. More...

Detailed Description

Useful if you like playing notes in tune.

Functions

float mtof (float midival)
 Converts midi note number to frequency. More...
 
int mtof (uint8_t midi_note)
 A good choice if you're using whole note values, want speed and simplicity, and accuracy isn't important. More...
 
int mtof (int midi_note)
 A good choice if you're using whole note values, want speed and simplicity, and accuracy isn't important. More...
 
Q16n16 Q16n16_mtof (Q16n16 midival_fractional)
 Converts midi note number to frequency with speed and accuracy. More...
 
template<uint64_t RANGE>
UFix< 16, 16 > mtof (UFix< 16, 16, RANGE > midival)
 Converts midi note number with speed and accuracy from a UFix<16,16>. More...
 
template<int8_t NI, int8_t NF, uint64_t RANGE>
UFix< 16, 16 > mtof (UFix< NI, NF, RANGE > midival)
 Converts midi note number with speed and accuracy from any UFix. More...
 
template<int8_t NI, int8_t NF, uint64_t RANGE>
UFix< 16, 16 > mtof (SFix< NI, NF, RANGE > midival)
 Converts midi note number with speed and accuracy from any SFix. More...
 
template<int8_t NI, uint64_t RANGE>
UFix< 16, 16 > mtof (UFix< NI, 0, RANGE > midival)
 Converts whole midi note number with speed and accuracy (more accurate that mtof(uint8_t))
 
template<int8_t NI, uint64_t RANGE>
UFix< 16, 16 > mtof (SFix< NI, 0, RANGE > midival)
 Converts whole midi note number with speed and accuracy (more accurate that mtof(uint8_t))
 

Function Documentation

◆ mtof() [1/6]

float mtof ( float  midival)
inline

Converts midi note number to frequency.

Caution: this can take up to 400 microseconds to run. It can seriously mess up the audio output if you use it in updateControl() or updateAudio(). This is a good choice in setup(), or where you need precise midi-pitch conversion and aren't doing much other audio calculation.

Note
Beware this returns an invalid result for midi note 0.
Timing: ~350 us
Parameters
midivala midi note number, 1.0 or greater. Like the mtof object in Pd, midi values can have fractions.
Returns
the frequency represented by the input midi note number..

Definition at line 75 of file mozzi_midi.h.

◆ mtof() [2/6]

int mtof ( int  midi_note)
inline

A good choice if you're using whole note values, want speed and simplicity, and accuracy isn't important.

Parameters
midi_notea midi note number.
Returns
an integer approximation of the midi note's frequency.

Definition at line 102 of file mozzi_midi.h.

◆ mtof() [3/6]

template<int8_t NI, int8_t NF, uint64_t RANGE>
UFix<16,16> mtof ( SFix< NI, NF, RANGE >  midival)
inline

Converts midi note number with speed and accuracy from any SFix.

Uses Q16n16_mtof internally.

Definition at line 163 of file mozzi_midi.h.

◆ mtof() [4/6]

template<uint64_t RANGE>
UFix<16,16> mtof ( UFix< 16, 16, RANGE >  midival)
inline

Converts midi note number with speed and accuracy from a UFix<16,16>.

Uses Q16n16_mtof internally.

Definition at line 143 of file mozzi_midi.h.

◆ mtof() [5/6]

template<int8_t NI, int8_t NF, uint64_t RANGE>
UFix<16,16> mtof ( UFix< NI, NF, RANGE >  midival)
inline

Converts midi note number with speed and accuracy from any UFix.

Uses Q16n16_mtof internally.

Definition at line 153 of file mozzi_midi.h.

◆ mtof() [6/6]

int mtof ( uint8_t  midi_note)
inline

A good choice if you're using whole note values, want speed and simplicity, and accuracy isn't important.

Parameters
midi_notea midi note number.
Returns
an integer approximation of the midi note's frequency.

Definition at line 93 of file mozzi_midi.h.

◆ Q16n16_mtof()

Q16n16 Q16n16_mtof ( Q16n16  midival_fractional)
inline

Converts midi note number to frequency with speed and accuracy.

Q16n16_mtofLookup() is a fast alternative to (float) mtof(), and more accurate than (uint8_t) mtof(), using Q16n16 fixed-point format instead of floats or uint8_t values. Q16n16_mtof() uses cheap linear interpolation between whole midi-note frequency equivalents stored in a lookup table, so is less accurate than the float version, mtof(), for non-whole midi values.

Note
Timing: ~8 us.
Parameters
midival_fractionala midi note number in Q16n16 format, for fractional values.
Returns
the frequency represented by the input midi note number, in Q16n16 fixed point fractional integer format, where the lower word is a fractional value.

Definition at line 119 of file mozzi_midi.h.