Mercurial > mplayer.hg
annotate libao2/ao_sdl.c @ 13544:b11c66fc5ace
-alang is not limited to the libdvdread dependant code anymore but used in other demuxers as well. Therefore it should not be inside a "#ifdef USE_DVDREAD".
author | mosu |
---|---|
date | Mon, 04 Oct 2004 18:34:39 +0000 |
parents | c1955840883d |
children | 2f8cfe66dbfd |
rev | line source |
---|---|
972 | 1 /* |
2 * ao_sdl.c - libao2 SDLlib Audio Output Driver for MPlayer | |
3 * | |
4 * This driver is under the same license as MPlayer. | |
11750 | 5 * (http://www.mplayerhq.hu) |
972 | 6 * |
7 * Copyleft 2001 by Felix Bünemann (atmosfear@users.sf.net) | |
8 * | |
9 * Thanks to Arpi for nice ringbuffer-code! | |
10 * | |
11 */ | |
12 | |
966 | 13 #include <stdio.h> |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
14 #include <stdlib.h> |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
15 #include <string.h> |
966 | 16 |
8027 | 17 #include "../config.h" |
18 #include "../mp_msg.h" | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
19 #include "../help_mp.h" |
8027 | 20 |
966 | 21 #include "audio_out.h" |
22 #include "audio_out_internal.h" | |
1066 | 23 #include "afmt.h" |
6184 | 24 #include <SDL.h> |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
25 #include "osdep/timer.h" |
966 | 26 |
972 | 27 #include "../libvo/fastmemcpy.h" |
28 | |
966 | 29 static ao_info_t info = |
30 { | |
31 "SDLlib audio output", | |
32 "sdl", | |
33 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
34 "" | |
35 }; | |
36 | |
37 LIBAO_EXTERN(sdl) | |
38 | |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
39 // turn this on if you want to use the slower SDL_MixAudio |
12908
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12714
diff
changeset
|
40 #undef USE_SDL_INTERNAL_MIXER |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
41 |
972 | 42 // Samplesize used by the SDLlib AudioSpec struct |
12113 | 43 #ifdef WIN32 |
12019
6ede5366bc47
fix compilation with sdl on mingw patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
11750
diff
changeset
|
44 #define SAMPLESIZE 2048 |
12113 | 45 #else |
46 #define SAMPLESIZE 1024 | |
47 #endif | |
972 | 48 |
49 // General purpose Ring-buffering routines | |
50 | |
974 | 51 #define BUFFSIZE 4096 |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
52 #define NUM_BUFS 8 |
972 | 53 |
54 static unsigned char *buffer[NUM_BUFS]; | |
55 | |
56 static unsigned int buf_read=0; | |
57 static unsigned int buf_write=0; | |
58 static unsigned int buf_read_pos=0; | |
59 static unsigned int buf_write_pos=0; | |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
60 #ifdef USE_SDL_INTERNAL_MIXER |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
61 static unsigned char volume=SDL_MIX_MAXVOLUME; |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
62 #endif |
972 | 63 static int full_buffers=0; |
64 static int buffered_bytes=0; | |
65 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
66 |
972 | 67 static int write_buffer(unsigned char* data,int len){ |
68 int len2=0; | |
69 int x; | |
70 while(len>0){ | |
71 if(full_buffers==NUM_BUFS) break; | |
72 x=BUFFSIZE-buf_write_pos; | |
73 if(x>len) x=len; | |
74 memcpy(buffer[buf_write]+buf_write_pos,data+len2,x); | |
12151
75fdb659f5bf
round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
12145
diff
changeset
|
75 if (buf_write_pos==0) |
75fdb659f5bf
round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
12145
diff
changeset
|
76 ++full_buffers; |
972 | 77 len2+=x; len-=x; |
78 buffered_bytes+=x; buf_write_pos+=x; | |
79 if(buf_write_pos>=BUFFSIZE){ | |
80 // block is full, find next! | |
81 buf_write=(buf_write+1)%NUM_BUFS; | |
82 buf_write_pos=0; | |
83 } | |
84 } | |
85 return len2; | |
86 } | |
87 | |
88 static int read_buffer(unsigned char* data,int len){ | |
89 int len2=0; | |
90 int x; | |
91 while(len>0){ | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
92 if(buffered_bytes==0) break; // no more data buffered! |
972 | 93 x=BUFFSIZE-buf_read_pos; |
94 if(x>len) x=len; | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
95 if (x>buffered_bytes) x=buffered_bytes; |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
96 #ifdef USE_SDL_INTERNAL_MIXER |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
97 SDL_MixAudio(data+len2,buffer[buf_read]+buf_read_pos,x,volume); |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
98 #else |
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
99 memcpy(data+len2,buffer[buf_read]+buf_read_pos,x); |
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
100 #endif |
972 | 101 len2+=x; len-=x; |
102 buffered_bytes-=x; buf_read_pos+=x; | |
103 if(buf_read_pos>=BUFFSIZE){ | |
104 // block is empty, find next! | |
105 buf_read=(buf_read+1)%NUM_BUFS; | |
106 --full_buffers; | |
107 buf_read_pos=0; | |
108 } | |
109 } | |
110 return len2; | |
111 } | |
112 | |
113 // end ring buffer stuff | |
966 | 114 |
12027
210e474436d3
Cygwin provides setenv. Fixes compilation on Cygwin.
diego
parents:
12019
diff
changeset
|
115 #if defined(__MINGW32__) || defined(HPUX) || defined(sgi) || (defined(sun) && defined(__svr4__)) |
12019
6ede5366bc47
fix compilation with sdl on mingw patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
11750
diff
changeset
|
116 /* setenv is missing on win32, solaris, IRIX and HPUX */ |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
117 static void setenv(const char *name, const char *val, int _xx) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
118 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
119 int len = strlen(name) + strlen(val) + 2; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
120 char *env = malloc(len); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
121 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
122 if (env != NULL) { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
123 strcpy(env, name); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
124 strcat(env, "="); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
125 strcat(env, val); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
126 putenv(env); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
127 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
128 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
129 #endif |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
130 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
131 |
966 | 132 // to set/get/query special features/parameters |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8027
diff
changeset
|
133 static int control(int cmd,void *arg){ |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
134 #ifdef USE_SDL_INTERNAL_MIXER |
6184 | 135 switch (cmd) { |
136 case AOCONTROL_GET_VOLUME: | |
137 { | |
138 ao_control_vol_t* vol = (ao_control_vol_t*)arg; | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
139 vol->left = vol->right = volume * 100 / SDL_MIX_MAXVOLUME; |
6184 | 140 return CONTROL_OK; |
141 } | |
142 case AOCONTROL_SET_VOLUME: | |
143 { | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
144 int diff; |
6184 | 145 ao_control_vol_t* vol = (ao_control_vol_t*)arg; |
146 diff = (vol->left+vol->right) / 2; | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
147 volume = diff * SDL_MIX_MAXVOLUME / 100; |
6184 | 148 return CONTROL_OK; |
149 } | |
150 } | |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
151 #endif |
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
152 return CONTROL_UNKNOWN; |
966 | 153 } |
154 | |
972 | 155 // SDL Callback function |
156 void outputaudio(void *unused, Uint8 *stream, int len) { | |
157 //SDL_MixAudio(stream, read_buffer(buffers, len), len, SDL_MIX_MAXVOLUME); | |
1066 | 158 //if(!full_buffers) printf("SDL: Buffer underrun!\n"); |
159 | |
972 | 160 read_buffer(stream, len); |
1066 | 161 //printf("SDL: Full Buffers: %i\n", full_buffers); |
966 | 162 } |
163 | |
164 // open & setup audio device | |
165 // return: 1=success 0=fail | |
166 static int init(int rate,int channels,int format,int flags){ | |
167 | |
972 | 168 /* SDL Audio Specifications */ |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
169 SDL_AudioSpec aspec, obtained; |
972 | 170 |
171 int i; | |
172 /* Allocate ring-buffer memory */ | |
983 | 173 for(i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE); |
972 | 174 |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
175 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_INFO, rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); |
983 | 176 |
1189 | 177 if(ao_subdevice) { |
178 setenv("SDL_AUDIODRIVER", ao_subdevice, 1); | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
179 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_DriverInfo, ao_subdevice); |
1189 | 180 } |
3095 | 181 |
7660 | 182 ao_data.channels=channels; |
183 ao_data.samplerate=rate; | |
184 ao_data.format=format; | |
185 | |
3137 | 186 ao_data.bps=channels*rate; |
3095 | 187 if(format != AFMT_U8 && format != AFMT_S8) |
188 ao_data.bps*=2; | |
966 | 189 |
1066 | 190 /* The desired audio format (see SDL_AudioSpec) */ |
191 switch(format) { | |
192 case AFMT_U8: | |
193 aspec.format = AUDIO_U8; | |
194 break; | |
195 case AFMT_S16_LE: | |
196 aspec.format = AUDIO_S16LSB; | |
197 break; | |
198 case AFMT_S16_BE: | |
199 aspec.format = AUDIO_S16MSB; | |
200 break; | |
201 case AFMT_S8: | |
202 aspec.format = AUDIO_S8; | |
203 break; | |
204 case AFMT_U16_LE: | |
205 aspec.format = AUDIO_U16LSB; | |
206 break; | |
207 case AFMT_U16_BE: | |
208 aspec.format = AUDIO_U16MSB; | |
209 break; | |
210 default: | |
12440
56bdb9b7a4bc
use fallback for unsupported formats instead of quitting
reimar
parents:
12151
diff
changeset
|
211 aspec.format = AUDIO_S16LSB; |
56bdb9b7a4bc
use fallback for unsupported formats instead of quitting
reimar
parents:
12151
diff
changeset
|
212 ao_data.format = AFMT_S16_LE; |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
213 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_SDL_UnsupportedAudioFmt, format); |
1066 | 214 } |
215 | |
966 | 216 /* The desired audio frequency in samples-per-second. */ |
217 aspec.freq = rate; | |
218 | |
219 /* Number of channels (mono/stereo) */ | |
220 aspec.channels = channels; | |
221 | |
222 /* The desired size of the audio buffer in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8192 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula: ms = (samples*1000)/freq */ | |
972 | 223 aspec.samples = SAMPLESIZE; |
966 | 224 |
225 /* This should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio and SDL_UnlockAudio in your code. The callback prototype is: | |
226 void callback(void *userdata, Uint8 *stream, int len); userdata is the pointer stored in userdata field of the SDL_AudioSpec. stream is a pointer to the audio buffer you want to fill with information and len is the length of the audio buffer in bytes. */ | |
972 | 227 aspec.callback = outputaudio; |
966 | 228 |
229 /* This pointer is passed as the first parameter to the callback function. */ | |
230 aspec.userdata = NULL; | |
231 | |
972 | 232 /* initialize the SDL Audio system */ |
233 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
234 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_SDL_CantInit, SDL_GetError()); |
972 | 235 return 0; |
236 } | |
237 | |
966 | 238 /* Open the audio device and start playing sound! */ |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
239 if(SDL_OpenAudio(&aspec, &obtained) < 0) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
240 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_SDL_CantOpenAudio, SDL_GetError()); |
966 | 241 return(0); |
242 } | |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
243 |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
244 /* did we got what we wanted ? */ |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
245 ao_data.channels=obtained.channels; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
246 ao_data.samplerate=obtained.freq; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
247 |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
248 switch(obtained.format) { |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
249 case AUDIO_U8 : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
250 ao_data.format = AFMT_U8; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
251 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
252 case AUDIO_S16LSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
253 ao_data.format = AFMT_S16_LE; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
254 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
255 case AUDIO_S16MSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
256 ao_data.format = AFMT_S16_BE; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
257 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
258 case AUDIO_S8 : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
259 ao_data.format = AFMT_S8; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
260 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
261 case AUDIO_U16LSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
262 ao_data.format = AFMT_U16_LE; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
263 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
264 case AUDIO_U16MSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
265 ao_data.format = AFMT_U16_BE; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
266 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
267 default: |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
268 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_SDL_UnsupportedAudioFmt, obtained.format); |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
269 return 0; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
270 } |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
271 |
8027 | 272 mp_msg(MSGT_AO,MSGL_V,"SDL: buf size = %d\n",obtained.size); |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
273 ao_data.buffersize=obtained.size; |
974 | 274 |
966 | 275 /* unsilence audio, if callback is ready */ |
276 SDL_PauseAudio(0); | |
277 | |
278 return 1; | |
279 } | |
280 | |
281 // close audio device | |
12145 | 282 static void uninit(int immed){ |
8027 | 283 mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n"); |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
284 while(buffered_bytes > 0) |
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
285 usec_sleep(50000); |
966 | 286 SDL_CloseAudio(); |
972 | 287 SDL_QuitSubSystem(SDL_INIT_AUDIO); |
966 | 288 } |
289 | |
290 // stop playing and empty buffers (for seeking/pause) | |
291 static void reset(){ | |
1066 | 292 |
1091 | 293 //printf("SDL: reset called!\n"); |
1066 | 294 |
972 | 295 /* Reset ring-buffer state */ |
296 buf_read=0; | |
297 buf_write=0; | |
298 buf_read_pos=0; | |
299 buf_write_pos=0; | |
300 | |
301 full_buffers=0; | |
302 buffered_bytes=0; | |
966 | 303 |
304 } | |
305 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
306 // stop playing, keep buffers (for pause) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
307 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
308 { |
1070 | 309 |
1091 | 310 //printf("SDL: audio_pause called!\n"); |
7897
7674e94baff7
Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents:
7660
diff
changeset
|
311 SDL_PauseAudio(1); |
1070 | 312 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
313 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
314 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
315 // resume playing, after audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
316 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
317 { |
1091 | 318 //printf("SDL: audio_resume called!\n"); |
7897
7674e94baff7
Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents:
7660
diff
changeset
|
319 SDL_PauseAudio(0); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
320 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
321 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
322 |
966 | 323 // return: how many bytes can be played without blocking |
324 static int get_space(){ | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
325 return NUM_BUFS*BUFFSIZE - buffered_bytes; |
966 | 326 } |
327 | |
328 // plays 'len' bytes of 'data' | |
329 // it should round it down to outburst*n | |
330 // return: number of bytes played | |
331 static int play(void* data,int len,int flags){ | |
972 | 332 |
12151
75fdb659f5bf
round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
12145
diff
changeset
|
333 len = (len/ao_data.outburst)*ao_data.outburst; |
985 | 334 #if 0 |
972 | 335 int ret; |
966 | 336 |
972 | 337 /* Audio locking prohibits call of outputaudio */ |
966 | 338 SDL_LockAudio(); |
972 | 339 // copy audio stream into ring-buffer |
340 ret = write_buffer(data, len); | |
966 | 341 SDL_UnlockAudio(); |
342 | |
972 | 343 return ret; |
344 #else | |
345 return write_buffer(data, len); | |
346 #endif | |
966 | 347 } |
348 | |
3095 | 349 // return: delay in seconds between first and last sample in buffer |
350 static float get_delay(){ | |
351 return (float)(buffered_bytes + ao_data.buffersize)/(float)ao_data.bps; | |
966 | 352 } |
353 | |
354 | |
355 | |
356 | |
357 | |
358 |