comparison libao2/ao_sdl.c @ 8027:b9da278e4c92

verbose can be negative
author arpi
date Fri, 01 Nov 2002 17:46:45 +0000
parents dc96a3eb9fab
children 12b1790038b0
comparison
equal deleted inserted replaced
8026:b465ba5897a3 8027:b9da278e4c92
11 */ 11 */
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 15
16 #include "../config.h"
17 #include "../mp_msg.h"
18
16 #include "audio_out.h" 19 #include "audio_out.h"
17 #include "audio_out_internal.h" 20 #include "audio_out_internal.h"
18 #include "afmt.h" 21 #include "afmt.h"
19 #include <SDL.h> 22 #include <SDL.h>
20 23
27 "Felix Buenemann <atmosfear@users.sourceforge.net>", 30 "Felix Buenemann <atmosfear@users.sourceforge.net>",
28 "" 31 ""
29 }; 32 };
30 33
31 LIBAO_EXTERN(sdl) 34 LIBAO_EXTERN(sdl)
32
33
34 extern int verbose;
35 35
36 // Samplesize used by the SDLlib AudioSpec struct 36 // Samplesize used by the SDLlib AudioSpec struct
37 #define SAMPLESIZE 1024 37 #define SAMPLESIZE 1024
38 38
39 // General purpose Ring-buffering routines 39 // General purpose Ring-buffering routines
151 151
152 int i; 152 int i;
153 /* Allocate ring-buffer memory */ 153 /* Allocate ring-buffer memory */
154 for(i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE); 154 for(i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE);
155 155
156 printf("SDL: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); 156 mp_msg(MSGT_AO,MSGL_INFO,"SDL: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
157 157
158 if(ao_subdevice) { 158 if(ao_subdevice) {
159 setenv("SDL_AUDIODRIVER", ao_subdevice, 1); 159 setenv("SDL_AUDIODRIVER", ao_subdevice, 1);
160 printf("SDL: using %s audio driver\n", ao_subdevice); 160 mp_msg(MSGT_AO,MSGL_INFO,"SDL: using %s audio driver\n", ao_subdevice);
161 } 161 }
162 162
163 ao_data.channels=channels; 163 ao_data.channels=channels;
164 ao_data.samplerate=rate; 164 ao_data.samplerate=rate;
165 ao_data.format=format; 165 ao_data.format=format;
187 break; 187 break;
188 case AFMT_U16_BE: 188 case AFMT_U16_BE:
189 aspec.format = AUDIO_U16MSB; 189 aspec.format = AUDIO_U16MSB;
190 break; 190 break;
191 default: 191 default:
192 printf("SDL: Unsupported audio format: 0x%x.\n", format); 192 mp_msg(MSGT_AO,MSGL_WARN,"SDL: Unsupported audio format: 0x%x.\n", format);
193 return 0; 193 return 0;
194 } 194 }
195 195
196 /* The desired audio frequency in samples-per-second. */ 196 /* The desired audio frequency in samples-per-second. */
197 aspec.freq = rate; 197 aspec.freq = rate;
209 /* This pointer is passed as the first parameter to the callback function. */ 209 /* This pointer is passed as the first parameter to the callback function. */
210 aspec.userdata = NULL; 210 aspec.userdata = NULL;
211 211
212 /* initialize the SDL Audio system */ 212 /* initialize the SDL Audio system */
213 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) { 213 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) {
214 printf("SDL: Initializing of SDL Audio failed: %s.\n", SDL_GetError()); 214 mp_msg(MSGT_AO,MSGL_ERR,"SDL: Initializing of SDL Audio failed: %s.\n", SDL_GetError());
215 return 0; 215 return 0;
216 } 216 }
217 217
218 /* Open the audio device and start playing sound! */ 218 /* Open the audio device and start playing sound! */
219 if(SDL_OpenAudio(&aspec, &obtained) < 0) { 219 if(SDL_OpenAudio(&aspec, &obtained) < 0) {
220 printf("SDL: Unable to open audio: %s\n", SDL_GetError()); 220 mp_msg(MSGT_AO,MSGL_ERR,"SDL: Unable to open audio: %s\n", SDL_GetError());
221 return(0); 221 return(0);
222 } 222 }
223 223
224 /* did we got what we wanted ? */ 224 /* did we got what we wanted ? */
225 ao_data.channels=obtained.channels; 225 ao_data.channels=obtained.channels;
243 break; 243 break;
244 case AUDIO_U16MSB : 244 case AUDIO_U16MSB :
245 ao_data.format = AFMT_U16_BE; 245 ao_data.format = AFMT_U16_BE;
246 break; 246 break;
247 default: 247 default:
248 printf("SDL: Unsupported SDL audio format: 0x%x.\n", obtained.format); 248 mp_msg(MSGT_AO,MSGL_WARN,"SDL: Unsupported SDL audio format: 0x%x.\n", obtained.format);
249 return 0; 249 return 0;
250 } 250 }
251 251
252 if(verbose) printf("SDL: buf size = %d\n",obtained.size); 252 mp_msg(MSGT_AO,MSGL_V,"SDL: buf size = %d\n",obtained.size);
253 ao_data.buffersize=obtained.size; 253 ao_data.buffersize=obtained.size;
254 254
255 /* unsilence audio, if callback is ready */ 255 /* unsilence audio, if callback is ready */
256 SDL_PauseAudio(0); 256 SDL_PauseAudio(0);
257 257
258 return 1; 258 return 1;
259 } 259 }
260 260
261 // close audio device 261 // close audio device
262 static void uninit(){ 262 static void uninit(){
263 if(verbose) printf("SDL: Audio Subsystem shutting down!\n"); 263 mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n");
264 SDL_CloseAudio(); 264 SDL_CloseAudio();
265 SDL_QuitSubSystem(SDL_INIT_AUDIO); 265 SDL_QuitSubSystem(SDL_INIT_AUDIO);
266 } 266 }
267 267
268 // stop playing and empty buffers (for seeking/pause) 268 // stop playing and empty buffers (for seeking/pause)