comparison libao2/ao_oss.c @ 3181:c8edb0691f09

Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
author steve
date Wed, 28 Nov 2001 12:46:23 +0000
parents b9ee2d8d7279
children 66134af21278
comparison
equal deleted inserted replaced
3180:d53f70e3c794 3181:c8edb0691f09
23 "OSS/ioctl audio output", 23 "OSS/ioctl audio output",
24 "oss", 24 "oss",
25 "A'rpi", 25 "A'rpi",
26 "" 26 ""
27 }; 27 };
28
29 /* Support for >2 output channels added 2001-11-25 - Steve Davies <steve@daviesfam.org> */
28 30
29 LIBAO_EXTERN(oss) 31 LIBAO_EXTERN(oss)
30 32
31 static char *dsp="/dev/dsp"; 33 static char *dsp="/dev/dsp";
32 static audio_buf_info zz; 34 static audio_buf_info zz;
93 95
94 // open & setup audio device 96 // open & setup audio device
95 // return: 1=success 0=fail 97 // return: 1=success 0=fail
96 static int init(int rate,int channels,int format,int flags){ 98 static int init(int rate,int channels,int format,int flags){
97 99
98 // printf("ao2: %d Hz %d chans %s\n",rate,channels, 100 printf("ao2: %d Hz %d chans %s\n",rate,channels,
99 // audio_out_format_name(format)); 101 audio_out_format_name(format));
100 102
101 if (ao_subdevice) 103 if (ao_subdevice)
102 dsp = ao_subdevice; 104 dsp = ao_subdevice;
103 105
104 if (verbose) 106 if (verbose)
122 } 124 }
123 printf("audio_setup: sample format: %s (requested: %s)\n", 125 printf("audio_setup: sample format: %s (requested: %s)\n",
124 audio_out_format_name(ao_data.format), audio_out_format_name(format)); 126 audio_out_format_name(ao_data.format), audio_out_format_name(format));
125 127
126 if(format != AFMT_AC3) { 128 if(format != AFMT_AC3) {
127 ao_data.channels=channels-1; 129 // We only use SNDCTL_DSP_CHANNELS for >2 channels, in case some drivers don't have it
128 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_data.channels); 130 ao_data.channels = channels;
129 131 if (ao_data.channels > 2) {
130 // set rate 132 if (ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels) == -1) {
131 ao_data.samplerate=rate; 133 printf("audio_setup: Failed to set audio device to %d channels\n", ao_data.channels);
132 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); 134 return 0;
133 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate); 135 }
136 }
137 else {
138 int c = ao_data.channels-1;
139 if (ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1) {
140 printf("audio_setup: Failed to set audio device to %d channels\n", ao_data.channels);
141 return 0;
142 }
143 }
144 printf("audio_setup: using %d channels (requested: %d)\n", ao_data.channels, ao_data.channels);
145 // set rate
146 ao_data.samplerate=rate;
147 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
148 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
134 } 149 }
135 150
136 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){ 151 if(ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &zz)==-1){
137 int r=0; 152 int r=0;
138 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n"); 153 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
193 return; 208 return;
194 } 209 }
195 210
196 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format); 211 ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_data.format);
197 if(ao_data.format != AFMT_AC3) { 212 if(ao_data.format != AFMT_AC3) {
198 ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_data.channels); 213 if (ao_data.channels > 2)
199 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate); 214 ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels);
215 else {
216 int c = ao_data.channels-1;
217 ioctl (audio_fd, SNDCTL_DSP_STEREO, &c);
218 }
219 ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
200 } 220 }
201 } 221 }
202 222
203 // stop playing, keep buffers (for pause) 223 // stop playing, keep buffers (for pause)
204 static void audio_pause() 224 static void audio_pause()
265 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps; 285 return ((float)(ao_data.buffersize-zz.bytes))/(float)ao_data.bps;
266 audio_delay_method=0; // fallback if not supported 286 audio_delay_method=0; // fallback if not supported
267 } 287 }
268 return ((float)ao_data.buffersize)/(float)ao_data.bps; 288 return ((float)ao_data.buffersize)/(float)ao_data.bps;
269 } 289 }
270
271
272
273