Skip to main content

Module audiosearch

Module audiosearch 

Source
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 by interpolation, 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 into beginning_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 after last_note_position, the one beginning nearest note_prediction is 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’s detectPitchFrequencies.
frequencies_from_wav
The frequency of each whole chunk of AUDIO_CHUNK_LENGTH frames of a WAV file, found by autocorrelation_frequency: music21’s getFrequenciesFromAudioFile. Each chunk’s bytes are read as 16-bit samples, every channel’s in turn, and taken to be sampled at RECORD_SAMPLE_RATE; frames after the last whole chunk are left out.
histogram
How many of data fall in each of bins equal bins from its least to its greatest, and the bins’ edges: music21’s histogram. 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 runs frequencies_from_wav, detect_pitch_frequencies, smooth_frequencies by seven, pitch_frequencies_to_objects, join_consecutive_identical_pitches and notes_and_durations_to_stream, rests at the beginning left out. Pitches are taken from scale, 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 from prepare_thresholds.
notes_and_durations_to_stream
A score of one part holding notes, each as long as its length in quantize_durationd quarters of the estimated quarter length, and that estimate: music21’s notesAndDurationsToStream. The estimate is quarter_length_estimation against the most common note length of score_notes where given, or against a quarter. With remove_rests_at_beginning, rests before the first note are left out. The score is titled Automatic 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’s pitchFrequenciesToObjects.
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 histogram of the lengths and nought, taken as most_repeated_quarter_length (a quarter where nought): music21’s quarterLengthEstimation.
smooth_frequencies
Each frequency averaged with its neighbours, smooth_levels at a time, and rounded to a whole number: music21’s smoothFrequencies. 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 last smooth_levels.