1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <vlc_common.h>
29 #include <vlc_playlist.h>
30 #include <vlc_input.h>
32 #include "equalizer.hpp"
33 #include "../utils/var_percent.hpp"
38 EqualizerBands::EqualizerBands( intf_thread_t *pIntf ): SkinObject( pIntf ),
41 for( int i = 0; i < kNbBands; i++ )
43 // Create and observe the band variables
44 VarPercent *pVar = new VarPercent( pIntf );
45 m_cBands[i] = VariablePtr( pVar );
47 pVar->addObserver( this );
52 EqualizerBands::~EqualizerBands()
54 for( int i = 0; i < kNbBands; i++ )
56 ((VarPercent*)m_cBands[i].get())->delObserver( this );
61 void EqualizerBands::set( string bands )
64 stringstream ss( bands );
68 for( int i = 0; i < kNbBands; i++ )
71 // Set the band value in percent
72 ((VarPercent*)m_cBands[i].get())->set( (val + 20) / 40 );
78 VariablePtr EqualizerBands::getBand( int band )
80 return m_cBands[band];
84 void EqualizerBands::onUpdate( Subject<VarPercent> &rBand, void *arg )
86 aout_instance_t *pAout = NULL;
88 playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
89 input_thread_t *pInput = playlist_CurrentInput( pPlaylist );
91 pAout = input_GetAout( pInput );
93 // Make sure we are not called from set()
98 // Write one digit after the floating point
99 ss << setprecision( 1 ) << setiosflags( ios::fixed );
101 // Convert the band values to a string
102 val = 40 * ((VarPercent*)m_cBands[0].get())->get() - 20;
104 for( int i = 1; i < kNbBands; i++ )
106 val = 40 * ((VarPercent*)m_cBands[i].get())->get() - 20;
110 string bands = ss.str();
112 config_PutPsz( getIntf(), "equalizer-bands", bands.c_str() );
115 // Update the audio output
116 var_SetString( pAout, "equalizer-bands", (char*)bands.c_str() );
121 vlc_object_release( pAout );
123 vlc_object_release( pInput );
127 EqualizerPreamp::EqualizerPreamp( intf_thread_t *pIntf ): VarPercent( pIntf )
130 VarPercent::set( 0.8 );
134 void EqualizerPreamp::set( float percentage, bool updateVLC )
136 aout_instance_t *pAout = NULL;
138 playlist_t *pPlaylist = getIntf()->p_sys->p_playlist;
139 input_thread_t *pInput = playlist_CurrentInput( pPlaylist );
141 pAout = input_GetAout( pInput );
143 VarPercent::set( percentage );
145 // Avoid infinite loop
148 float val = 40 * percentage - 20;
150 config_PutFloat( getIntf(), "equalizer-preamp", val );
153 // Update the audio output
154 var_SetFloat( pAout, "equalizer-preamp", val );
159 vlc_object_release( pAout );
161 vlc_object_release( pInput );