Jump to content
Sign in to follow this  
analmux

Implementation of Pokey 2-tone-filter in emulation?

Recommended Posts

The post I made in the other thread prior to the one with the perl code has the has the .xex file:

pokeyvol.zip ( 10.36K )

http://www.atariage.com/forums/index.php?a...st&id=90202

 

There is a loud tone at the beginning that should be used to calibrate the recording level. This tone should not be clipped. It is the loudest possible tone.

 

The recoding will be 10-15 minutes long. I would like a .wav or .flac file, not .mp3 because it might distort the data. It will be a fairly large file.

 

OK. I've made a recording.

 

it is to be found nowhere (EDITED OUT, as perry_m has received the file)

 

it is a 16bit 44khz mono '.wav' audio file

 

the weird thing is though, that I didn't hear a loud tone at the beginning, but I made sure that the recording level was not too high.

EDIT: I noticed that you made 2 versions :)

 

some other weird things I noticed were this:

 

1) I took a look at the waveform graph. Sometimes the wave has sharper peaks than other times

 

2) sometimes peaks are cut off, or clipped, but not on other times.

 

 

Did you consider the volume rule for pokey?

when total volume exceeds a certain value (I don't know exactly what it is, but I think it's 40 or something), then the signal also gets somewhat distorted....so, when you see some clipped signals, that could also be a possible cause

Edited by Analogue Multiplexer

Share this post


Link to post
Share on other sites

That extra oscillation is called 'ringing'.

 

Much of what we're seeing is probably the effect of harmonic distortion in the audio buffer (opamp) circuit. It would be interesting to compare with the signal from the actual audio pin on Pokey.

 

http://en.wikipedia.org/wiki/Ringing

http://en.wikipedia.org/wiki/Square_wave

Edited by Bryan

Share this post


Link to post
Share on other sites

OK, I've changed the source for the included picture in post 25. Instead of A.A.-space, it's now at my own account, such that people can have a look at it without the need to log in on A.A.

 

 

@ perry_m

 

are you satisfied with the recordings?

can I remove it now?

Share this post


Link to post
Share on other sites
the signal also gets somewhat distorted....so, when you see some clipped signals, that could also be a possible cause

http://cnx.org/content/m0041/latest/

 

The Fourier Series kinda explains what happens. It's simply the result of a low-pass filter on a "perfect" square wave. To have a perfect square wave signal, you need unlimited high frequencies passing without damping which is impossible on any existing signal media.

Share this post


Link to post
Share on other sites
the signal also gets somewhat distorted....so, when you see some clipped signals, that could also be a possible cause

http://cnx.org/content/m0041/latest/

 

The Fourier Series kinda explains what happens. It's simply the result of a low-pass filter on a "perfect" square wave. To have a perfect square wave signal, you need unlimited high frequencies passing without damping which is impossible on any existing signal media.

 

The low pass filter only would build some "sinewave"-shape on the corners of the squarewave. It's the "ringing" effect (Schwingkreis zwischen Kondensator (kapazitiv) und Spule (induktiv) ), which causes ups and downs after the voltage switching. The more the capacitor is loading the longer is the time for un-loading.

Share this post


Link to post
Share on other sites
The low pass filter only would build some "sinewave"-shape on the corners of the squarewave. It's the "ringing" effect (Schwingkreis zwischen Kondensator (kapazitiv) und Spule (induktiv) ), which causes ups and downs after the voltage switching.

The ringing effect is the result of a low-pass filtered square wave. If you look at the Fourier Series, you will get the ringing when the higher frequencies are missing.

Share this post


Link to post
Share on other sites
@ perry_m

 

are you satisfied with the recordings?

can I remove it now?

I downloaded it sucessfully.

 

I notice some clipping and I would like to know if this is produced inside the Atari or the PC.

 

I think the ringing is Gibbs Phenomenon

 

I notice these artifacts appear on top of what looks like clipped signals. Possibly they are produced by resampling the audio after the sound card ADC. The sample rate was 44100 but I believe many sound cards have a native rate of 48000. Perhaps it was converted after sampling. Resampling would produce ringing artifacts on a flat, clipped signal.

 

The clipping is produced after the [corrected, was low]high-pass filter stage, since it cuts off the peaks of the signal where the decay is occuring. This makes me think it is produced externally to the Atari.

 

