This is a simple program for speaker sound in Linux. The following is the source program.
# Include
# Include
Void play (unsigned int * freq, unsigned int * delay );
Main ()
{
Int I;
Unsigned int freq [] = {330,392,330,294,330,392,
330,394,330,330,392,330,
294,262,294,330,392,294,
262,262,220,196,196,220,
262,294,330,262, 0 };
Unsigned int time [] = {50, 50, 50, 25, 25, 50,
25, 25,100, 50, 50, 25,
25, 50, 50, 25, 25,100,
50, 25, 25, 50, 25, 25,
50, 25, 25,100 };
Unsigned int freq2 [] = {
196,262,262,262,330,294,262,294,330,294,262,
330,394,440,440,394,330,330,262,294,262,294,
330,294,262,230,230,196,262,440,394,330,330,
262,294,262,294,440,394,330,330,394,440,523,
394,330,330,262,294,262,294,330,294,262,230,
230,196,262,440,394,330,330,262,294,262,294,
440,394,330,330,394,440,523,394,330,330,262,
294,262,294,330,294,262,230,230,196,262, 0
};
Unsigned int time2 [] = {
25, 38, 12, 25, 25, 38, 12, 12, 56, 25, 25, 50, 25,
25,100, 12, 12, 12, 25, 12, 38, 25,
38,12, 12,12, 38,12, 25,25, 38,12, 25,25, 100,25, 38,
12, 12, 12, 38, 12, 12, 12, 12, 25, 25, 38,
12, 12, 12, 38, 12, 25, 25, 38, 12, 25, 25,100, 25, 38, 12,
25,100
};
Unsigned int freq_alert [] = {
2000,240 0, 0
};
Unsigned int time_alert [] = {
50, 60
};
For (I = 0; I <5; I ++)
{
Play (freq_alert, time_alert );
}
Play (freq2, time2 );
}
Void play (unsigned int * freq, unsigned int * time)
{
Int I;
For (I = 0; freq [I]! = 0; I ++)
{
Speaker (freq [I], time [I]);
}
}
Int speaker (unsigned int freq, unsigned int delay)
{Static int flag = 0, bit;
If (flag = 0)
{
Flag = 1;
Iopl (3 );
}
Outb (0xb6, 0x43 );
Outb (freq & 0xff), 0x42 );
Outb (freq> 8), 0x42 );
Bit = inb (0x61 );
Outb (3 | bit, 0x61 );
Usleep (10000 * delay );
Outb (0xfc | bit, 0x61 );
}