diff options
author | faust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-04-01 19:33:58 +0000 |
---|---|---|
committer | faust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-04-01 19:33:58 +0000 |
commit | 591a524fbfcc9bd5cd244b5b916e8097604d5381 (patch) | |
tree | 8f090d11c3fd40194944f9d825e8809a7befc312 /libao2/ao_sdl.c | |
parent | 0b048dec0d7d17bbb5a48fe98c31f8bda26ffd0d (diff) |
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
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12094 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libao2/ao_sdl.c')
-rw-r--r-- | libao2/ao_sdl.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libao2/ao_sdl.c b/libao2/ao_sdl.c index 1dd388ceb6..9c14ae1a0e 100644 --- a/libao2/ao_sdl.c +++ b/libao2/ao_sdl.c @@ -12,6 +12,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "../config.h" #include "../mp_msg.h" @@ -20,6 +21,7 @@ #include "audio_out_internal.h" #include "afmt.h" #include <SDL.h> +#include "osdep/timer.h" #include "../libvo/fastmemcpy.h" @@ -34,16 +36,12 @@ static ao_info_t info = LIBAO_EXTERN(sdl) // Samplesize used by the SDLlib AudioSpec struct -#ifdef WIN32 #define SAMPLESIZE 2048 -#else -#define SAMPLESIZE 1024 -#endif // General purpose Ring-buffering routines #define BUFFSIZE 4096 -#define NUM_BUFS 16 +#define NUM_BUFS 8 static unsigned char *buffer[NUM_BUFS]; @@ -51,7 +49,7 @@ static unsigned int buf_read=0; static unsigned int buf_write=0; static unsigned int buf_read_pos=0; static unsigned int buf_write_pos=0; -static unsigned int volume=127; +static unsigned char volume=SDL_MIX_MAXVOLUME; static int full_buffers=0; static int buffered_bytes=0; @@ -80,11 +78,11 @@ static int read_buffer(unsigned char* data,int len){ int len2=0; int x; while(len>0){ - if(full_buffers==0) break; // no more data buffered! + if(buffered_bytes==0) break; // no more data buffered! x=BUFFSIZE-buf_read_pos; if(x>len) x=len; - memcpy(data+len2,buffer[buf_read]+buf_read_pos,x); - SDL_MixAudio(data+len2, data+len2, x, volume); + if (x>buffered_bytes) x=buffered_bytes; + SDL_MixAudio(data+len2,buffer[buf_read]+buf_read_pos,x,volume); len2+=x; len-=x; buffered_bytes-=x; buf_read_pos+=x; if(buf_read_pos>=BUFFSIZE){ @@ -122,15 +120,15 @@ static int control(int cmd,void *arg){ case AOCONTROL_GET_VOLUME: { ao_control_vol_t* vol = (ao_control_vol_t*)arg; - vol->left = vol->right = (float)((volume + 127)/2.55); + vol->left = vol->right = volume * 100 / SDL_MIX_MAXVOLUME; return CONTROL_OK; } case AOCONTROL_SET_VOLUME: { - float diff; + int diff; ao_control_vol_t* vol = (ao_control_vol_t*)arg; diff = (vol->left+vol->right) / 2; - volume = (int)(diff * 2.55) - 127; + volume = diff * SDL_MIX_MAXVOLUME / 100; return CONTROL_OK; } } @@ -265,6 +263,8 @@ void callback(void *userdata, Uint8 *stream, int len); userdata is the pointer s // close audio device static void uninit(){ mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n"); + while(buffered_bytes > 0) + usec_sleep(50000); SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); } @@ -304,7 +304,7 @@ static void audio_resume() // return: how many bytes can be played without blocking static int get_space(){ - return (NUM_BUFS-full_buffers)*BUFFSIZE - buf_write_pos; + return NUM_BUFS*BUFFSIZE - buffered_bytes; } // plays 'len' bytes of 'data' |