FamiTone2 problem - not all notes played?

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

Moderator: Moderators

Post Reply
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

FamiTone2 problem - not all notes played?

Post by JoeGtake2 »

Hey all - followed along the readme file to get a song written in FamiTracker into a ROM file. Got it working no problem - the update is at the end of the NMI. There's not much else in the file - was just trying to get the audio to work in a small practice file before loading it into something more complex.

Strangely, the song only seems to play about ever 4th 'beat' or so...I can tell it is loading information from the song - correct instruments, correct basic progression, but as if quantized to whole notes (likely not updating correctly?)

Anyone have this problem / have an idea as to a solution?

Using ASM6 to assemble.

Thanks!

** Alright, I have made a LITTLE progress on this. I redid everything and made a very 'blank' file. No matter what I do, if I put the FamiToneUpdate in the NMI, I get some really funky stuff that does not really resemble the song.

So just for kicks, I moved the FamiToneUpdate into the main loop. This actually works...sort of. The entire first 20 lines seem corrupted...they're just one ugly noise channel playing...and then the song begins and plays as expected, however about every measure, there is an obnoxious and very random triangle wave (I think) tone playing as well that is not in the actual song. I've tracked this down to the noise channel. The noise channel is not working as expected, and seems to be playing a different instrument or something.

So the solution is still not reached - I can not account for the ugly 20 lines of noise nor figure out what is wrong with the noise channel info...

Any thoughts at all?
Dimeback
Posts: 10
Joined: Sat Nov 23, 2013 4:23 pm
Location: Papillion, Nebraska

Re: FamiTone2 problem - not all notes played?

Post by Dimeback »

Hey, I'm also having a problem with FamiTone2. The problem seems to be stemming from the txt2data conversion. I think it's broken. When I load up my song into my program, the triangle channel is completely silent. Pitch sequences aren't working either. I figured it must be a problem with my program's code, so I tried changing some things, nothing works. I then try putting my song into the demo supplied with FamiTone2, same results. The sound effect that uses the triangle channel still works though. I finally try composing a new song in FamiTracker, text export and convert it. I put it in the FT2 demo. Same results. It has to be the txt2data application, I don't know what else could be causing this issue.
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: FamiTone2 problem - not all notes played?

Post by JoeGtake2 »

Dimeback - what assembler are you using? I am using ASM6. My issue is not exactly the same as yours, but maybe there's a connection.
Dimeback
Posts: 10
Joined: Sat Nov 23, 2013 4:23 pm
Location: Papillion, Nebraska

Re: FamiTone2 problem - not all notes played?

Post by Dimeback »

I'm using NESASM, but I'm unsure whether that could be the problem, since the other song in the demo works fine.
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: FamiTone2 problem - not all notes played?

Post by JoeGtake2 »

Gotcha. Well, my plot with it thickens...

Like I said, I'd made a ROM file that simply loaded up and would play the song, just to see how FamiTone2 worked and whatnot. This gave me the ugly 32 steps of ugly noise. Well...just to play out a hypothesis, I added a gamepad function so that the song wouldn't start until I pressed the start button. Here's the wacky thing...that ugly noise channel nonsense was still there, still lasted what I can figure is approximately 32 steps...and then, as figured, no music. When I started the music, the music played absolutely fine, exactly as it should....

This tells me that there is something in the program that is running some junk info before the FamiToneMusicPlay routine is even called.

The weird noise channel funkyness seems to have been a noise channel pitch that this whole process didn't particularly like. I edited that channel with a different note value (same instrument) and it seems to work fine now...strange. There is probably more to this too.

I'll report back with findings. In the meantime, if anyone knows why the file might be playing junk data for 32 steps, even prior to FamiToneMusicPlay being called, I'm stumped!


*** More update - I used the FCEUX frame counter. This ugly noise lasts for 260 frames. No matter what, it lasts for 260 frames. So this is even stranger to me. I took out the FamiToneMusicPlay and used the start button to trigger the init function. What I found was that it was *silent* until I hit the start button and the init data was called. As soon as it was, I got the random noise (even though there was no playing of music). Stranger still, if I wait til, say, 250 frames to press start, I only get noise for those 10 frames. If I wait the full 260 and THEN press start to load the FamiTone inits, there's no funky random noise at all.

*scratches head*

So there is something happening prior to even loading any FamiTone stuff for 260 frames, and that is undetectable until the FamiToneInit is called, which activates whatever and makes whatever is happening for those 260 frames to make that random noise...

hmmm....
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: FamiTone2 problem - not all notes played?

Post by Kasumi »

There's really nothing to go on here. Post a rom, the song in question, source code, something.

With what you've given us, we could say "Famitone2 is broken somewhere." and that doesn't really help you. Or we could say, "Your code is broken somewhere." and that doesn't really help you.

Heck, it could be you using stuff in famitracker that famitone straight up doesn't support. We don't know that you're not. We're guessing.

Just for kicks, try vanilla famitone and see if you get the same thing: viewtopic.php?t=7329

edit: How are you defining your own RAM, and how is famitone2 doing it? It's possible you've overlapped RAM.
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: FamiTone2 problem - not all notes played?

Post by JoeGtake2 »

Here's the ASM. You'll see, it's pretty much completely stripped away...it's just a file to learn FamiTone and try to get something created with FamiTracker to play in an emulator for now.

Btw - this doesn't seem to be an issue with the song file - here it is even replaced with the default file that comes with FamiTone just to check that. Same problem. 260 steps of noise, if the APU becomes enabled (I think I have that right).

Code: Select all


PAD_A		= $01
PAD_B		= $02
PAD_SELECT 	= $04
PAD_START	= $08
PAD_U		= $10
PAD_D		= $20
PAD_L		= $40
PAD_R		= $80	
	
	.enum $0000
	vblankTimer .dsb 1 	
	temp	.dsb 1
	gamepad .dsb 1		
	musicIsPlaying .dsb 1
	.ende
	


	.org $c000
	
RESET:
	SEI				
	LDA #$00
	STA $2000		
	STA $2001		
	STA $4010		
	STA $4015		
	LDA #$40		
	STA $4017		
	CLD				
	LDX #$FF		
	TXS				
	
;5. First vblank wait
	bit $2002
vbwait1:
	bit $2002
	BPL vbwait1
	
;6. Clear all ram excelt $0100
	LDA #$00
	LDX #$00
clrMemLoop:
	STA $0000,x
	STA $0200,x
	STA $0300,x
	STA $0400,x
	STA $0500,x
	STA $0600,x
	STA $0700,x
	LDA #$FE
	STA $0300,x		
	INX
	BNE clrMemLoop
	
		
	
;7. Second vblank
vbwait2:
	bit $2002
	BPL vbwait2
	
;8. Enable NMI
	LDA #%10010000	
	STA $2000

	JMP main
	
	
NMI:
			
	PHA				; push current accum values to stack
	TXA
	PHA
	TYA
	PHA
	
					; set OAL DMA
	LDA #$00
	STA $2003
	LDA #$02
	STA $4014

	
	LDA #%10010000	; PPU setup again
	STA $2000
	LDA #%00011110
	STA $2001
	LDA #$00
	STA $2005		; reset x scroll of screen to 0
	STA $2005		; reset y scroll of screen to 0
	
					;; restore accum values from stack
	PLA
	TAY
	PLA
	TAX
	PLA	
	
	DEC vblankTimer	

	
	RTI				; return from interupt
	
	
	
	
main:
	LDA #$00
	STA musicIsPlaying
	
	LDA #$01
	LDX #<(Song1_music_data)
	LDY #>(Song1_music_data)
	JSR FamiToneInit
mainGameLoop:
	
	LDA vblankTimer
vblankTimerLoop:
	CMP vblankTimer
	BEQ vblankTimerLoop
	JSR FamiToneUpdate
	JSR GamepadCheck
GPCheckStart:
	LDA gamepad
	AND #PAD_START
	BEQ GPCheckDone
	

	LDA musicIsPlaying
	BNE GPCheckDone
	LDA #$01
	STA musicIsPlaying
	LDA #$00
	JSR FamiToneMusicPlay
GPCheckDone:
	JMP mainGameLoop

	
GamepadCheck:
	;strobe the gamepad
	LDA #$01
	STA $4016
	LDA #$00
	STA $4016
	LDX #$08
