主题 : OSS如何设置录音源为LINE-IN(已解决) 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 9416
精华: 1
发帖: 6
金钱: 80 两
威望: 40 点
综合积分: 32 分
注册时间: 2009-09-28
最后登录: 2017-09-13
楼主  发表于: 2009-09-28 23:16

 OSS如何设置录音源为LINE-IN(已解决)

mini2440 2.6.29内核,演示录音程序默认是麦克风,
我想从con10插座接上耳机插座,拿音频线一头PC,另一头接con10,这样就像LINE-IN一样
以下程序在PC上可以看到,SOUND_MIXER_READ_RECMASK返回了很多可用录音源,


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/soundcard.h>
#include <time.h>

#define DEVICE_NAME "/dev/dsp"
#define BUF_SIZE 4096
int audio_fd;
int mixer_fd;
unsigned char audio_buffer[BUF_SIZE];


int main(int argc, char *argv[])
{
    int version;
    
    int ret;
    if ((audio_fd = open(DEVICE_NAME, O_RDONLY, 0)) == -1)
    {

    perror(DEVICE_NAME);
    exit(1);
    }
    if ((mixer_fd = open("/dev/mixer", O_RDONLY, 0)) == -1)
    {

        perror(DEVICE_NAME);
        exit(1);
    }
    ret=ioctl(audio_fd,OSS_GETVERSION,&version);
    if(ret<0)
    {
        perror("OSS_GETVERSION");
    }
    printf("the version is 0x0%x\n",version);
    printf("After convert\n");
    printf("the OSS api version is %x.%x  and %x rd\n",(version>>16)&0xff ,(version>>8)&0xff,(version>>4)&0x0f);

    int mask;
    if (ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &mask) == -1)
    {
        perror("/dev/mixer");
    }
    printf("%x\n",mask);
    if (ioctl(mixer_fd, SOUND_MIXER_READ_RECSRC, &mask) == -1)
    {
        perror("/dev/mixer");
    }
    
    printf("%x\n",mask);

    close(audio_fd);
    close(mixer_fd);
      return 0;
}



但是在mini2440上,SOUND_MIXER_READ_RECMASK和SOUND_MIXER_READ_RECSRC都是0
就是说没有可用的录音设备啊,
强行设置一个录音源,没有报错,可是还是显示两个0
mask = 1<<SOUND_MIXER_MIC;
    ret=ioctl(mixer_fd, SOUND_MIXER_WRITE_RECSRC, &mask);
    if(ret<0)
{
    perror("set recsrc");
}

再顺带问一下,如何编译到mini2440上能运行的程序阿,
我是把以上代码 arm-linux-gcc  加上 -static 编译后才能在板子上跑,
总觉得不好,请教各位高手
[ 此帖被deep_pro在2009-10-07 21:42重新编辑 ]
级别: 新手上路
UID: 9416
精华: 1
发帖: 6
金钱: 80 两
威望: 40 点
综合积分: 32 分
注册时间: 2009-09-28
最后登录: 2017-09-13
1楼  发表于: 2009-09-29 09:21
补充 手册上的con10口标记错误
在无OSS的情况下用2440test测试con10录音通过
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
2楼  发表于: 2009-09-29 10:08
引用第1楼deep_pro于2009-09-29 09:21发表的  :
补充 手册上的con10口标记错误
在无OSS的情况下用2440test测试con10录音通过

把具体的错误告诉论坛上的qq2440吧,希望友善之臂能尽快更新手册
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 9416
精华: 1
发帖: 6
金钱: 80 两
威望: 40 点
综合积分: 32 分
注册时间: 2009-09-28
最后登录: 2017-09-13
3楼  发表于: 2009-10-07 21:43
自己动手,丰衣足食
下个2.6.29的代码,diff一下,/sound中只改了一行代码