FamiTone - audio library (release)

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

Moderator: Moderators

Wave
Posts: 110
Joined: Mon Nov 16, 2009 5:59 am

Post by Wave »

I think there's a bug on Famitone, at least on CA65 port.
On line 781: jsr FamiToneSampleStartS
Shouldn't this be a jmp like on line 776?
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Seems it is just an unnecessary line, added by some reason. It still works the same.
User avatar
MottZilla
Posts: 2837
Joined: Wed Dec 06, 2006 8:18 pm

Post by MottZilla »

I'll have to try this out when I get a chance. The demo ROM sounds nice.
Wave
Posts: 110
Joined: Mon Nov 16, 2009 5:59 am

Post by Wave »

Shiru wrote:Seems it is just an unnecessary line, added by some reason. It still works the same.
I think it will do twice FamiToneSampleStartS.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Didn't noticed it is jsr, not jmp. Well, ManicGenius probably had reasons to add this. It wasn't like this in the original version.
ManicGenius
Posts: 42
Joined: Fri Jul 09, 2010 5:37 pm

Post by ManicGenius »

Shiru wrote:Didn't noticed it is jsr, not jmp. Well, ManicGenius probably had reasons to add this. It wasn't like this in the original version.
Dunno. My current version has progressed a little beyond what I submitted, uses structs n' such. However I'm moving my code over to NESHLA so anyone who want's to improve/fix the CA65 version go ahead. TBH I just tried to port it as fast as possible and potentially massacred the code in the process.

However that JSR I think is definitely a bug. Technically it looks like it could just fall-through.
ManicGenius
Posts: 42
Joined: Fri Jul 09, 2010 5:37 pm

Post by ManicGenius »

Just tested Famitone on a PowerPak. Works fantastically on real NES NTSC hardware at least.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

I've got a problem that not all the sound effects converts correctly, sometimes converter can't detect end of an effect (marked with Zxx). Also, this problem varied between NSFs made with different FamiTracker versions, so I decided to change detection method.

Now you should use C00 effect in end of every effect (C00 just stops playback). Converter changed, archive is updated.
UncleSporky
Posts: 388
Joined: Sat Nov 17, 2007 8:44 pm

Post by UncleSporky »

I'm trying to convert Famitone to get it to work in asm6. Admittedly I am probably not the best person for this job, as I'm rusty with this stuff and also was never that smart to begin with. :P

There were four main things that stopped asm6 from compiling.

First was the labels - they're all meant to be local, but asm6 handles its local labels differently. I went through and added + and - to the beginning of all labels accordingly, and I think this problem is fixed.

Secondly, lines like lda [FT_TEMP],y resulted in a "label not found" error. I changed the brackets to parenthesis and the errors stopped. Still not sure whether this was a mistake because I'm having trouble prior to reaching one of these statements...

Third was NESASM's LOW() function. From what I can tell, asm6's version of this is the < operator, so I replaced instances of LOW with <. However, this may not be working correctly.

I tried to get Famitone working with an existing program of mine, but upon calling FamiToneInit, the program seems to hang. When I step through it, it gets to the line ldx #<(FT_CHANNELS) which evaluates to ldx #<($600+6)...and for some reason, this loads the value 6 into x, even though that RAM location is empty and I'd expect 0 from the low bits.

The final problem I had was that there were two lines with a "value out of range" error. This one from the envelopeStep routine:
-readByte
lda ($40),y ;read byte of the envelope
iny ;increase pointer
ora #0
bpl +special ;if it is below 127, it is special code
clc ;otherwise it is an output value+192
adc #-192
*** Value out of range.

sta $0600+0,x
tya
sta $0600+4,x ;remember the pointer and return
rts
And this one from FamiToneSfxUpdate:
-readByte
lda ($40),y ;read byte of effect
iny
cmp #$10 ;if it is less than $10, it is register write
bcc +getData
cmp #$ff ;if it is $ff, it is end of the effect
bcs +eof
adc #-$10 ;otherwise it is number of repeats +$10
*** Value out of range.
Since they both appeared to be attempting to add a negative, I just changed each into subtracting a positive and that eliminated the error. I haven't gotten far enough that I can test this yet to make sure it's not causing any problems.

---

As a side note to this, using text2data to convert a song to asm6 format resulted in errors for me. The resulting file contained references to a nonexistent .env_default, when I'm sure it meant @env_default:
...

@ins
dw @env_default,@env_default,@env_default
db $30,$00
dw @env_vol0,@env_arp2,.env_default
db $30,$00
dw @env_vol1,.env_default,@env_pitch0
db $70,$00
dw @env_vol2,@env_arp0,.env_default
db $70,$00
dw @env_vol2,@env_arp1,.env_default
db $70,$00
dw @env_vol3,.env_default,.env_default
db $30,$00
dw @env_vol4,@env_arp0,.env_default
db $70,$00
dw @env_vol4,@env_arp1,.env_default
db $70,$00
dw @env_vol5,.env_default,.env_default
db $30,$00

...
Possibly a bug in text2data? It compiled fine after I changed them to @s instead of .s.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Actually, FamiTone is full of minor bugs (mostly in tools, not in the sound code), which aren't found and not fixed yet because no one used it in an actual project.

Today I'm fixed a problem with sound effects converter, some bugs in TextExporter (weren't noticeable on old computer by some reason), and a bug in text2data reported by UncleSporky above.

I still use NESASM, so don't know about Asm6 much. LOW/HI functions are value&255 and value/256. So, LOW($600+6) is $06.
UncleSporky
Posts: 388
Joined: Sat Nov 17, 2007 8:44 pm

Post by UncleSporky »

That must not be the problem at all, then...I'll keep looking and see if I can get it to work.

Specifically what is happening now is that my main loop is supposed to spin on $2002, waiting for vblank. After I add in a line to call FamiToneInit during the regular initialization, after I turn IRQs on and read $2002 once it jumps to IRQ (which is just rti) and stays there forever.

Definitely something due to my own ignorance, I'll keep at it.

EDIT: Disabling IRQs gets past this, but I'd rather fix the problem than leave it like that. I'm assuming it's DMC related, though I thought I turned off Famitone's DMC related code.

In any case, in a few minutes I should be able to see if I can at least get the music playing.

EDIT: Awesome, I got the music working! Except my entire background is now bouncing up and down for some reason. Ah well.
Last edited by UncleSporky on Sun May 08, 2011 6:28 pm, edited 1 time in total.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

One common cause of endless IRQs like that is an APU frame IRQ that isn't getting acknowledged. To disable that:

Code: Select all

  lda #$40
  sta $4017
UncleSporky
Posts: 388
Joined: Sat Nov 17, 2007 8:44 pm

Post by UncleSporky »

Thanks a lot tepples, that was all it took to stop the IRQs. I'm surprised I never saw that in anyone's startup code before.

EDIT: My screen was jumping to the music because I was updating Famitone during vblank instead of the main loop.

Here is my port of FamiTone to asm6.

Thank you so much for this tool Shiru, it's going to be extremely helpful to people like me who don't want to mess with the nitty gritty of audio and just want to play some music and sound effects.
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Post by Shiru »

Another bug in sound effects converter fixed, file is updated.

Link to UncleSporky's Asm6 port added to the first post of this thread.
UncleSporky
Posts: 388
Joined: Sat Nov 17, 2007 8:44 pm

Post by UncleSporky »

As the source states, all the FamiTone variables take up 112 + (15 * the number of SFX streams). By default (with 4 streams) this should be 172 bytes, which means that by default the first available byte after FamiTone's data is $3AC. Correct?

It's just not always immediately obvious what the limits are by checking a debugger. Just wanted to confirm it before I go changing stuff and end up with hard-to-fix bugs.
Post Reply