Best way to get from Famitracker to useable ASM code?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
NeverCameBack
Posts: 31
Joined: Mon Feb 24, 2020 12:22 am

Best way to get from Famitracker to useable ASM code?

Post by NeverCameBack » Sat Mar 28, 2020 11:28 pm

Anyone out there have a good method to take a song written in Famitracker (or another program) and have it export the notes of the song so that you can use them in a game? I've gotten halfway through the NerdyNights music tutorial, and understand the sound engine to some extent. There is a note look-up table, where you store your song as actual notes (G5, G6, E4, etc.), and they will be matched with the 16 bit word that the APU designates for that specific note.

It looks like the Famitracker export gives me the actual bytes (not the notes like G5, G6, E4, etc.).
For every note, it gives me all four bytes (That I would enter into $4000 - $4003 for example).

I'm guessing I need to re-configure the NerdyNights sound engine in order to use the unaltered exported Famitracker file as the source of my music.
Would anyone else agree that this is the fastest way to go from music made in Famitracker to playing it in your NES game?

Pokun
Posts: 1446
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Best way to get from Famitracker to useable ASM code?

Post by Pokun » Sun Mar 29, 2020 3:39 am

Nerdy Nights teaches you how the APU works and how to code your own sound driver. The sound driver you make in that tutorial is similar to how some commercial games does sound, but it's not at all compatible with the one Famitracker uses, and reconfiguring Famitracker is probably not a viable option either. If you are good at coding you could design your own MML-compiler or maybe even a tracker that outputs sound data for your own sound driver if you don't want to compose songs by punching in the raw sound data manually (which isn't that far from doing it in MML though). Or you could use your knowledge of the APU and make a new sound engine that is compatible with Famitracker data.

Actually a lot of people skips learning how to program the APU (it's not that easy after all) and just uses an open sound driver that supports Famitracker data or some other open sound driver like NSD.Lib that supports MML. That is probably the fastest option if you really want to use Famitracker for composing. But since you already learned a lot about the APU you have a lot of more options than a lot of people.

I have never really messed with Famitracker since I have very little experience with trackers, and I prefer MML anyway. Also I prefer to make my own sound driver (based on the one in Nerdy Nights) if I can.

User avatar
dougeff
Posts: 2679
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Best way to get from Famitracker to useable ASM code?

Post by dougeff » Sun Mar 29, 2020 6:08 am

http://wiki.nesdev.com/w/index.php/Tools

Scroll to the bottom for the most popular music drivers (engines). Any of those will do ok.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
NeverCameBack
Posts: 31
Joined: Mon Feb 24, 2020 12:22 am

Re: Best way to get from Famitracker to useable ASM code?

Post by NeverCameBack » Sun Mar 29, 2020 11:49 am

I downloaded NSD.Lib and may try to get working with that once I figure out how to do it with the Famitracker. Even with NSD.Lib, wouldn't you still end up with a file or list of data that you'd have to write into $4000 - $4003, once per "x" number of frames, and again for each instrument? Ultimately that is the only way to get sound working on the NES right? Does the NSD.Lib export somehow do this for you once it is instructed to by your program?

To edit the NerdyNights sound engine, what I'm finding out is the note look-up table provided in NerdyNights is different than whatever lookup table the Famitracker output is expecting to use.

It seems like Famitracker outputs in the following format:

1 = Volume (and Duty Cycle, etc. written to $4000)
2 = The note (as an address in a look-up table that I may have to create myself - This will be mapped to a 16 bit word and written to $4002 & $4003)
3 = Space between sounds
MusicQ2_0.PNG

The look-up table in the NerdyNights tutorial.
The red circled "offsets" from Nerdy NIghts don't seem to match with the Famitracker offsets (#2s in the picture above). The Famitracker off-sets are always a value of 22 or 23 away from the NerdyNights offsets.
MusicQ2_1.PNG
Another problem is that if no volume is specified, like for the 5th note - Famitracker just skips outputting that byte. So that would throw the sound engine off. Same if I use effects - Famitracker will output more bytes in the series, but only for those rows that use an effect. So one row may have 6 bytes, and the next by have 2... It seems hard to deal with because there is no consistency.
I'll post my progress if I get something working.


I downloaded "Lizard music engine".
The engine is written in a ".s" format (not .asm?).
When I open it in my editor, I get 300+ errors when trying to compile... Didn't spend much time trying to figure out why, but it looks promising if all you'd have to do is save your famitracker .fts file in a folder and this sound engine will play the file.

tepples
Posts: 21971
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Best way to get from Famitracker to useable ASM code?

Post by tepples » Sun Mar 29, 2020 12:48 pm

A converter reads FamiTracker's text export and converts the sequence and instrument data into a compact format usable by a driver. Then at runtime, the driver reads the sequence and instrument data and performs the appropriate writes to $4000-$4013 to play it back.

User avatar
NeverCameBack
Posts: 31
Joined: Mon Feb 24, 2020 12:22 am

Re: Best way to get from Famitracker to useable ASM code?

Post by NeverCameBack » Sun Mar 29, 2020 1:27 pm

tepples wrote:
Sun Mar 29, 2020 12:48 pm
A converter reads FamiTracker's text export and converts the sequence and instrument data into a compact format usable by a driver. Then at runtime, the driver reads the sequence and instrument data and performs the appropriate writes to $4000-$4013 to play it back.
So in other words, a converter is a program that takes the Famitracker .asm export, converts it to different text, and saves it as a separate text file that is hopefully formatted to be compiled in assembly.
The "driver" is actually a "sound engine" written in .asm, which can be included in your game .asm code, and when called it will play the converted Famitracker music that is now in a format it can interpret?

I'm not at all a computer whiz, so some of these tools are making my head spin.
The fact that I just got 300 errors when compiling "Lizard music" tells me that maybe it was written without my NESASM3 compiler in mind. I tried asm6 but no luck yet. I believe same error codes.

I also downloaded neslib-master.
I can't even tell what I'm looking at - many unfamiliar folders and files. I can't begin to even understand what I'd do with these. The read-me is all about "rights reserved" and what not. Obviously not for a layman like myself, so maybe I'll stick to NerdyNights until I get a firm grasp on getting music to play the long way.

User avatar
rainwarrior
Posts: 7812
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Best way to get from Famitracker to useable ASM code?

Post by rainwarrior » Sun Mar 29, 2020 1:38 pm

NeverCameBack wrote:
Sun Mar 29, 2020 1:27 pm
The fact that I just got 300 errors when compiling "Lizard music" tells me that maybe it was written without my NESASM3 compiler in mind. I tried asm6 but no luck yet. I believe same error codes.
At the bottom of the Lizard Music page are instructions for building it, and a list of the needed tools.

As you are no doubt learning quickly, "assembly" does not automatically mean NESASM3. There are many different dialects of assembly language, and different assemblers do not understand each other. Lizard Music's assembler is CC65.

If you need to integrate with an NESASM3 project, I recommend finding a different engine that is written for it. However, if you just want to make a ROM that plays a Famitracker tune, the steps in that readme will get you there.

Pokun
Posts: 1446
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Best way to get from Famitracker to useable ASM code?

Post by Pokun » Sun Mar 29, 2020 3:12 pm

Even with NSD.Lib, wouldn't you still end up with a file or list of data that you'd have to write into $4000 - $4003, once per "x" number of frames, and again for each instrument? Ultimately that is the only way to get sound working on the NES right? Does the NSD.Lib export somehow do this for you once it is instructed to by your program?
Yes the APU (Audio Processing Unit, a piece of hardware found inside the NES CPU chip) is the only thing that produces sound, and you program it by writing to the APU registers like you learned at Nerdy Nights. A program that interprets audio data (like a song or sound effect) and writes it to the APU registers in a timed manner to produce music and sound is what we call a sound driver/engine. Every sound driver/engine uses its own format for its data. If you write your own driver you invent your own format for it (that's what Nerdy Nights teaches).

The NSD.Lib sound driver is also written in ca65 so it's not very good if want to use nesasm or asm6. There is ppMCK which is a sound driver written in nesasm and the music data is made using an MML. I like it a lot for making NSF music files, but unfortunately it's not suited to be used in games. It's mainly meant to be used for making NSF music.

unregistered
Posts: 1071
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Best way to get from Famitracker to useable ASM code?

Post by unregistered » Tue Jun 02, 2020 1:08 pm

Hi, no one has mentioned Famitone 2... why? That’s what I’ve been using... it’s excellent to convert Famitracker to nes use. :)

It’s written extremely great by Shiru. Have learned some nifty 6502 tricks from time spent watching/looking-at famitone’s code.

Post Reply