Speaker Applet in Linux

Source: Internet
Author: User

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 );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.