summaryrefslogtreecommitdiffstats
path: root/libao2
diff options
context:
space:
mode:
authorfaust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-04-01 19:33:58 +0000
committerfaust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-04-01 19:33:58 +0000
commit591a524fbfcc9bd5cd244b5b916e8097604d5381 (patch)
tree8f090d11c3fd40194944f9d825e8809a7befc312 /libao2
parent0b048dec0d7d17bbb5a48fe98c31f8bda26ffd0d (diff)
downloadmpv-591a524fbfcc9bd5cd244b5b916e8097604d5381.tar.bz2
mpv-591a524fbfcc9bd5cd244b5b916e8097604d5381.tar.xz
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')
-rw-r--r--libao2/ao_sdl.c26
-rw-r--r--libao2/ao_win32.c26
2 files changed, 27 insertions, 25 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'
diff --git a/libao2/ao_win32.c b/libao2/ao_win32.c
index df48983cdf..124c612d37 100644
--- a/libao2/ao_win32.c
+++ b/libao2/ao_win32.c
@@ -28,15 +28,15 @@
#include "audio_out_internal.h"
#include "../mp_msg.h"
#include "../libvo/fastmemcpy.h"
+#include "osdep/timer.h"
-#define SAMPLESIZE 1024
+#define SAMPLESIZE 2048
#define BUFFER_SIZE 4096
-#define BUFFER_COUNT 16
+#define BUFFER_COUNT 8
static WAVEHDR* waveBlocks; //pointer to our ringbuffer memory
static HWAVEOUT hWaveOut; //handle to the waveout device
-static DWORD restoredvolume; //saves the volume to restore after playing
static unsigned int buf_write=0;
static unsigned int buf_write_pos=0;
static int full_buffers=0;
@@ -58,9 +58,12 @@ static void CALLBACK waveOutProc(HWAVEOUT hWaveOut,UINT uMsg,DWORD dwInstance,
{
if(uMsg != WOM_DONE)
return;
- if(full_buffers==0) return; //no more data buffered!
- buffered_bytes-=BUFFER_SIZE;
- --full_buffers;
+ if (full_buffers) {
+ buffered_bytes-=BUFFER_SIZE;
+ --full_buffers;
+ } else {
+ buffered_bytes=0;
+ }
}
// to set/get/query special features/parameters
@@ -149,7 +152,6 @@ static int init(int rate,int channels,int format,int flags)
return 0;
}
//save volume
- waveOutGetVolume(hWaveOut,&restoredvolume);
//allocate buffer memory as one big block
buffer = malloc(totalBufferSize);
memset(buffer,0x0,totalBufferSize);
@@ -157,7 +159,6 @@ static int init(int rate,int channels,int format,int flags)
waveBlocks = (WAVEHDR*)buffer;
buffer += sizeof(WAVEHDR) * BUFFER_COUNT;
for(i = 0; i < BUFFER_COUNT; i++) {
- waveBlocks[i].dwBufferLength = BUFFER_SIZE;
waveBlocks[i].lpData = buffer;
buffer += BUFFER_SIZE;
}
@@ -168,11 +169,11 @@ static int init(int rate,int channels,int format,int flags)
// close audio device
static void uninit()
{
- waveOutSetVolume(hWaveOut,restoredvolume); //restore volume
+ while (buffered_bytes > 0)
+ usec_sleep(50000);
waveOutReset(hWaveOut);
waveOutClose(hWaveOut);
mp_msg(MSGT_AO, MSGL_V,"waveOut device closed\n");
- full_buffers=0;
free(waveBlocks);
mp_msg(MSGT_AO, MSGL_V,"buffer memory freed\n");
}
@@ -202,7 +203,7 @@ static void audio_resume()
// return: how many bytes can be played without blocking
static int get_space()
{
- return (BUFFER_COUNT-full_buffers)*BUFFER_SIZE - buf_write_pos;
+ return BUFFER_COUNT*BUFFER_SIZE - buffered_bytes;
}
//writes data into buffer, based on ringbuffer code in ao_sdl.c
@@ -212,7 +213,7 @@ static int write_waveOutBuffer(unsigned char* data,int len){
int x;
while(len>0){
current = &waveBlocks[buf_write];
- if(full_buffers==BUFFER_COUNT) break;
+ if(buffered_bytes==BUFFER_COUNT*BUFFER_SIZE) break;
//unprepare the header if it is prepared
if(current->dwFlags & WHDR_PREPARED)
waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
@@ -222,6 +223,7 @@ static int write_waveOutBuffer(unsigned char* data,int len){
len2+=x; len-=x;
buffered_bytes+=x; buf_write_pos+=x;
//prepare header and write data to device
+ current->dwBufferLength = buf_write_pos;
waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR));
waveOutWrite(hWaveOut, current, sizeof(WAVEHDR));