The polarity of the signal is opposite to that of Rybag's setup. The initial movement is negative for your data but it was positive in Rybags' data.

 

In both your data and Rybags', clipping was more severe on the positive side of 0.

 

The clipping is around 0.105 on the positive side and -0.125 on the negative side. On the negative side, clipping is seen only with the initial transition from silence to a loud volume signal. Due to the DC-offset removal, this transition is larger than the ones which follow it.

 

Did you consider the volume rule for pokey?

when total volume exceeds a certain value (I don't know exactly what it is, but I think it's 40 or something), then the signal also gets somewhat distorted....so, when you see some clipped signals, that could also be a possible cause

What is this volume rule? Is the distortion produced inside the Atari or outside?

Edited by perry_m

Share this post


Link to post
Share on other sites

I can remember old documentation mentioning 2 things about POKEY:

- don't exceed a volume of 10 on a single channel.

- don't exceed a volume of 15 for all channels combined (I think it even mentioned possible hardware damage).

 

Of course, I don't think anyone ever took those advisories seriously.

 

The recordings I did earlier most likely had the recording level on my PC way too high - not quite used to this motherboard's sound system. In previous experience, I've found a level of 60-65% to be optimal for recording audio.

 

Seems with this one, even half that can be too much.

Share this post


Link to post
Share on other sites

Simple clipping of the audio signal should result in a perfectly flat part in the graphs, I don't remember to have seen that.

 

What is this volume rule? Is the distortion produced inside the Atari or outside?

 

Good question. I'm rather sure it's happening inside the Atari, because the effect is heard directly on a monitor- or TV-speaker, but also on the direct output of the audio line, when recording it to a PC (captured with soundcard!)

 

But maybe it's partially external. Maybe the distortion effect is slightly differing by choosing a different output apparatus.

 

Just try to play a tune with all 4 voices at highest possible volume. It sounds like a mess. Then put all volumes around 8, then it sounds clean.

 

 

Anyway, I'll delete the audio file again to make free some of my space.

Share this post


Link to post
Share on other sites
The low pass filter only would build some "sinewave"-shape on the corners of the squarewave. It's the "ringing" effect (Schwingkreis zwischen Kondensator (kapazitiv) und Spule (induktiv) ), which causes ups and downs after the voltage switching.

The ringing effect is the result of a low-pass filtered square wave. If you look at the Fourier Series, you will get the ringing when the higher frequencies are missing.

 

Exactly when the capacitor unload time changes the stored voltage. The longer the time (lower frequencies) the more the capacitor unloads.

At higher frequencies the capacitor keeps a higher loading voltage which results in smaller "ringing". When the frequency is higher(faster) than the unloading of the capacitor, you don't have capacitive actions and the ringing doesn't happen.

Share this post


Link to post
Share on other sites

Anyway, returning back to the main subject....

 

Maybe it's an idea to make a test tune with instruments using the 2-tone-filter.

 

As there are no trackers available that support the 2-tone-filter, it can be harder. But making already some backbone of a song in RMT, then changing the player routine a little bit by hand, then interesting things should be possible....but it's still a matter of trial and error to get some interesting demonstration.

 

This might be the first thing I'd like to work on coming days. Maybe I have some executable and some recordings ready tomorrow or on sunday.

Edited by Analogue Multiplexer

Share this post


Link to post
Share on other sites
I can remember old documentation mentioning 2 things about POKEY:

- don't exceed a volume of 10 on a single channel.

- don't exceed a volume of 15 for all channels combined (I think it even mentioned possible hardware damage).

 

From what I remember is if the sums of the volumes on all channels is over 32 you get overmodulation. Above 32 you actually tend to lose volume and get buzzing. I don't remember anything about a single channel volume limit, just the sum total.

Share this post


Link to post
Share on other sites
Simple clipping of the audio signal should result in a perfectly flat part in the graphs, I don't remember to have seen that.

It could be resampled after clipping. For example, if the sound device has a native sampling rate of 48000 and it was coverted to 44100. That could cause ringing artifacts.

 

There are some clipped parts on the negative side which look like they are slanted rather than flat. I can't account for that with the resampling explaination.

 

