亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4008 | 回復(fù): 4
打印 上一主題 下一主題

linux音頻設(shè)備驅(qū)動問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2008-05-06 11:20 |只看該作者 |倒序?yàn)g覽
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>

#define BUF_LENGTH 2000
#define CHANNELS 0  /*0--single channel;2--double channel*/
#define SAMPLE_RATE 8000   

int set_fmt(int audio_fd, int bits, int rate, int channel)
{
        int status = -1;

        if( -1 == ioctl(audio_fd, SNDCTL_DSP_SAMPLESIZE, &bits))
        {
                perror("ioctl SNDCTL_DSP_SAMPLESIZE");
                exit(1);
        }

        if(-1 == ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate))
        {
                perror("ioctl SNDCTL_DSP_SPEED");
                exit(1);
        }

        if(-1 == ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channel))
        {
                perror("ioctl SNDCTL_DSP_CHANNELS");
                exit(1);
        }

        return(0);
}

main()
{
        int audio_fd = 0;
        int bytes = 0;
        int i = 0;
        char buf[BUF_LENGTH];

       
        audio_fd = open("/dev/dsp", O_RDWR);
        if(audio_fd < 0)
        {
                perror("open /dev/dsp");
                exit(1);
        }
       
        if(-1 == (set_fmt(audio_fd, AFMT_U8, SAMPLE_RATE, CHANNELS)))
        {
                perror("set_fmt");
                exit(1);
        }

        for(i=0; i<5000; i++)
        {
                if(-1 == (bytes = read(audio_fd, buf, BUF_LENGTH)))
                {
                        perror("read");
                        exit(1);
                }
                if(-1 == write(audio_fd, buf, bytes))
                {
                        perror("write");
                        exit(1);
                }
               
        }
       
        printf("It'll be closed\n");
        close(audio_fd);
}

使用這段代碼編譯后,為什么不能使用阿?沒有任何錯誤信息,就是不出聲!!

論壇徽章:
0
2 [報告]
發(fā)表于 2008-05-06 13:02 |只看該作者

回復(fù) #1 cc-liuwei 的帖子

請分開些,打開設(shè)備的時候不要用O_RDWR!
O_RDONLY - record
O_WRONLY - playback

OSS里面好像建議這樣做

論壇徽章:
0
3 [報告]
發(fā)表于 2008-05-06 14:08 |只看該作者
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>

#define BUF_LENGTH 2000
#define CHANNELS 0  /*0--single channel;2--double channel*/
#define SAMPLE_RATE 8000   

int set_fmt(int audio_fd, int bits, int rate, int channel)
{
        int status = -1;

        if( -1 == ioctl(audio_fd, SNDCTL_DSP_SAMPLESIZE, &bits))
        {
                perror("ioctl SNDCTL_DSP_SAMPLESIZE");
                exit(1);
        }

        if(-1 == ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate))
        {
                perror("ioctl SNDCTL_DSP_SPEED");
                exit(1);
        }

        if(-1 == ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channel))
        {
                perror("ioctl SNDCTL_DSP_CHANNELS");
                exit(1);
        }

        return(0);
}

main()
{
        int audio_fd = 0;
        int bytes = 0;
        int i = 0;
        char buf[BUF_LENGTH];

       
        audio_fd = open("/dev/dsp", O_RDONLY);
        if(audio_fd < 0)
        {
                perror("open /dev/dsp");
                exit(1);
        }
       
        if(-1 == (set_fmt(audio_fd, AFMT_U8, SAMPLE_RATE, CHANNELS)))
        {
                perror("set_fmt");
                exit(1);
        }

        for(i=0; i<500; i++)
        {
                if(-1 == (bytes = read(audio_fd, buf, BUF_LENGTH)))
                {
                        perror("read");
                        exit(1);
                }
        }
        close(audio_fd);
       
        audio_fd = open("/dev/dsp", O_WRONLY);
        if(audio_fd < 0)
        {
                perror("open /dev/dsp");
                exit(1);
        }
       
        if(-1 == (set_fmt(audio_fd, AFMT_U8, SAMPLE_RATE, CHANNELS)))
        {
                perror("set_fmt");
                exit(1);
        }

        for(i=0; i<500; i++)
        {
        if(-1 == write(audio_fd, buf, bytes))
                {
                        perror("write");
                        exit(1);
                }
               
        }
       
        printf("It'll be closed\n");
        close(audio_fd);
}
是這樣寫馬?不行阿,好像打開設(shè)備就有問題……程序就是到open這里就運(yùn)行不了了……

論壇徽章:
0
4 [報告]
發(fā)表于 2008-05-06 19:23 |只看該作者

回復(fù) #3 cc-liuwei 的帖子

我用你的代碼編譯過,試過了, 代碼邏輯沒有問題。但是運(yùn)行時間可能有些久,是不是你說的運(yùn)行不了就是指的程序沒有結(jié)束呢?如果是這樣,那請你多等一會,如果不是,就再說了。反正在我這邊是沒有問題的.

時間久的原因:低采樣率和采樣精度,因?yàn)?K 8bit的采樣率每秒產(chǎn)生的數(shù)據(jù)量是很低的。填充總長是2K*500的buffer需要一定時間。可以選擇小的循環(huán)次數(shù)來做測試。

論壇徽章:
0
5 [報告]
發(fā)表于 2008-05-23 12:37 |只看該作者
我也用你的編程試過,是可以跑的,只是時間會比較久。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP