Mercurial > mplayer.hg
changeset 12672:9709ce101949
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
author | alex |
---|---|
date | Sat, 26 Jun 2004 09:14:20 +0000 |
parents | c1fc3d58f66e |
children | c1371fce7267 |
files | help/help_mp-en.h mixer.c mixer.h mplayer.c |
diffstat | 4 files changed, 102 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/help/help_mp-en.h Sat Jun 26 07:07:19 2004 +0000 +++ b/help/help_mp-en.h Sat Jun 26 09:14:20 2004 +0000 @@ -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
--- a/mixer.c Sat Jun 26 07:07:19 2004 +0000 +++ b/mixer.c Sat Jun 26 09:14:20 2004 +0000 @@ -1,4 +1,3 @@ - #include <string.h> #ifndef __MINGW32__ #include <sys/ioctl.h> @@ -8,82 +7,105 @@ #include <unistd.h> #include "config.h" +#include "libao2/audio_out.h" +#include "libaf/af.h" #include "mixer.h" -#include "libao2/audio_out.h" -extern ao_functions_t *audio_out; +#include "help_mp.h" char * mixer_device=NULL; char * mixer_channel=NULL; -int muted = 0; -float mute_l = 0.0f; -float mute_r = 0.0f; - -void mixer_getvolume( float *l,float *r ) +void mixer_getvolume(mixer_t *mixer, float *l, float *r) { ao_control_vol_t vol; *l=0; *r=0; - if(audio_out){ - if(CONTROL_OK != audio_out->control(AOCONTROL_GET_VOLUME,&vol)) - return; + if(mixer->audio_out){ + if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_GET_VOLUME,&vol)) { + if (!mixer->afilter) + return; + else { + float db_vals[AF_NCH]; + if (!af_control_any_rev(mixer->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; } } -void mixer_setvolume( float l,float r ) +void mixer_setvolume(mixer_t *mixer, float l, float r) { 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(mixer->audio_out){ + if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_SET_VOLUME,&vol)) { + if (mixer->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(mixer->afilter, + AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals)) { + mp_msg(MSGT_GLOBAL, MSGL_HINT, MSGTR_NeedAfVolume); + return; + } + } + } } - muted=0; + mixer->muted=0; } -#define MIXER_CHANGE 3 - -void mixer_incvolume( void ) -{ - float mixer_l, mixer_r; - mixer_getvolume( &mixer_l,&mixer_r ); - mixer_l += MIXER_CHANGE; - if ( mixer_l > 100 ) mixer_l = 100; - mixer_r += MIXER_CHANGE; - if ( mixer_r > 100 ) mixer_r = 100; - mixer_setvolume( mixer_l,mixer_r ); -} - -void mixer_decvolume( void ) +void mixer_incvolume(mixer_t *mixer) { float mixer_l, mixer_r; - mixer_getvolume( &mixer_l,&mixer_r ); - mixer_l -= MIXER_CHANGE; - if ( mixer_l < 0 ) mixer_l = 0; - mixer_r -= MIXER_CHANGE; - if ( mixer_r < 0 ) mixer_r = 0; - mixer_setvolume( mixer_l,mixer_r ); + mixer_getvolume(mixer, &mixer_l, &mixer_r); + mixer_l += mixer->volstep; + if ( mixer_l > 100 ) mixer_l = 100; + mixer_r += mixer->volstep; + if ( mixer_r > 100 ) mixer_r = 100; + mixer_setvolume(mixer, mixer_l, mixer_r); } -float mixer_getbothvolume( void ) +void mixer_decvolume(mixer_t *mixer) { float mixer_l, mixer_r; - mixer_getvolume( &mixer_l,&mixer_r ); - return ( mixer_l + mixer_r ) / 2; + mixer_getvolume(mixer, &mixer_l, &mixer_r); + mixer_l -= mixer->volstep; + if ( mixer_l < 0 ) mixer_l = 0; + mixer_r -= mixer->volstep; + if ( mixer_r < 0 ) mixer_r = 0; + mixer_setvolume(mixer, mixer_l, mixer_r); } -void mixer_mute( void ) +void mixer_getbothvolume(mixer_t *mixer, float *b) { - if ( muted ) mixer_setvolume( mute_l,mute_r ); + float mixer_l, mixer_r; + mixer_getvolume(mixer, &mixer_l, &mixer_r); + *b = ( mixer_l + mixer_r ) / 2; +} + +void mixer_mute(mixer_t *mixer) +{ + if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r); else { - mixer_getvolume( &mute_l,&mute_r ); - mixer_setvolume( 0,0 ); - muted=1; + mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r); + mixer_setvolume(mixer, 0, 0); + mixer->muted=1; } } - - -
--- a/mixer.h Sat Jun 26 07:07:19 2004 +0000 +++ b/mixer.h Sat Jun 26 09:14:20 2004 +0000 @@ -1,19 +1,28 @@ - #ifndef __MPLAYER_MIXER #define __MPLAYER_MIXER +#include "libaf/af.h" +#include "libao2/audio_out.h" + extern char * mixer_device; extern char * mixer_channel; -extern int muted; -extern void mixer_getvolume( float *l,float *r ); -extern void mixer_setvolume( float l,float r ); -extern void mixer_incvolume( void ); -extern void mixer_decvolume( void ); -extern float mixer_getbothvolume( void ); -void mixer_mute( void ); +typedef struct mixer_s { + ao_functions_t *audio_out; + af_stream_t *afilter; + int volstep; + int muted; + float last_l, last_r; +} mixer_t; + +void mixer_getvolume(mixer_t *mixer, float *l, float *r); +void mixer_setvolume(mixer_t *mixer, float l, float r); +void mixer_incvolume(mixer_t *mixer); +void mixer_decvolume(mixer_t *mixer); +void mixer_getbothvolume(mixer_t *mixer, float *b); +void mixer_mute(mixer_t *mixer); //extern void mixer_setbothvolume( int v ); -#define mixer_setbothvolume( v ) mixer_setvolume( v,v ) +#define mixer_setbothvolume(m, v) mixer_setvolume(m, v, v) #endif
--- a/mplayer.c Sat Jun 26 07:07:19 2004 +0000 +++ b/mplayer.c Sat Jun 26 09:14:20 2004 +0000 @@ -524,6 +524,8 @@ extern void mp_input_register_options(m_config_t* cfg); #include "mixer.h" +static mixer_t mixer; + #include "cfg-mplayer.h" void parse_cfgfiles( m_config_t* conf ) @@ -1902,6 +1904,9 @@ } #endif } + mixer.audio_out = audio_out; + mixer.afilter = sh_audio->afilter; + mixer.volstep = 3; } current_module="av_init"; @@ -2488,7 +2493,7 @@ edl_decision = 1; next_edl_record = next_edl_record->next; } else if( next_edl_record->action == EDL_MUTE ) { - mixer_mute(); + mixer_mute(&mixer); #ifdef DEBUG_EDL printf( "\nEDL_MUTE: [%f]\n", next_edl_record->start_sec ); #endif @@ -2657,25 +2662,27 @@ if( abs ) { - mixer_setvolume( (float)v, (float)v ); + mixer_setvolume(&mixer, (float)v, (float)v ); } else { if(v > 0) - mixer_incvolume(); + mixer_incvolume(&mixer); else - mixer_decvolume(); + mixer_decvolume(&mixer); } #ifdef USE_OSD if(osd_level && sh_video){ + float vol; osd_visible=sh_video->fps; // 1 sec vo_osd_progbar_type=OSD_VOLUME; - vo_osd_progbar_value=(mixer_getbothvolume()*256.0)/100.0; + mixer_getbothvolume(&mixer, &vol); + vo_osd_progbar_value=(vol*256.0)/100.0; vo_osd_changed(OSDTYPE_PROGBAR); } #endif } break; case MP_CMD_MUTE: - mixer_mute(); + mixer_mute(&mixer); break; case MP_CMD_LOADFILE : { play_tree_t* e = play_tree_new();