Go Down

Topic: serial midi speed/dropouts... (Read 60 times) previous topic - next topic

lokki

hi there,

i have a pretty useless example code (it is basically a stripped down version of what i do in a larger sketch) and i have a question regarding serial midi output. could sending these messages cause a dropout in the serial stream, as in the arduino does not send all that it should? i get stuck notes on a synth and was wondering if it is the "bad" midi implementation of the synth or the arduino dropping something.

Code: [Select]

/*
 MIDI note player

 This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
 If this circuit is connected to a MIDI synth, it will play
 the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.


 The circuit:
 * digital in 1 connected to MIDI jack pin 5
 * MIDI jack pin 2 connected to ground
 * MIDI jack pin 4 connected to +5V through 220-ohm resistor
 Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

 created 13 Jun 2006
 modified 13 Aug 2012
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Midi

 */

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
 
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, 0x45, 0x45);
    noteOn(0x90, 0x50, 0x45);
    noteOn(0x90, 0x45, 0);
    noteOn(0x90, 0x50, 0);
    delay(100);

}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}


i know this code makes no sense, because the notes will be ultrashort. my focus is on the 12 consecutive Serial.write( ); can this cause problems? or is the buffer easily large enough? i tried to issue a Serial.flush(); after the four noteOn(); calls, with no difference.

thanks for any insights

Grumpy_Mike

The Arduino can cope with 12 bytes without a glitch. Looks like your synth can't. What happens when yo put a small delay between note on and note off?

Look up what serial flush does it is not what you think.

el_supremo

Try this:
Code: [Select]
    noteOn(0x90, 0x45, 0x45);
    noteOn(0x90, 0x50, 0x45);
    delay(200);
    noteOn(0x90, 0x45, 0);
    noteOn(0x90, 0x50, 0);
    delay(500);


Does it play those properly?

Pete
Don't send me technical questions via Private Message.

lokki

The Arduino can cope with 12 bytes without a glitch. Looks like your synth can't. What happens when yo put a small delay between note on and note off?

Look up what serial flush does it is not what you think.
hmm??

this:

Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.) 

yeah but i guess it's my synth that can't cope. a delay is not a good option, since this will slow down my controller. (it has four channels of midi running in a for loop and a delay would slow all channels down) will experiment some more and see if i find something, thanks!

lokki

#4
Today at 10:47 am Last Edit: Today at 10:54 am by lokki
ok, i tried with a few more examples, including four counter variables  that count up for each for cycle individually and issue the note on and offs at different times (different counter values) . this all works code wise but the synth still glitches :-(

so definitely a synth issue, not arduino. thanks!

el_supremo

You still haven't tried my code and answered my question.

Quote
four counter variables  that count up for each for cycle individually]/quote]
Without seeing your code I can't be sure but it sounds like you are using 'for' loops to kill time. This can result in spectacular failure because the compiler may well optimize the loops out of existence and what you end up testing is exactly what you had in your original code.

Pete
Don't send me technical questions via Private Message.

lokki

#6
Today at 08:41 pm Last Edit: Today at 08:49 pm by lokki
thanks
ok, i tried with a few more examples, including four counter variables  that count up for each for cycle individually and issue the note on and offs at different times (different counter values) . this all works code wise but the synth still glitches :-(

so definitely a synth issue, not arduino. thanks!
thanks for your answer. as i said i tried a couple of possibilities, among those also a delay, and it also does not work. unless i set the delay so long, that it is noticeable (unusable). sorry for not being clear about that.

the for loop is fine, i'm sure of that :-) i'm not using it to kill time but to read  four fsr's and ribbon controllers. it's because of that i did not want to put a delay in there, because it would then slow down all four "strings". i defined counters that are individual for each for loop iteration, but it still did not work. it's a huge project, a midi-ribbon-bass controller with fsr's. i tried some other hardware synths today and they are all fine and working with the existing code, so it is definitely the synth. find attached a picture of the build. awesome what you can do with an arduino micro!!!
it has serial midi and usb in and out (at the same time)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy