VOGONS


Reply 20 of 38, by OPLx

User metadata
Rank Member
Rank
Member
ViTi95 wrote on 2021-09-13, 14:32:

This is great! The code looks very simple and sounds pretty decent, maybe I can add support for FastDoom with this technique.

One little question, what's the maximum frequency the GameBlaster supports?

EDIT: Another question, does this work on DosBox?

The SAA1099s on the GameBlaster are clocked at 7.15909 MHz, so the highest frequency the tone generators can reach is about 6.99 kHz. Since the technique stefan mentioned doesn't use the envelope generators, it should work. Sadly, I don't have any time to try to verify this myself.

Reply 21 of 38, by ViTi95

User metadata
Rank Member
Rank
Member
Tiido wrote on 2021-03-13, 16:44:
SAA output should be logarithmic as is AY and the Ti PSG. You will need to take this into account for a decent sound quality. He […]
Show full quote

SAA output should be logarithmic as is AY and the Ti PSG. You will need to take this into account for a decent sound quality. Here are two examples I have done on Sega Master System, one without taking the log scale into account and one that does :
http://www.tmeeco.eu/BitShit/SMSPCM0.SMS
http://www.tmeeco.eu/BitShit/SMSPCM1.SMS

And here is one that has double sample rate + log compensation : http://www.tmeeco.eu/BitShit/SMSPCM.SMS

A good emulation is necessary for good sound, or actual hardware off flashcart.

Another question, is there any formula that allows to convert regular 8-bit PCM audio to any logarithmic scale? I'm trying to make an OPL2 play PCM sounds, and it works but the sound isn't as good as it should. The main issue is the same, the volume scale is logarithmic and it should be taken into account (6-bits available, ranging from 0,75db to 24db), but I don't know exactly how to solve this problem.

https://www.youtube.com/@viti95

Reply 22 of 38, by Tiido

User metadata
Rank l33t
Rank
l33t

I only have a partial answer, I got some linear to variable log transform going as part of PCM playback on a log space such as YM chips and TI PSG but I don't know why exactly the code does what it does anymore
Ratio is the change between levels that is entered. 0.5 would mean -6db so this is something I calculated out first in some way. I think I used some online web calculator that told the ratio when you entered db. It shouldn't be too hard to find how it is defined and calculate it yourself from the db figure alone.

Here is the code (for FreeBASIC) :

DIM LogSteps!(255), LogTable%(255)
CLS
PRINT "Tiido's kick„ss WAV to YM PCM converter v0.1 !": PRINT

SamOffs% = 7
HeaderSize& = 46

'Ratio! = .917275935389# '-0.75db
Ratio! = .963274358699# '-0.325db

LogSteps!(255) = 127
FOR i% = 254 TO 0 STEP -1
LogSteps!(i%) = (LogSteps!(i% + 1) * Ratio!)
NEXT i%

LogTable%(0) = 0
FOR i% = 1 TO 255
LogTable%(i%) = LogSteps!(i%)
NEXT i%


OPEN "GREENSXG.WAV" FOR BINARY AS #1
FileSize& = LOF(1) - HeaderSize&
REDIM FileBuffer(FileSize&) AS UBYTE
GET #1,HeaderSize&,FileBuffer()
CLOSE #1

FOR i& = 0 TO FileSize&
FileBuffer(i&) = LogTable%(FileBuffer(i&))
NEXT i&

OPEN "YMPCM.BIN" FOR BINARY AS #1
PUT #1,1,FileBuffer()
CLOSE #1

It may be useful to get going with a superior solution ~

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 23 of 38, by bakemono

User metadata
Rank Oldbie
Rank
Oldbie

attenuation = log (PCM / 255) * 20

(log base 10 that is)

255 = 0dB
254 = -0.034dB
253 = -0.068dB
...
129 = -5.919dB
128 = -5.986dB

again another retro game on itch: https://90soft90.itch.io/shmup-salad

Reply 25 of 38, by ViTi95

User metadata
Rank Member
Rank
Member

Huge thanks Tiido and bakemono, I've been able to add OPL2 PCM support to FastDoom!!!. Now I understand much better how it works, next step will be adding CMS PCM support (but first I need a compatible sound card ^^).

https://www.youtube.com/@viti95

Reply 26 of 38, by Tiido

User metadata
Rank l33t
Rank
l33t

Congrats, I hope it sounds good ~

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 27 of 38, by ViTi95

User metadata
Rank Member
Rank
Member

Hi again! I've been able to add C/MS support to FastDoom thanks to your code @Tronix (although I'm using only CH2 from the SAA1099 in a simpler way). But here is a question, I cannot find specific information about the amplitude register, the datasheets don't explain if it is linear or logarithmic nor the number of dB used between steps. Is there any information available about this?

https://www.youtube.com/@viti95

Reply 28 of 38, by Tiido

User metadata
Rank l33t
Rank
l33t

It should be logarithmic and same step size as AY but I am not 100% sure either.

EDIT: MAME source suggests it is using a linear scale, dividing full scale into 15 steps.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 29 of 38, by ViTi95

User metadata
Rank Member
Rank
Member

Small update, maybe you're interested in this @Tronix. It's possible to generate stereo 4-bit DAC sound with the GameBlaster, just using the same idea but using each chip for left / right channels. Also you can make it faster by setting the amplitude register just once, and then updating the value without setting each time the register (in case you use only one envelope channel for each sound channel, avoids one out instruction per sample). Next release of FastDoom will include this, the sound code i've implemented is here: https://github.com/viti95/FastDoom/blob/maste … STDOOM/ns_cms.c

EDIT: Tiido you're right, it's linear, so no need for a LUT to make it sound better.

https://www.youtube.com/@viti95

Reply 30 of 38, by stgiga

User metadata
Rank Newbie
Rank
Newbie

Honestly I think that doing 8bit stereo PCM on the Gameblaster back in the day would have been an incentive for Creative to keep the Gameblaster chips on their later SB cards, even if on a hypothetical SB16 version of the card it would have just served as a secondary PCM channel. For context, Rob Hubbard in 688 Attack Sub's Tandy version actually used volume register PCM on the TI SN76489 clone used in the Tandy and PCjr. This same trick of feeding the chip no input and just using the volume register as PCM also works on the Gameblaster SAA1099 chips and the Covox Sound Master card (AY8930 or AY-3-8930, which is a souped-up version of the AY-3-8910 chip cloned and doubled by Philips into the SAA1099 which the Gameblaster has two of.) People on NEC PC98 have used volume register PCM on the AY clone inside the YM2203, YM2608, OPN3, and YMF297/OPN4. It's a trick known as SSGPCM. Also the YMF297/OPN4 can actually be used on Western PCs because it's an OPL3-L (low power) and OPN3 on the same die that can be toggled between OPL3 and OPN3 mode, but is in the same package as the OPL3-L used on some IBM PC sound cards that were SB16-compatible. Also the YMF297 has the fancy OPL cursive on it. You can take such an OPL3-L sound card, desolder the OPL3-L and then solder the YMF297 in place, and theoretically it would work and thus you could play PC98 VGM files that don't use OPNA PCM on a Western DOS PC. In addition, in OPN3 mode you could of course use SSGPCM. The way that AY-series chips, the YM2149 clone family of the AY-3-8910, and the SAA1099 are even able to play their envelopes as audio is by having the square wave disabled and enabling the envelope. For PCM playback, you don't have to enable anything. Just send your PCM as writes to the volume and it will obey. And you don't really have an upper limit on sample rate. You can just send data to that register as fast as you want, sorta like how there's no rate limit on the Covox Speech Thing dongle.

I'm Nonbinary and neurodivergent.
I use they/them. It can also be written as ᵺ㏟.

Reply 31 of 38, by ViTi95

User metadata
Rank Member
Rank
Member

I wonder how it's possible to get 8-bit PCM resolution on the SAA1099, if the volume registers are only 4-bit. I guess the idea is the same as for the SN76489:

