audio2midi - measures the midi-pitch amplitudes, and generates MIDI
audio2midi infile.wav outfile.mid audio2midi -l 55 -h 93 infile.wav outfile.mid # audio2midi -p 61 infile.wav outfile.mid # uses brass-section patch audio2midi -s 150 infile.wav outfile.mid # ignores short notes # then... midiedit outfile.mid
This script measures the amplitudes of a range of midi-note-pitches in a given .wav file, and generates a MIDI file with corresponding 'note' events.
It works taking a sliding Fourier Transform (with an exponentially decaying window) for each of the midi-pitch frequencies. It only outputs notes on one midi-channel, using one patch.
It does not handle drum-kits well, especially high frequencies like snare-drum, cymbals or hand-claps.
It was the subject of
a talk to the Tasmanian Linux User Group
in July 2019.
Sets the Highest midi-note that will be extracted. The default is 84 (soprano-C), but if your wav file is of a descant recorder, or piccolo or tin-whistle, you might want to try something like -h 96
Sets the Lowest midi-note that will be extracted. The default is 28 (bass-guitar E string), but if your wav file is of a flute, you might want to try something like -l 60, because audio2midi will then run a lot faster.
Sets the midi-Patch which the output-file will use, to 82 = Calliope in this example. The default is 0 = Piano. See pjb.com.au/muscript/gm.html for a list of the General-Midi patches.
Sets (in milliseconds) the Shortest note which will be detected. The
default is 90 mS, but if you have a wav-file with some very short
notes you may find even down to -s 40
helps. Or if you
have a wav-file with only long notes but are generating a midi-file
with high-short-note artifacts, you may find that even something like
-s 200
helps. The default is -s 90
Print the Version
This lua script is available at pjb.com.au/midi/free/audio2midi
Then just move it to somewhere in your $PATH
, make it
executable, and if necessary edit the first line to correspond to where
lua is installed on your system.
You will also need the MIDI.lua module, eg:
luarocks install midi
You will also need sox installed, eg:
aptitude install sox
Peter J Billam, pjb.com.au/comp/contact.html
20190428 1.4 defend against a short last block
20190421 1.3 more fiddling with the heuristics of sounding()
20190420 1.2 renamed to audio2midi, and accepts flac, mp3, ogg
20190419 localised the scaled[p] criterion
20190417 1.1 much fiddling with the heuristics of sounding()
20190415 1.0 add -p option, and .wav and .mid filenames
20190414 first half-working version
pjb.com.au/comp/lua/MIDI.html
pjb.com.au/midi/midiedit.html
sox.sourceforge.net/
sox.sourceforge.net/AudioFormats.html
pjb.com.au/midi/audio2midi_talk/
pjb.com.au/midi/free/audio2midi_talk.tgz
pjb.com.au/