Jump to content
IGNORED

Initializing and updating stereo Pokeys


Recommended Posts

This is the last problem I have in my game that I partly solved and have some understanding of, but I did not get to the finish line with and left it sitting for a while. 

 

All music and Pokey driving is self / hand implemented. I get periodic "phase shift" sound problems when playing my sounds in stereo (later on I will provide hearing samples for this if needed, can't do it at the moment), the effect is as if the sounds shifts to the side for some time. I did study this earlier in the process, and looked at the waves in Audacity, and there I could see the visual reason for it, it happens when one channel is shifted a bit with respect to the other so that positive amplitude in one overlaps with the negative in the other channel, something like this:

 

L: __--__--__--
R: --__--__--__

 

This is the part that sounds bad IIRC (the sound is away / empty). When they are following the same amplitude sides like this:

 

L: __--__--__--
R: __--__--__--

 

it sounds much better. I presume this is due to to wrapping around one of the clocks in either of the Pokeys and the two having different phase for a short while before the other one also wraps to beginning. Or at least that was my best guess. But, anyway I tried to modify the Pokey init routines or updating routines I could only make it a bit better or worse, but never get rid of the problem. The fact that the effect is a bit different on the Emulator and on the real HW does not help either (but it is there on both).

 

I also looked into the RMT module to see how they update the sound, there all L/R coupled registers are updated as close to each other as possible. When I do this in my code, the effect is even worse for some reason, what I actually had to do is to shift the L and R updates away a proper handful of cycles. This sounds a bit worse in general (each single sound on the two channels is "too separated"), but the phasing effect occurs less, but it is still there periodically.

 

So what am I missing here? How should the stereo init and update be done correctly to avoid this? Or is it a feature I have to live with? Does it have anything to do with the sound being only 64kHz mode on two channels and 1.79MHz full 16bit on the other two? Please also forgive me for very superficial of understanding of sound and music, it is one of my weak points ;) 
 

Link to comment
Share on other sites

Shifting the timing of POKEY updates is unlikely to help much. For standard square wave output, the AUDF1-4 registers are only used when the timer underflows and resets anyway, so for regular audio pitches there is a window of hundreds to thousands of cycles where the write cycle offset doesn't matter. At best you could shift the chances of cancellation happening for your specific tune, but even then you could only rely on it if you locked down the audio write timing to be fully deterministic (by burning cycles on WSYNC).

 

Fundamentally, it sounds like you have a problem with random phase on the two POKEYs where attempting to play a mono sound will sometimes result in cancellation. This depends on the state of the noise flip/flops on the audio channels, which are influenced by the previously played sounds on that channel. They can be reset with STIMER, but that has the downside of disturbing all audio channels. Another possibility is to shift the frequencies slightly so that the two POKEYs aren't playing the exact same pitch -- but the steps are bit big for this with 8-bit dividers.

 

You could also switch to a noise generator for the problematic sounds. 4/9/17-bit noise doesn't rely on previous flip/flop state and the offset between the POKEYs can be deterministically set through SKCTL.

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

This is the reason why I consider this forum the best one I had ever chance to be on ;) You did not solve my problem directly, but the single fact that I wrote my problem down got me thinking about this a bit more, started suspecting something, and then you topped it off with your answer, I looked at my code, let me show. This is the fragment of my Pokey update routine:

 

	lda saudf1 : ldx saudf1r
	sta audf1 : stx audf1+$10
	lda saudf2 : ldx saudf2r
	sta audf2 : stx audf2+$10

	lda saudc2 : ldx saudc2r
	sta audc2  : stx audc2+$10

	lda saudf3r : ldx saudf3
	sta audf3 : stx audf3+$10

	lda saudc3r : ldx saudc3
	sta audc3 : stx audc3+$10

	lda saudf4 : ldx saudf4r
	sta audf4 : stx audf4+$10
	lda saudc4 : ldx saudc4r
	sta audc4 : stx audc4+$10

 

And this is the fragment of what my Pokey (re-)niit routine WAS:

	lda #0 : sta skctl+$10 : sta skctl : sta wsync : sta wsync
	lda #$03 : sta skctl+$10 : sta skctl
	lda #($50+ctlmask) : sta audctl+$10 : sta audctl

 

Now, why I did the (re-)initialization in the reverse order of Pokeys, is totally beyond me, I just have no idea what I was thinking. Needless to say, doing it in the same order as updating the Pokeys SOLVED THE PROBLEM!

 

Equipped with this knowledge now I only need to also look into my half frame Pokey update function for just one channel that kicks in occasionally, that one has a slightly different structure and needs a small overhaul. 

 

BTW, it was really suspicious to me that I did not hear any such problem in any of the existing stereo productions, I somehow knew it had to be my fault :D 

 

EDIT: Though I am yet to try it on the actual computer ;) 

Edited by woj
  • Like 3
Link to comment
Share on other sites

9 hours ago, Rybags said:

