PC speaker tones generator?

I was unable to find any plug-in to make sounds like from PC speaker. I’d like to use generated sounds in a game as an ambient sound for PC… Also want to play with and listen to what some basic melodies may sound like from PC speaker… Is there any way to make a plug-in for pc speaker tones generator?

Can be also possible to make effect filter for converting sounds to pc speaker like melody?

And what do you mean exactly with pc-speaker sound?
I assume it isn’t a simple beep…
Even Lo-Fi sound has its variations. We’ve discussed a Spectrum (ZX81 or so) emulation a while ago (there are also converters available for this kind of sound, using existing audio files).
It is basically a oscillator and a noise generator with a resolution of 4 bit (not up too much dynamic range…).
A tracker plug-in can also effectively be used to extract the main melody and assign it to a simple wave form (sine, saw, square, ring modulator).

BIOS and MS-DOS like OS use PC speaker to warn user about something going wrong, occured errors etc. That are simple beeps created on a monotone frequency. Some old DOS games can produce melodies via PC speaker (for example Tetris), which are combination of various frequency settings for various beep durations. It is also possible to write DOS application for play simple melody “Happy Birthday” via PC speaker…

    Sound(200); {start playing a tone of frequency 200 Hz}
    Delay(500); {duration for 0.5 seconds}
    NoSound;    {stops}

This simple code will play a beep at frequency of 200 Hz for a half of second. This can be edited to make a simple melody and text file with this code can be used as a reference for making digital sound record by requested plug-in…

This can produce pc speaker when regular application is written…

This is how the plug-in dialog would look like. I’m not much good at programming, I’m happy I have made simple PHP apps for my personal use :slight_smile:

I’m not sure if you want to produce sound from the actual PC (Desktop/Tower) speaker (the little 2 inch speaker that is traditionally inside the case of the base unit and goes “beep”) or if you want to create sounds that sound like old PC (DOS/1970’s era) tunes.

Audacity/Nyquist can only access the normal computer sound system - if you want to rout that through to some other speaker then you need to find some other way to do that, but Audacity/Nyquist do not have access to that.

To make sounds that sound like the old 1970’s style computer music, then as Robert was saying, Nyquist plug-ins can be written to produce simple tones (beeps) and, with some interface limitations, what you seem to be asking should be possible (and fun) to do.

Please clarify what the idea is - we’re not quite sure what you mean. :wink:

I want to reconstructe sound as it would sound like from pc speaker. It might be generator, not recorder. It will play normaly from speakers usualy standing with monitor, but will sound like it was made by pc speaker in the case…

In other words, I want to be able generate sounds by now non-existing plug-in (generator) and save it as normal sound file. It will sound like from pc speaker, but will play from speakers as you normally play a music from…

There are some plug-ins here that may serve as the basis for such a plug-in. http://wiki.audacityteam.org/wiki/Nyquist_Generate_Plug-ins

I’m looking for plug-in directly generating that type of sound. Try to start BIOS and do some action resulting in an error. You will hear a short high-pitch beep, which is from pc speaker. I’m looking for a plug-in that can generate a waveform of that type. I’m not good at programming, nor I know waveforms for various sounds including beeps… I installed some custom plug-ins like Morse code generator or Buzz tone generator, but haven’t found any plug-in that can produce waveform as pc speaker normally does… I heard pc speaker beep when tried to do severaly an action on lagged computer. Any chance to produce similar sound with Nyquist plug-in? Does anybody know the beep waveform from pc speaker?

The pc-speaker is a quite simple device. It only knows two states: +5V and no current.
You feed a timer with a down-count number until the next change. This produces a pulse train:
0 0 1 1 1 1 0 0 1 1 1 0 1 0
(1 = full expansion, 0 = rest position)
A square tone generated in Audacity can simulate the pc beep tone. However, this is only one aspect of a pulse. Former game developers were quite creative in order to produce other waveforms or other amplitudes (remember, we had in principle only one level for the square wave). I think that we can emulate a lot of this behaviour with nyquist, it depends how much you want to implement.
The nyquist function is called “osc-pulse” and produces wave-forms that do alternate between 1 and -1 values (which is good for normal speakers).
An example for the Nyquist prompt:

