Page 1 of 2

FamiTone2 audio library

Posted: Mon Jan 13, 2014 8:37 am
by Shiru
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

Re: FamiTone2 audio library

Posted: Mon Jan 13, 2014 8:41 am
by Dwedit
Dendy support too?

Re: FamiTone2 audio library

Posted: Mon Jan 13, 2014 8:47 am
by Shiru
No.

Re: FamiTone2 audio library

Posted: Mon Jan 13, 2014 11:27 am
by zzo38
Which assemblers are supported, which expansion audio is supported, and can any other formats be imported (such as MML or Csound)?

Re: FamiTone2 audio library

Posted: Mon Jan 13, 2014 12:12 pm
by tepples
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.

Re: FamiTone2 audio library

Posted: Mon Jan 13, 2014 2:06 pm
by Shiru
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.

Re: FamiTone2 audio library

Posted: Tue Jan 14, 2014 7:04 am
by DevEd
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?

Re: FamiTone2 audio library

Posted: Tue Jan 14, 2014 8:11 am
by rainwarrior
If music_play is a fastcall function with one parameter, that parameter is in A. What are you doing with X?

Re: FamiTone2 audio library

Posted: Tue Jan 14, 2014 8:55 am
by thefox
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).

Re: FamiTone2 audio library

Posted: Tue Jan 14, 2014 1:36 pm
by DevEd
What exactly do I need to do in order to get a song to play with cc65?

Re: FamiTone2 audio library

Posted: Tue Jan 14, 2014 2:01 pm
by rainwarrior
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?

Re: FamiTone2 audio library

Posted: Tue Jan 14, 2014 5:09 pm
by Punch
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.

Re: FamiTone2 audio library

Posted: Wed Feb 05, 2014 7:11 am
by JRoatch
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

Re: FamiTone2 audio library

Posted: Wed Feb 05, 2014 11:10 am
by pops
Tempo support makes this a huge improvement. Thank you Shiru!

Re: FamiTone2 audio library

Posted: Fri Feb 07, 2014 12:17 pm
by pops
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.