Where do you store/manage the engine for music and why

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Where do you store/manage the engine for music and why

Post by Banshaku »

@DRW

Since I'm using the famitone/famitracker combo, I will test how much famitone can be separated in a fixed bank without issue. For the music, I think switching bank in the nmi seems a reasonable solution.

Now that I received many feedback, I will experiment based on that and see how it goes. I may have questions later if something goes wrong.

Thanks everyone!
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Where do you store/manage the engine for music and why

Post by DRW »

Banshaku wrote:Since I'm using the famitone/famitracker combo
You mean the version where you use the FamiTracker driver for the music and FamiTone for the sound effects?
Not really what I would suggest. The FamiTracker driver is so big and quite CPU-heavy that I wouldn't use it in an actual game.

But if you really want to use such a big driver, you might just as well do the following, given that you use a mapper like MMC-1 where you can configure at runtime which bank is the fixed bank:

You put the FamiTracker and FamiTone driver plus some wrapper functions into bank A.
You put music into bank B or in several different banks.
You put sound effects into bank C.
The regular code is in fixed bank X.

Whenever you need to do something with music and sound effects, you do this:

(The code bank X is now in the fixed bank.)
1. You load bank A into the variable bank.
2. You call a function from bank A that switches which one is the fixed and which is the variable bank.
(Now bank A is the fixed bank and bank X is the variable one.)
3. You load bank B or C into the now new variable bank.
(Bank X is now inactive.)
4. You call any music and sound effects functions, switching between bank B and C as necessary.
5. You put the original code bank X back into the variable bank.
6. You switch which bank is the variable bank and which is the fixed one.
(Bank A is now the variable bank again and bank X is the fixed bank, just like in the beginning.)
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: Where do you store/manage the engine for music and why

Post by Banshaku »

Yes, I'm aware that this driver is heavy :lol:

My current project is used as a place holder for making my engine so once a "real" project will be created, I will remove the code under the sound_driver facade that just call the famitracker/famitone combo code in the back. So I'm not too concerned on the impact on my engine since the goal is not to have something performant but to use my old code/assets and see the performance impact with all those things together. It will be interesting to see where it slow down, when and why.

Once I make some original game I will just target my music for famitone 2 (or any other lightweight driver available at the time) and will be fine.

Because of the size, I will test the "swap the driver in the nmi" pattern to see how it goes and check how you need to organize your code based on that. That will be a lot of new things to learn from it. What you wrote is very close to what I will do so I will keep you example if I have issues with my test.

Thank again for the example!
Post Reply