Dwedit's Board

Enjoy the board

You are not logged in.

Announcement

Welcome, fellow visitors from other websites!
Whenever you download a file, I'd appreciate it if you posted a nice "Thank You" message, then tell me which site you came from. Thanks.
- Dwedit

#1 2009-05-28 1:08:45 pm

Dwedit
Administrator
From: Chicago
Registered: 2004-12-12
Posts: 1,017
Website

Code to change square wave volume without reset artifacts

I've written a new program that sets the GBC Square Wave channels' frequency and volume independently, without using volume envelopes. Normally, you need to reset the waveform in order to change the volume for the square channels.
I've written a test program that calculates the exact time it's okay to reset the phase of the wave with no artifacts, then performs the write to change the volume at that time.

The program itself isn't anything special, it just plays a chord of two square waves repeatedly, but it sounds correct on hardware, and fails miserably on current builds of VBA. I'm about to revise PocketNES to use this method for sound.

The basic algorithm:
You have the Sound Period for the GB channel
Multiply it by 16
That's your timer frequency (Negate it before you use it as a timer reload value obviously)
Add some "fudge" factor to set the initial value of the timer. I'm using 192.
Whenever you write to the sound register, set the timer's initial value and restart the sound channel at the same time.  Then you can put the correct reload value in after you've added the fudged initial timer value.
When you want to change the sound, enable IRQs for that timer.
The interrupt handler for the timer will wait until the exact instant it should rewrite the sound register and timer. If the timer interrupt triggered too late, wait one more waveform before trying again.


Attachments:
Attachment Icon synced_sound_test.zip, Size: 31,844 bytes, Downloads: 96

"We are merely sprites that dance at the beck and call of our button pressing overlord."

Offline

Registered users online in this topic: 0, guests: 1
[Bot] claudebot

Board footer

Powered by FluxBB
Modified by Visman