Jump to content
IGNORED

TIA2POKEY


glurk

Recommended Posts

So...  I'm REALLY out of my depth here.  I've been working again on my too-long-neglected 2600 Barnstorming port to 8-bit.  Progress is being made, especially with graphics, but I've hit the "audio portion" now, and I just have no idea whatsoever.

 

So my question is, is there any "general" or "accepted" way to convert TIA audio values to POKEY values that will be at least CLOSE???

 

I searched for info on this, and came up rather empty.  I guess converting FREQ values from 0-31 to 0-255 for POKEY is just some ASL (multiplies) and from there it's trial-and-error??  I don't know.  I know just about ZERO about audio programming stuff.  Trying to put in values directly, my biplane sounds like a jetplane, LOL!!!  In my particular case, this isn't even about music, more of just sound effect stuff.

 

Hopefully, phaeron or someone with audio experience could shed some light here.  I'm kind of hoping for a conversion "formula" or "algorithm" to get me in the ballpark...

 

Link to comment
Share on other sites

The base clock is different and much of the poly stuff different.  As well as only having 5 bit frequency control.

 

I was wanting some time back to make an emulator but the sticking point for me is working out how the different poly types work.

Given that the sound possibilities per voice are only in the low hundreds it'd be fairly feasible to just make a cheap/nasty table based emulation system where you pick the nearest match sounds for each set of values.  Pure tone I imagine could be matched near enough exactly if 16-bit mode was used.

Link to comment
Share on other sites

For distortion $Ax (square waves) this should work. For other distortions, it's more complicated, let me know if you need that.

 

EDIT: this just blindly puts the closest value, without indicating which ones are useful. I'll add some formatting...

EDIT: also the 15 kHz frequencies are all wrong...

EDIT: I removed this file. Find updated version below.

 

Link to comment
Share on other sites

Pat Brady-

 

  That PDF is helpful, so thanks.  But one thing - what I'm converting stores #10 ($0A) in AUDCTL0 and the PDF doesn't even list that one.  I looked it up, and see that it duplicates $06 (I think).  Maybe you could add those equivalents to the PDF.

 

EDIT: I don't mean list them all, just a note that $0A is equivalent to $06, etc.  I guess 2600 programmers know that stuff by heart...

 

Here's a conversion "algorithm" I came up with, so far it works (for this particular case):

 

   LDA audioFrequence00Value
   ASL
   ASL
   ASL
   ORA #7
   STA AUDF1 ; $D200
   LDA #$81
   STA AUDCTL; $D208
   LDA audioChannel00Value
   ASL
   ASL
   ASL
   ASL
   ORA audioVolume00Value
   STA AUDC1; $D201 

 

Edited by glurk
Link to comment
Share on other sites

25 minutes ago, glurk said:

That PDF is helpful, so thanks.  But one thing - what I'm converting stores #10 ($0A) in AUDCTL0 and the PDF doesn't even list that one.  I looked it up, and see that it duplicates $06 (I think).  Maybe you could add those equivalents to the PDF.

Yes, TIA has several redundant AUDC values:

$4 and $5

$6 and $A

$7 and $9

$C and $D

 

Also, $E and $F produce the same frequencies with different waveforms, as do $6 and $7 (and their pairs).

 

Not sure I can add that information to the table without messing up my formulas or adding clutter. Once you know these equivalences, picking the correct TIA AUDC should be straightforward.

 

I'll see if I can add columns for POKEY $Cx to match noisy waveforms.

Link to comment
Share on other sites

There shouldn't be any frequency error when using POKEY 16-bit mode. TIA's base audio clock is 3.58MHz / 114, while POKEY's base clock is 3.58MHz / 2. All you have to do to match frequencies exactly for pure tone is to add 1 to convert from TIA AUDFx value to divisor, multiply by 57 to convert to POKEY divisor, then subtract 7 to get the 16-bit POKEY AUDFx value. If you are only replicating the TIA sounds, then there is no need to approximate as you can just run dual 16-bit channels, which is what all of my conversions do.

 

