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
{