Audio to MIDI

Status
Not open for further replies.

Kirazvora

Banned
I need help with my project. I try get control over CC by amplitude from microphone audio signal. Maybe someone can help me with my code? Almost is done, but I can’t get midi to work. Unfortunately maths functions is not my best, still have some problems with understanding how to using it for good results .

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputAnalog adc1; //xy=164,95
AudioAnalyzePeak peak1; //xy=317,123
AudioConnection patchCord1(adc1, peak1);
// GUItool: end automatically generated code


void setup() {
AudioMemory(8);
Serial.begin(115200);
}

// for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.

elapsedMillis fps;

int mod;

void loop() {
if (fps > 48) {
if (peak1.available()) {
fps = 0;
int monoPeak = peak1.readPeakToPeak() * 80.0;
for
(int cnt=0; cnt<monoPeak; cnt++) {
mod = map(mod,0,1023,0,127);
}

usbMIDI.sendControlChange(1, mod, 0);



}

}
}
 
readPeakToPeak() returns a floating point value in the range from zero to two. Multiplying that by 80 will set monoPeak to an integer in the range zero to 160. Then the for loop does nothing useful for up to 160 times because 'mod' is a global 'int' initialized to zero and the map function will just map zero to zero over and over again.
Try this instead:
Code:
    if (peak1.available()) {
      fps = 0;
      // monoPeak will be in the range 0 - 126
      int monoPeak = peak1.readPeakToPeak() * 63.0;
      usbMIDI.sendControlChange(1, monoPeak, 1);
    }
The channel (3rd argument) is specified from 1 - 16, not from zero.

Pete
 
Thank you Pete,
I tried it and getting CC1 to work for few seconds and all stop working. I need again upload sketch because Teensy not want to start. I tried it few times and always happens the same story. I’m not sure why. Code is simple, should working. I try it with Ableton on MacBook Pro. Tomorrow I will trying with Windows and FL Studio and see what happens.


Update:
I checking everything again and I used midi monitor and found that is too much data sending, continuous flow even if is no input audio signal. I will try implementing threshold.
I got 0-126 range proportional to the amplitude :)
When I get it to work without problems I share the code. If someone can give me hints how to improve this simple amplitude to midi cc converter I will be happy :)
 
Last edited:
Try slowing down the sampling rate by changing this:
Code:
if (fps > 48) {
to this:
Code:
if (fps > 100) {
fps is in units of milliseconds. Set the value even higher to slow it down more if necessary.

Pete
 
You might consider using the RMS analysis. Perhaps check only if available() is true so you get new data every 2.9ms. To get a "peak", maybe store several of those in an array and use the largest number.
 
Thanks Pete and Paul.
Yeah slowly FPS better working also I tried RMS like Paul said, and working very fine. But I still looking for options how to do with trigger. I want by trigger start processing, like another condition if happens, then start amplitude converter and if conditions finish, also amplitude converter go to stop. The process initial condition can be level incoming audio signal. Today I will get it to work with trigger.

Also I wondering about sending notes in range 0-127 depending from amplitude, similar like pitch to note. Just for experimenting.
 
Maybe AMP object will be good for threshold/trigger? If level audio achieve threshold point then go to “ON” and send signal to amplitude object or something like that.
 
I got almost all what I want but how to stop sending messages with every detected peak?
Now sending lots of messages, I want to get something like smooth follow.
 
That sounds like you want an envelope follower.

Is there not one in the audio tool yet?

It's essentially a low pass on a rectified signal.

Typically the cut off is very, very low.

Sometimes a 'slew rate' is adjustable separately for rise and fall. In digital this can be done using the sign of the difference between samples to toggle between two weight parameters in the transfer function. Effectively mixing in more or less of the current value depending on if the current sample is above the current average.

https://en.m.wikipedia.org/wiki/Exponential_smoothing

Limiting the MIDI after that should be similar to analog controllers.
 
Yeah oddson
Exactly I need envelope follower but digital not analog. I had done EF analog circuit and it working pretty well but I use it by analogRead 0-5v. My circuit requires + - 15v and couple IC and other things including LPF, active rectifier and so on.
I need moving to digital with it :) because I hope that I can get better accuracy and didn’t need external circuit like that.

I try to imagine how starting with writing code for EF but at first glance it looks difficult for me. Lots of things still I need to learn.
Now I working with filters objects for signal conditioning.

Another idea is using analogue comparator for signal and passing through digitalRead or so.
 
Status
Not open for further replies.
Back
Top