The tricky part is the distortions. Although the waveforms won't be exactly the same, you can get the same kind of sounds by folding the additional frequency multipliers into the AUDFx value and then matching the polynomial types, e.g. poly4 to poly4 and poly17 to poly17. The easiest way to do this is just with a bunch of lookup tables -- one to map the distortion, and another to look up which frequency table to use.

 

The one mode that isn't easy to match and is noticeably different is the poly5 div 6 mode, due to the 5-bit polynomial working differently than the others in POKEY (it affects clocking instead of being sampled). It sounds metallic on TIA and more muffled when emulated in POKEY. Don't know a good solution for this one.

 

  • Like 3
Link to comment
Share on other sites

OK.  So I'm using the 16-bit audio, and it's generally working.  But I'm getting a glitch (in my Barnstorming port).  If you hit a "goose" and a windmill at the exact same time, it glitches / beeps.  I have tried EVERYTHING to fix this, so maybe someone else can see the issue.  It happens when rapidly changing from a $Ax to $8x distortion, or maybe vice-versa.  Here's the relevant code, which may be messy, I've been trying to fix it...  The "engine" part at the top is ok, it's the crash/bump part that has issues.

 

; ENGINE AUDIO (Now 16-bit)
    lda #%01111000
    sta AUDCTL
    lda audioChannel01Value
    ora audioVolume01Value
    sta AUDC2
    lda audioVolume00Value
    bne .doengine
    sta AUDCTL
    beq .doneengine
.lsbtab    .byte $73,$E6,$5A,$CD,$41,$B4,$28,$9B,$0F,$82,$F6,$69
.msbtab    .byte $48,$4B,$4F,$52,$56,$59,$5D,$60,$64,$67,$6A,$6E
.doengine
    ora #$A0
    sta AUDC2
    lda audioFrequence00Value
    sec
    sbc #$14
    tax
    lda .lsbtab,x
    sta AUDF1
    lda .msbtab,x
    sta AUDF2
.doneengine

; CRASH/BUMP AUDIO

    lda audioChannel01Value
    ora audioVolume01Value
    tay
    lda audioFrequence01Value
    cmp #$1F
    beq .bump
    sec
    sbc #$14
    tax
    lda .lsbtab,x
    sta AUDF3
    lda .msbtab,x
    tax
    bne .doneaudio
.bump
    ldx #$14
    sta AUDF3
.doneaudio
    stx AUDF4
    sty AUDC4

 

Link to comment
Share on other sites

I'm not sure what the code is attempting to do by writing $00 to AUDCTL on TIA AUDV0=0, it certainly won't mute audio.

 

Also, you're not masking off dont-care bits in the TIA register values. It's common for 2600 games to write 1 bits into unused parts of registers, particularly when bit-packing data.

 

Link to comment
Share on other sites

Yes, my fault for not explaining it well.  I changed the audio values in the 2600 code to speed things up so I don't have to do the 4x LSR shifts/masking.

 

I know all the values being stored (on the 2600), because I single-stepped through them in Stella.  I've since found a work-around that eliminates the problem, in my port, but it causes another problem, sigh.

 

What I SHOULD have asked is if there is a way to / how to single step (by frame) in Altirra while watching the pokey values.  I know it can do it, I just don't know how.  Audio is my weak area, and I've hardly programmed for it before, much less tried to debug it.

Link to comment
Share on other sites

You could use this command sequence:

 

bx "vpos=0 and hpos<5" ".pokey"

g

Enter

Enter

etc.

 

That "bx" expression will usually catch every frame start, just once, but it might fail if a write to WSYNC happens near the start of scanline. Perhaps use a "bp" breakpoint to stop when PC is just after your POKEY update routine.

 

You could also just run the following two commands repeatedly:

 

gf

.pokey

 

Not sure if those could be combined into a single macro so you could just repeatedly hit Enter to advance.

 

You can also use "wb" or "ww" to watch memory addresses. Altirra displays them as an overlay on the main screen. But those won't work for POKEY registers since they have different meanings for read and write. But if you have shadow registers, that could work. Then you could just run "gf" repeatedly to advance frame by frame.

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