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 > The EmmA sound engine - assistance needed

#163137 - Kyoufu Kawa - Tue Sep 23, 2008 7:28 pm

Now before I start, I'd like to say that this project may be considered illegal here. If so, just say the word and I won't speak of it again. This is also why this post does not include any links to the work so far.

Backstory
I started the OpenPok? project in a pirated copy of the NoA development kit. Soon enough me and Cearn ported it to Devkit, leaving only two things (a few defines and an OAM structure that'd be a total pain to replace) and the sound engine commonly but incorrectly referred to as Sappy.

Now, I'd really like to replace this engine with something more legal, but nothing quite worked out right. To properly imitate a Pok?mon Advance game engine's sound, you'd need something really close to Sappy. You might have noticed if you know a thing or two about Sappy that I tried to steer Ruben into similar directions. I'm such a cad.

EmmA
Knowing much about the music and instrument format (conveniently ignoring how exactly), I decided a Sappy rewrite might be a nice idea. I have a very basic music data interpreter down, but there are a couple of things missing:
* it requires the usage of a BIOS -- Sappy uses its own in-rom revisions of the same routines.
* being bad at math as well as music theory, I can't get the timing to work out.
* it can only play one song at a time -- Sappy can run four songs, each with up to sixteen tracks, with a priority system distributing it among twelve mixer channels, not counting GBC instruments.

If this falls in an appropriately light-greyish area, any assistance on any of these problems would be highly appreciated.

#163229 - Ruben - Fri Sep 26, 2008 11:42 am

Well, I'm pretty sure games like Final Fantasy on the GBA use something like that (explanation how I know below; nothing illegal), and I've taken a look at the memory and stuff... it seems that it uses a HIGHLY inefficient mixing routine per channel (like 4 loads per sample, per channel, no unrolling) and a LOT of IWRAM (or maybe someone just didn't place it in EWRAM). Seeing that... I think your best bet at something legal would be to re-write your music into a compatible tracker format and use kusma's pimpmobile... that is, of course, if I can't finish my engine on time >.>" (and if I can't find out where to get a PD sample bank from, or if I can use my keyboard as a sound source). Both have downsides, though:

pimpmobile:
-Have to convert all your music (hard but possible)

AGBMid: (my player)
-Have to wait >.>"

Mods:
If you think this is an illegal/etc post, please delete. (I think that goes without saying >.>")

Explanation as to my knowledge of the Sappy/M4A driver:
I used to own FFVa, until it broke along with my GBA (LONG story). Luckily, I had backed it up, along with the BIOS, right after getting it out of the box and testing. Did a few comparisons on the sound memory (after trial and error) and found a similarity between that and the BIOS sound routines. The post above just confirmed my thoughts.

#163234 - Kyoufu Kawa - Fri Sep 26, 2008 4:34 pm

Yeah, well. My point is that I have the code to recognizably reproduce Sappy music data, but I can't do the missing commands/effects -- and it uses the BIOS mixer.

So I need assistance with a non-BIOS mixer as well as things like timing.

And Ruben? The engine was named Sappy after a Windows music player I took over from DJ Bouch? called Sappy. Most if not all GBA games with a Japanese origin use that engine ;)

#163235 - Ruben - Fri Sep 26, 2008 5:02 pm

Non-BIOS mixer? So you mean you have all the channel structures of the BIOS synth? If so, I can easily code you a fast mixing routine.

Timing? That's easy too. With a non-BIOS mixer, it'd be easier to mix a variable amount of samples so you can use:
samples per tick = (mix frequency*5) / (tempo*2)

Feel free to PM me for more details.

#163238 - Kyoufu Kawa - Fri Sep 26, 2008 7:19 pm

Being part of NoA's headers, I'll send you the channel structures in private when I finish this post.

As for timing, I think I'm still not quite understood right. I didn't mean timing as in shifting pitch by speeding up or slowing down the samples, but timing as in how fast the music plays. On the other hand, I'm not sure I understood you either.

As an example, http://helmetedrodent.kickassgamers.com/rick2.mid (warning, obvious rickroll), according to NoteWorthy Composer, has ♩=113. In the .s file, this is written as
Code:
.byte TEMPO , 113*rick2_tbs/2
where rick2_tbs is earlier defined to be 1.

Note that the .s files used by Sappy are split in measures by numbered line comments, each measure being about 96 ticks:
Code:
@ 001 ----------------------------------------
.byte W96
That's an empty measure - the song has a little drum intro in another track.

Unfortunately, I know quite little about music theory.

#163246 - Ruben - Sat Sep 27, 2008 2:54 am

No, no. I wasn't referring to the pitching of the samples. That's kinda easy to manage. I was referring to how fast a song plays and how often it gets updated.

Basically, you divide the master mixing frequency by the frequency of the song (f = t*2/5). Using a bit of algebra, you can make that:
spt = (mf*5) / (tempo*2)
That's how many samples are going to get mixed between each tick. For more information on that, take a look at Deku's sound mixing tutorial.