gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > How to identify the midi percussion channel?

#3297 - gb_feedback - Fri Feb 21, 2003 10:05 pm

OK maybe this should be in Off-Topic?

I'm writing a GBA MIDI file player. It is designed to play whatever file the user throws at it. Some files (off the internet) use channel 10 for percussion and some channel 16 (some clever MS idea I gather - let's wreck the standard). I had thought to see which channels were used, and which of those didn't receive a Program Change; this would be the percussion. But it isn't working out that simply. I've seen the percussion channel being set to Program 0 (I thought that was Piano). And yet other players seem to guess correctly. I tried searching the web for this topic but with no success.

Anyone ever come across a workable algorithm?
_________________
http://www.bookreader.co.uk/

#3299 - NEiM0D - Fri Feb 21, 2003 11:27 pm

Why MIDI?
It's such a crappy format plus you'll need to use DirectSound anyhow.

#3301 - tepples - Sat Feb 22, 2003 12:46 am

General MIDI specifies channel 10 for percussion. Back when Adlib-based cards such as the original Sound Blaster were the most common, Microsoft created another standard that used only channels 13 through 16 and put percussion on 16. Some older MIDI files have data both on channels 1-10 (for expensive sound cards) and channels 13-16 (for Adlib); the driver ignores the channels not intended for it.

To detect a song written only for old SBs, look for no data at all in MIDI channels 1-10. There's no foolproof way to distinguish a dual-mode file from a full GM file, but if you can find close resemblances between channels 16 and 10, you have a good chance of having a dual-mode file.

Quote:
I've seen the percussion channel being set to Program 0

You're looking at a Roland GS MIDI file. Roland GS is an extension of the General MIDI sound set. Among other things, it specifies that program changes on channel 10 can select different banks of drum sounds (e.g. standard vs. orchestral vs. hard rock vs. techno).

But I agree that using raw .mid files in a console game is a Bad Idea. The .mid format 1 is just too dang big (try 14 bytes per note*) and doesn't allow repetition of e.g. drum or bass patterns. Convert the .mid files to another format that more concisely represents the musical events.

* EDIT: This is the worst case.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Sun Feb 23, 2003 3:54 am; edited 1 time in total

#3306 - gb_feedback - Sat Feb 22, 2003 3:34 pm

tepples: Thanks for the insights . It may be that most of my trouble stems from incorrect midi files ( or maybe just some obscure 'standard'). For example I found a quite nice Copland 'Fanfare for the common man' with cymbals on channel 10 using a program setting of String Ensemble 1, and a bass drum on channel 14 with no program setting. Strangely Windows Media Player still interpretted it correctly.

No I wouldn't use midi for a gba game. The project is a MIDI player, so it's hard to use another format! There's a pc rom builder application (used by the final user) which takes the raw midi files, and then makes the GBA image. I do actually reprocess the file by converting it to mode 0, and re-timing it so that events can only occur at exact frame intervals. And I strip out the unused commands. Nothing really stops further processing/shrinking stages if I decide it's worth it. And yes it is then played by using some instrument samples through the sound fifo.

On average though, starting and stopping a midi note takes between 5 and 6 bytes. 14 may be a slight exaggeration, at least for typical classical music performances.
_________________
http://www.bookreader.co.uk/

#3343 - tepples - Sun Feb 23, 2003 3:52 am

Perhaps 14 bytes was an exaggeration (I had forgotten some specifics of .mid at the time), but to start or stop a MIDI note in a format 0 MIDI file takes one or two bytes for the delta time, one byte each for cmd+channel, note, volume. That's 8 to 10 bytes to get a note on and off. In format 1 you lose the cmd+channel bytes, but you're still looking at 6 bytes to turn a note on and off.

The optimizations my tracked format makes vs. MIDI:

  • hybrid of format 1 and format 2, allowing say a drum pattern to be repeated with a less repetitive melody on top of it
  • volume is set with the expression pedal command rather than with every note because for non-live performances, volume is likely to remain constant across several notes
  • the resolution of delta times is reduced to sixteenth notes, reducing the byte length of delta times
  • some commands such as program change and expression pedal assume a zero delta time before the next event
  • range of MIDI notes is limited to 36-99, the practical range reproducible by the GBA, freeing up an extra bit in note_on commands
  • the delta time contains a bit for turning the note off first
  • channels are monophonic; a note_on turns the previous note off


Of course, if you're trying to make a conforming MIDI file player, you can't make these optimizations, but most game music doesn't seem to need all the freedom MIDI provides.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.