This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

The famitracker driver thread

The famitracker driver thread
by on (#38333)
When I was asking questions in the newbie forum regarding Famitracker driver, I was told that if I find how to play sound fx with it that I should inform the community on how to do it.

To do it, I had to modify the driver so it can disable some channels on demand. Once a channel is disabled, in your main code, you can play your sound fx. It was not possible to ask FamiTracker to play the effect with another song since it would had required to have virtually 2 times the variables for the song's information: the old one still play while the new one take's over. Since the footprint in memory is already 220 bytes, I decided that it's not worth it for now.

At the end of the process, you restore the channels and the music continue to work properly.

Here's the link to the my updated sample with the working sound effects: (removed)

You just press the a button and your will hear a sound fx. This version correct the issue with square channels compared to the one in the newbie forum.

Of course this sample doesn't have a sound fx engine, I just play one sound and that's it. If you start a sound a decide in the middle to start another one, you have to restore the channels first then start playing your new songs. If you don't, the squares channels of your song could be affected.

I can explain later in more details how to use it if some people are interested. For now, the current sample should (?) be enough. If you have questions regarding the code, don't be afraid to ask :)

If people do get interested in this driver, I don't know if someday if would be interesting to port it to other assembler like nesasm, wla etc. That could be an interesting quick project to do.

edit (2008-10-14):

I renamed the thread since I want to use only one for this subject and stop starting new one. I will add new content when my progress goes forward.

edit 2008-10-24:

You should not use the experimental version anymore. Take the RC1 instead mentioned below.

by on (#38401)
I guess this is just a bump of this thread since I didn't know if editing my own post was going to change the flag to new or not. Sorry about that.

It seems my first breakthrough (if we can call it that way) even though I'm no nes expert was not that interesting.

I will try to see if I can convert it to virtual registers since most of the code before playing is in the APU module. So I guess it can be done. I cannot grasp yet what advantage would it bring, I though letting the player do is job and acting on only the channels you want was better but if that's what peoples wants then why not. That will make me learn more about 6502 coding along the way.

by on (#38402)
Great to hear you've been making progress. It'll be useful for alot of people.

by on (#38411)
MottZilla wrote:
Great to hear you've been making progress. It'll be useful for alot of people.


Thanks for the words of encouragement, I really appreciate it. This give me more motivation to work on the second phase which will be virtual registers. I guess I can do it since the code in the APU module doesn't seems that complicated. Just one part needs to do some post processing in certain conditions.

Once this is done, I want to port it to other assembler like nesasm if people have any interest in it.

by on (#38473)
I didn't have a chance to explore too much about the virtual register approach but it's coming.

Instead, I ported my current WIP to nesasm so now people can benefit from famitracker and can start to play sound effects too.

Here the link to the experimental version: (removed)

Compared to the ca65 version which is my research project, there is no graphic shown on the screen, only the music is playing. If you press a, a sound effect will be played.

I hope it will benefit everyone that like using nesasm and that have some projects that doesn't have a sound driver yet. I will try to port it to other well known assembler once I have a chance.

Note: I'm very new to nesasm so my code it still not perfect. There's a few things I need to figure out or change in the FT code base to make it simpler to use.

edit 2008-10-24:

You should not use the experimental version anymore. Take the RC1 instead.

by on (#38924)
Here's the link to the RC1 of the updated famitracker driver:

File here

What is new:

- You can specify the address of your music data
- nesasm version and ca65 version
- sound test sample only

Both version contain a sample. It doesn't show anything on the screen, only play some music. If you press a,b,select or start, a sound fx will be played.

It is quite stable for now, just in some situation when I play a sound fx with a specific song on a square channel (song #5 in the sample), sometime the music is not 100% restored. I need to figure out this one. There is a few sample songs that you can play with it. Song #5 contains DPCM data.

Any comment always appreciated.

by on (#38925)
It's getting there!

I noticed on the longer playing sound effect, the start button, I believe it was, the sound wouldn't get cut short if I played another sound effect while that was going on. I know it's an early work, but I thought I'd point that out as food for thought.

I noticed you said something about there being more than one song, but I couldn't figure out how to change it. Maybe you meant for us to build it for each song?

Great job so far man!

by on (#38953)
Roth wrote:
It's getting there!


Yes! And I will use it in my game too. It seems quite useful in it current state already.

Roth wrote:
I noticed on the longer playing sound effect, the start button, I believe it was, the sound wouldn't get cut short if I played another sound effect while that was going on. I know it's an early work, but I thought I'd point that out as food for thought.


It's actually by design. The reason is since there is no real joystick buffering handler, you could have send many request for the same button and that would have played the same sound fx too many times, creating some kind of buzz before it can really launch. So I decided for now is once you send a request, you cannot launch another one.

This is for this demo only. You can actually cut a sound fx any time in the current state of the driver, it's just the way I coded this example. I may update the example later so you can cut a currently playing sound fx.

Roth wrote:
I noticed you said something about there being more than one song, but I couldn't figure out how to change it. Maybe you meant for us to build it for each song?


Since it's a sample for programmers, I left a few songs in the music folder so people can play with it. They are mostly 1 track loop song for testing the sound driver. I could try to put all of them in the example and you could change the song by pressing a button. I may do it in the final examples and I should put simple screen that explain what you can do with it too.

by on (#39065)
Famitracker sound driver RC2 is now available here: file here

I mostly updated the sample to make it easier for people to test.

What is new:
- There is now a screen that explain how to use the sample (feels less empty)
- A sound fx can now be interrupted at any time (suggestion by Roth)
- The sample song data has been included and can now be selected by pressing up

The driver is almost complete. I just need to figure out 2 bugs and after that it will be working 100%.

The first bug can be heard in the the first song at startup. If you play some square sound fx, sometime the channel is not restored properly. I'm not sure what is the cause. Sweep is used in the sound fx. From JSR comment, only register 4003$/4007$ must be restored to stabilize the song. It seems something else is missing.

Second bug (if it's really one), if you play the noise sound fx with the sample song that uses this channel for drum, the sound fx pitch change. I guess it's a bug in my song effect, not the driver.

If some people that do have experience with the APU could test the sample and give me their opinion on what could be the cause of the error, that would help me find it. Looking at the code is not required: just an opinion on the possible cause would help me a lot.

Once those bugs are fixed, we now have a working sound driver for everyone. I don't mind to maintain it. Soon JSR will release a version with VRC6 so more interesting things will be possible. I don't think Nerd Tracker support VRC6 so that would be a great help for people that want to make music with this chip. There is good chances that I will port the new driver too.

by on (#39067)
Good job man : ) I see what you mean about the first bug. I'm not sure why it would do that, but I'm sure some of the more APU knowledgeable folks here could chime in. Very impressive dude, you're doing good work on this, and I'm sure it will come in handy for people for sure!

EDIT: I didn't notice in the old ROM that the different buttons are different channels. With this new ROM, I see that now. Knowing that, the sound effects shouldn't interrupt each other across channels, only in the one channel. So like, if a sound effect is playing in square 1, and a noise effect plays, the square 1 shouldn't get interrupted. However, if a square 1 sound is playing and another square 1 sound happens during that time, then there would be an interrupt in that channel alone.

P.S.: I hope I'm not making your life miserable! : P

by on (#39087)
On the GBA, I've developed a sound effect engine with a primitive priority system: a sound effect doesn't interrupt a sound effect that finishes later. For example, if I play a 30 frame sound effect, and then 17 frames later I try play a 5 frame sound effect on the same channel, the 5 frame sound effect won't play because 5 is less than the 13 frames left in the first sound effect. It can also move a single sound effect between square 1 and square 2 if needed.

Source code in Lockjaw for GBA

by on (#39144)
Roth wrote:
EDIT: I didn't notice in the old ROM that the different buttons are different channels. With this new ROM, I see that now. Knowing that, the sound effects shouldn't interrupt each other across channels, only in the one channel. So like, if a sound effect is playing in square 1, and a noise effect plays, the square 1 shouldn't get interrupted. However, if a square 1 sound is playing and another square 1 sound happens during that time, then there would be an interrupt in that channel alone.


My first goal was to allow the driver to play sound fx because before there was no way to tell it to stop a specific channel so you can play other sounds on it. This goal as been reached but the restoration of the square channels is not perfect yet.

About interrupting sound, I could always make a sample on how to do it but it was not part of my goal since it will not be part of the driver, it is just some code sample using the driver. I don't want to impose my own sound fx format on people, it was never my intention. People should be free to use any format they want, not my specific one. For the music data, that we have no choice thought :)

If I have a chance, I will had what you said to the sample. I will need that functionality later in my game so I can start to experiment on how to approach it.

Tepples@

I will try to check you sample once I have a chance, this will give me some idea on how to approach it. Thanks.

Edit:

I fixed the square channel sweep issue! It feel good to at last figuring this one out. Here the link to RC3: file here

What is left to be done:
- Figure out why noise sample is sometime distorted
- Update sample so you can start multiple sound at same time (Roth's suggestion)

If someone could just give me their opinion on why the sound fx in the noise channel could be affected by the previous one, that would help me figure out this one. That must be something that I didn't read yet in the APU documentation. It's almost like it kept some parameters of the previous sound, don't know why.