QNX系统中播放wav文件

QNX 中播放音频,用的是libasound 库。
官方提供的 wave.c 的代码,用于播放一个wav格式的音频文件。
但在QNX 6.6 虚拟机里一直播放不了,原因是虚拟机没有/dev/snd/ 而且该目录下也没什么设备。继续看官方的帮助文档,是要运行/sbin/io-audio加载声卡驱动才能播放。

The io-audio command can load the following shared objects:

deva-ctrl-4dwave.so
Sound driver for the Trident 4DWave!.
deva-ctrl-audiopci.so
Sound driver for the AudioPCI chip family.
deva-ctrl-cs4281.so
Sound driver for the CS4281.
deva-ctrl-cs46xx.so
Sound driver for the CS46xx family of chips.
deva-ctrl-cyberpro5.so
Sound driver for the CyberPro5XXX.
deva-ctrl-ess1938.so
Sound driver for the ESS1938.
deva-ctrl-geode.so
Sound driver for the National Semiconductor Geode family of chips.
deva-ctrl-i8x0.so
Sound driver for the Intel 8X0.
deva-ctrl-nmg6.so
Sound driver for the Neomagic 6 family of chips.
deva-ctrl-sb.so
Sound driver for Sound Blaster 16 and compatible soundcards.
deva-ctrl-via686.so
Sound driver for the VIA686.
deva-ctrl-vortex.so
Sound driver for the Vortex.
deva-ctrl-ymfds1.so
Sound driver for the Yamaha DS1.
deva-mixer-ac97.so
Mixer DLL for the AC97 codec.
deva-ak4531.so
Mixer DLL for the AK4531 codec.
deva-util-restore.so
Shared object used to restore an audio driver’s state.

在虚拟机内执行:

/sbin/io-audio -d audiopci

加载驱动后,出现了/dev/snd/ 目录,而且目录下有文件

# /sbin/io-audio -d audiopci    
# ls /dev/snd/
controlC0        mixerC0D0        pcmC0D0c         pcmC0D0p         pcmC0D1p         pcmPreferredc    pcmPreferredp

这样就可以用官网那个例子进行播放了,播放命令如下:

# ./playWave -a 0:0 Wave1.wav       
Using card 0 device 0 
SampleRate = 11025, Channels = 2, SampleBits = 16
Format Signed 16-bit Little Endian 
Frag Size 131072 
Total Frags 2 
Rate 11025 
Voices 2 
Mixer Pcm Group [PCM]

将wave.c 中调音量等复杂功能裁剪掉,写成一个只播放的demo:

#include <errno.h>
#include <fcntl.h>
#include <gulliver.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/termio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/slogcodes.h>
#include <ctype.h>
#include <limits.h>

#include <sys/asoundlib.h>
#define max(a,b) (a>b)?a:b
#define min(a,b) (a<b)?a:b

const char *kRiffId = "RIFF";
const char *kWaveId = "WAVE";

typedef struct
{
    char    tag[4];
    long    length;
}
RiffTag;

typedef struct
{
    char    Riff[4];
    long    Size;
    char    Wave[4];
}
RiffHdr;

typedef struct
{
    
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值