Lookup for 8-bit PCM

A stream of 8-bit PCM data is read from ROM (one sample per byte) and used to look up a triplet of SN76489 attenuation commands from a table in ROM. These are emitted in close succession. By careful construction of the lookup table, the commands are able to address a large number of volume levels by combining the non-linear volumes.

During the transition from one sample to another, this can produce unwanted artefacts because the intermediate total attenuation may not lie between the start and end points. For example, transitioning from attenuations 4,0,0 (total output level 79.9%) to 2,1,0 (total output level 80.1%) may temporarily be in the state 2,0,0 (total output level 87.7%). This can be avoided by minimising the transition time, but seems to still produce noise.

https://www.youtube.com/@viti95

Reply 32 of 38, by stgiga

User metadata
Rank Newbie
Rank
Newbie
ViTi95 wrote on 2022-08-31, 07:44:

I wonder how it's possible to get 8-bit PCM resolution on the SAA1099, if the volume registers are only 4-bit. I guess the idea is the same as for the SN76489:

Lookup for 8-bit PCM

A stream of 8-bit PCM data is read from ROM (one sample per byte) and used to look up a triplet of SN76489 attenuation commands from a table in ROM. These are emitted in close succession. By careful construction of the lookup table, the commands are able to address a large number of volume levels by combining the non-linear volumes.

During the transition from one sample to another, this can produce unwanted artefacts because the intermediate total attenuation may not lie between the start and end ints. For example, transitioning from attenuations 4,0,0 (total output level 79.9%) to 2,1,0 (total output level 80.1%) may temporarily be in the state 2,0,0 (total output level 87.7%). This can be avoided by minimising the transition time, but seems to still produce noise.

SSGPCM on PC98 also does 8 bit PCM via using up two or 3 SSG channels. Even back in the PC98 heyday it was used for speech, and doing it on the SSG allowed the speech to be used on the original YM2203 OPN chip which was just 3 FM channels plus the SSG. The General Instrument AY chip was a great example of happy accidents, since you could disable most of the chip yet get audio by feeding the wanted audio as PCM to the volume register. You could mix tone and noise to get additional drums, and the volume envelope feature originally meant as fade out could be set to be the audio fed to the volume register via the first trick, and then pushed into the range at which humans could audibly hear the envelope, allowing triangle and sawtooth. You could also create funny modulation via turning tone and envelope on together. The AY-3-8930 used in the Covox Sound Master was an over-engineered successor to the original AY that was partially designed by C64 SID engineers. Firstly, each channel had its own envelope, and the envelopes gained more range in audible frequencies, because using the envelope for saw and triangle was a trick known even in the 1980s. Also the chip gained 8 additional pulse widths, for a total of 9 including square. It also gained a significantly over-engineered noise generator for each channel. It had AND/OR masks, and could be coaxed into producing tone rather than noise, and it had more pitch range. Via tone+noise on AY8930, you could make smooth PWM, Atari PoKEY and TIA bass and 2-tone, as well as chords on the same channel. You can also do without CPU drain what Atari ST people did with double PWM created via using the CPU to drive the chip at a very high refresh rate. The noise on AY8930 can be made to sound like the Commodore VIC20 noise fairly easily. Also the AY8930 noise can even sound like sampled drums. The AY8930 can also be used to fake other sound chips of the 80s. And you can still do PCM on it. All happy accidents. I'm sure that General Instrument didn't intend for people to use their chip as a DAC, but people did.

I'm Nonbinary and neurodivergent.
I use they/them. It can also be written as ᵺ㏟.

Reply 33 of 38, by Tiido

User metadata
Rank l33t
Rank
l33t

PCM can be done on most sound chips where a volume register is available, there are a variety of limits though and full 8 bits is a tall order and unachievable on most of them in practical settings, but you can get effective 6...7 bits but at great CPU use cost since levels need to be combined and in (very) specific ways to go beyond 3...4 bits. I have experimented with this a lot in past, it actually was among the first things I did as far as sound went on consoles and computers 🤣. A lot is possible but often not when other things must be done at the same time... interrupt every line, or even several has a huge toll on what is left of the CPU time for the main task.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 34 of 38, by ViTi95

