Expand description
Finding the notes in a recording: music21’s audioSearch.
Finding the notes in a recording: music21’s audioSearch.
A recording is cut into chunks of AUDIO_CHUNK_LENGTH frames; each
chunk’s frequency is found by autocorrelation
(autocorrelation_frequency) and snapped to the nearest pitch of a
scale (detect_pitch_frequencies). The frequencies are smoothed
(smooth_frequencies), turned into pitches whose octaves are evened
out (pitch_frequencies_to_objects), and runs of one pitch long
enough to be a note become notes and rests
(join_consecutive_identical_pitches), whose lengths are quantized
against the most common length (notes_and_durations_to_stream).
monophonic_stream_from_wav does all of it, as music21’s
transcriber.monophonicStreamFromFile does.
As music21 does, every recording is taken to be sampled at
RECORD_SAMPLE_RATE, whatever its file says, and its samples are read
as 16-bit numbers. music21’s recording from a microphone and its score
follower are not here.
Constants§
- AUDIO_
CHUNK_ LENGTH - How many frames of a recording each frequency is found from: music21’s
audioChunkLength. - RECORD_
SAMPLE_ RATE - The sample rate every recording is taken to have: music21’s
recordSampleRate.
Functions§
- autocorrelation_
frequency - The frequency a signal sounds, found by autocorrelation: music21’s
autocorrelationFunction. The signal’s correlation with itself at each lag is taken; past the first lag where it starts to rise, its highest point, placed between samples byinterpolation, is the period. A signal whose correlation never rises is a rest, frequency ten. - decision_
process - Which of the parts a score follower is weighing to take as where the
player is, and the count of doubtful guesses so far: music21’s
decisionProcess. Each part is its index intobeginning_data, where it begins, and how well it matched; parts are in order of how well they matched. Of the parts matching within nine tenths of the best and beginning afterlast_note_position, the one beginning nearestnote_predictionis taken; the countdown grows when the guess is doubtful and is otherwise reset. - detect_
pitch_ frequencies - Each frequency’s nearest pitch of
scale(C major on C4 where none is given), and the frequency of that pitch in the octave it sounds: music21’sdetectPitchFrequencies. - frequencies_
from_ wav - The frequency of each whole chunk of
AUDIO_CHUNK_LENGTHframes of a WAV file, found byautocorrelation_frequency: music21’sgetFrequenciesFromAudioFile. Each chunk’s bytes are read as 16-bit samples, every channel’s in turn, and taken to be sampled atRECORD_SAMPLE_RATE; frames after the last whole chunk are left out. - histogram
- How many of
datafall in each ofbinsequal bins from its least to its greatest, and the bins’ edges: music21’shistogram. A value on an edge counts in the bin below it. - interpolation
- Where between three points about a peak the top of the parabola
through them lies: music21’s
interpolation. A peak at either end is taken as it is. - join_
consecutive_ identical_ pitches - Notes and rests from runs of one pitch, and how many pitches each
lasted: music21’s
joinConsecutiveIdenticalPitches. A run of six or more is a note of its last pitch; fifteen or more pitches in shorter runs before a note make a rest. The first pitch is taken as a rest’s, and as in music21 the first pitch after each run is passed over. - monophonic_
stream_ from_ wav - The notes of a recording of one line, as a part: music21’s
transcriber.monophonicStreamFromFile, which runsfrequencies_from_wav,detect_pitch_frequencies,smooth_frequenciesby seven,pitch_frequencies_to_objects,join_consecutive_identical_pitchesandnotes_and_durations_to_stream, rests at the beginning left out. Pitches are taken fromscale, C major on C4 where none is given. - normalize_
input_ frequency - The scale pitch a frequency falls nearest, put in the octave it sounds
in, and the frequency of that pitch as the scale has it: music21’s
normalizeInputFrequency, with thresholds and pitches fromprepare_thresholds. - notes_
and_ durations_ to_ stream - A score of one part holding
notes, each as long as its length inquantize_durationd quarters of the estimated quarter length, and that estimate: music21’snotesAndDurationsToStream. The estimate isquarter_length_estimationagainst the most common note length ofscore_noteswhere given, or against a quarter. Withremove_rests_at_beginning, rests before the first note are left out. The score is titledAutomatic Music21 Transcription. - pitch_
frequencies_ to_ objects - The pitches of a list of frequencies, each the nearest pitch of
scale(C major on C4 where none is given), with each run of one name put in the run’s average octave, and the frequencies so placed: music21’spitchFrequenciesToObjects. - prepare_
thresholds - The thresholds between a scale’s pitches, as fractions of an octave
above the octave’s C, and the pitches: music21’s
prepareThresholds. The scale is the chromatic scale on C4 where none is given. - quantize_
duration - A length, in quarters, snapped to a sixteenth, eighth, quarter, dotted
quarter, half or whole: music21’s
quantizeDuration. - quarter_
length_ estimation - How many pitches a quarter note lasts, from how many each note lasted:
the middle of the last of the fullest bins of an eight-bin
histogramof the lengths and nought, taken asmost_repeated_quarter_length(a quarter where nought): music21’squarterLengthEstimation. - smooth_
frequencies - Each frequency averaged with its neighbours,
smooth_levelsat a time, and rounded to a whole number: music21’ssmoothFrequencies. As in music21, each average takes in those already made before it, and the first and last few frequencies are the truncated average of the first and lastsmooth_levels.