(scale 0.25 
      (osc-pulse (pwl 0 440 1 880 1) 0.75) 

The first function scales the wave-form to 0.25 or -12 dB - I am actually cheating here, because you can not do that with the pc-speaker.
Then comes a low-pass filter to smooth the squares a bit (frequencies above 16000 Hz are attenuated) and reduce aliasing effects.
The pulse itself is a sweep from 440 Hz to 880 Hz over the selection length (in the selected track). Instead of the ‘(pwl …)’ we could as well provide a single Hz value for a constant beep.
The 0.75 value is the ratio between -1 and 1 values. 0 would mean that both values are equally lon (i.e. 1 1 1 -1 -1 -1 1 1 1…).; -1 = all at -1 and 1 = all at +1. In the Wikipedia article are values for 50 % (= 0), 25 % (= 0.5) and 12.5 % (= 0.75) mentioned and how they were often used in older games.
But there are also techniques that use the pulse train as a carrier for other waveforms (pulse with modulation) and this allows a higher bit resolution. You can thus produce wave-forms with 72 different levels - about 6 bit audio.
That’s all for now.

I read a short article showing Turbo Pascal code for generate a beep at frequency 200 Hz for a half of second:

    Sound(200); {start playing a tone of frequency 200 Hz}
    Delay(500); {duration for 0.5 seconds}
    NoSound;    {stops}

Is it wrong? Can you record your pc speaker when an error occurs? You simply tell me pc speaker has only two states which results in square waveform and various settings will produce different waveforms relying on the basic square? So article I read was quite wrong…
Okay, wil try such combination with tone generator…

(scale 0.25 
      (osc-pulse (pwl 0 440 1 880 1) 0.75) 

This is code for Nyquist prompt. Where to find that prompt in Audacity 2.0.3? I looked in File, Edit, View, Tracks, Create, Filters, Analysis and Help, no entry for Nyquist prompt line. I know it was in earlier versions…

The “Nyquist Prompt” is in the “Effect” menu.

This forum board is for things to do with Nyquist plug-ins and code - I don’t know of anyone here that can help you with Turbo Pascal code.

Perhaps they were writing about a different computer? Some old computers had more sophisticated control of the speaker than others.

I think this gives quite a good PC speaker tone emulation:

(setq shape 
    (osc (hz-to-step 1) 0.5 *sine-table* -90)))

(setq envelope
  (list 0 0.1 0 0.1 1 0.3 1 0.3 0
        0.31 0 0.31 1 0.61 1 0.61 0
        0.62 0 0.62 1 0.92 1 0.92 0
        1 0))

  (mult 0.2 
    (pwlv-list envelope)
        (osc-pulse 1000 -0.717 shape)

The Nyquist prompt is in the effect menu.
I have Windows 7 64 and there’s no pc-speaker access provided anymore (if other audio devices are available)., so I can not record the beep. There’s not even a beep on startup anymore.
The simplest beep can be produced by sending the ASCII value 7 to the output. For example by pressing Ctrl + g in the dos prompt after the echo command (start>run>cmd; on Windows).
By accessing the kernel32.dll, it is even possible to send a beep command with an arbitrary frequency and duration. That’s exactly what your Pascal program does. The frequency goes from 37 to 32767 Hz.
As I’ve said, the pc-speaker knows only two states and there are also two possibilities to produce a single beep. One is to produce a square wave by switching the applied current with a timer. The second is also controlled by a timer, but it gives a simple click at every state switch:
0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1 0 …
Here, the sound is made up of the average values over some samples that create the illusion of a specific pitch. We can of course also vary the full cone expansion time (the value 1) and thus combine the two methods.
Let’s take a simple beep:

(scale 0.25 (osc-pulse 523 0))

Does this sound familiar?
It is a square wave with equally distributed amplitudes of 0.25 and -0.25 respectively. The frequency is 523 Hz.
Now, a higher pitched tone:

(scale 0.125 (osc-pulse 8000 0))

We will now modulate the width of this carrier frequency with a sine wave at 523 Hz:

(scale 0.125 (osc-pulse 8000 (hzosc 523)))

I know, it sounds awfully.
The trick is to move the carrier outside the audible range. Try for example 8 Hz instead of 8000.
The actual clock frequency (for every PC) is 1.19318 mHz. This allows a higher carrier frequency, that won’t be audible anymore.
We could for example choose a carrier frequency of 22 kHz and the pulse width of the carrier would therefore be about 500 samples. this can produce a frequency of about 88 Hz as a minimum (I’ve not yet calculated those values explicitly, so take them only as a guide line).
In conclusion, we have to oversample the the pulse train if we want to use a higher carrier. 44100 Hz would only yield [1 -1 1 -1…] for a carrier of 22025 Hz.
By virtually multiplying the sample rate by 500 or so, we would be able to modulate the pulse width efficiently.
The resampling to 44100 Hz would afterwards take the average of this samples and we had finally a wave-form that has other sample values than +/- maximum (i.e. the value 0.125 in the samples above).

That’s all getting very confusing, I know. Note that it took several years until game developers were able to produce these advanced sound effects/wave-forms with the console speaker alone.
I propose that you start out with creating primitive melodies with square waves.
If you want to implement it in a plug-in, you can either use a text box to enter the melody tones or read them out from a text file. It all depends on what exactly you want to achieve and how realistic the emulation should be (including ugliness of sound…).

Here’s a plug-in that I think may be along the lines of what you want:
beeptune.ny (2.18 KB)

Okay, thanks, will try later :slight_smile: