FamiTone4.1 song glitches if played after other song, if played first sounds fine?

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
samcan
Posts: 13
Joined: Fri May 29, 2020 9:06 pm

FamiTone4.1 song glitches if played after other song, if played first sounds fine?

Post by samcan » Sun Jul 19, 2020 6:51 pm

I'm using nesdoug's FamiTone4.1 (https://github.com/nesdoug/famitone4.1) with asm6 and having weird problems with the music I'm exporting from FamiTracker 0.4.6. In my project file I had multiple songs. When I loaded the second song in my game after playing the first (for the title screen), there was a weird issue where it sounded like the Pulse 2 and Triangle channels were slightly offset from the Pulse 1, creating an "off-beat" effect which I hadn't written.

I thought that perhaps I had some error in one of the songs in my project which was causing my second song to load improperly. So I deleted all of the songs in the project except for the first two to try to create a minimum-size sample—the first one, which had loaded correctly, and the second one, which was exhibiting the off-beat effect. Then when I load the second song, it doesn't even play the second song, just a long tone.

But, if I load the second song first, it plays properly, with no glitches or off-beat effects. This seems to imply that there's a problem with how I'm loading, playing, and stopping the songs, correct?

My engine logic is in my NMI thread. I start playing a song by calling "FamiToneMusicPlay" in a "draw new screen" routine that's called during NMI. Then, on the next NMI, at the end of NMI, I call "FamiToneUpdate."

If the user presses a button that indicates to my engine that we need to switch to a different game state, I call "FamiToneMusicStop." Once I call FamiToneMusicPlay, do I need to call FamiToneUpdate in that same NMI?

If my NMI is too long so I'm getting another NMI called partway through, how can I tell? I'm using Mesen. There is only very minimal logic being called when I'm playing music, so I don't think I'm running out of NMI cycles, but who knows.

Neither of these two songs are using any effects. The only envelope used by the instruments is the "volume" envelope. And these two songs only use the Pulse 1, Pulse 2, and Triangle channels.

I've confirmed that the memory page is initialized to zero; on the forums, someone said they had issues if the memory wasn't initialized to zero.

The usage notes for FamiTone4.1 say "use volume column for Square 1, Square 2, and Noise Channels." Perhaps this means that the volume envelope isn't supported and I should only use the volume column?

My cut-down FamiTracker project is attached. Thanks!
Attachments
audio_data_test.ftm
(6.39 KiB) Downloaded 21 times

samcan
Posts: 13
Joined: Fri May 29, 2020 9:06 pm

Re: FamiTone4.1 song glitches if played after other song, if played first sounds fine?

Post by samcan » Sun Jul 19, 2020 7:18 pm

So I looked at the demo source code for the original FamiTone2 v.1.15 (there's no demo source code for FamiTone4.1). Interestingly, even though the README says that we only need to call "FamiToneInit" once, the demo source code calls it every single time before playing a song.

I tried this, adding FamiToneInit calls before my FamiToneMusicPlay calls, and that seems to fix the issue with the second song. I wonder if I'm misreading the documentation, or there's some other "best practices" way I'm supposed to do this, but it is at least now playing correctly.

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

Re: FamiTone4.1 song glitches if played after other song, if played first sounds fine?

Post by dougeff » Sun Jul 19, 2020 8:21 pm

Your songs work fine on my machine.
The usage notes for FamiTone4.1 say "use volume column for Square 1, Square 2, and Noise Channels." Perhaps this means that the volume envelope isn't supported and I should only use the volume column?
Famitone 4.1 supports Volume, Arpeggio, and Pitch Envelopes. Pitch can't bend more than -64 to 63 from the base note.

You can (and should) have 1 entry in the Duty Cycle Envolope for Instruments for Pulse 1+2 and Noise Channels.
nesdoug.com -- blog/tutorial on programming for the NES

samcan
Posts: 13
Joined: Fri May 29, 2020 9:06 pm

Re: FamiTone4.1 song glitches if played after other song, if played first sounds fine?

Post by samcan » Sun Jul 19, 2020 9:09 pm

dougeff wrote:
Sun Jul 19, 2020 8:21 pm
Your songs work fine on my machine.
The usage notes for FamiTone4.1 say "use volume column for Square 1, Square 2, and Noise Channels." Perhaps this means that the volume envelope isn't supported and I should only use the volume column?
Famitone 4.1 supports Volume, Arpeggio, and Pitch Envelopes. Pitch can't bend more than -64 to 63 from the base note.

You can (and should) have 1 entry in the Duty Cycle Envolope for Instruments for Pulse 1+2 and Noise Channels.
Thanks dougeff! So if I'm understanding you and http://famitracker.com/wiki/index.php?title=Duty_cycle correctly, I should set a Vxx effect for those three channels for every song?

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

Re: FamiTone4.1 song glitches if played after other song, if played first sounds fine?

Post by dougeff » Sun Jul 19, 2020 9:14 pm

No.

When you click on an instrument, a box pops up. The bottom one is Duty Cycle. Click that, and create an envelope with one entry.
nesdoug.com -- blog/tutorial on programming for the NES

samcan
Posts: 13
Joined: Fri May 29, 2020 9:06 pm

Re: FamiTone4.1 song glitches if played after other song, if played first sounds fine?

Post by samcan » Sun Jul 19, 2020 9:17 pm

dougeff wrote:
Sun Jul 19, 2020 9:14 pm
No.

When you click on an instrument, a box pops up. The bottom one is Duty Cycle. Click that, and create an envelope with one entry.
That's what I get for not being at my computer and just responding from memory as to the options available in the instrument editor. :-D

I see a "Duty / Noise" envelope in FamiTracker 0.4.6; I presume this is what you're referring to, as the instruments FamiTracker page confirms that it "Sets the duty cycle and noise mode."

Post Reply