forked from skaman/shairport
-
Notifications
You must be signed in to change notification settings - Fork 1
/
audio_ao.c
125 lines (105 loc) · 2.79 KB
/
audio_ao.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
//#include <sys/signal.h>
#include <ao/ao.h>
#include "common.h"
#define NUM_CHANNELS 2
static char libao_driver[56] = "";
static char libao_devicename[56] = "";
static char libao_deviceid[56] = ""; // ao_options expects "char*"
void parse_audio_arg(char* arg)
{
if (!strncmp(arg, "--ao_driver=",12))
{
strncpy(libao_driver,arg+12,55);
}
if (!strncmp(arg, "--ao_devicename=",16))
{
strncpy(libao_devicename,arg+16,55);
}
if (!strncmp(arg, "--ao_deviceid=",14))
{
strncpy(libao_deviceid,arg+14,55);
}
}
void print_audio_args()
{
printf(" --ao_driver=<driver> Sets libao driver\n");
printf(" --ao_devicename=<devicename> Sets libao device name\n");
printf(" --ao_deviceid=<deviceid> Sets libao device ID\n");
}
/*
void audio_set_driver(char* driver) {
if (strlen(driver)!=0){
libao_driver = driver;
}
}
void audio_set_device_name(char* device_name) {
if (strlen(device_name)!=0){
libao_devicename = device_name;
}
}
void audio_set_device_id(char* device_id) {
if (strlen(device_id)!=0){
libao_deviceid = device_id;
}
}
char* audio_get_driver(void)
{
return libao_driver;
}
char* audio_get_device_name(void)
{
return libao_devicename;
}
char* audio_get_device_id(void)
{
return libao_deviceid;
}
*/
inline void audio_play(char* outbuf, int samples, void* priv_data)
{
ao_device* dev = priv_data;
ao_play(dev, outbuf, samples*4);
}
void* audio_init(int sampling_rate)
{
ao_initialize();
int driver;
if (strlen(libao_driver)!=0) {
// if a libao driver is specified on the command line, use that
driver = ao_driver_id(libao_driver);
if (driver == -1) {
die("Could not find requested ao driver");
}
} else {
// otherwise choose the default
driver = ao_default_driver_id();
}
ao_sample_format fmt;
memset(&fmt, 0, sizeof(fmt));
fmt.bits = 16;
fmt.rate = sampling_rate;
fmt.channels = NUM_CHANNELS;
fmt.byte_format = AO_FMT_NATIVE;
ao_option *ao_opts = NULL;
if(strlen(libao_deviceid)!=0) {
ao_append_option(&ao_opts, "id", libao_deviceid);
} else if(strlen(libao_devicename)!=0){
ao_append_option(&ao_opts, "dev", libao_devicename);
// Old libao versions (for example, 0.8.8) only support
// "dsp" instead of "dev".
ao_append_option(&ao_opts, "dsp", libao_devicename);
}
ao_device *dev = ao_open_live(driver, &fmt, ao_opts);
if (dev == NULL) {
die("Could not open ao device");
}
return dev;
}
void audio_deinit(void)
{
// deinitialization not required with libao?
}