Is there a way to validate a .mid file? I created .mid files to use as sound effects and music for a video game. They work on some devices but not others. So far I can't tell if it's an issue with my program, with the devices, or my MIDI files. I'm wondering if there could be something wrong with my MIDI files that some players overlook but cause problems for other players.
Here's a simple sound effect file. It's just 2 short notes. It works fine on some devices, but I can't hear anything at all on other devices:
https://github.com/pandcorps/pandam/blob/master/game-botsnbolts/src/main/resources/org/pandcorps/botsnbolts/sound/Attack.mid?raw=true
Here's a music file. It has some percussion, a bassline, and some higher notes designed to sound kind of like a twinkling effect. It also works fine on some devices, but on other devices I only hear the percussion and bassline without hearing the higher notes:
https://github.com/pandcorps/pandam/blob/master/game-botsnbolts/src/main/resources/org/pandcorps/botsnbolts/music/HailBot.mid?raw=true
I made them myself using Java's built-in midi library, which probably isn't a very common way to create MIDI files, so I'm wondering if I did something wrong. Can anyone tell if there are problems with these files?
Hello Andrew,
I've had a quick look at your two midi files. Just looking at the data, I'll try to play them, but I don't think this will tell me anything else.
The data seems all perfectly normal, except for one thing. All the notes show a VERY short duration, i.e. 2 ticks, or even 1. I'd guess that many of the instruments used will have an envelope of some sort, and two ticks will not be long enough for the sound to even start. So the first thing you should do is to increase the duration, i.e. the size or length of the note. I'm not sure where you've got a setting as low as you have, I don't think that this would be any sort of normal note - not even 1/64th? but I've not decoded the tempt and note resolution (PPQ) settings in the file yet,
Try making the note lengths longer, even just a few, and see what difference that makes.
The Ch 10 (percussion) notes may be OK, as these often do not have a Note Off anyway as the sound is totally dependant on the envelope. Your other notes have a Note On, then a VERY short delay, and then an explicit Note Off.
Or change the instrument to something with an instant attack, i.e. no Attack at all, and see what difference that makes?
The reason this will work on some devices is that the envelope of the sound will be different, i.e. the the short duration of the note may be just enough that you DO hear something.
Also, make sure that the playing device is set to receive data on the channels you're using. One file is using Ch 1 only, the other is using 1, 2 and 10. However, that numbering is based on 1 thru 16. Some devices may work to 0 thru 15, in which case you're using Ch 0, 1, and 9, but if you've set up such a device to receive Ch 1, 2 and 10 then there'll be a problem.
Geoff
Can you tell us what devices don't work? I like collecting examples of quirks and compatibility problems with MIDI files and MIDI devices.
These MIDI files use a very slow tempo (18.447... quarter notes per minute) and very short musical note durations (256th notes in Attack, and 512th notes in HailBot). Perhaps try multiplying the tempo and note durations by 8 to get more musically typical values that will sound the same when played (147.578... quarter notes per minute, and 32nd notes and 64th notes).
More technical hypothesis: Your MIDI files use a resolution of 128 ticks per quarter note and the shortest notes are 2 ticks in Attack and 1 tick in HailBot. Perhaps the devices that don't work use a coarser resolution, like 24 or 48 ticks per quarter note. When a device like that opens your MIDI files, it probably converts the tick positions of events into its own internal resolution. The beginning and end of the 1 or 2 tick notes in your MIDI files would end up at the same tick position in the device's internal resolution, so maybe the "Note Off" overwrote the "Note On" or something similar causing the device to discard the very short notes.
I ran them both through Sema's test-midi-files, and they are both valid.
The sound effect produces no noise on my particular setup because it takes too long for Winamp to "kick in" to play it before it stops. I also have that issue with Winamp and very short mp3 and wav sound effects.
As for the music, as far as I can tell it plays on my system fine. I tried three different players and they all played.
My only suggestions are what was mentioned above about the notes maybe being too short, and the MIDI capabilities of the devices you are having trouble with. Many MIDI instruments only have a certain range of notes that they reproduce, and it can vary from device to device. It's possible that the pitch is too high for the problematic devices? Though I can only find ranges mentioned for orchestral instruments, and not for Clavinet as you have set. Just for the heck of it, you can try this modified version where I dropped the clavinet 3 octaves, so now it sounds more like an evil laugh :p (A note that my software adds bank selects, but I don't think that should affect anything).
Thank you all for replying, and sorry it took me so long to come back to this. Bavi_H, you asked about the device that doesn't work for me. I use these midi files in a video game that I wrote. When I play that game on a Samsung Galaxy S20 FE phone, I run into these problems where I can't hear certain sound effect files (and can't hear some notes of some music files). If you're really curious, and have an Android phone/tablet/device, and want to see if you can reproduce the problem, you can get the game in Google Play:
https://play.google.com/store/apps/details?id=org.pandcorps.botsnbolts
(There are also graphical bugs on newer devices. I started noticing a bunch of issues after upgrading my phone, but it's mostly still playable. The Attack.mid file plays whenever the player shoots, so it's pretty easy to test that one.)
Jason, you mentioned that the pitch could be too high. I'm pretty sure that the pitch is part of the problem. The sound effects that I can hear are all lower. For example, this file seems to work just fine:
https://github.com/pandcorps/pandam/raw/master/game-botsnbolts/src/main/resources/org/pandcorps/botsnbolts/sound/EnemyAttack.mid
I think it's pretty much the same as Attack.mid, but each note is a little lower.
I might try multiplying the tempo and note durations by 8 like Bavi_H said. I'd be a little surprised if that works, since my other files have the same tempo and short notes and seem fine (I didn't realize they were so short since I don't really know what I'm doing).
I'll also try different instruments. Geoff, you mentioned changing the instrument to something with an instant attack, i.e. no Attack at all. Do you know where I could find a list of instruments with no attack at all? I tried a quick search but couldn't find anything. (I wasn't even familiar with that term until now.)
Again, thank you all. This seems like a very cool forum. I'm glad I tried it!
I tried changing the instrument from clavinet to electric piano 2. It seems like that fixed the problem, so I guess that's good enough. Thanks again for the feedback!