User metadata
Rank Member
Rank
Member

Maybe a bit off-topic, I reopen this asking for help. I've been trying to add support for ISA Tandy (SN76489) clone cards to FastDoom, but I haven't been able to make it sound "good". I don't have a real one, so everything I've done is tested on 86Box. Right now I'm using a LUT to do linear-to-logarithmic conversion for the attenuation commands (4-bit volume), and while it makes recognizable sounds, there is a very high pitched noise running on the ground all the time.

The initialization process silences all the channels and sets the channel 0 frequency to 0. How can I minimize that high pitched noise? Maybe should I change the 4-bit attenuation based playback to three attenuation commands playback? Or there is a better way to implement PCM sound on the SN76489?

You can take a look at the source code here: https://github.com/viti95/FastDoom/blob/tandy … DOOM/ns_tandy.c

https://www.youtube.com/@viti95

Reply 35 of 38, by Tiido

User metadata
Rank l33t
Rank
l33t

0 is lowest possible freq on the Ti PSG which is going to result in big holes in the sound but not at "very high pitch"... 1 which in the highest possible freq should work better, the gaps are ultrasonic compared to any sample rate you can achieve and should average out into fixed levels much better in the analog stages. You also may be hitting some analog deficiency, for example Ti PSG is prone to oscillation on its output amplifier. This can be supressed a bit with external components, but I have no idea if this is the case and if there's already steps taken to reduce the problem.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜

Reply 36 of 38, by OPLx

User metadata
Rank Member
Rank
Member
ViTi95 wrote on 2023-03-12, 00:09:

Maybe a bit off-topic, I reopen this asking for help. I've been trying to add support for ISA Tandy (SN76489) clone cards to FastDoom, but I haven't been able to make it sound "good". I don't have a real one, so everything I've done is tested on 86Box. Right now I'm using a LUT to do linear-to-logarithmic conversion for the attenuation commands (4-bit volume), and while it makes recognizable sounds, there is a very high pitched noise running on the ground all the time.

The initialization process silences all the channels and sets the channel 0 frequency to 0. How can I minimize that high pitched noise? Maybe should I change the 4-bit attenuation based playback to three attenuation commands playback? Or there is a better way to implement PCM sound on the SN76489?

You can take a look at the source code here: https://github.com/viti95/FastDoom/blob/tandy … DOOM/ns_tandy.c

Basically what you are doing is the way to play PCM on the SN76489.

You could try changing line 76 to this:

outp(TANDY_Port, 0x81);

I think that will cause the output of the channel volume to go and remain high (at least this is what I've seen VGMs that play PCM on the Tandy 1000 do). You may also need to tinker around with the LUT values. Sadly, I don't have much experience with this to give any additional suggestion as to what good LUT values could be.

Reply 37 of 38, by ViTi95

User metadata
Rank Member
Rank
Member

Well I've solved the high pitched noise, basically I had an error on the LUT. I've been testing and the difference between setting the frequency to 0 or to 125KHz is pretty much the same (don't know exactly why, maybe on real hardware exists a bigger difference). The quality isn't very good (sounds like 2-bit quality), so I guess the only way to make it better is to use volume commands for three channels instead of only one. Again thanks for helping!

https://www.youtube.com/@viti95

Reply 38 of 38, by Tiido

User metadata
Rank l33t
Rank
l33t

Emulators may not treat the extremes right, i.e for Sega VDP PSG, settings 0 and 1 are same on the hardware, but on actual TI PSG, 0 is same as $400. For real hardware you definitely want the highest possible freq for this instead of the lowest possible.

T-04YBSC, a new YMF71x based sound card & Official VOGONS thread about it
Newly made 4MB 60ns 30pin SIMMs ~
mida sa loed ? nagunii aru ei saa 😜