glurk Posted November 10, 2021 Share Posted November 10, 2021 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... Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted November 10, 2021 Share Posted November 10, 2021 @phaeron has posted sources to the forum so you should be able to establish things from them. I tried a bit from when I had a stab at Combat (subsequently done right by phaeron) but thought things could be better. On 8/29/2015 at 11:26 PM, MrFish said: Midnight Magic Seaquest Stampede Quote Link to comment Share on other sites More sharing options...
Rybags Posted November 10, 2021 Share Posted November 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
+Pat Brady Posted November 10, 2021 Share Posted November 10, 2021 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. Quote Link to comment Share on other sites More sharing options...
+Pat Brady Posted November 10, 2021 Share Posted November 10, 2021 Here's an improved version. Fixed 15 kHz frequencies, added error columns, and color-coding for audible errors. Dark purple is slightly sharp, light purple is very sharp, dark orange is slightly flat, light orange is very flat. TIA to POKEY.pdf 1 1 Quote Link to comment Share on other sites More sharing options...
glurk Posted November 11, 2021 Author Share Posted November 11, 2021 (edited) 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 November 11, 2021 by glurk Quote Link to comment Share on other sites More sharing options...
+Pat Brady Posted November 11, 2021 Share Posted November 11, 2021 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. Quote Link to comment Share on other sites More sharing options...
phaeron Posted November 11, 2021 Share Posted November 11, 2021 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. 3 Quote Link to comment Share on other sites More sharing options...
glurk Posted November 18, 2021 Author Share Posted November 18, 2021 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 Quote Link to comment Share on other sites More sharing options...
phaeron Posted November 18, 2021 Share Posted November 18, 2021 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. Quote Link to comment Share on other sites More sharing options...
glurk Posted November 19, 2021 Author Share Posted November 19, 2021 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. Quote Link to comment Share on other sites More sharing options...
Xuel Posted November 19, 2021 Share Posted November 19, 2021 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.