科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道基础软件Linux下扬声器发声的小程序

Linux下扬声器发声的小程序

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

这是一个很简音的Linux下扬声器发声的小程序,以下为源程序。

作者:www_from2003_com 来源:中国软件网 2008年3月31日

关键字: 扬声器 Linux C++ C

  • 评论
  • 分享微博
  • 分享邮件

这是一个很简音的Linux下扬声器发声的小程序,以下为源程序。 

#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,25,12,12,56,25,25,50,25,
        38,12,12,12,38,12,25,12,12,38,12,25,25,100,25,
        38,12,12,12,38,12,25,25,38,12,25,25,100,25,38,
        12,12,12,38,12,25,12,12,38,12,25,25,100,25,38,
        12,12,12,38,12,25,25,38,12,25,25,100,25,38,12,
        12,12,38,12,25,12,12,38,12,25,25,100
    };
   unsigned int freq_alert[]={
        2000, 2400, 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);
}

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章