The polarity difference is interesting. If the Atari hardware that you and Rybags have is the same, and the polarity difference is external to the Atari, then why would the positive peaks be clipped more than the negative peaks in both instances?

 

I think Rybags said he used his VCR to feed the signal through?

 

I noticed something in Rybags's data and yours that is interesting. Can someone please run stimer.xex on a real Atari and tell us which numbers (1-4) appear on the screen when a tone is heard, and which appear when there is silence?

stimer.zip

Edited by perry_m

Share this post


Link to post
Share on other sites
I noticed something in Rybags's data and yours that is interesting. Can someone please run stimer.xex on a real Atari and tell us which numbers (1-4) appear on the screen when a tone is heard, and which appear when there is silence?

 

OK, I did this.

 

In emulation it is:

 

1,2: tone is heard

3,4: silence

 

On my real machine:

 

1,2: silence

3,4: tone is heard

 

Remark:

On my real atari the tone sounds clean

In emulation the sound is slightly distorted

Share this post


Link to post
Share on other sites

OK, when I woke up this morning an easy solution popped in my mind to generate 2-tone-filter instruments with RMT.

 

The ratio of frequencies between channel 1 and 2 plays the role of timbre selection. This is exactly what happens when just playing a melody on channel 2 in RMT, but in silence. On channel 1 the same melody must be played, but transposed upwards by a fixed note. And, off course, the AUDC1 setting determines volume and distortion.

 

The only thing needed to add to the .xex file of an RMT song is a write to SKCTL at the start, to enable 2-tone-mode

When transposing upwards, we can distinguish between different settings (according to harmonic laws)

 

DF = Difference in notes between channel 1 and 2: DF = Semitone(channel1) - Semitone(channel2)

 

case 1) DF lies between 1 octave higher (12 semitones) and 1 octave + quintic (19 semitones): 2-tone-filter modus 2

case 2) DF lies between 1 octave + quintic (19 semitones) and 2 octaves (24 semitones): 2-tone-filter modus 3

case 3) DF lies between 2 octaves higher (24 semitones) and 1 octave + major third (28 semitones): 2-tone-filter modus 4

....etc.

 

Using this for a reference, there should be an easy way to make a demonstration.

Share this post


Link to post
Share on other sites

Isn't there a way in RMT to set AUDCTL to any desired value?

 

If so, maybe an easy hack/solution would be to re-assign bit 7.

 

Rather than changing the noise poly counter, the program could set 2-tone mode. Problem is, that would be easy on the Atari, but not so easy for the Windows based editor.

 

 

I haven't really had experience using RMT, but I did once create a hacked XEX version which played back waveforms (forced volume) in place of a specific voices notes.

Share this post


Link to post
Share on other sites

OK, my 2-tone-filter demosong is ready.

 

This link contains a .zip file of the following:

 

*) 2 rmt files. the 2nd is the final song

*) an exported version of the 2nd song to .xex: here I did one simple modification

*) a small infofile of how to make the 2-tone-filter modification to an exported .xex file

*) an MP3 recording, for those who can't run the .atr file directly on the real machine (by sio2pc)

 

if people have further questions, please feel free to ask.

 

 

@ Rybags: 2-tone-filter isn't activated by AUDCTL, thus in RMT you can't do it directly. You need to write to SKCTL.

Edited by Analogue Multiplexer

Share this post


Link to post
Share on other sites

I know that - just suggesting that maybe it could be hacked into RMT by utilizing existing (I assume) ability to set AUDCTL.

 

Code patch would have to branch off and do a little extra processing, but it might be a workable solution until/if proper support is added.

Share this post


Link to post
Share on other sites
I know that - just suggesting that maybe it could be hacked into RMT by utilizing existing (I assume) ability to set AUDCTL.

 

Code patch would have to branch off and do a little extra processing, but it might be a workable solution until/if proper support is added.

 

Oh yes, by rereading I see what you were after.

 

I think my solution is the simplest, but it's only useful for an early demonstration.

 

When the .xex file is exported you only need to change one byte of it (with a hex-editor), and it will work....but it will stay activated during the whole song.

 

After composing and exporting a song with single-pokey, you only need to change one value at $02d4 (position in .xex file). The default value there is $03, which is written to $d20f (skctl) to initialize pokey and to make sure the right mode is activated. Just change it to $8b. This is the value which sets bit 3 to activate 2-tone-mode and sets bit 7 to activate resyncing channel 1 by channel 2 which the 2-tone-mode is responsible for.