Shouldn't wave interference of same frequencies only be a problem if they're both outputting to the same speaker?

 

I think in this case, when the interference is "proper" then they would fully cancel each other out resulting in (almost) silence, but see above, my understanding of sound is really shallow. In any case, the effect is less audiable on headphones, more on crappy close to each other speakers where the sound waves get to mix in the air before they get to your ears.

 

I tried it on the HW yesterday and it indeed also worked. Sadly, all of what @phaeron said holds, playing for a while, once there are enough situations that the two channels get to play different notes and then go back to the same note, the interference can still kick in, what's worse, it seems to hold longer and more persistently. But this is experience from the emulator on a computer that has a speaker system of very questionable quality (Teams friendly monitor connected through a docking station with the emulator running on Wine). But in any case, my fix did make it better, and if I understand right what Avery said, I will have to live with the remaining artifacts.

Link to comment
Share on other sites

As Rybags notes, you won't get true cancellation unless the stereo output is being downmixed to mono. With stereo output, the inverted phase offset between the channels gives a "fake stereo" effect that can be weird or unpleasant, almost like the sound is pulling hard to one or both sides.

 

There is another option -- since you're already requiring VBXE, use the blitter to do the sound mixing and just play the digital output on the two POKEYs. :)

 

  • Like 1
Link to comment
Share on other sites

21 minutes ago, phaeron said:

With stereo output, the inverted phase offset between the channels gives a "fake stereo" effect that can be weird or unpleasant, almost like the sound is pulling hard to one or both sides.

Yes, this is precisely what I get, I now did some tests with the headphones and there are no ill effects there. What I really need to do is to hook up my Atari to my proper stereo and see what happens there, that would be my ground truth.

 

21 minutes ago, phaeron said:

There is another option -- since you're already requiring VBXE, use the blitter to do the sound mixing and just play the digital output on the two POKEYs. :)

Please elaborate? I have some clue about the trouble and work you are trying to get me into, but then not really to be honest. Any example of this done by someone before?

Edited by woj
Link to comment
Share on other sites

Looks like the issue is pretty much solved, but it would be interesting to see the VBXE music if not for this but another project, perhaps different music players etc. stereo beeper stream as some refer to gtia music etc.

 

Link to comment
Share on other sites

7 hours ago, woj said:

Yes, this is precisely what I get, I now did some tests with the headphones and there are no ill effects there. What I really need to do is to hook up my Atari to my proper stereo and see what happens there, that would be my ground truth.

 

Please elaborate? I have some clue about the trouble and work you are trying to get me into, but then not really to be honest. Any example of this done by someone before?

Basically the audio version of this:

https://forums.atariage.com/topic/346885-vbxe-particle-system

 

This would be a "swatting a fly with a nuclear bomb" kind of solution, as you'd need to reserve some blitter time per frame and run a 15KHz interrupt to play the result.... buuut it would absolutely guarantee being able to control the phase of the center-oriented tracks.

 

  • Like 3
Link to comment
Share on other sites

Hello woj

 

15 hours ago, woj said:

... I now did some tests with the headphones and there are no ill effects there.

 

You only get sound cancelation if the sound of both channels reaches your (left and/or right) ear.  With a normal headphone, your left air only hears one channel and your right ear only hears the other channel.  For sound cancelation to occur, the ear needs to "hear" both channels.

 

Sincerely

 

Mathy

 

 

  • Thanks 1
Link to comment
Share on other sites

18 hours ago, Mathy said:

Hello woj

 

 

You only get sound cancelation if the sound of both channels reaches your (left and/or right) ear.  With a normal headphone, your left air only hears one channel and your right ear only hears the other channel.  For sound cancelation to occur, the ear needs to "hear" both channels.

 

Sincerely

 

Mathy

 

 

In theory yes, practice is sometimes something else ;) Attached two files, the first one has the phasing problem, the second does not. And you can hear the problem also with the headphones, though it is not really the amplitude cancellation when using the headphones (there is no pronounced effect of "fake stereo"), but you can hear the sound is not uniform, like it is in the second recording. (The actual sound is repetitive Popeye punch when scrolling the letters on the score entering screen.)

 

  • Like 1
Link to comment
Share on other sites

Cool effect. It's like a brain massage :-D

But yeah, RMT does it well. Update both pokeys close together, but mainly, in the same orders, and if possible, with same cycle offsets. Ideally use the same code for both init and update.

 

Link to comment
Share on other sites

  • 2 months later...

Just to complete the story, as said, after fixing the obvious bug I had in the code the cancellation effect got much better (as in it disappeared), mostly, but I was still getting this effect from time to time. Until today I though there is probably something more I could do (for example, periodically reset the Pokeys, but then when exactly, kind of difficult when the music and SFX are constantly playing), but I happened to play Speed Up! Gold Edition today and noticed that it suffers from the same thing, that is, occasional configuration of two Pokeys after playing certain SFX that causes the same kind cancellation. I was not even aware that the game is in stereo, but apparently so.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...