mirror of https://github.com/mpv-player/mpv
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12673 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
a26c2b997e
commit
ba3c4568fb
|
@ -363,6 +363,8 @@ static char help_text[]=
|
|||
// 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
|
||||
|
|
100
mixer.c
100
mixer.c
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <string.h>
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/ioctl.h>
|
||||
|
@ -8,82 +7,105 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "mixer.h"
|
||||
#include "libao2/audio_out.h"
|
||||
#include "libaf/af.h"
|
||||
#include "mixer.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 )
|
||||
void mixer_incvolume(mixer_t *mixer)
|
||||
{
|
||||
float mixer_l, mixer_r;
|
||||
mixer_getvolume( &mixer_l,&mixer_r );
|
||||
mixer_l += MIXER_CHANGE;
|
||||
mixer_getvolume(mixer, &mixer_l, &mixer_r);
|
||||
mixer_l += mixer->volstep;
|
||||
if ( mixer_l > 100 ) mixer_l = 100;
|
||||
mixer_r += MIXER_CHANGE;
|
||||
mixer_r += mixer->volstep;
|
||||
if ( mixer_r > 100 ) mixer_r = 100;
|
||||
mixer_setvolume( mixer_l,mixer_r );
|
||||
mixer_setvolume(mixer, mixer_l, mixer_r);
|
||||
}
|
||||
|
||||
void mixer_decvolume( void )
|
||||
void mixer_decvolume(mixer_t *mixer)
|
||||
{
|
||||
float mixer_l, mixer_r;
|
||||
mixer_getvolume( &mixer_l,&mixer_r );
|
||||
mixer_l -= MIXER_CHANGE;
|
||||
mixer_getvolume(mixer, &mixer_l, &mixer_r);
|
||||
mixer_l -= mixer->volstep;
|
||||
if ( mixer_l < 0 ) mixer_l = 0;
|
||||
mixer_r -= MIXER_CHANGE;
|
||||
mixer_r -= mixer->volstep;
|
||||
if ( mixer_r < 0 ) mixer_r = 0;
|
||||
mixer_setvolume( mixer_l,mixer_r );
|
||||
mixer_setvolume(mixer, mixer_l, mixer_r);
|
||||
}
|
||||
|
||||
float mixer_getbothvolume( void )
|
||||
void mixer_getbothvolume(mixer_t *mixer, float *b)
|
||||
{
|
||||
float mixer_l, mixer_r;
|
||||
mixer_getvolume( &mixer_l,&mixer_r );
|
||||
return ( mixer_l + mixer_r ) / 2;
|
||||
mixer_getvolume(mixer, &mixer_l, &mixer_r);
|
||||
*b = ( mixer_l + mixer_r ) / 2;
|
||||
}
|
||||
|
||||
void mixer_mute( void )
|
||||
void mixer_mute(mixer_t *mixer)
|
||||
{
|
||||
if ( muted ) mixer_setvolume( mute_l,mute_r );
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
27
mixer.h
27
mixer.h
|
@ -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
|
||||
|
|
19
mplayer.c
19
mplayer.c
|
@ -524,6 +524,8 @@ static void exit_sighandler(int x){
|
|||
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 @@ if(sh_audio){
|
|||
}
|
||||
#endif
|
||||
}
|
||||
mixer.audio_out = audio_out;
|
||||
mixer.afilter = sh_audio->afilter;
|
||||
mixer.volstep = 3;
|
||||
}
|
||||
|
||||
current_module="av_init";
|
||||
|
@ -2488,7 +2493,7 @@ if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
|
|||
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 (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
|
|||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue