Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /storage/content/49/145849/famitracker.com/public_html/forum/classes/dbHandler.php on line 29 FamiTracker
Login:
Menu:
Post: Author:
FamiTracker > General > Source and development > NSF Format Questions Owner: modusponens New post
Page 1 of 1 Sort:  
NSF Format Questions Posted: 2012-07-16 06:13 Reply | Quote
modusponens

Avatar

Member for: 4743 days
Location: Redmond, WA
Status: Offline

#36822
(I'm aware that "NSF format" is redundant. Sorry.)

I'm pretty curious about the NSF format. I have a number of questions about it, but anyone who feels like volunteering information that I'm not specifically asking for would be more than welcome to do so.

So, let me see if I can formulate a decent couple of concrete questions here.

1. What is/are the difference/s between an FTM module and an NSF file? I'm aware that FTM is a FamiTracker-specific format, and is designed to be human-readable when opened in FT, and NSF is more universal and is only "designed" to be understood by an NSF driver or player or an NES emulator or whatever. But what is an NSF file actually like? How does it encode its music and sounds and so forth? And what is an FTM file like? (Lately I've wished that I could open an FTM in Notepad++ and see human-readable code, like MML or something.)

2. Is there any message or signal or event or whatever that gets dispatched when an individual track in an NSF file gets to the end and loops? I ask because I often wonder if it would be possible to make an NSF player that would automatically, by default, take songs that end with instructions to repeat and, after, say, the second time taking the repeat, begin to fade out and then move on to the next track.

3. Similar to the above, does an NSF file "know" anything about its musical structure, like what its tempo is, or how long a "measure" is, or a "frame" or what have you?

Thanks! I've always wondered about this stuff and never gotten around to asking.

Posted: 2012-07-16 07:24  (Last Edited: 2012-07-16 07:37) Reply | Quote
rainwarrior

Avatar

Member for: 4150 days
Location: Canada
Status: Offline

#36823
[url=http://wiki.nesdev.com/w/index.php/NSF]http://wiki.nesdev.com/w/index.php/NSF

An NSF is really just a container for NES software, a lot like an NES ROM. There are very few rules as far as what goes into an NSF. There is very little different between an NES emulator and an NSF player, except there are no capabilities for graphics or input.

There is no part of the NSF that is specifically music data, or any inherent organization of that data. The NSF holds both a machine code program and the data it consumes; the format of that data is completely up to the program. There is no one way to do things, though there are a bunch of common practices (e.g. most NES music engines have some form of envelope macro).

When you export the FTM to NSF, what happens is the NSF is built from two things. The first thing is the machine code program that plays the music data generated by Famitracker, and the second thing is the music data itself.

No, there is no "loop" marker in an NSF, as the program is not required to loop or end, and the NES has no internal concept of looping. There is an NSFE format which contains track times, which can solve this problem (though it is not yet widely supported).

The reason why the NSF format did not have a loop device is that it was intended to contain the music code/data from games, which even though games have looping music, the NES itself doesn't know what a loop is or how it happens (since this is a function of the game's program, not the hardware). Figuring out how each game represents a loop point would be a quite tedious for the NSF ripper; normally when you rip an NSF you have to find the music data and code, separate it from the rest of the game data, and hack it a little bit to fit nicely with the way NSF works. Normally this does not require learning how the music code or data actually works; in merely requires finding where that code and data are and how to make them play the song. Actually going in and figuring out how they work, how notes are represented, how loops are represented, this takes much much longer, and it was never intended that the NSF ripper would have to do such a thing.

Posted: 2012-07-16 08:02 Reply | Quote
modusponens

Avatar

Member for: 4743 days
Location: Redmond, WA
Status: Offline

#36826
Fascinating. So how does an NSF file loop, then? Is is something like a while loop or a goto statement or something like that, but in NES ASM?

Posted: 2012-07-16 08:16  (Last Edited: 2012-07-16 08:20) Reply | Quote
rainwarrior

Avatar

Member for: 4150 days
Location: Canada
Status: Offline

#36828
Well, not really. Playback is driven by a timer that executes at about 60Hz. The playback code is supposed to do its thing, update the NES sound registers (e.g. tell each channel what pitch and volume to play, etc.) then return control to the system and wait for the next timer.

In most cases you have a stream of music data, and you read a little bit of it each frame. You keep track of where you are in it with a pointer (just a number that tells you where the next bit of data to read is). When you read music data that means "loop", you set the pointer back to the loop point and continue reading your music data from there. (This is one way to do it; there are infinite variations on this though.)

While loops and goto statements are devices to get around in code, but a loop is moving around in your music data, so the devices that operate on that are different. However, tou could write a program where all the data is translated directly into code, but this is a very inefficient way to store your music so it is not normal. In this case, though, a loop could maybe be implemented like a goto.

Posted: 2012-07-16 09:06 Reply | Quote
modusponens

Avatar

Member for: 4743 days
Location: Redmond, WA
Status: Offline

#36831
I see, I see. It's kind of like looping through an array with a variable that's keeping track of the index. It does something with the array element at that index and then moves on. Sometimes that something is playing music data, and sometimes it's changing the value of the index variable. Right?

Now, assuming that this analogy is decent, does it automatically know to increment the index variable every time, or do the instructions that get executed at each location tell it where to go next, and in most cases, that simply ends up being the next element in the array?

Posted: 2012-07-16 09:17 Reply | Quote
Necrophageon

Avatar

Member for: 3965 days
Location: Minnesota
Status: Offline

#36833
The simplest solution to the loop-detection problem is to just go with NSFe, yes? Would it be easy to tack such an export feature onto FamiTracker as-is?

_______________________
The only things certain in life are death and uncertainty.
Posted: 2012-07-16 09:47 Reply | Quote
rainwarrior

Avatar

Member for: 4150 days
Location: Canada
Status: Offline

#36834
If you want to make an NSFE from an NSF there is a tool for that. Guide here: [url=http://chipmusic.org/forums/topic/1465/nsfe-nsfextra-thread-tutorial-discussion-etc/]http://chipmusic.org/forums/topic/1465/nsfe-nsfextra-thread-tutorial-discussion-etc/

Or you can just make MP3s or something.

NSFPlay does not currently support NSFE but I plan to add this in the next version. Relatively few NSF players support NSFE, unfortunately.


modusponens, I'm not sure what you're asking at this point. If you want to learn how to write a music engine for NES, maybe try [url=http://nintendoage.com/pub/faq/NA/nerdy_nights_out.html]this tutorial.

Posted: 2012-07-16 09:57 Reply | Quote
Necrophageon

Avatar

Member for: 3965 days
Location: Minnesota
Status: Offline

#36835
Right. MP3, NSFe... Not terribly important in the grand scheme of things. Well it'd be nice to see later down the road, I guess.

_______________________
The only things certain in life are death and uncertainty.
Posted: 2012-07-16 10:19 Reply | Quote
modusponens

Avatar

Member for: 4743 days
Location: Redmond, WA
Status: Offline

#36836
Nah, I'm just curious. I'm in no position to write a music engine, but thanks for the link.

Page 1 of 1 Sort: