lazy_midi Module

MIDI representation data & note-frequency relationship

Summary of module contents:

Name Description
MIDI_A4 int(x=0) -> integer int(x, base=10) -> integer
FREQ_A4 float(x) -> floating point number
SEMITONE_RATIO float(x) -> floating point number
str2freq Given a note string name (e.g. “F#2”), returns its frequency in Hz.
str2midi Given a note string name (e.g. “Bb4”), returns its MIDI pitch number.
freq2str Given a frequency in Hz, returns its note string name (e.g. “D7”).
freq2midi Given a frequency in Hz, returns its MIDI pitch number.
midi2freq Given a MIDI pitch number, returns its frequency in Hz.
midi2str Given a MIDI pitch number, returns its note string name (e.g. “C3”).
octaves Given a frequency and a frequency range, returns all frequencies in that range that is an integer number of octaves related to the given frequency.
str2freq(note_string)[source]

Given a note string name (e.g. “F#2”), returns its frequency in Hz.

str2midi(note_string)[source]

Given a note string name (e.g. “Bb4”), returns its MIDI pitch number.

freq2str(freq)[source]

Given a frequency in Hz, returns its note string name (e.g. “D7”).

freq2midi(freq)[source]

Given a frequency in Hz, returns its MIDI pitch number.

midi2freq(midi_number)[source]

Given a MIDI pitch number, returns its frequency in Hz.

midi2str(midi_number, sharp=True)[source]

Given a MIDI pitch number, returns its note string name (e.g. “C3”).

octaves(freq, fmin=20.0, fmax=20000.0)[source]

Given a frequency and a frequency range, returns all frequencies in that range that is an integer number of octaves related to the given frequency.

Parameters:
  • freq – Frequency, in any (linear) unit.
  • [fmin – ...
  • fmax] – Frequency range, in the same unit of freq. Defaults to 20.0 and 20,000.0, respectively.
Returns:

A list of frequencies, in the same unit of freq and in ascending order.

Examples:
>>> from audiolazy import octaves, sHz
>>> octaves(440.)
[27.5, 55.0, 110.0, 220.0, 440.0, 880.0, 1760.0, 3520.0, 7040.0, 14080.0]
>>> octaves(440., fmin=3000)
[3520.0, 7040.0, 14080.0]
>>> Hz = sHz(44100)[1] # Conversion unit from sample rate
>>> freqs = octaves(440 * Hz, fmin=300 * Hz, fmax = 1000 * Hz) # rad/sample
>>> len(freqs) # Number of octaves
2
>>> [round(f, 6) for f in freqs] # Values in rad/sample
[0.062689, 0.125379]
>>> [round(f / Hz, 6) for f in freqs] # Values in Hz
[440.0, 880.0]