How do I modify a BIOS POST beeper from a PC to play the Can-can song? If polyphony is possible, how do I do it?
How do I play music with a BIOS POST beeper?
May 02, 2021
Last reply: 5 years ago
20 Replies
You reprogram the timer/counter.
You beat me to it. I actually did that one time way back in the day when PCs still used TTL chips in them. The timer counter was an Intel chip with one counter for driving the speaker and another counter for timing the PC timer interrupt (the third was for DRAM refresh or DMA or something). I reprogrammed the time interrupt to 8 kHz and used the speaker timer as a PWM output. The audio was rough, but recognizable. At the time I was working for a company making equipment for monitoring various comms equipment including phone line modems. The only sound file I had handy was a modem protocol so I used that. A manager stuck his head in the lab when he heard the sound. At that time "multimedia" cards were a not so cheap option and so PCs just didn't have sound mostly. He wanted to know how I was making that sound and I explained it. Turns out they had a customer for their training software who could not get approval for "multimedia" add ons (they were considered a frill) so the training was done without ever actually hearing the sounds which the operator would hear when using the software. He was very interested in this even though it was crude.
I don't know if this would work as well these days. There's a lot going on and getting a timely response to the 8 kHz interrupt might not be so easy. I'm not sure they even have the real time clock timer anymore or if you can access the hardware directly. But it's worth a try.
Doesn't matter if it works or not. Just "sound good".
Seem like another remote interviewing questions. You are hired for the engineering and i am hired for the marketing. For marketing, they need tease and elegant sounding solution, not necessary the best solution. So:
- How to do CPU fan out video and audio - FPGA synthesized input phase locked freq up shifted audio and down shifted single pixel video monitor.
- How to play PC speaker music - 5 nm FinFET x86 single chip digital audio processor with programmable timer/counter.
You can find examples for that at rosettacode.org/wiki/Musical_scale#Forth in Forth or any other language you may prefer.
Accessing a speaker may require root privilege. You need a classic boat ancre pc, not a tablet (duh).
Groetjes Albert
albert@cherry.(none) (albert) wrote in news:608ebc42$0$21168$ snipped-for-privacy@news.xsall.nl:
You have to use a boot loader that allows it.
My Linux PC plays 'Fur Elise' and the theme from Close Encounters when it boots.
I used a variant of GRUB called BURG. It is no longer in development or support, ut getting an old version to work and play an audio chirp song through the BIOS is one thing it was able to do before choosing the OS one wants to boot.
albert@cherry.(none) (albert) wrote in news:608ebc42$0$21168$ snipped-for-privacy@news.xsall.nl:
No polyphony in BIOS audio. Single tones and tone duration only.
Nonsense. The timing generator is working as a PWM DAC. It will produce as many phonies as you establish in the audio to be reproduced.
What I have always wanted was a simple interface to allow me to play sound files from a Forth app without the app having special privileges. I've never found a way to do that which doesn't require paying for special development tools.
In general the timer is used and intended as single tones and tone duration. It is certainly not working as PWM just so. If you have a reference to how to make it work as PWM, that would be nice. It is probably easier to bitbang a handshake bit on an RS232 port.
That the program need to be installed in grub is nonsense. This is how I compile and run a program that is available from the rosetta code site :
~/PROJECT/ciforths/ciforth/TOOLS$ lina -c rosetta.frt # : ISN'T UNIQUE $-PREFIX : (WARNING) NOT PRESENT, THOUGH WANTED
1 ~/PROJECT/ciforths/ciforth/TOOLS$ sudo ./rosettaYou can pick up the lina compiler from
formatting link
the .deb is easy to install).
/---------------------------------------------------------------
\ Copyright (2001): Dutch Forth Workshop Holland by GNU Public License.
\ The sound is produced by the internal speaker that is directly \ connected to the motherboard. No speaker, no sound. \ This works on IBM-compatible pc's from 80's XT-pC to current day \ UEFI 8-core's.
WANT $-PREFIX WANT -scripting- WANT PC! WANT XOS
\ Real time section ---------------------------------------------------
\ Set N on the timer of the `pc'. This is the time for one \ sound cycle, so the reciprocal of a frequency. : SET-FREQUENCY $B6 $43 PC! DUP $42 PC! 8 RSHIFT $42 PC! ;
\ Let the cycles generated by the timer onto the speaker. : SPEAKER-ON $61 PC@ 3 OR $61 PC! ;
\ And block them again. : SILENT-SPEAKER $61 PC@ $FC AND $61 PC! ;
\ NOTE -> one secunde higher NOTE, ratio of a secunde, 2^(1/12). \ Uses best 16 bit convergent for 1.0594630943593 : secunde 17843 18904 */ ;
\ Conversion table a note number to a wave frequency. \ Entries must be 16-bit unsigned representable. CREATE _notes 17806 ( C2) 12 0 DO DUP , secunde LOOP DROP
\ For midi NOTE get timing CONSTANT. : >timing 36 - 12 /MOD SWAP CELLS _notes + @ SWAP RSHIFT ;
\ Start a midi NOTE the speaker). : NOTE-ON >timing SET-FREQUENCY SPEAKER-ON ;
\ Perform a note off EVENT (for the speaker). : NOTE-OFF DROP SILENT-SPEAKER ;
\ Play a NOTE for DURATION. : PLAY-NOTE OVER NOTE-ON MS NOTE-OFF ;
\ Play a scale starting at the keyhole c. : PLAY-SCALE 60 1000 PLAY-NOTE \ c' 62 1000 PLAY-NOTE \ d' 64 1000 PLAY-NOTE \ e' 65 1000 PLAY-NOTE \ f' 67 1000 PLAY-NOTE \ g' 69 1000 PLAY-NOTE \ a' 71 1000 PLAY-NOTE \ b' 72 1000 PLAY-NOTE \ c'' 3000 MS ;
\ This program can be run on a 16 bit Forth on MSDOS. \ It wil also with root privileges on a 32 bit ciforth, \ with the following addition.
WANT -syscalls-
\ Make the io-port PORT accessable, i.e. guarantee the privilege \ to acces it. (port -- ) : MAKE-ACCESSABLE 1 1 __NR_ioperm XOS DUP IF ." You cannot access i/o ports, become root" CR THROW THEN ;
\ Hardware ports in use for the speaker itself and the timer connected \ to the speaker. : MAKE-SPEAKER-ACCESSABLE $42 MAKE-ACCESSABLE $43 MAKE-ACCESSABLE $61 MAKE-ACCESSABLE ;
: doit MAKE-SPEAKER-ACCESSABLE PLAY-SCALE ; .
\ The strength is that it really shows how to get sound from your computer \ to the lowest level. \ The weakness is that is is not a portable Forth program (but then, \ how could it.).
/---------------------------------------------------------------
On a MS-Windows system it is easy because there is a player for midi messages in WINMM.DLL ("Multi Media")
You only need calls to MidiOutOpen MidiOutClose MidiOutShortMsg It worked last time I used MS-Windows. (That was Windows XP). You can do that from d it
Groetjes Albert
Sorry, "d it"?
On Linux it's easy there's a "beep" command with command line arguments for frequency and duration, apt-get install beep on Debian/Ubuntu. also snd-pcsp module lets you use the pc speaker as a crude DAC.
If a -nix type OS isn't allowed then hopefully your x86 assembler is good because you can't do it on Windows; 'in' and 'out' assembly instructions aren't available to user-mode programs and there's no API to make the equivalent of a kernel-mode system call to access the internal speaker.
If you're expected to do the whole exercise yourself you have to write a custom bootloader to boot the x86 processor into real mode and do it from there.
.byte, .word or equivalent is usually your friend there.
Not sure I follow you there, but you can't access the "real" memory space where memory-mapped I/O devices live from a user-mode process, any attempt to go outside the bounds of the virtual address table for the process will segfault the program.
Might be able to write a kernel-mode device driver and your own API for it but AFAIK nothing like this is included stock with Windows.
Rick C snipped-for-privacy@gmail.com wrote in news: snipped-for-privacy@googlegroups.com:
Horseshit. The motherboard sound gen is single tone and duration. Period. Just like the sound in upright video games.
Maybe you are trying to access your soundcard. A completely different animal.
albert@cherry.(none) (albert) wrote in news:608f0810$0$21162 $ snipped-for-privacy@news.xsall.nl:
I never said some lame program you refer to had to be installed in GRUB.
*I* suggested using BURG, and THAT bootloader includes access to the motherboard sound gen without installing anything else. ALL BEFORE any OS boots.
I know it is pointless to try to explain things to you, but I will explain again for the benefit of others...
What the Decadent Linux Loser is talking about it using one of the timers in the 8253 programmable interval timer as a square wave generator which is the most basic method of generating sounds using the PC speaker. That is NOT what I did.
As I explained previously, I used this timer as a PWM generator. It ran at a fixed frequency (don't ask me what frequency that was, probably 8 kHz, but maybe not. The PWM value was in essence the DAC sample. On the average the output signal would have a level proportional to this value relative to the full scale value set by the period of this timer.
The only thing remaining to be added was an interrupt from the PC clock timer which was changed from something around 50 Hz I think to 8 kHz. This interrupt would get a TSR link that would program a different value into the other timer which was the PWM value. These values were read from a file for the sound to be produced. Since these two timers working together produced what was in essence a PWM based DAC, ANY TYPE OF SOUND could be produced on a PC through the built in speaker.
The quality was rather poor and I'm sure improvements could be made to the timing and the sound, but it worked well enough that a manager recognized the modem training sounds that were being produced.
As I had said, this did not use the sound or "multimedia" card, because they still cost around $1,000 at that time and none of our PCs had one unless it was being used for a special project. This was a general lab machine that I used sometimes.
This is a simple thing that is done often on low end MCUs these days and is no big deal. There is nothing in the old PCs that precluded doing this. It worked, it happened, get over it and stop pushing your bad memory on the story. Try just once to actually understand what I just told you.
There'a also a snd-pcsp kernel module that makes a sound device capable of play ┌────────────────── PC-Speaker support (READ HELP!) ──────────────────┐ │ CONFIG_SND_PCSP: │ │ │ │ If you don't have a sound card in your computer, you can include a │ │ driver for the PC speaker which allows it to act like a primitive │ │ sound card. │ │ This driver also replaces the pcspkr driver for beeps. │ │ │ │ You can compile this as a module which will be called snd-pcsp. │ │ │
It probably is,
linux-4.19.181/sound/drivers/pcsp$ wc * 2 9 98 Makefile 239 596 5502 pcsp.c 83 254 2276 pcsp.h 117 292 2304 pcsp_input.c 15 36 327 pcsp_input.h 360 880 9315 pcsp_lib.c 164 437 4112 pcsp_mixer.c 980 2504 23934 total
about 1000 lines of code turn it into a generic mono sound device.
A similar technique was used in MODPlay/MODEdit, to replay 4 channels of sampled audio via the PC speaker. Quality *was* rough, but it worked. An actual DAC was better, or multiple DACs (one per channel) as mapped I/O devices, printer port hacks (parallel out to a DAC) etc, and all were supported by different "drivers" for sound output devices, including ability to add your own.
Of course, it also covered the standard SoundBlaster too, for those that could afford one.
Yep. and anything you could do with the instruction set of the 16 bit
8086 you should be able to do on a modern x86 processor in real mode prior to entering protected mode, with a simple boot-loader that just never enters it, all the same interval timers and timer overflow interrupt vectors should be there.Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required