It is currently Mon May 20, 2019 11:26 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu May 09, 2019 5:33 am 
Offline
User avatar

Joined: Fri Jan 24, 2014 9:05 am
Posts: 187
Location: Hungary
Hi there,

I've had yet another idea to cram more into my DMC IRQ-based PCM music player, since a scheduler meant to handle game logic tasks during a wait inside the IRQ handler proved to be of very little added efficiency to a game. Since I need to wait more than 100 cycles / IRQ, I thought I could use a trick to continously reset the phase of a pulse channel by writing the high period register to continously output the first 1-step of the 75% duty waveform, letting me use the channel as a 4-bit DAC via the volume register. I would use this to play sound effects without having to software mix them with the music being played via $4011.
However, while the wave sequence is reset when the write happens, the timer is not from what I gather? That of course means that no matter what, I will get a "cut" in the sound every 2049 APU cycles (when the divider underflows and reloads from the period), which when aligned the worst, should persist for the time between two phase resets. This should be 432 CPU cycles, or possibly more (432 + 512 ± 1) if an OAM DMA happens to block the IRQ at the worst possible time as well.

Is there any way to ensure that the waveform remains completely flatlined, volume changes excluded (e.g.: by changing back-and-forth between two duty cycles at the precise moment) to make this work without added distortion?


Top
 Profile  
 
PostPosted: Thu May 09, 2019 10:12 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7711
Location: Chexbres, VD, Switzerland
I think if you write to $4003/$4007 the phase will reset, so doing this "constantly" will ensure a DC output, leading to the effect you want. I'm not sure of the phase, either duty cycles %00, %01, %10 will work and %11 won't work, or it's the oposite. This is actually the only difference between duty cycles %01 and %11. Someone more knownledgeable about the APU, or experiment on real hardware, should be able to answer this question.

The reason this "trick" was never experimented used is because this has basically no advantage over using $4011. Even mixing different things into $4011 should be as fast as using the pulse channels for this, as it's a simple addition operation.


Top
 Profile  
 
PostPosted: Thu May 09, 2019 11:07 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 8366
Location: Seattle
za909 wrote:
Is there any way to ensure that the waveform remains completely flatlined, volume changes excluded (e.g.: by changing back-and-forth between two duty cycles at the precise moment) to make this work without added distortion?
No, there's no "stop the pulse channel" to get the same DAC that people have tricked out of the other PSGs.

The best I think you'll manage is to set the pulse channel to its maximum frequency, and hope that people won't be bothered by the 12.4kHz modulation noise, or as you found, having to write to the phase reset not less often than every 2049 APU cycles.


Top
 Profile  
 
PostPosted: Fri May 10, 2019 1:11 am 
Offline
User avatar

Joined: Fri Jan 24, 2014 9:05 am
Posts: 187
Location: Hungary
Bregalad wrote:
I think if you write to $4003/$4007 the phase will reset, so doing this "constantly" will ensure a DC output, leading to the effect you want. I'm not sure of the phase, either duty cycles %00, %01, %10 will work and %11 won't work, or it's the oposite. This is actually the only difference between duty cycles %01 and %11. Someone more knownledgeable about the APU, or experiment on real hardware, should be able to answer this question.

The reason this "trick" was never experimented used is because this has basically no advantage over using $4011. Even mixing different things into $4011 should be as fast as using the pulse channels for this, as it's a simple addition operation.


Yes, the %11 duty will play a bit sequence of 1 0 0 1 1 1 1 1, all the others start with a 0 (so the click heard when crossing an 8-bit period boundary is much more noticeable here than it is for the other duty cycles). It has its advantages over %01 though, depending on what you want, like a slightly heavier "attack", creating a "dirtier" sound when switching back-and-forth between %10 and %11, better bass properties depending on your sound system, and it can create a tinny, high-pass filtered sound when combining it with a detuned %01 pulse from the other channel.

Mixing into $4011 should work if the extra addition does not delay my first write too much. Unlike the music, which I update twice in the IRQ handler (first right after the IRQ fires, and then after waiting enough time to be right in-between two IRQs), the sound effects should be fine even with one update, at 4.1kHz. Does it make sense to have a fixed restriction on the range of the music to accomodate the additional 4-bit sound, or do these things typically not add up to cause clipping (or clamping if I adjust the mix in that case)?


Top
 Profile  
 
PostPosted: Fri May 10, 2019 10:47 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 8366
Location: Seattle
To the best of my knowledge, the NES's audio path doesn't clip, even when all five channels are emitting their maximum value simultaneously.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: bleubleu and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group