Add Music, Famitracker

I wrote some (terrible) songs and sound effects in Famitracker. So, first the songs. Put all songs in the same Famitracker file (adding songs in the module properties). I wrote another page on the limitations of the famitone music engine. Basically, no effects allowed except looping backwards (the Bxx effect, where xx is the frame number).

Export all the songs as a text export, and then process the .txt with text2data (command line program). Make sure to include the -ca65 tag.

Sound effects were put on another Famitracker file. Again, each sound effect on a unique song, using module properties to add another song. You can use any kind of sound effect (I think). But there is an annoying limitation on the length of sound effects. You can actually get around that limitation, by rewriting the famitone.s source (but I can’t show you that rewrite, because it’s not open source code. Sorry.) I have a habit of ending each sound effect with — cut sound and then C00 end of song (on separate lines). I believe this properly ends the sound effect.

Anyway, save all the sound effects as 1 FTM file. Process it with ftm2data (with the -ca65 tag).

Include the music data, in crt0, right after the label music_data: and include the SFX data in crt0 after sounds_data. The crt0 I have, will automatically initialize (set up some pointers) the data, during startup.

Now…use music_play(0); to start the first song. You pass it the song number, starting with 0, of course. If the song number is too high, music will stop. (That’s not the rigtht way to make music stop, btw).

To pause the music, use music_pause(1). To unpause, use music_pause(0). To stop the music (and lose your place in the song) use music_stop().

To trigger a sound effect, use sfx_play(unsigned char sound,unsigned char channel). I didn’t enable (in crt0) more than 1 sound effect channel, but you can, if you want some sound effects to have priority over the others. Notice, I have Square Channel 2 blank in the songs, and exclusively use Square Channel 2 for sound effects. That’s so they don’t collide. If you put song parts on the same channel as the sound effect, make sure you use a less important song part, so the main melody doesn’t cut out every time a sound effect plays.

I just remembered. I have previously used a modified version of famitone.s…but I think I’m using the original verion here. I may change that in the future. No worries. Just make sure the volume of sound effects stays at least as loud as the music channel…or else it won’t play. In a modified version (not here) sound effects always had priority over music, regardless of volume.

That’s it. Easy. The song’s suck, but I didn’t want to spend much time on this. Here’s the example code. Pong, with sound and music (but still no scoreboard).



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s