Jump to content
patjomki

Knocking sound instead of silence (Pokey)

Recommended Posts

Hi,

 

I try to use different sound envelopes. Due to the fact that Pokey doesn't have ADSR registers I need to adjust the volume register (AUDC1, $D201/53761) manually. This works fine when playing tunes but when I try to play a pause (e.g. frequency 0 for AUDF1, $D200/53760) the speaker produces a knocking sound.

 

Here is an example in ATARI Basic (to keep it simple there are no sound envelopes):

10 POKE 53775,3:REM POKEY INIT PART 1
20 POKE 53768,0:REM POKEY INIT PART 2
30 POKE 53760,0:REM AUDF1 = 0 MEANS NO SOUND 
40 POKE 53761,15+160:REM VOLUME TO THE MAX AND PURE RECTANGLE SOUND

99 REM MAIN LOOP
100 FOR I=0 TO 100:NEXT I
110 POKE 53761,160:REM VOLUME TO ZERO BUT STILL RECTANGLE
120 FOR I=0 TO 100:NEXT I
130 POKE 53761,15+160 VOLUME AGAIN TO MAX STILL RECTANGLE
140 GOTO 100

Any ideas why this happens?

 

Edited by patjomki

Share this post


Link to post
Share on other sites

Freq 0 is a valid value and will often produce sound.  The best way to do silence is leave the AUDF alone and just zero the AUDC register.

You can still get clicks that way and also by doing ADSR effects but that's just the way it is.

  • Like 1

Share this post


Link to post
Share on other sites

Didn't know that 0 is a valid value. Thanks a lot for that info. Now I play the adsr envelope with zeroing the AUDC register when I want to have a a silent note (aka: pause) et voilà: clicks are gone.

Edited by patjomki

Share this post


Link to post
Share on other sites
23 hours ago, patjomki said:

Hi,

 

I try to use different sound envelopes. Due to the fact that Pokey doesn't have ADSR registers I need to adjust the volume register (AUDC1, $D201/53761) manually. This works fine when playing tunes but when I try to play a pause (e.g. frequency 0 for AUDF1, $D200/53760) the speaker produces a knocking sound.

 

Any ideas why this happens?

 

Freq. 0 is as such valid, though the frequency is too high to be audible. However, there is a DC bias in Pokey if it generates sound, and the bias is relative to the volume. So the knocking sound is the variable DC bias due to the amplitude modulation. The sound itself is not audible.

 

Share this post


Link to post
Share on other sites
9 hours ago, thorfdbg said:

Freq. 0 is as such valid, though the frequency is too high to be audible. However, there is a DC bias in Pokey if it generates sound, and the bias is relative to the volume. So the knocking sound is the variable DC bias due to the amplitude modulation. The sound itself is not audible.

 

Does this also happen with freq. $0E in $Cx or $4x AUDCx settings?

Share this post


Link to post
Share on other sites
13 hours ago, Synthpopalooza said:

Does this also happen with freq. $0E in $Cx or $4x AUDCx settings?

AUDxC =E is not any different from $A, so yes. However, if you use other distortions, e.g. $C, you can hear frequency 0.

 

Share this post


Link to post
Share on other sites

In BASIC, if I had a sound like this:

 

SOUND 1,100,10,10

 

To turn it off I would use

 

SOUND 1,100,10,0

 

I found it reduced the clicking more than using SOUND 1,0,0,0.  I am wondering if setting AUDCx to $A0 as opposed to $00 (if you are playing in the $Ax setting) would be a preferable alternative.

Share this post


Link to post
Share on other sites

Also $0E in the $Cx settings generates silence, due to the way the bitcounter is read for frequencies divisible by 15.  I have used this method alot to introduce note rests in my music when using the $Cx or $4x settings.

Share this post


Link to post
Share on other sites

Likely the click difference is due to the fact that the AUDF and AUDC stores would be some cycles apart.

If you zeroed AUDF first, then there might be time especially in Basic for a couple of countdown cycles to complete.

If you zero AUDC first, there should only be a single change in modulation at most.

By zeroing the volume but leaving the poly mode the same, you'd either be setting the voice output to a 0 state or remaining in it though I suspect the audio result would be the same as just setting AUDC to 00.

 

Share this post


Link to post
Share on other sites
On 9/5/2019 at 7:51 PM, Synthpopalooza said:

Also $0E in the $Cx settings generates silence, due to the way the bitcounter is read for frequencies divisible by 15.  I have used this method alot to introduce note rests in my music when using the $Cx or $4x settings.

 

Couldn't get this method to work. But since using the volume bits with AUDC works I now have a solution for playing pauses.

 

So now that I can play rectangle tones and pauses I try to fix another issue (of course in assembler and not in basic due to timing reasons).

 

Compared to the sid pokey can only produce rectangle sounds. So in order to have different waveforms I try to simulate those waveforms with using the volume bits of AUDC. How can this be done correctly?

 

