diff -ur MPlayer-cvs/help/help_mp-en.h MPlayer-test/help/help_mp-en.h --- MPlayer-cvs/help/help_mp-en.h 2004-06-03 19:44:49.000000000 +0200 +++ MPlayer-test/help/help_mp-en.h 2004-06-19 14:03:43.000000000 +0200 @@ -363,6 +363,8 @@ // x11_common.c #define MSGTR_EwmhFullscreenStateFailed "\nX11: Couldn't send EWMH fullscreen Event!\n" +#define MSGTR_NeedAfVolume "Mixer: This ao needs -af volume for changing volume\n" + // ====================== GUI messages/buttons ======================== #ifdef HAVE_NEW_GUI diff -ur MPlayer-cvs/libaf/af.c MPlayer-test/libaf/af.c --- MPlayer-cvs/libaf/af.c 2004-06-18 22:15:15.000000000 +0200 +++ MPlayer-test/libaf/af.c 2004-06-19 13:31:10.000000000 +0200 @@ -598,3 +598,16 @@ af->data->len=len; return AF_OK; } + +// send control to all filters, starting with the last until +// one responds with CONTROL_OK +int af_control_any_rev (af_stream_t* s, int cmd, void* arg) { + int res = AF_UNKNOWN; + af_instance_t* filt = s->last; + while (filt && res != AF_OK) { + res = filt->control(filt, cmd, arg); + filt = filt->prev; + } + return (res == AF_OK); +} + diff -ur MPlayer-cvs/libaf/af.h MPlayer-test/libaf/af.h --- MPlayer-cvs/libaf/af.h 2004-06-18 22:15:15.000000000 +0200 +++ MPlayer-test/libaf/af.h 2004-06-18 22:47:08.000000000 +0200 @@ -151,6 +151,11 @@ // Filter data chunk through the filters in the list af_data_t* af_play(af_stream_t* s, af_data_t* data); +// send control to all filters, starting with the last until +// one accepts the command with AF_OK. +// Returns true if accepting filter was found. +int af_control_any_rev (af_stream_t* s, int cmd, void* arg); + /* Calculate how long the output from the filters will be given the input length "len". The calculated length is >= the actual length */ diff -ur MPlayer-cvs/libao2/ao_sdl.c MPlayer-test/libao2/ao_sdl.c --- MPlayer-cvs/libao2/ao_sdl.c 2004-06-18 22:15:16.000000000 +0200 +++ MPlayer-test/libao2/ao_sdl.c 2004-06-19 13:50:18.000000000 +0200 @@ -53,7 +53,6 @@ static unsigned int buf_write=0; static unsigned int buf_read_pos=0; static unsigned int buf_write_pos=0; -static unsigned char volume=SDL_MIX_MAXVOLUME; static int full_buffers=0; static int buffered_bytes=0; @@ -87,7 +86,7 @@ x=BUFFSIZE-buf_read_pos; if(x>len) x=len; if (x>buffered_bytes) x=buffered_bytes; - SDL_MixAudio(data+len2,buffer[buf_read]+buf_read_pos,x,volume); + memcpy(data+len2,buffer[buf_read]+buf_read_pos,x); len2+=x; len-=x; buffered_bytes-=x; buf_read_pos+=x; if(buf_read_pos>=BUFFSIZE){ @@ -121,23 +120,7 @@ // to set/get/query special features/parameters static int control(int cmd,void *arg){ - switch (cmd) { - case AOCONTROL_GET_VOLUME: - { - ao_control_vol_t* vol = (ao_control_vol_t*)arg; - vol->left = vol->right = volume * 100 / SDL_MIX_MAXVOLUME; - return CONTROL_OK; - } - case AOCONTROL_SET_VOLUME: - { - int diff; - ao_control_vol_t* vol = (ao_control_vol_t*)arg; - diff = (vol->left+vol->right) / 2; - volume = diff * SDL_MIX_MAXVOLUME / 100; - return CONTROL_OK; - } - } - return -1; + return CONTROL_UNKOWN; } // SDL Callback function diff -ur MPlayer-cvs/mixer.c MPlayer-test/mixer.c --- MPlayer-cvs/mixer.c 2004-06-18 22:15:03.000000000 +0200 +++ MPlayer-test/mixer.c 2004-06-19 14:13:17.000000000 +0200 @@ -10,8 +10,15 @@ #include "config.h" #include "mixer.h" #include "libao2/audio_out.h" +#include "libaf/af.h" +#include "libmpdemux/stream.h" +#include "libmpdemux/demuxer.h" +#include "libmpdemux/stheader.h" + +#include "help_mp.h" extern ao_functions_t *audio_out; +extern sh_audio_t *sh_audio; char * mixer_device=NULL; char * mixer_channel=NULL; @@ -25,8 +32,19 @@ ao_control_vol_t vol; *l=0; *r=0; if(audio_out){ - if(CONTROL_OK != audio_out->control(AOCONTROL_GET_VOLUME,&vol)) - return; + if(CONTROL_OK != audio_out->control(AOCONTROL_GET_VOLUME,&vol)) { + if (!sh_audio || !sh_audio->afilter) + return; + else { + float db_vals[AF_NCH]; + if (!af_control_any_rev(sh_audio->afilter, + AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET, db_vals)) + return; + af_from_dB (2, db_vals, db_vals, 20.0, -200.0, 60.0); + vol.left = db_vals[0] * 90.0; + vol.right = db_vals[1] * 90.0; + } + } *r=vol.right; *l=vol.left; } @@ -37,8 +55,28 @@ ao_control_vol_t vol; vol.right=r; vol.left=l; if(audio_out){ - if(CONTROL_OK != audio_out->control(AOCONTROL_SET_VOLUME,&vol)) - return; + if(CONTROL_OK != audio_out->control(AOCONTROL_SET_VOLUME,&vol)) { + if (!sh_audio || !sh_audio->afilter) + return; + else { + // af_volume uses values in dB + float db_vals[AF_NCH]; + int i; + // a volume of 90% will give 0 dB (no change) + // like this, amplification is possible as well + db_vals[0] = l / 90.0; + db_vals[1] = r / 90.0; + for (i = 2; i < AF_NCH; i++) { + db_vals[i] = (l + r) / 180.0; + } + af_to_dB (AF_NCH, db_vals, db_vals, 20.0); + if (!af_control_any_rev(sh_audio->afilter, + AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals)) { + mp_msg(MSGT_GLOBAL, MSGL_HINT, MSGTR_NeedAfVolume); + return; + } + } + } } muted=0; } diff -ur MPlayer-cvs/mplayer.c MPlayer-test/mplayer.c --- MPlayer-cvs/mplayer.c 2004-06-18 22:15:13.000000000 +0200 +++ MPlayer-test/mplayer.c 2004-06-18 22:39:12.000000000 +0200 @@ -311,7 +311,7 @@ static stream_t* stream=NULL; static demuxer_t *demuxer=NULL; -static sh_audio_t *sh_audio=NULL; +sh_audio_t *sh_audio=NULL; static sh_video_t *sh_video=NULL; char* current_module=NULL; // for debugging