I want reading midi files from sd card (module) and play.
Are there any finished codes out there which is shared as open source?
I want reading midi files from sd card (module) and play.
Are there any finished codes out there which is shared as open source?
You can get a libiary that reads MIDI files here:-
i have tested the examples from MD_MIDIFile in DEBUG mode but it runs very very slow. on uno and on mega 2560 same result.
only very small simple tones runs well. this cant be the true
only very small simple tones runs well. this cant be the true
Why not?
Trying to generate tones requires a quite a lot of processing power and memory, both in short supply on the Arduino Uno and Mega. You would have to go to a more powerful processor like the Zero, Due or Teensy 3.6 before the tones got better.
If you want to stick with a Uno or Mega then you might want to look into Mozzi libiary
Here is a video of a project you can do with it. https://www.youtube.com/watch?v=fdp2hsqUPJ0
Umm, I meant, it should not generate tones, it should only read midi file and then send midi data to servo movings and leds.
I am sure, arduino can play complex midi files. Because reprap printers also use atmega 2560 and gcode files are very big, above megabytes.
I think there is a problem with loading file from sd card.
When I play midi file which is 225 bytes big, it works well
x-y-a.com/simple.jpg
When I play midi file which is 3,21 Kbytes big, it works very slow
http://x-y-a.com/complex.jpg
So that mean, when I play mozard midi file, so it is absoluty impossible to play it.
I think this
int MD_MIDIFile::load ( void )
tries to load the entire midi file, but the arduino memory is too small. So it should not load the entire midi file, it should read only in chunks. Am I right ?
I am not c++ expert, but this is the code from MD_MIDIFile::load and I am not sure, what exactly this code do.
int MD_MIDIFile::load()
// Load the MIDI file into memory ready for processing
{
uint32_t dat32;
uint16_t dat16;
if (_fileName[0] == '\0')
return(0);
// open the file for reading:
if (!_fd.open(_fileName, O_READ))
return(2);
// Read the MIDI header
// header chunk = "MThd" + <header_length:4> + <format:2> + <num_tracks:2> + <time_division:2>
{
char h[MTHD_HDR_SIZE+1]; // Header characters + nul
_fd.fgets(h, MTHD_HDR_SIZE+1);
h[MTHD_HDR_SIZE] = '\0';
if (strcmp(h, MTHD_HDR) != 0)
{
_fd.close();
return(3);
}
}
Does MD_MIDIFile have streaming function ?
tries to load the entire midi file
No it does not. It reads from the SD card library one byte at a time. The SD card library does the buffering. There is no limit to the size of the .MID file.
I am not c++ expert, but this is the code from MD_MIDIFile::load and I am not sure, what exactly this code do
That code does exactly what the comment says it does:
// Read the MIDI header
// header chunk = "MThd" + <header_length:4> + <format:2> + <num_tracks:2> + <time_division:2>
it reads the header file from the .MID file so it can work out how many tracks are in the file, where they start and what the timing signals are.
The library works fine if you are outputting the MIDI stream to a player. It will not work if you use delay() in your code as you will throw out the timing of what is happening and things will be not in the correct tempo.
How are you playing the notes?
How about showing us your code so we have some idea of what you are doing with the MIDI data if it is not playing notes. Moving servos and LEDs doesn't seem very musical to me but it is exactly the sort of thing that can slow a program right down if not done correctly.
Steve