Example: Let's say I would play a rectangle sound with 100Hz (it's not a real note but I'm using this frequency in my example to make it easier to explain what my problem is), this means that pokey produces a rectangle wave 100 times a second.

So pokey starts the sound with the volume stored in audc then after half of the period of oscillation (0.005 seconds pokey) automatically sets the volume to zero then after a complete period of oscillation (0.005 seconds multiplied by 2 = 0.01 seconds) again with the volume stored in audc etc. Is that right?

 

To put it in other words if this is true pokey produces a rectangle wave with a fixed pulse width modulation.

 

So let's assume I want to have a 100Hz sawtooth wave instead which means that I have to simulate it with software (volume bits). For this I would start a timer of 100Hz which begins to play a tone with a volume of 9 (example to keep it easy again because this means 10 volume steps (0 to 9)) at a frequency of 100Hz. Then the sawtooth emulation starts by reducing the volume every 0.001 seconds so that after 0.01 seconds the volume would reach zero.

 

BUT due to the fact that pokey already sets the volume to zero after 0.005 seconds one half of my sawtooth is cut even though the volume is still 5.

 

Does that mean that in order to avoid this situation I have I to keep the speed of my timer but play a lower tone (50Hz instead of 100Hz) so that my sawtooth wave reaches 0 at the same time when the pokey sets the volume to 0 and then my timer triggers again and plays the rectangle sound (50Hz) again with a volume of 9?

 

I have attached a picture to show what I mean.

 

 

pokey_saw.JPG

Share this post


Link to post
Share on other sites

Pokey square wave output is pretty much that at the audio pin on the chip but once it goes through the external circuitry the waveform actually has decay in it.

There's other threads around about it.  Though the resultant sound is still practically identical to what would be expected.

 

If you're doing digital sound for your own waveforms, ie changing amplitude thousands of times per second, then you want to use values $10 through $1F in AUDCn.

That's "forced volume" mode and the poly/square wave stuff gets ignored and the voice just outputs the amplitude you select from the lower nybble.

  • Like 1

Share this post


Link to post
Share on other sites
51 minutes ago, Synthpopalooza said:

Meant to say, $0E for silence only works when using $Cx distortions ... the saw wave, not on the standard $Ax square wave. 

Ok, don't know what I did first time but now I got it working. Thank you.

 

 

Share this post


Link to post
Share on other sites
5 hours ago, Rybags said:

Pokey square wave output is pretty much that at the audio pin on the chip but once it goes through the external circuitry the waveform actually has decay in it.

There's other threads around about it.  Though the resultant sound is still practically identical to what would be expected.

 

If you're doing digital sound for your own waveforms, ie changing amplitude thousands of times per second, then you want to use values $10 through $1F in AUDCn.

That's "forced volume" mode and the poly/square wave stuff gets ignored and the voice just outputs the amplitude you select from the lower nybble.

 

I don't want to go the way of a digitracker. First of all the maximum resolution is 6 bit and even with 4 bits only at a frequency of 8Mhz you get 8000 sample values which means a little bit less than 4K for just a single 1 second tone which isn't even enough for a lot of instruments, e.g. piano more than 2 seconds for a single tone, apart from the fact that a single player can use more than one key at a time, so you have to use more samples (-> even more memory consumption) or calculate them which leads to no cpu time left for more than digisound (and of course we already have inertia, Protracker and Neotracker).

 

So I want to got the chiptracker way. Yes, we already have RMT but if I understood correctly it doesn't support different waveforms. Btw, it's a tragedy that both Raster and Analmux died when they were so young. 😥

 

First step of my goal is to have sawtooth, triangle, rectangle with variable pulse width modulation and most important sine waveforms. Therefore I try to program the volume bits. 

Second step is to add ADSR envelopes but that's another story.

 

And thanks again for the explanation, all of your answers help a lot to understand pokey more and more. Please don't misunderstand if I am telling things you already know (e.g. the needed ram for sampling in my calculation above) but for me programming sounds on the xl is completely new so I just want to make sure I don't make some false assumptions. Feel free to correct me whenever I write something wrong.

 

Perhaps one way to go would be:

 

https://en.wikipedia.org/wiki/Pulse-width_modulation

 

like you suggested in this thread:

 

In the meantime I also found the following threads:

https://atariage.com/forums/topic/278463-pwm-experiments/page/2/#comments

 

https://atariage.com/forums/topic/295770-my-pokey-experiments-using-nonstandard-settings/

 

https://atariage.com/forums/topic/216807-complete-pokey-note-table-for-all-distortion-settings/

 

Edited by patjomki
  • Like 2

Share this post


Link to post
Share on other sites

PWM can be even costlier since you need to set output to 1 then back to 0 at the end of the duty cycle to generate each sample.

With PCM it's only a single store per sample.

Also PWM gives you the unwanted carrier frequency, and the only way we can deal with it is to use a high sample rate.

Share this post


Link to post
Share on other sites

