comparison libao2/ao_sdl.c @ 983:cb0e3b29a0dd

Several small changes (like driver selection).
author atmosfear
date Mon, 04 Jun 2001 00:27:55 +0000
parents 65353ed24ac5
children 95391cf9e994
comparison
equal deleted inserted replaced
982:20e57b98de98 983:cb0e3b29a0dd
32 // ao_channels 32 // ao_channels
33 // ao_format 33 // ao_format
34 // ao_bps 34 // ao_bps
35 // ao_outburst 35 // ao_outburst
36 // ao_buffersize 36 // ao_buffersize
37
38 extern int verbose;
39 /* audio driver to be used by SDLlib */
40 char *sdl_adriver;
37 41
38 // Samplesize used by the SDLlib AudioSpec struct 42 // Samplesize used by the SDLlib AudioSpec struct
39 #define SAMPLESIZE 512 43 #define SAMPLESIZE 512
40 44
41 // General purpose Ring-buffering routines 45 // General purpose Ring-buffering routines
119 /* SDL Audio Specifications */ 123 /* SDL Audio Specifications */
120 SDL_AudioSpec aspec; 124 SDL_AudioSpec aspec;
121 125
122 int i; 126 int i;
123 /* Allocate ring-buffer memory */ 127 /* Allocate ring-buffer memory */
124 for(i=0;i<NUM_BUFS;i++) buffer[i]=malloc(BUFFSIZE); 128 for(i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE);
125 129
126 printf("SDL: Samplerate: %iHz Channels: %s Format %iBit\n", rate, (channels > 1) ? "Stereo" : "Mono", format); 130 printf("SDL: Samplerate: %iHz Channels: %s Format %iBit\n", rate, (channels > 1) ? "Stereo" : "Mono", format);
131
132 if(sdl_adriver) {
133 setenv("SDL_AUDIODRIVER", sdl_adriver, 1);
134 printf("SDL: using %s audio driver\n", sdl_adriver);
135 }
136
127 137
128 /* The desired audio frequency in samples-per-second. */ 138 /* The desired audio frequency in samples-per-second. */
129 aspec.freq = rate; 139 aspec.freq = rate;
130 140
131 /* The desired audio format (see SDL_AudioSpec) */ 141 /* The desired audio format (see SDL_AudioSpec) */
154 if(SDL_OpenAudio(&aspec, NULL) < 0) { 164 if(SDL_OpenAudio(&aspec, NULL) < 0) {
155 printf("SDL: Unable to open audio: %s\n", SDL_GetError()); 165 printf("SDL: Unable to open audio: %s\n", SDL_GetError());
156 return(0); 166 return(0);
157 } 167 }
158 168
159 printf("SDL buf size = %d\n",aspec.size); 169 if(verbose) printf("SDL: buf size = %d\n",aspec.size);
160 if(ao_buffersize==-1) ao_buffersize=aspec.size; 170 if(ao_buffersize==-1) ao_buffersize=aspec.size;
161 171
162 /* unsilence audio, if callback is ready */ 172 /* unsilence audio, if callback is ready */
163 SDL_PauseAudio(0); 173 SDL_PauseAudio(0);
164 174
165 return 1; 175 return 1;
166 } 176 }
167 177
168 // close audio device 178 // close audio device
169 static void uninit(){ 179 static void uninit(){
180 if(verbose) printf("SDL: Audio Subsystem shutting down!\n");
170 SDL_CloseAudio(); 181 SDL_CloseAudio();
171 SDL_QuitSubSystem(SDL_INIT_AUDIO); 182 SDL_QuitSubSystem(SDL_INIT_AUDIO);
172 } 183 }
173 184
174 // stop playing and empty buffers (for seeking/pause) 185 // stop playing and empty buffers (for seeking/pause)
193 // plays 'len' bytes of 'data' 204 // plays 'len' bytes of 'data'
194 // it should round it down to outburst*n 205 // it should round it down to outburst*n
195 // return: number of bytes played 206 // return: number of bytes played
196 static int play(void* data,int len,int flags){ 207 static int play(void* data,int len,int flags){
197 208
198 #if 0 209 #if 1
199 int ret; 210 int ret;
200 211
201 /* Audio locking prohibits call of outputaudio */ 212 /* Audio locking prohibits call of outputaudio */
202 SDL_LockAudio(); 213 SDL_LockAudio();
203 // copy audio stream into ring-buffer 214 // copy audio stream into ring-buffer