/**
* file: test.c
* author: rare
* date: 2009/04/15
*/
#include <stdio.h>
#include <ao/ao.h>
int main(int argc, char** argv)
{
FILE* fp;
char buf[4096];
int len;
ao_device* dev;
ao_sample_format fmt = {0};
fp = fopen(argv[1], "rb");
if (!fp)
{
perror("fopen error/n");
exit(-1);
}
ao_initialize();
fmt.bits = 16;
fmt.rate = 8000;
fmt.channels = 1;
fmt.byte_format = AO_FMT_NATIVE;
dev = ao_open_live(ao_default_driver_id(), &fmt, NULL);
while (!feof(fp))
{
len = fread(buf, 1, 4096, fp);
if (len > 0)
ao_play(dev, buf, len);
}
ao_close(dev);
ao_shutdown();
fclose(fp);
return 0;
}
参考:
http://www.xiph.org/ao/doc/overview.html