next up previous contents
Next: 7.2 Programming a sound Up: 7 Sound Programming Previous: 7 Sound Programming

7.1 Programming the internal speaker

Believe it or not, your PC speaker is part of the Linux console and thus a character device. Therefore, ioctl() requests exist to manipulate it. For the internal speaker the following 2 requests exist:

  1. KDMKTONE

    Generates a beep for a specified time using the kernel timer.

    Example: ioctl (fd, KDMKTONE,(long) argument).

  2. KIOCSOUND

    Generates an endless beep or stops a currently sounding beep.

    Example: ioctl(fd,KIOCSOUND,(int) tone).

The argument consists of the tone value in the low word and the duration in the high word. The tone value is not the frequency. The PC mainboard timer 8254 is clocked at 1.19 MHz and so it's 1190000/frequency. The duration is measured in timer ticks. Both ioctl calls return immediately so you can this way produce beeps without blocking the program.
KDMKTONE should be used for warning signals because you don't have to worry about stopping the tone.
KIOCSOUND can be used to play melodies as demonstrated in the example program splay (please send more .sng files to me). To stop the beep you have to use the tone value 0.



Converted on:
Fri Mar 29 14:43:04 EST 1996

Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:57:43