主题 : mini2440 2.6.29内核不能录音 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 6642
精华: 0
发帖: 60
金钱: 335 两
威望: 113 点
综合积分: 120 分
注册时间: 2009-06-10
最后登录: 2018-10-14
楼主  发表于: 2009-12-13 16:27

 mini2440 2.6.29内核不能录音

板上自带的录音程序可以录音,自己找了一个程序,在班上跑没问题,就是录不到声音,在44100采样率的时候,放出来的是噪声
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#define LENGTH 3    /* 存储秒数 */
#define RATE 8000   /* 采样频率 */
#define SIZE 8      /* 量化位数 */
#define CHANNELS 1  /* 声道数目 */
/* 用于保存数字音频数据的内存缓冲区 */
unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];
int main()
{
  int fd;        /* 声音设备的文件描述符 */
  int arg;        /* 用于ioctl调用的参数 */
  int status;   /* 系统调用的返回值 */
  /* 打开声音设备 */
  fd = open("/dev/dsp", O_RDONLY);
  if (fd < 0) {
    perror("open of /dev/dsp failed");
    exit(1);
  }
  /* 设置采样时的量化位数 */
  arg = SIZE;
  status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
  if (status == -1)
    perror("SOUND_PCM_WRITE_BITS ioctl failed");
  if (arg != SIZE)
    perror("unable to set sample size");
  /* 设置采样时的声道数目 */
  arg = CHANNELS;
  status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
  if (status == -1)
    perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
  if (arg != CHANNELS)
    perror("unable to set number of channels");
  /* 设置采样时的采样频率 */
  arg = RATE;
  status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
  if (status == -1)
    perror("SOUND_PCM_WRITE_WRITE ioctl failed");
  /* 循环,直到按下Control-C */
// while (1) {
//   printf("Say something:\n");
    status = read(fd, buf, sizeof(buf)); /* 录音 */
    if (status != sizeof(buf))
      perror("read wrong number of bytes");
//   printf("You said:\n");
//    status = write(fd, buf, sizeof(buf)); /* 回放 */
//    if (status != sizeof(buf))
//     perror("wrote wrong number of bytes");
    /* 在继续录音前等待回放结束 */
//   status = ioctl(fd, SOUND_PCM_SYNC, 0);
//   if (status == -1)
//     perror("SOUND_PCM_SYNC ioctl failed");
//  }
}
级别: 新手上路
UID: 6720
精华: 0
发帖: 6
金钱: 30 两
威望: 6 点
综合积分: 12 分
注册时间: 2009-06-13
最后登录: 2010-01-05
1楼  发表于: 2009-12-24 11:26
头痛死了,不知道怎么解决~
级别: 新手上路
UID: 6720
精华: 0
发帖: 6
金钱: 30 两
威望: 6 点
综合积分: 12 分
注册时间: 2009-06-13
最后登录: 2010-01-05
2楼  发表于: 2009-12-24 18:09
你这程序只有录,没有保存,也没有放