FamiTone2 audio library

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

FamiTone2 audio library

Post by Shiru » Mon Jan 13, 2014 8:37 am

Download FamiTone2

The original FamiTone got a major update, with data formats change and player and tools code rewrite. The most important improvements are:

- Built-in FamiTracker text export support instead of the old TextExporter plug-in
- Faster code
- Smaller data size
- Tempo support
- Full NTSC/PAL support, with pitch and speed compensation

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: FamiTone2 audio library

Post by Dwedit » Mon Jan 13, 2014 8:41 am

Dendy support too?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Re: FamiTone2 audio library

Post by Shiru » Mon Jan 13, 2014 8:47 am

No.

zzo38
Posts: 1050
Joined: Mon Feb 07, 2011 12:46 pm

Re: FamiTone2 audio library

Post by zzo38 » Mon Jan 13, 2014 11:27 am

Which assemblers are supported, which expansion audio is supported, and can any other formats be imported (such as MML or Csound)?
[url=gopher://zzo38computer.org/].[/url]

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

Re: FamiTone2 audio library

Post by tepples » Mon Jan 13, 2014 12:12 pm

zzo38 wrote:Which assemblers are supported
From readme.txt:
text2data outputs data in NESASM format by default, you can use -ca65 or -asm6 switches to get output for these assemblers.
From text2data.cpp:

Code: Select all

#define OUT_NESASM	0
#define OUT_CA65	1
#define OUT_ASM6	2
which expansion audio is supported
Doesn't look like any. From text2data.cpp:

Code: Select all

#define MAX_PACKED_PATTERNS	(5*MAX_ORDER*MAX_SUB_SONGS)
That covers pulse, pulse, triangle, noise, and DPCM.

From nsf2data.cpp:

Code: Select all

	if(nsf_data[0x7b])
	{
		printf("Expansion chips are not supported\n");
		free(nsf_data);
		return 1;
	}
Let me know which expansion audio is supported by any all-new-parts flash cartridge.
and can any other formats be imported (such as MML or Csound)?
I see something that appears designed for sound effects in FamiTracker NSFs, but not much more.

Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Re: FamiTone2 audio library

Post by Shiru » Mon Jan 13, 2014 2:06 pm

Is it really necessary to quote random code pieces and make guesses when everything is clearly stated in the readme.txt, and is not changed since the original version? Please understand, I don't need any docs by myself, I spend quite some time and effort to write them for your convenience. Please read them.
line 14 of the readme.txt wrote:Expansion sound chips are not supported.
'How to use the library' section wrote:The main version of the FamiTone2 is written in NESASM. There are
versions for CA65 and ASM6 assemblers included in the package as well.
zzo38 wrote:can any other formats be imported (such as MML or Csound)
No. It is clearly explained in the readme.txt which formats are supported and how it all works. It is possible to use other import sources, but you'll have to write your own converter, which is a good half of the whole thing.

User avatar
DevEd
Posts: 51
Joined: Thu Dec 12, 2013 4:00 pm
Contact:

Re: FamiTone2 audio library

Post by DevEd » Tue Jan 14, 2014 7:04 am

I'm having trouble getting this to work with cc65. I have sound effects working fine, but I can't get music to work at all.

This line of code is what *SHOULD* play the music:

Code: Select all

if(controllerInput&PAD_START) music_play(music_test);
Here is the function definition for music_play (I DID modify it slightly):

Code: Select all

_music_play:
	stx <PTR
	tax
	ldy <PTR
	jmp FamiToneMusicPlay
Is there something I'm missing?
You know, the DevSound guy.

There are two kinds of people in this world: those who are convinced there are two kinds of people in this world, and those who aren't. - Unknown

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

Re: FamiTone2 audio library

Post by rainwarrior » Tue Jan 14, 2014 8:11 am

If music_play is a fastcall function with one parameter, that parameter is in A. What are you doing with X?

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: FamiTone2 audio library

Post by thefox » Tue Jan 14, 2014 8:55 am

The confusion maybe stems from the fact that in FamiTone1, FamiToneMusicStart took a 16-bit parameter (pointer to the music data), whereas in FamiTone2 FamiToneMusicPlay takes a single byte (sub song number).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

User avatar
DevEd
Posts: 51
Joined: Thu Dec 12, 2013 4:00 pm
Contact:

Re: FamiTone2 audio library

Post by DevEd » Tue Jan 14, 2014 1:36 pm

What exactly do I need to do in order to get a song to play with cc65?
You know, the DevSound guy.

There are two kinds of people in this world: those who are convinced there are two kinds of people in this world, and those who aren't. - Unknown

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

Re: FamiTone2 audio library

Post by rainwarrior » Tue Jan 14, 2014 2:01 pm

Your _music_play function is broken, is what I was saying. I don't know where you got that from, as it does not appear to be part of FamiTone2.

The first question is whether it is declared correctly. If it takes one parameter in A, it should be declared like this:

Code: Select all

extern void __fastcall__ music_play(unsigned char a);
The second problem is the contents of your _music_play routine. There is no useful value in X when it music_play is called from C, so storing it is counter-productive. Similarly, I don't know what you're doing with X or Y before you call FamiToneMusicPlay, which according to the readme takes a single parameter in A. Your _music_play should just look like this:

Code: Select all

_music_play:
    jmp FamiToneMusicPlay
The rest of how to use it is in the readme, from what I can tell. Did you initialize it?

User avatar
Punch
Posts: 345
Joined: Sat Feb 16, 2013 11:52 am

Re: FamiTone2 audio library

Post by Punch » Tue Jan 14, 2014 5:09 pm

Yes, thanks! I really didn't have any problems with version 1 but I appreciate the work that went in the text export support and better performance.
This is a block of text that can be added to posts you make. There is a 255 character limit.

JRoatch
Formerly 43110
Posts: 388
Joined: Wed Feb 05, 2014 7:01 am
Location: us-east
Contact:

Re: FamiTone2 audio library

Post by JRoatch » Wed Feb 05, 2014 7:11 am

With these changes, Dendy can be supported by separating out tempo and pitch. Note the different input spec of A for FamiToneInit

Code: Select all

--- famitone2.s	2014-02-03 11:15:22.886592429 -0500
+++ famitone2-edit.s	2014-02-03 11:17:29.781515804 -0500
@@ -209,7 +209,7 @@
 
 ;------------------------------------------------------------------------------
 ; reset APU, initialize FamiTone
-; in: A   0 for PAL, not 0 for NTSC
+; in: A   bit 7 is frame rate. bit 6 is pitch. 0 for PAL, 1 for NTSC
 ;     X,Y pointer to music data
 ;------------------------------------------------------------------------------
 
@@ -221,10 +221,7 @@
 	sty <FT_TEMP_PTR_H
 
 	.if(FT_PITCH_FIX)
-	tax						;set SZ flags for A
-	beq @pal
-	lda #64
-@pal:
+	and #192				; mask out other bits
 	.else
 	.if(FT_PAL_SUPPORT)
 	lda #0
@@ -374,8 +371,8 @@
 	bne @set_channels
 
 
-	lda FT_PAL_ADJUST		;read tempo for PAL or NTSC
-	beq @pal
+	bit FT_PAL_ADJUST		;read tempo for PAL or NTSC
+	bpl @pal
 	iny
 	iny
 @pal:
@@ -580,6 +577,7 @@
 	adc FT_CH1_NOTE_OFF
 	.if(FT_PITCH_FIX)
 	ora FT_PAL_ADJUST
+	and #127				;zero out bit 7
 	.endif
 	tax
 	lda FT_CH1_PITCH_OFF
@@ -613,6 +611,7 @@
 	adc FT_CH2_NOTE_OFF
 	.if(FT_PITCH_FIX)
 	ora FT_PAL_ADJUST
+	and #127				;zero out bit 7
 	.endif
 	tax
 	lda FT_CH2_PITCH_OFF
@@ -646,6 +645,7 @@
 	adc FT_CH3_NOTE_OFF
 	.if(FT_PITCH_FIX)
 	ora FT_PAL_ADJUST
+	and #127				;zero out bit 7
 	.endif
 	tax
 	lda FT_CH3_PITCH_OFF
@@ -1010,8 +1010,8 @@
 
 	.if(FT_PITCH_FIX)
 
-	lda FT_PAL_ADJUST		;add 2 to the sound list pointer for PAL
-	bne @ntsc
+	bit FT_PAL_ADJUST		;add 2 to the sound list pointer for PAL tempo
+	bmi @ntsc
 	inx
 	bne @no_inc1
 	iny
Edit: typo
Last edited by JRoatch on Wed Feb 05, 2014 11:15 am, edited 1 time in total.

pops
Posts: 91
Joined: Sun Apr 04, 2010 4:28 pm

Re: FamiTone2 audio library

Post by pops » Wed Feb 05, 2014 11:10 am

Tempo support makes this a huge improvement. Thank you Shiru!

pops
Posts: 91
Joined: Sun Apr 04, 2010 4:28 pm

Re: FamiTone2 audio library

Post by pops » Fri Feb 07, 2014 12:17 pm

I translated the FamiTone2 library to the assembler format used by Ophis. Because Ophis does not support conditional compilation (ifdef, etc.), I simply left all features enabled.

Total library size is 1632 bytes, including 259 bytes of data. Song data for my project is 20% smaller than the previous version of FamiTone.
Attachments
famitone2ophis.asm
(27.16 KiB) Downloaded 180 times

Post Reply