Share this post


Link to post
Share on other sites
OK, I did this.

 

In emulation it is:

 

1,2: tone is heard

3,4: silence

 

On my real machine:

 

1,2: silence

3,4: tone is heard

 

Remark:

On my real atari the tone sounds clean

In emulation the sound is slightly distorted

OK that proves that the documentation on STIMER is wrong.

 

When you store to STIMER, channels 1&2 are *off* and channels 3&4 are *on*.

 

This is contrary to the published documentation.

Share this post


Link to post
Share on other sites

post-7804-1199001339_thumb.jpg

 

Proof there. 5 seperate recordings.

 

I setup a DLI which does a store to WSYNC and STIMER store, so you'll always have the same waveforms repeating every 1/50th of a second.

 

The top two are Voice 1, next 2 are Voice 3. Bottom one is just a forced volume ascending sawtooth on Voice 1.

 

Also, you notice that the waves immediately folowing a STIMER doe't necessarily have the same voltage readings, although the net amplitude seems to be similar, and it balances out in time.

 

 

You can also very easily prove that Voices 1,2 are phase inverted in relation to 2 and 3.

 

Just play the same sound on two voices, then store to STIMER.

 

If the voices in action are 1 & 2, you still hear sound. If they're voices 1 & 3, they cancel each other out.

Share this post


Link to post
Share on other sites

Here are the results:

 

I found a glitch in the file 1.wav at 7:05.955

 

It is missing some data there. The two pieces on either side of the glitch are different tones. However, there was enough of both sides that I could use them. I would like to know if there was a problem in recording the data or if it got corrupted somehow.

 

The 1.wav that I have is 62,660,492 bytes, if the original is this size then it must be a recording glitch.

 

pokeymix.inc is a C array of 65536 values that can be used to emulate the pokey mixing.

pokeymix.txt are the volume of the 3875 (3876-1) audible tones numbered 0-3874.

pokeyvol.pl is the program I used to analyze 1.wav and includes some hacks for the problem I found in it.

 

I tested the new mixing in emulation and it sounded OK. I notice more distortion using this method in some songs. But it is probably authentic distortion. I think linear mixing sounds cleaner, but a real Atari probably distorts due to non-linear mixing.

 

The triangle wave worked.

pokeymix.zip

Share this post


Link to post
Share on other sites
Here are the results:

 

I found a glitch in the file 1.wav at 7:05.955

 

It is missing some data there. The two pieces on either side of the glitch are different tones. However, there was enough of both sides that I could use them. I would like to know if there was a problem in recording the data or if it got corrupted somehow.

 

The 1.wav that I have is 62,660,492 bytes, if the original is this size then it must be a recording glitch.

 

The file I have here is also of that size.

My system suffers from glitches more often.

It depends on how much other programs are running at the same time.

 

pokeymix.inc is a C array of 65536 values that can be used to emulate the pokey mixing.

 

I wonder if in a final version (of the update) all the 65536 values are needed. Maybe there are some 'symmetries' to discover. Isn't it possible to simplify the table hugely to minimize the data? I suppose the mixing effect is equally distributed over all 4 channels f.e.

 

The triangle wave worked.

 

That's great news!!!

 

But, when you want to use triangle wave for music, then you have to take care of heavy distorting volume levels of other channels. It sounds a bit like an audio compressor. When a triangle note is played, other voices are less loud. The non-linear response explains this in a nice way.

 

I wonder if the so called 'amplified triangle wave' also works out now in Emu.

It is achieved by combining 3 channels. '16-bit-filter' is involved then.

 

amplified triangle works like this:

 

P=53760
POKE P+8,64+32+16
POKE P+5,175:POKE P+1,175:POKE P+3,175
POKE P+2,0
POKE P,F
POKE P+4,F+4

POKE P+9,0

 

Typical values for F: 43.

 

Why did I use timer reset with STIMER (P+9)? ...I noticed there's some (for me unexplained) timing difference that causes non-deterministic volume insecurities/deviations. The STIMER trick works in 9 out of 10 cases. This is a thing I'd like to gain more insight of.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...