Mercurial > mplayer.hg
annotate libao2/ao_sdl.c @ 12501:cd0d9a99b730
remove index flag
max_short_distance
reserved_v -> reserved_count
header repeation rules
some of this is from rich
author | michael |
---|---|
date | Tue, 25 May 2004 20:42:22 +0000 |
parents | 56bdb9b7a4bc |
children | c1371fce7267 |
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" | |
19 | |
966 | 20 #include "audio_out.h" |
21 #include "audio_out_internal.h" | |
1066 | 22 #include "afmt.h" |
6184 | 23 #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
|
24 #include "osdep/timer.h" |
966 | 25 |
972 | 26 #include "../libvo/fastmemcpy.h" |
27 | |
966 | 28 static ao_info_t info = |
29 { | |
30 "SDLlib audio output", | |
31 "sdl", | |
32 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
33 "" | |
34 }; | |
35 | |
36 LIBAO_EXTERN(sdl) | |
37 | |
972 | 38 // Samplesize used by the SDLlib AudioSpec struct |
12113 | 39 #ifdef WIN32 |
12019
6ede5366bc47
fix compilation with sdl on mingw patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
11750
diff
changeset
|
40 #define SAMPLESIZE 2048 |
12113 | 41 #else |
42 #define SAMPLESIZE 1024 | |
43 #endif | |
972 | 44 |
45 // General purpose Ring-buffering routines | |
46 | |
974 | 47 #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
|
48 #define NUM_BUFS 8 |
972 | 49 |
50 static unsigned char *buffer[NUM_BUFS]; | |
51 | |
52 static unsigned int buf_read=0; | |
53 static unsigned int buf_write=0; | |
54 static unsigned int buf_read_pos=0; | |
55 static unsigned int buf_write_pos=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
|
56 static unsigned char volume=SDL_MIX_MAXVOLUME; |
972 | 57 static int full_buffers=0; |
58 static int buffered_bytes=0; | |
59 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
60 |
972 | 61 static int write_buffer(unsigned char* data,int len){ |
62 int len2=0; | |
63 int x; | |
64 while(len>0){ | |
65 if(full_buffers==NUM_BUFS) break; | |
66 x=BUFFSIZE-buf_write_pos; | |
67 if(x>len) x=len; | |
68 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
|
69 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
|
70 ++full_buffers; |
972 | 71 len2+=x; len-=x; |
72 buffered_bytes+=x; buf_write_pos+=x; | |
73 if(buf_write_pos>=BUFFSIZE){ | |
74 // block is full, find next! | |
75 buf_write=(buf_write+1)%NUM_BUFS; | |
76 buf_write_pos=0; | |
77 } | |
78 } | |
79 return len2; | |
80 } | |
81 | |
82 static int read_buffer(unsigned char* data,int len){ | |
83 int len2=0; | |
84 int x; | |
85 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
|
86 if(buffered_bytes==0) break; // no more data buffered! |
972 | 87 x=BUFFSIZE-buf_read_pos; |
88 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
|
89 if (x>buffered_bytes) x=buffered_bytes; |
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
|
90 SDL_MixAudio(data+len2,buffer[buf_read]+buf_read_pos,x,volume); |
972 | 91 len2+=x; len-=x; |
92 buffered_bytes-=x; buf_read_pos+=x; | |
93 if(buf_read_pos>=BUFFSIZE){ | |
94 // block is empty, find next! | |
95 buf_read=(buf_read+1)%NUM_BUFS; | |
96 --full_buffers; | |
97 buf_read_pos=0; | |
98 } | |
99 } | |
100 return len2; | |
101 } | |
102 | |
103 // end ring buffer stuff | |
966 | 104 |
12027
210e474436d3
Cygwin provides setenv. Fixes compilation on Cygwin.
diego
parents:
12019
diff
changeset
|
105 #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
|
106 /* 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
|
107 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
|
108 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
109 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
|
110 char *env = malloc(len); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
111 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
112 if (env != NULL) { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
113 strcpy(env, name); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
114 strcat(env, "="); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
115 strcat(env, val); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
116 putenv(env); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
117 } |
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 #endif |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
120 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
121 |
966 | 122 // to set/get/query special features/parameters |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8027
diff
changeset
|
123 static int control(int cmd,void *arg){ |
6184 | 124 switch (cmd) { |
125 case AOCONTROL_GET_VOLUME: | |
126 { | |
127 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
|
128 vol->left = vol->right = volume * 100 / SDL_MIX_MAXVOLUME; |
6184 | 129 return CONTROL_OK; |
130 } | |
131 case AOCONTROL_SET_VOLUME: | |
132 { | |
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
|
133 int diff; |
6184 | 134 ao_control_vol_t* vol = (ao_control_vol_t*)arg; |
135 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
|
136 volume = diff * SDL_MIX_MAXVOLUME / 100; |
6184 | 137 return CONTROL_OK; |
138 } | |
139 } | |
140 return -1; | |
966 | 141 } |
142 | |
972 | 143 // SDL Callback function |
144 void outputaudio(void *unused, Uint8 *stream, int len) { | |
145 //SDL_MixAudio(stream, read_buffer(buffers, len), len, SDL_MIX_MAXVOLUME); | |
1066 | 146 //if(!full_buffers) printf("SDL: Buffer underrun!\n"); |
147 | |
972 | 148 read_buffer(stream, len); |
1066 | 149 //printf("SDL: Full Buffers: %i\n", full_buffers); |
966 | 150 } |
151 | |
152 // open & setup audio device | |
153 // return: 1=success 0=fail | |
154 static int init(int rate,int channels,int format,int flags){ | |
155 | |
972 | 156 /* SDL Audio Specifications */ |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
157 SDL_AudioSpec aspec, obtained; |
972 | 158 |
159 int i; | |
160 /* Allocate ring-buffer memory */ | |
983 | 161 for(i=0;i<NUM_BUFS;i++) buffer[i]=(unsigned char *) malloc(BUFFSIZE); |
972 | 162 |
8027 | 163 mp_msg(MSGT_AO,MSGL_INFO,"SDL: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); |
983 | 164 |
1189 | 165 if(ao_subdevice) { |
166 setenv("SDL_AUDIODRIVER", ao_subdevice, 1); | |
8027 | 167 mp_msg(MSGT_AO,MSGL_INFO,"SDL: using %s audio driver\n", ao_subdevice); |
1189 | 168 } |
3095 | 169 |
7660 | 170 ao_data.channels=channels; |
171 ao_data.samplerate=rate; | |
172 ao_data.format=format; | |
173 | |
3137 | 174 ao_data.bps=channels*rate; |
3095 | 175 if(format != AFMT_U8 && format != AFMT_S8) |
176 ao_data.bps*=2; | |
966 | 177 |
1066 | 178 /* The desired audio format (see SDL_AudioSpec) */ |
179 switch(format) { | |
180 case AFMT_U8: | |
181 aspec.format = AUDIO_U8; | |
182 break; | |
183 case AFMT_S16_LE: | |
184 aspec.format = AUDIO_S16LSB; | |
185 break; | |
186 case AFMT_S16_BE: | |
187 aspec.format = AUDIO_S16MSB; | |
188 break; | |
189 case AFMT_S8: | |
190 aspec.format = AUDIO_S8; | |
191 break; | |
192 case AFMT_U16_LE: | |
193 aspec.format = AUDIO_U16LSB; | |
194 break; | |
195 case AFMT_U16_BE: | |
196 aspec.format = AUDIO_U16MSB; | |
197 break; | |
198 default: | |
12440
56bdb9b7a4bc
use fallback for unsupported formats instead of quitting
reimar
parents:
12151
diff
changeset
|
199 aspec.format = AUDIO_S16LSB; |
56bdb9b7a4bc
use fallback for unsupported formats instead of quitting
reimar
parents:
12151
diff
changeset
|
200 ao_data.format = AFMT_S16_LE; |
8027 | 201 mp_msg(MSGT_AO,MSGL_WARN,"SDL: Unsupported audio format: 0x%x.\n", format); |
1066 | 202 } |
203 | |
966 | 204 /* The desired audio frequency in samples-per-second. */ |
205 aspec.freq = rate; | |
206 | |
207 /* Number of channels (mono/stereo) */ | |
208 aspec.channels = channels; | |
209 | |
210 /* 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 | 211 aspec.samples = SAMPLESIZE; |
966 | 212 |
213 /* 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: | |
214 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 | 215 aspec.callback = outputaudio; |
966 | 216 |
217 /* This pointer is passed as the first parameter to the callback function. */ | |
218 aspec.userdata = NULL; | |
219 | |
972 | 220 /* initialize the SDL Audio system */ |
221 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) { | |
8027 | 222 mp_msg(MSGT_AO,MSGL_ERR,"SDL: Initializing of SDL Audio failed: %s.\n", SDL_GetError()); |
972 | 223 return 0; |
224 } | |
225 | |
966 | 226 /* 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
|
227 if(SDL_OpenAudio(&aspec, &obtained) < 0) { |
8027 | 228 mp_msg(MSGT_AO,MSGL_ERR,"SDL: Unable to open audio: %s\n", SDL_GetError()); |
966 | 229 return(0); |
230 } | |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
231 |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
232 /* did we got what we wanted ? */ |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
233 ao_data.channels=obtained.channels; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
234 ao_data.samplerate=obtained.freq; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
235 |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
236 switch(obtained.format) { |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
237 case AUDIO_U8 : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
238 ao_data.format = AFMT_U8; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
239 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
240 case AUDIO_S16LSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
241 ao_data.format = AFMT_S16_LE; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
242 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
243 case AUDIO_S16MSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
244 ao_data.format = AFMT_S16_BE; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
245 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
246 case AUDIO_S8 : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
247 ao_data.format = AFMT_S8; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
248 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
249 case AUDIO_U16LSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
250 ao_data.format = AFMT_U16_LE; |
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_U16MSB : |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
253 ao_data.format = AFMT_U16_BE; |
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 default: |
8027 | 256 mp_msg(MSGT_AO,MSGL_WARN,"SDL: Unsupported SDL audio format: 0x%x.\n", obtained.format); |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
257 return 0; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
258 } |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
259 |
8027 | 260 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
|
261 ao_data.buffersize=obtained.size; |
974 | 262 |
966 | 263 /* unsilence audio, if callback is ready */ |
264 SDL_PauseAudio(0); | |
265 | |
266 return 1; | |
267 } | |
268 | |
269 // close audio device | |
12145 | 270 static void uninit(int immed){ |
8027 | 271 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
|
272 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
|
273 usec_sleep(50000); |
966 | 274 SDL_CloseAudio(); |
972 | 275 SDL_QuitSubSystem(SDL_INIT_AUDIO); |
966 | 276 } |
277 | |
278 // stop playing and empty buffers (for seeking/pause) | |
279 static void reset(){ | |
1066 | 280 |
1091 | 281 //printf("SDL: reset called!\n"); |
1066 | 282 |
972 | 283 /* Reset ring-buffer state */ |
284 buf_read=0; | |
285 buf_write=0; | |
286 buf_read_pos=0; | |
287 buf_write_pos=0; | |
288 | |
289 full_buffers=0; | |
290 buffered_bytes=0; | |
966 | 291 |
292 } | |
293 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
294 // 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
|
295 static void audio_pause() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
296 { |
1070 | 297 |
1091 | 298 //printf("SDL: audio_pause called!\n"); |
7897
7674e94baff7
Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents:
7660
diff
changeset
|
299 SDL_PauseAudio(1); |
1070 | 300 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
301 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
302 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
303 // 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
|
304 static void audio_resume() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
305 { |
1091 | 306 //printf("SDL: audio_resume called!\n"); |
7897
7674e94baff7
Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents:
7660
diff
changeset
|
307 SDL_PauseAudio(0); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
308 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
309 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
310 |
966 | 311 // return: how many bytes can be played without blocking |
312 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
|
313 return NUM_BUFS*BUFFSIZE - buffered_bytes; |
966 | 314 } |
315 | |
316 // plays 'len' bytes of 'data' | |
317 // it should round it down to outburst*n | |
318 // return: number of bytes played | |
319 static int play(void* data,int len,int flags){ | |
972 | 320 |
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
|
321 len = (len/ao_data.outburst)*ao_data.outburst; |
985 | 322 #if 0 |
972 | 323 int ret; |
966 | 324 |
972 | 325 /* Audio locking prohibits call of outputaudio */ |
966 | 326 SDL_LockAudio(); |
972 | 327 // copy audio stream into ring-buffer |
328 ret = write_buffer(data, len); | |
966 | 329 SDL_UnlockAudio(); |
330 | |
972 | 331 return ret; |
332 #else | |
333 return write_buffer(data, len); | |
334 #endif | |
966 | 335 } |
336 | |
3095 | 337 // return: delay in seconds between first and last sample in buffer |
338 static float get_delay(){ | |
339 return (float)(buffered_bytes + ao_data.buffersize)/(float)ao_data.bps; | |
966 | 340 } |
341 | |
342 | |
343 | |
344 | |
345 | |
346 |