Write NES Music In NSF Format

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Write NES Music In NSF Format
by on (#240662)
I've been studying NES music for a few months now and started initially as just being interested in emulkating the sounds using a Korg MS-20, but then became interested in creating NSF files. I'm interested in learning 6502 Aseembly because I want to eventually write my own NES game by hand. I have a background in programming and visual art as well and I have a hungry curiousity. My plan is to take a preexisting NSF file and edit it to make different sounds.

Anything I should be aware of before proceeding? Is this idea fundamentally flawed?
Re: Write NES Music In NSF Format
by on (#240663)
An NSF is really just a ROM. In the case of NSFs that contain audio from commercial game, it's the commercial ROM with the game engine/graphical display/enemy and player logic hacked out, leaving only the music player and data.

Editing an NSF to have new sounds is not fundamentally flawed, but it's not something I'd recommend starting with unless you're already familiar with 6502. It's editing a program you didn't write in compiled or assembled form, meaning no access to source code, comments, and existing blocks of code can't be made longer (because branches/jmps refer to places that were decided when the ROM was assembled). You're dead in the water unless you're already familiar with the language or you're making very small data changes. (You still need 6502 knowledge to find what is data vs what is code.)

FamiTracker: http://famitracker.com/ Lets you create music with a GUI, and can export to NSF. If all you want is an NSF, that's a good path to take.

If you want to learn 6502, there's easy6502 which lets you write/test code right in your browser with no extra software or anything: https://skilldrick.github.io/easy6502/
It's not the greatest teaching material, I've realized, but if you already have some programming background, you should be able to get there with it.
6502 is separate from NES hardware, which is the real hidden boss of any of this. Nerdy Nights: http://nintendoage.com/pub/faq/NA/index ... _out.html#

teaches 6502 as well as NES hardware. Unfortunately some of the zips in the audio sections are dead, and you'd have to find mirrors. If you can make an NES ROM (and truly understand how one is put together), you can make an NSF just by reading about the differences. Again, an NSF is really just an NES ROM focused on audio.

If you really want to write your own music engine, you're welcome to by figuring out how audio works from either nerdy nights, or the wiki: https://wiki.nesdev.com/w/index.php/APU_basics

But there are also several open source ones you can freely use. (Including Famitracker's which basically supports everything NES audio hardware can do already.) https://wiki.nesdev.com/w/index.php/Tools#Music_tools

Unless you want to do some really nuts stuff or do it just for the sake of it, it may not be worth writing your own
music engine. The game itself will be hard enough.

Edit: Oh, hey, I recognize your name. You PM'd me on NES Maker's forum. I did respond, it just ended up taking a while since I was having some computer issues at the time.
Re: Write NES Music In NSF Format
by on (#240664)
If you just want to write music as NSF files, there are a couple ways to go about it.

- If you have experience with LilyPond or MML, or you want a composing interface and workflow that resemble those of programming, Pently or NSD.Lib may be more your style. (Full disclosure: I wrote Pently.)
- If you prefer a tracker interface similar to OpenMPT, j0CC-FamiTracker is the popular tool. It runs in Windows or Wine (except on macOS Catalina). Its sound driver isn't really optimized for use in games, as it uses quite a bit of RAM and there's no built-in support for sound effects, but there exist converters to turn FamiTracker's text export into things that game-oriented drivers (Pently, FamiTone2, FamiTone4, and GGSound) can read. NESmaker in particular currently uses GGSound.
Re: Write NES Music In NSF Format
by on (#240668)
Kasumi wrote:
An NSF is really just a ROM. In the case of NSFs that contain audio from commercial game, it's the commercial ROM with the game engine/graphical display/enemy and player logic hacked out, leaving only the music player and data.

Editing an NSF to have new sounds is not fundamentally flawed, but it's not something I'd recommend starting with unless you're already familiar with 6502. It's editing a program you didn't write in compiled or assembled form, meaning no access to source code, comments, and existing blocks of code can't be made longer (because branches/jmps refer to places that were decided when the ROM was assembled). You're dead in the water unless you're already familiar with the language or you're making very small data changes. (You still need 6502 knowledge to find what is data vs what is code.)

FamiTracker: http://famitracker.com/ Lets you create music with a GUI, and can export to NSF. If all you want is an NSF, that's a good path to take.

If you want to learn 6502, there's easy6502 which lets you write/test code right in your browser with no extra software or anything: https://skilldrick.github.io/easy6502/
It's not the greatest teaching material, I've realized, but if you already have some programming background, you should be able to get there with it.
6502 is separate from NES hardware, which is the real hidden boss of any of this. Nerdy Nights: http://nintendoage.com/pub/faq/NA/index ... _out.html#

teaches 6502 as well as NES hardware. Unfortunately some of the zips in the audio sections are dead, and you'd have to find mirrors. If you can make an NES ROM (and truly understand how one is put together), you can make an NSF just by reading about the differences. Again, an NSF is really just an NES ROM focused on audio.

If you really want to write your own music engine, you're welcome to by figuring out how audio works from either nerdy nights, or the wiki: https://wiki.nesdev.com/w/index.php/APU_basics

But there are also several open source ones you can freely use. (Including Famitracker's which basically supports everything NES audio hardware can do already.) https://wiki.nesdev.com/w/index.php/Tools#Music_tools

Unless you want to do some really nuts stuff or do it just for the sake of it, it may not be worth writing your own
music engine. The game itself will be hard enough.

Edit: Oh, hey, I recognize your name. You PM'd me on NES Maker's forum. I did respond, it just ended up taking a while since I was having some computer issues at the time.


Hi Kasumi. Yes I do remember you too. I don't remember where we left off with our conversation though. I got annoyed with NESmaker and went on my own journey that lead me back to writing a NES game but instead focusing on sound first. After I posted here, I did look at Nerdy Nights again. I am going to try to get through the Nerdy Nights material again next. I got distracted by this whole Commodore 64 and sound synthesis tangent. Long story short I'm back to NESDev.

I think I am going to start with the Nerdy Nights Sound section this time and see how far I get. Will come back with questions.
Re: Write NES Music In NSF Format
by on (#240669)
tepples wrote:
If you just want to write music as NSF files, there are a couple ways to go about it.

- If you have experience with LilyPond or MML, or you want a composing interface and workflow that resemble those of programming, Pently or NSD.Lib may be more your style. (Full disclosure: I wrote Pently.)
- If you prefer a tracker interface similar to OpenMPT, j0CC-FamiTracker is the popular tool. It runs in Windows or Wine (except on macOS Catalina). Its sound driver isn't really optimized for use in games, as it uses quite a bit of RAM and there's no built-in support for sound effects, but there exist converters to turn FamiTracker's text export into things that game-oriented drivers (Pently, FamiTone2, FamiTone4, and GGSound) can read. NESmaker in particular currently uses GGSound.


Thanks tepples. I will investigate these routes. I plan to start with Nerdy Nights sound section and see where it takes me.
Re: Write NES Music In NSF Format
by on (#240670)
FWIW I had more luck reading the nesdev wiki than the nerdy nights tutorial.

One thing to note is that many APU features aren't necessary. You don't need to use envelopes and sweep. Many sound engines don't.
Re: Write NES Music In NSF Format
by on (#240671)
pubby wrote:
FWIW I had more luck reading the nesdev wiki than the nerdy nights tutorial.

One thing to note is that many APU features aren't necessary. You don't need to use envelopes and sweep. Many sound engines don't.


Hi pubby. Whats wrong with the Nerdy Nights tutorial? I actually would like to use all of the availables features in the APU and learn them well. I want to make really good and interesting sound. I got into sound synthesis recently and I am currently focusing on building on that knowledge with the NES.

Likely I would end up working through the Nerdy Nights tutorials and then referencing wikis as needed. All tools can be useful.
Re: Write NES Music In NSF Format
by on (#240672)
Oh there's nothing wrong with Nerdy Nights. It's a good tutorial! But if you find it's not your style, try the wiki instead.

The features I mentioned are somewhat redundant. To get started, all you really need to know is pitch, volume, and duty. Envelopes and sweep can be done in software by writing to pitch, volume, and duty. You typically don't need to use the built-in hardware implementation to get envelopes and sweeps.
Re: Write NES Music In NSF Format
by on (#240688)
davidpgil wrote:
I actually would like to use all of the availables features in the APU and learn them well.


Once you have a little familiarity with the register bits, it might be enlightening to play some NSF files in a player that lets you view the audio registers. GNSF and my own NSF player (http://membler-industries.com/SNES/) are the only 2 that come to mind. What you'll see is that only the very earliest games fully used the hardware effects. Here's my own review of the lesser-used ones.

envelope generator: the distinctive sound of early NES games. The fadeout is linear and loud. One could easily recreate it with a software envelope if that sound was really wanted, and that's the way to go. Dragon Quest/Warrior maybe tried the hardest to use it, it plays held notes before enabling the envelope generator to fade them out. I haven't seen anything else try to do that.

envelope looped mode: Weird! When you want something that sounds like tremolo picking, and you want it full volume, there it is. Magmax underground section comes to mind, and the Mappy theme.

sweep: It has the advantage of not resetting the pulse phase, as a $4003/$4007 write does. It's normally for sfx though, Double Dragon is the only game I know of that uses it in music for pitch bends, and it's excellent there. It seems easier to manually control the freq vs using sweep hardware though. If you play the sweep unit in both channels with the same settings, you'll get phasing (boss alarm in The Guardian Legend)

DMC IRQ: Criminally underused feature. See http://slack.net/~ant/misc/nes-saw/
Re: Write NES Music In NSF Format
by on (#240834)
davidpgil wrote:
Whats wrong with the Nerdy Nights tutorial? I actually would like to use all of the availables features in the APU and learn them well. I want to make really good and interesting sound. I got into sound synthesis recently and I am currently focusing on building on that knowledge with the NES.

Likely I would end up working through the Nerdy Nights tutorials and then referencing wikis as needed. All tools can be useful.
For me the wiki was way too technical to get anything useful out of it when I started out. The Nerdy Nights sound tutorial however teaches you all you need to know in layman terms (except for the DPCM channel, but you can learn that later), including software envelopes and a load of other stuff. I also used both the wiki and Nerdy Nights for understanding everything though.

Only problem with the Nerdy Nights might be that although it's beginner level it gets a bit more complicated than the original Nerdy Nights tutorial that just teaches you how to make Pong. It took me longer to understand everything than the Pong tutorial did. On the other hand, besides teaching how to make a sound engine, it also teaches you how to make a system for buffering background characters as a side effect of making the sound player menu. That's something you never learn in the Pong tutorial, and is essential in a game.