天嵌 ARM开发社区

 找回密码
 注册
查看: 2467|回复: 5

tq2440声音播放的问题

[复制链接]
队长阿超 发表于 2013-2-26 12:24:56 | 显示全部楼层 |阅读模式
光盘自带的2.6.30.4内核使用的声卡驱动为ALSA的,因为ALSA兼容OSS的API,所以我用OSS的函数写了一个播放程序,但是在板子上运行时,声音跟快进一样,但是使用板子中QT的播放程序播放正常。
我的代码如下:
  1. //play


  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. #include "unistd.h"
  5. #include "fcntl.h"
  6. #include "sys/types.h"
  7. #include "sys/ioctl.h"
  8. #include "linux/soundcard.h"
  9. #include "termios.h"

  10. #define RATE 8000
  11. #define CHANNELS 1
  12. #define BITS 16
  13. #define SIZE 320


  14. unsigned char buf[SIZE];


  15. int main(int argc,char **argv)
  16. {
  17.         int dspw;
  18.         int arg;
  19.         FILE *outfd;
  20.         char *name;
  21.        
  22.         if(argc!=2)
  23.         {
  24.                 printf("usage:        %s                file_name\n",argv[0]);
  25.                 return 0;               
  26.         }
  27.         name=argv[1];
  28.        
  29.         //write only /dev/dsp
  30.         dspw=open("/dev/dsp",O_WRONLY);
  31.         if(dspw<0)
  32.         {
  33.                 perror("open /dev/dsp writeonly error\n");
  34.                 return 1;
  35.         }
  36.                 arg=BITS;
  37.         if(ioctl(dspw,SOUND_PCM_WRITE_BITS,&arg)==-1)
  38.         {
  39.                 perror("set writeonly /dev/dsp bits error\n");
  40.                 return 1;
  41.         }
  42.         arg=RATE;
  43.         if(ioctl(dspw,SOUND_PCM_WRITE_RATE,&arg)==-1)
  44.         {
  45.                 perror("set writeonly /dev/dsp rate error\n");
  46.                 return 1;
  47.         }
  48.         arg=CHANNELS;
  49.         if(ioctl(dspw,SOUND_PCM_WRITE_CHANNELS,&arg)==-1)
  50.         {
  51.                 perror("set writeonly /dev/dsp channels error\n");
  52.                 return 1;
  53.         }
  54.        
  55.         //outfile open
  56.         outfd=fopen(name,"r");
  57.         if(outfd==NULL)
  58.         {
  59.                 printf("open %s error\n",argv[1]);
  60.                 return 1;
  61.         }
  62.        
  63.         while(!feof(outfd))
  64.         {
  65.                 fread(buf,1,sizeof(buf),outfd);
  66.                 write(dspw,buf,sizeof(buf));
  67.         }
  68.        
  69.         close(dspw);
  70.         fclose(outfd);
  71.         return 0;
  72. }

复制代码

 楼主| 队长阿超 发表于 2013-2-26 13:41:27 | 显示全部楼层
自顶。。。。
回复

使用道具 举报

TQ-lkp 发表于 2013-2-26 13:58:15 | 显示全部楼层
先在windows下或使用mplayer查看下你播放的声频文件使用的频率,通道之类的参数,声音播放参数要匹配,否则就会像你说的快进之类的现象
回复

使用道具 举报

 楼主| 队长阿超 发表于 2013-2-26 15:39:13 | 显示全部楼层
我看过了,8khz,采样位数16bit,单声道,配置应该没错
回复

使用道具 举报

 楼主| 队长阿超 发表于 2013-2-26 17:12:26 | 显示全部楼层
奇了怪了,我的音频文件时单声道,16bit的,在编程时设置声道数和采样位数如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复

使用道具 举报

 楼主| 队长阿超 发表于 2013-2-26 17:12:57 | 显示全部楼层
有谁对音频比较了解的,帮帮我把
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2025-6-23 23:32 , Processed in 2.048162 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表