2-tone mode and the rather misnamed hi pass filter can emulate the PWM to a degree.  In both cases, using $Ax distortion, you would play your carrier frequency in one channel, using the standard $Ax 8-bit note table, and the exact same pattern in the other channel, but transpose that channel up to between 12 to about 23 semitones.  The greater the transposition, the greater the pulse width.

Edited by Synthpopalooza

Share this post


Link to post
Share on other sites
17 hours ago, Rybags said:

PWM can be even costlier since you need to set output to 1 then back to 0 at the end of the duty cycle to generate each sample.

With PCM it's only a single store per sample.

Also PWM gives you the unwanted carrier frequency, and the only way we can deal with it is to use a high sample rate.

Oh. That was a misunderstanding from my side. For me PCM, PDM and PWM are still mysteries.

 

I thought I could try the following method? Picture is from here: https://de.wikipedia.org/wiki/Pulsweitenmodulation

 

I mean, if I generate square waves with pokey like the pink graph the loudspeaker should produce a sinus wave like the green graph, right?

 

660px-Pwm.png

Edited by patjomki

Share this post


Link to post
Share on other sites
1 hour ago, patjomki said:

Oh. That was a misunderstanding from my side. For me PCM, PDM and PWM are still mysteries.

 

I thought I could try the following method? Picture is from here: https://de.wikipedia.org/wiki/Pulsweitenmodulation

 

I mean, if I generate square waves with pokey like the pink graph the loudspeaker should produce a sinus wave like the green graph, right?

 

660px-Pwm.png

That's the point. POKEY can only produce "Square Waves", and what you hear is what the circuitry behind it is producing.  

Other device manufacturers put intentionally limiters to the output of a chip, to control the result. 

Actually a LOW Pass Filter , a dedicated Capacitor, would have solved all volume problems of POKEY. But the Creators of the Atari built HIGH pass filters behind POKEY's output. 

Really, if there wasn't the Fun of learning Basic with that great built in Basic, and the huge amount of great games for the Atari, one could think "everything what Idiots could have done, they did it with that Hardware" .

  

Actually, on Arcade Machines the put LOW Pass Filters behind POKEY.  

 

As a User of those machines , you could only ask "WTF" a thousand times, as EVERYTHING is so close to perfection, but suffering by that tiny little imperfection…

 

Share this post


Link to post
Share on other sites
On 9/3/2019 at 7:48 PM, Rybags said:

Freq 0 is a valid value and will often produce sound.  The best way to do silence is leave the AUDF alone and just zero the AUDC register.

You can still get clicks that way and also by doing ADSR effects but that's just the way it is.

 

I've been experimenting with Pokey music and sounds more and I'm experiencing this.  What I'm doing in my sound routine in VBI while playing a 3-note series of chords on channels AUDC2/3/4  and percussion sound on AUDC1,  I sometimes clear channels AUDC2/3/4 with a value of #$E0.   

 

1. Read from a table and populate the notes to AUDF1/2/3/4. Read from a 2nd table to populate the volumes into AUDC1/2/3/4.

2. If 'State #2' is set, after then end of Step #1, I clear out AUCF2/3/4 . This was the simple way to eliminate a chord playing while AUDC1 (percussion channel) still plays for a few beats. 

 

It works, but both on Altirra and on XEGS hardware,  there is a very quiet click you can hear in the background when the music channels are silent.  I think the soft clicks are from my setting AUDC2/3/4 with a value and then a few instructions later resetting them to #$E0 to silence them, every frame.    It makes Pokey generate this click sound, the registers being updated even with a Volume 0 ?

 

I could leave it as-is , it isn't ruining the sound, but to get a cleaner sound, I wonder if instead of this 'easy' method, I could make the logic smarter  ... 

 

New step 2. If 'State #2' is set, then only clear out AUDC2/3/4 1 time.  1 Frame.  On subsequent frames, AUDC2/3/4 would remain the value of 0 volume #$E0. And I wouldn't have to update them.  Thus there would still be a click, but only on 1 frame I assume and you wouldn't even notice it.  

 

Thoughts or comments and the click, why it happens, or my proposed solution.   I'll try my "new Step 2" solution tonight and report back what happens. 

Share this post


Link to post
Share on other sites
1 hour ago, Cafeman said:

I think the soft clicks are from my setting AUDC2/3/4 with a value and then a few instructions later resetting them to #$E0 to silence them, every frame.    It makes Pokey generate this click sound, the registers being updated even with a Volume 0 ?

If the values you are setting AUDC2/3/4 to have a volume (i.e. $xy and y != 0), you will get those clicks. Easiest is to maintain shadow registers for $D200-$D208 and write them only once to hardware at the beginning of each call to your play routine. Not at the end, because the code path to the end can be shorter or longer, depending on what happens in your play routine.

 

Share this post


Link to post
Share on other sites

If you set a note then clear even for a few cycles you'll still get unwanted clicks.

For normal audio notes, the jitter of a variable length VBlank playback routine won't really matter.  There's a technique to skip every 6th frame on NTSC so that music playback matches PAL and even that's not really noticable.

Share this post


Link to post
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.

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...