Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Gez

PC speaker sound question

Recommended Posts

I have looked a bit into it and found something interesting. However, there's something I'm curious about and which I didn't find in fraggle & andrewj's reverse-engineered specs: what is precisely the formula to derive frequency from counter value?

It seems to be that frequency = 1193170 / counter, but I'm not really sure about that. The first value corresponds exactly to 1193150 / counter and xx50 and it seems to give the smallest maximal deviation from the frequencies that are listed in the specs, though xx70 is closer to the average value.

Share this post


Link to post

I don't understand the question. What are counter values? Do you mean value column from the Talk:PC_speaker_sound_effects page? These values are already frequencies, but not very precise.

440*(2^((194-Pos-98)/24)) is correct formula for same indexes.

Share this post


Link to post
entryway said:

I don't understand the question. What are counter values? Do you mean value column from the Talk:PC_speaker_sound_effects page?

Yeah, it's what was sent to the Intel 8523 counter.

This table specifies the frequency for values in PC speaker sound effects.
The value is given along with the corresponding output frequency and the
precise counter value which should be programmed into the 8253 timer chip
found in PCs to give this frequency. 



entryway said:

440*(2^((194-Pos-98)/24)) is correct formula for same indexes.


(194-Pos-98)? Is that 96-Pos ((194-Pos)-98), or 292-Pos (194-(Pos-98))?



Basically what I want to do is generate PCM data to convert Doom's PC speaker sounds into RIFF-WAV sounds.

Share this post


Link to post

I extended f=440*(2^((n-49)/12)) formula for 24 notes per octave f=440*(2^((n-98)/24)) and 'fix' it for indexes form 'talk' page.

Share this post


Link to post

Main thing to realise is that it's a musical scale. The chromatic scale used in western music has 12 tones, and the PC speaker format uses 24 (twice the "detail"). 440Hz is 'A'. Hence entryway's equations.

Share this post


Link to post

Turns out that RIFF-WAV files don't work right at 140 hz. (At least not with the lib I use for playback.) I had to multiply each speaker data byte by some arbitrary large value to obtain the notes I was supposed to get. (I chose 315 because 140x315=44100.) With this increased sample rate, the formula I saw everywhere of sin(2 * PI * sample_num * frequency / sample_rate) does work.

Share this post


Link to post

If you do make the WAV files, please filter them a bit so they're easier on the ear.

Share this post


Link to post

Adding filters would be completely overkill for my purposes, which were simply to add playback for this format in SLADE 3.

Which is in, as of devbuild b3-150. It's not perfect, but it's good enough for me.

Share this post


Link to post

There's already "PC Speaker to WAVE" code in Chocolate Doom and Mocha Doom, if you want to make your life a bit easier. The PC speaker sound are essentially sequences of fixed-length,fixed-volume, variable-frequency tones.

Once you figure out the correct frequency however, you can substitute square waves of a given frequency with sine or triangle waves, if you want a smoother or cheesier effect. Of course you need to generate tones that will have the correct duration at the target sample rate. tThere are 140 tones per second, so you have to divide the target sample rate (e.g. 44100/140) in order to find out how long each tone should be.

Of course, the frequency you must generate must be adapted to the sample frequency, too. If the PC speaker instructions tell you to play a 100 Hz tone at some point, said tone will be different at a sample rate of 11025, 22050 and 44100 Hz.

Share this post


Link to post

I believe he wanted to make sure that code was entirely accurate, and we have found through reverse engineering that it isn't, 100%.

There should be 128 values in the pitch table, mainly. Those values may not be used by any of the stock PC speaker SFX, but I assume by supporting this, SLADE intends to allow new ones to be created which should sound like they sound under DMX playback.

I'd encourage fraggle to update Choco's support with the newly discovered information.

Share this post


Link to post

I'm not sure if allowing to create new PC speaker sounds is really pertinent (I don't expect that many people to actually use it), but I wanted to get playback for those that exist. What I got sounds close enough that I'm happy leaving it in that state, but is still a bit off. Maybe it'd be closer if I used a table of frequencies instead of the table of integer values I found in the exe.

Share this post


Link to post

I think I've found the answer to my original question here.

frequency = 1193181 / value
The magic number is probably 1193181.

Share this post


Link to post

No, based on what they say on the shikadi.net wiki, Wolf stores the inverse frequency data directly, but divided by 60 to fit into a syngle byte. So for Doom:

frequency = 1193181 / freqs[byte value]
And for Wolfenstein 3D:
frequency = 1193181 / (60 * byte value)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×