Need some help with Game Music Emu

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Need some help with Game Music Emu
by on (#112194)
Hello everyone!
I'm working on a project, built in AS3, that will look and sound like a very early NES game. I'm using palette and sprite limitations, trying to stay as close as possible to something from that era and that hardware. At first I used prerecorded sound and music, but since I'm trying to get a small final swf, I decided to check if it was possible to play nsf files on as3 and found a port of Game Music Emu by Blargg compiled as a swc library via adobe Alchemy. Then I created a nsf file that contains music and sfx. When using this nsf, I cannot get music and sfx to play at the same time; whenever I play some sound, music stops. I've tried different approaches (separating music and sfx on different nsf files, creating multiple instances of the gme library, and a combination of both) but nothing works. The moment the sound starts playing, the music stops. If anyone is familiar with Game Music Emu (on flash or otherwise), I'd really appreciate the help.
Re: Need some help with Game Music Emu
by on (#112198)
GME plays NSF files, which only support one track playing at a time. You'd need to run two instances of GME if you want sound effects at the same time. Though, I didn't do the swf porting, so maybe the author did something to help with sound effects (I vaguely remember an email about this issue, but can't find it offhand in my mailbox).
Re: Need some help with Game Music Emu
by on (#112199)
Is there something that prevents playing music as NSFs using GME, but playing prerecorded sound effects as MP3? Prerecorded sound effects shouldn't take much room, and storing the music in NSF would save a lot of room alone.
Re: Need some help with Game Music Emu
by on (#112217)
First of all: Blargg, your libraries are absolutely awesome! Thanks for sharing such a really great work!

Now, about the nsf playing issue: I've tried using two instances of gme, playing each a copy of the nsf file, or playing each a different nsf file (one with music, and one with sfx). Neither approach is working. When loading two copies of the same file, I get the same original error (that is, music stops after the first sfx plays). When I use two different nsf on two different instances of gme, only the audio of the last loaded file plays. I'll recheck all my code to see if I've done something wrong, cause I understand some games (Super Mario Crossover comes to mind) managed to do all of the audio with nsf files. Anyway, if I can't make it work, I'll probably try using nsf for music and prerecorded for sfx, like Shiru suggests. Thx a lot for your answers, I'll post my results if I can make this thing work.

(Please, excuse if my english is not very good, it's not my native language)
Re: Need some help with Game Music Emu
by on (#112219)
In order to make this sound completely authentic, you would have to modify the NSF driver you are using (I assume Famitracker's) to store both the music and sound effect that is playing and support channel stealing to only drop certain channels out of the music while the sound effect plays.

Using WAV files for sound effects and muting the corresponding sound channel in Game Music Emu would be much easier.
Re: Need some help with Game Music Emu
by on (#112226)
I am using Famitracker, but I've just started using it. In fact, I've never composed any music or sound, this is a first. I'm using three channels for music (pulse1, triangle and noise), leaving one channel for sfx (the sfx tracks are all composed on pulse2). When you say 'modify the driver' are you refering to source code, or can it be done on the software as an option before exporting nsf?
Re: Need some help with Game Music Emu
by on (#112227)
Grapeshot wrote:
In order to make this sound completely authentic, you would have to modify the NSF driver you are using (I assume Famitracker's) to store both the music and sound effect that is playing and support channel stealing to only drop certain channels out of the music while the sound effect plays.

...and write a custom emulator for it, since NSF doesn't allow any communication with the player, and clears memory when starting a new track.
Re: Need some help with Game Music Emu
by on (#112231)
blargg wrote:
...and write a custom emulator for it, since NSF doesn't allow any communication with the player

The custom emulator need not be written from scratch. It should be possible to extend NSF to establish a page of shared memory ($0700-$07FF?) between the NSF player and the program using it, so long as the code in the NSF is aware of the shared memory.
Re: Need some help with Game Music Emu
by on (#112249)
Since I don't think I'm skillful enough to mess with emulator code, I settled for checking all the as3/alchemy compilation mess. I'm not really sure, but I believe that all instances of the gme library create static emulators (in flash at least). Anyway, I solved my problem in a very simple way: linking two different swc of gme to my project. Now it works wonderfully. Is not a good solution, since it requires recompiling gme with alchemy into two different swc libraries that work in exactly the same way, but are in different packages, and it takes more space on the final swf than it should (but can be reduced by using just the nsf part of gme). I'll keep trying to find a better solution. Thx for all your answers.
Re: Need some help with Game Music Emu
by on (#127344)
I know this post is old, but there's a version of GME that now uses FlasCC / CrossBridge. You can find it at https://github.com/mcannizz/gme-flascc

It uses SWIG and is much faster than the GME Alchemy SWC from https://code.google.com/p/game-music-emu-flash/ assuming that's where you got the SWC from.
Re: Need some help with Game Music Emu
by on (#127347)
Great news! Thx for the reply. I'll check this version of gme as soon as possible.