A simple utility that interprets spectral analysis data created by SPEAR (http://www.klingbeil.com/spear/) and creates MIDI files based on this information. It is hoped that this will be of use for musicians who want a quick way to access notation of a spectral analysis of a sound.
The program reads text files in SPEAR's 'text - partials' format. These files contain time, frequency and amplitude data generated by SPEAR's sinusoidal partials analysis. The data are processed and formatted as events which are written to file as MIDI using mido
https://mido.readthedocs.io
Steps for Mac/OSX (will be similar for other platforms):
- Requires Python 3. If this is not installed, download and install: www.python.org.
- Download the code in this repository: 'Clone or download' -> 'Download Zip'
- Extract the .zip file (anywhere on your computer).
- Open Terminal and navigate to the SPEAR_to_MIDI folder, e.g. by typing
cd
followed by space, dragging the folder from the finder into the Terminal window and then pressing enter. - Type the command
pip3 install -r requirements.txt
and press enter to install dependencies (in this case themido
library).
- Create a spectral analysis using SPEAR. Use a relatively high 'Minimum amplitude threshold' value (e.g. -20dB) for best results.
- In SPEAR, under 'File' -> 'Export Format' select 'Text - Partials', then 'File' -> 'Export As...'
- Save the file inside the SPEAR_to_MIDI folder.
- Open Terminal and navigate to the SPEAR_to_MIDI folder.
- Type the command
python3 SPEAR_to_MIDI.py input_file output_file bpm
to run the program. Replace input_file, output_file and bpm with your files and choice for bpm. You do not have to specify them, the default to: input_file = "SPEAR.txt", output_file = "output.mid" and bpm = 60. - A MIDI file with the specified name will then be created. This can be opened and edited in a score editing program like Sibelius or MuseScore.
- The program works best for relatively simple spectral analyses that don't have large numbers of simultaneous partials. If the program fails, try setting a higher value for 'Minimum amplitude threshold' when analysing the audio in SPEAR.
- Pitch: MIDI note numbers are calculated based on the average frequency of each partial.
- Loudness: MIDI velocity is calculated based on the average amplitude of each partial. Currently, this is scaled linearly.
- Time: Timestamps are converted from seconds to delta (relative) values in ticks once MIDI-like events have been created and sorted.
- Add exponential scaling for amplitude to velocity conversions (currently linear).
- Write unit tests. (Currently using
doctest
). - Identify and fix issues that prevent the program from processing analyses with high numbers of simultaneous partials.
- Experiment with higher beat resolution (PPQN) for improved timing accuracy.
- Improve data parsing efficiency.
- Add a CLI / GUI and user-configurable parameters.
- Create compiled applications for Mac and Windows.
Stephen Bradshaw ([email protected])