This Python script captures audio input from the default microphone, performs real-time Fourier analysis, and adjusts MIDI note and velocity based on the audio signal. It serves as the audio-to-MIDI script mentioned in the CircuitPython RGB LED Visualizer documentation.
- Python 3.x
- soundcard
- numpy
- matplotlib
- scipy
- mido
- Connect a MIDI output device.
- Run the script.
- Adjust microphone sensitivity and MIDI output levels interactively.
Note: This script relies on live audio input, and the microphone should be connected and accessible.
- Connect the MIDI output of the device running this script to the USB port of the CircuitPython device running the RGB LED Visualizer.
- Ensure the RGB LED Visualizer script is configured to receive MIDI input through the USB port.
- Run the RGB LED Visualizer script on the CircuitPython device.
- Run this audio-to-MIDI script on a computer or another compatible device.
- Play audio through the default microphone to observe the real-time RGB LED visualizer reacting to the audio input.
WINDOW
: Number of data points for Fourier analysis.
normalize(v)
: Normalize the input array 'v' between 0 and 1.get_levels(aud_data)
: Perform a Fourier transform on the input audio data and return the resulting levels.freq_to_note(freq)
: Convert frequency to MIDI note number.rms(data)
: Calculate the root mean square (RMS) of the input data.pretty_data(args, eq)
: Display formatted data including MIDI note, velocity, RMS, and equalizer levels.equalizer(fft, levels)
: Adjust the Fourier transform levels using an equalizer profile.norm(a, b, x)
: Normalize the input array 'x' between 'a' and 'b'.get_adjustment_levels(prev_notes, bands)
: Calculate adjustment levels based on previous note frequencies.
main()
: Capture audio input, perform analysis, and adjust MIDI output in real-time.
- Adjust parameters and equalizer profile as needed.
- Connect a MIDI source to the USB port to see the audio-to-MIDI conversion in action.
Feel free to explore and modify the script to suit your specific requirements or integrate it into larger projects.