Jump to content
IGNORED

frequency 16bit pokey in TurboBasic


Marius

Recommended Posts

Hi All,

 

Seriously, I have no idea what is happening here. 

 

I am working on a TURBO BASIC program that will let the user exercise their (relative) ear. It is planned to test intervals melodic and harmonic and probably a few other things.

 

To come as close as possible to the wanted frequency (I have really a sensitive and precise ear) I use 16-bit pokey registers in stead of 8bit. Downside is that I only can play 2 tones together, but ok... Perhaps I might decide later to go to the 8bit 4# voice capabilities of pokey.

 

Earlier today I found that DSOUND 0,4020,10,10 would produce a perfect 220Hz A and  and DSOUND 0,2008,10,10 would produce a perfect 440Hz A.

I was very happy with the results, I saved my program to disk and that was that. Now I fired up the Atari with Turbo Basic and I was playing again with the DSOUND command and I was not as satisfied as I was earlier today. I was like: hmm it is not right. So I started playing again with it and I found different values. After checking:

 

DSOUND 0,4028,10,10 gives the perfect 220Hz A

 

DSOUND 0,2017,10,10 gives the perfect 440Hz A

 

DSOUND 0,1001,10,10 gives the perfect 880Hz A

 

Ok it is not really a big difference, but still, I was not as close as I would have thought.

 

So my 2 questions are:

How stable is this anyway? Can I assume that pokey in 16bit modus produces a steady frequency or does it fluctuate (when colder/warmer) or is it a different part on the PCB that might have influence on the frequency? (Like the audio-out circuit)? I am using the speaker of my television set, so it is not directly what comes out of pokey. 

 

In the Turbo Basic Manual by Wil Braakman I read a formula:

 

"de berekende frequentie in HERZ nu 1789790 / (2*freq+14) bedraagt. De frequentie bedraagt dan 16 bit (0 . . . . 65535)" (Braakman, 1988, p. 3-36).

 

This means that the 16bit pokey value for 440Hz would be:

1789790 / (2*440+14) is approx. 2002 which is closer to my earlier find of 2008, and than my newer find of 2017. 

 
It seems that either this formula is wrong, or my ears/tuner-app. My personal findings using ear and tuner-app come way more close to 220Hz, 440Hz and 880hz than this formula. Is there a better formula somewhere? Or is there something else wrong? Or do I ask too much of a formula anyway? 

 

I am really interested in this stuff, I hope someone can help. 

Marius

--
Braakman, W. (1988). TURBO BASIC XL 1.5 MANUAL. 's-Hertogenbosch, Netherlands: Stichting Atari Gebruikers. 

 

 

Link to comment
Share on other sites

It is as stable as the oscillator in the system. Pokey creates sounds by dividing the clock frequency, and the division is always the same. What may not be the same is the base frequency of the oscillator. It is a crystal oscillator which are *usually* quite stable, but the machine is old, and so may be the crystal.

  • Thanks 1
Link to comment
Share on other sites

9 minutes ago, Gunstar said:

What does the 14 in the formula represent? 

Actually, the formula computes the output frequency given the value of the pokey timer values. It is *2 since the output is inverted every time the timer underflows, and it is +7 (or +14 = 7*2) because this is the number of cycles Pokey needs to reload its internal counters from the timer values.

  • Thanks 1
Link to comment
Share on other sites

There is an issue with the formula that you have found. PAL and NTSC computers differ in master clock rates by 0.9%, and thus different values are needed to produce the same pitch. The formula you have is for NTSC, and the value is slightly inaccurate. It should be 1789773 for NTSC and 1773446 for PAL -- derived from dividing the master clock at 14.31818MHz or 14.18757MHz by 8.

 

Regardless, the values needed should be exact ratios of two, once the -7 bias is taken into account. POKEY's timers run in deterministic logic driven off of the master clock, so a period value of 2011 will produce exactly half the frequency of a value of 1002 (2011 + 7 = 2*(1002 + 7)). Even if the master clock varies, the frequencies produced should still be in perfect relative pitch because they will all be scaled together. That it would seem to require otherwise is odd.

 

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

1 hour ago, phaeron said:

There is an issue with the formula that you have found. PAL and NTSC computers differ in master clock rates by 0.9%, and thus different values are needed to produce the same pitch. The formula you have is for NTSC, and the value is slightly inaccurate. It should be 1789773 for NTSC and 1773446 for PAL -- derived from dividing the master clock at 14.31818MHz or 14.18757MHz by 8.

 

Regardless, the values needed should be exact ratios of two, once the -7 bias is taken into account. POKEY's timers run in deterministic logic driven off of the master clock, so a period value of 2011 will produce exactly half the frequency of a value of 1002 (2011 + 7 = 2*(1002 + 7)). Even if the master clock varies, the frequencies produced should still be in perfect relative pitch because they will all be scaled together. That it would seem to require otherwise is odd.

 

Thanks for the explanation! This is very interesting. Great to get so much insight. 

 

I am in PAL land. 

 

After I read your post, I tried a few things, but still I do not get the right value out of any formula. 

 

A pure "A"-tone is 440Hz. So how do I calculate what the 16-bit pokey value should be to let the pokey play 440Hz?

 

1773446/(2*440+7)? This is approx 1999....

 

But when I DSOUND that value, the tone is too high (higher than 440Hz). It should be around 2017. 

 

Probably I am doing something wrong....

 

  • Like 1
Link to comment
Share on other sites

53 minutes ago, Marius said:

A pure "A"-tone is 440Hz. So how do I calculate what the 16-bit pokey value should be to let the pokey play 440Hz?

 

1773446/(2*440+7)? This is approx 1999....

 

But when I DSOUND that value, the tone is too high (higher than 440Hz). It should be around 2017.

Should be 1773446/(2*440) - 7 = 2008. The closest divisor is 1773446/(2*440) = 2015, and then 7 is subtracted off to get the POKEY value. Of that 7, 1 cycle is because the counter resets when it goes below zero instead of hitting zero, and 3 cycles each for the low and high timers to roll over. Subtract 7 to convert a division ratio to a DSOUND value, and add 7 to convert a DSOUND value to a division ratio.

 

Link to comment
Share on other sites

12 hours ago, Marius said:

(Braakman, 1988, p. 3-36).

 

 

12 hours ago, Marius said:

Braakman, W. (1988). TURBO BASIC XL 1.5 MANUAL. 's-Hertogenbosch, Netherlands: Stichting Atari Gebruikers. 

 

@Mathy Thanks for your reply. You might have overlooked it, but I did use APA-style referencing to make clear that I was using the original Wil Braakman edition. 

 

I love the Wil Braakman edition from the day I bought it. It's a nice looking book in a great format. I should check out sleepy's edition indeed! Good advice. I have it too.

Edited by Marius
  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

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