Playing arbitrary PCM sound throught the PC speaker

audio

As a child I've played one DOS game called Electro Body.

The game did something amazing – it played back PCM samples through the PC speaker. Not the crappy square beeps – it played real sound effects!

It was super quiet in comparison to the usual beeps that the PC speaker makes, but it was a completely new quality of sound. I never heard anything like that before or after that game.

I wonder – if there is a way in GNU/Linux to play arbitrary PCM sound streams through the PC speaker apart from just "beeps" that the beep command makes? Can I play WAV or Ogg files through that?

Apart from the fact that it'd be cool to make some sophisticated noises, one could probably use this as an analogue voltage control output – for whatever crazy DIY project.

Best Answer

I don't have a system to test it on, but it appears that ALSA can provide mapping of output to the PC speaker. FYI, there are many pages out there that say this is a bad idea because the driver is intended as a "toy" and not for general use (it will burn a lot of CPU cycles), but that said, this should work:

# Load the PC speaker driver
sudo modprobe snd-pcsp
# Reload ALSA to find the new driver
sudo alsa force-reload
# You should now see pcsp (pcspeaker) as an ALSA output option
sudo aplay -l

Select the sound card as your output and have fun!

Sources:

http://wiki.archlinux.org/index.php/PC_speaker#ALSA

http://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture#Set_the_default_sound_card

http://www.linuxquestions.org/questions/slackware-14/how-do-you-use-snd-pcsp-in-slackware-14-1-a-4175534306/

Related Question