ReadControllerBytesLoop:
	PHA
	LDA $4016
	AND #%00000011
	CMP #%00000001
	PLA
	ROR
	DEX
	BNE ReadControllerBytesLoop
	STA gamepad
	RTS
	

	
PaletteData:
	.db #$0F, #$0F, #$0F, #$0F, #$0F, #$00, #$10, #$20, #$0F, #$19, #$0A, #$37, #$0F, #$0f, #$0F, #$0F
	.db #$0F, #$0F, #$0F, #$0F, #$0F, #$00, #$10, #$20, #$0F, #$19, #$0A, #$37, #$0F, #$0f, #$0F, #$0F

	
	.org $d000
	.include "famitone2_asm6.asm"
	
	.org $e000
	.include "Song1.asm"
	
	
	.org $fffa
	.dw NMI
	.dw RESET
	.dw 00
	
	
	;.incbin "myChar.chr"

	
See anything glaring here? Thanks!
Attachments
demo.nes
And here is the ROM. This is the default FamiTone tune. Start button will start the music...if you wait until the *noise* is done, it plays fine.
(16.02 KiB) Downloaded 181 times
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: FamiTone2 problem - not all notes played?

Post by thefox »

Your variables overlap the area used by FamiTone2 by default (3 bytes of ZP for scratchpad at $00). Check the beginning of the file famitone2_asm6.asm to move the FamiTone variables, or move your own variables elsewhere.

(The zeropage locations used by FamiTone likely don't need to survive over calls to FamiTone functions, but the problem is that the NMI handler, which modifies $00, could be triggered in the middle of the play routine.)

EDIT: BTW, I hope you have applied the patch from this post: viewtopic.php?p=126131#p126131
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: FamiTone2 problem - not all notes played?

Post by Kasumi »

What thefox suggests is true, but doesn't fix the noise issue. Apparently if FT_SFX_ENABLE is defined, Famitone assumes you definitely want sound effects and you definitely initialized them. (This was SUPER fun to find out, you have no idea. :roll: )

Code: Select all

LDA #$01
   LDX #<(h_music_data)
   LDY #>(h_music_data)
   JSR FamiToneInit
   
   LDX #<(h_music_data)
   LDY #>(h_music_data)
   JSR FamiToneSfxInit
I just did that, where the pointer used for SFX is the same as the regular data. (That sounds totally hacky, and it is. Because just undefining FT_SFX_ENABLE made my music play at the wrong tempo. Which is a problem for another day, I think.)

Edit: Nah the tempo thing was me undefining FT_DPCM_ENABLE which is even mentioned in the readme. So undefine FT_SFX_ENABLE, but not FT_DPCM_ENABLE and then you don't have to do the JSR FamiToneSfxInit and you'll be mostly good.

Other stuff: Don't call FamiToneMusicPlay unless you're changing songs (so call it once before the main loop, and never again if you have just the one song). FamiToneMusicPlay isn't in charge of playing the song (heh), FamiToneUpdate is. Running FamiToneMusicPlay every frame just restarts the song at the beginning, and then FamiToneUpdate will play the first note over and over.

Edit2: Oh, wait. You're not doing that. Still preserving the post, but making this edit to save some face.

Move FamiToneUpdate back to the end of your NMI.
Last edited by Kasumi on Tue Jul 22, 2014 2:12 pm, edited 3 times in total.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: FamiTone2 problem - not all notes played?

Post by thefox »

Kasumi wrote:What thefox suggests is true, but doesn't fix the noise issue.
Yeah I figured it was unlikely to fix this specific issue, but I don't usually like to go hunting for more bugs until the old ones are fixed. :)

Good job finding the cause though. I also thought the cause may have been rogue sound effects given that if START was pressed right when the ROM started, the song "started" from the middle somewhere after the noise was gone.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
JoeGtake2
Posts: 333
Joined: Tue Jul 01, 2014 4:02 pm

Re: FamiTone2 problem - not all notes played?

Post by JoeGtake2 »

Annnnnnnnnnd Kasumi for the win. Haha. Yep, that fixed it! I certainly would not have thought to do that in a million years, and sounds from your post that it was unintuitive for you too? That makes me feel a little bit better about my confusion. Haha.

And The Fox - thanks for pre-empting THAT headache too when I actually put this into a more complex engine. *wipes brow*.

Have I said how much you guys rock yet? haha
Post Reply