00001 /***************************************************************************** 00002 * volume.cpp 00003 ***************************************************************************** 00004 * Copyright (C) 2003 the VideoLAN team 00005 * $Id: volume.cpp 11824 2005-07-23 19:18:17Z ipkiss $ 00006 * 00007 * Authors: Cyril Deguet <[email protected]> 00008 * Olivier Teulière <[email protected]> 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. 00023 *****************************************************************************/ 00024 00025 #include <stdio.h> // snprintf 00026 00027 #include <vlc/aout.h> 00028 #include "volume.hpp" 00029 00030 00031 Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf ) 00032 { 00033 // Initial value 00034 audio_volume_t val; 00035 aout_VolumeGet( getIntf(), &val ); 00036 VarPercent::set( val * 2.0 / AOUT_VOLUME_MAX ); 00037 } 00038 00039 00040 void Volume::set( float percentage ) 00041 { 00042 // Avoid looping forever... 00043 if( (int)(get() * AOUT_VOLUME_MAX) != 00044 (int)(percentage * AOUT_VOLUME_MAX) ) 00045 { 00046 VarPercent::set( percentage ); 00047 00048 aout_VolumeSet( getIntf(), (int)(get() * AOUT_VOLUME_MAX / 2.0) ); 00049 } 00050 } 00051 00052 00053 string Volume::getAsStringPercent() const 00054 { 00055 int value = (int)(100. * VarPercent::get()); 00056 // 0 <= value <= 100, so we need 4 chars 00057 char *str = new char[4]; 00058 snprintf( str, 4, "%d", value ); 00059 string ret = str; 00060 delete[] str; 00061 00062 return ret; 00063 } 00064