[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/kmix
From:       Christian Esken <esken () kde ! org>
Date:       2011-09-17 18:11:36
Message-ID: 20110917181136.92227AC882 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1254102 by esken:

CCBUGS: 266175
Some more on average calculation (more usage of float instead of long).

 M  +1 -1      core/mixdevicecomposite.cpp  
 M  +11 -19    core/volume.cpp  
 M  +2 -2      core/volume.h  
 M  +3 -1      dbus/dbuscontrolwrapper.cpp  


--- trunk/KDE/kdemultimedia/kmix/core/mixdevicecomposite.cpp #1254101:1254102
@@ -83,7 +83,7 @@
 
         Volume& vol =  ( vt == Volume::CaptureVT ) ? md->captureVolume() : \
md->playbackVolume();  if (vol.hasVolume() && (vol.maxVolume() != 0) ) {
-            long normalizedVolume =
+            qreal normalizedVolume =
                       ( vol.getAvgVolume(Volume::MALL) * MixDeviceComposite::VolMax \
)  /   vol.maxVolume();
             volSum += normalizedVolume;
--- trunk/KDE/kdemultimedia/kmix/core/volume.cpp #1254101:1254102
@@ -147,20 +147,9 @@
 
 /**
  * Copy the volume elements contained in v to this Volume object.
- * Only those elments are copied, that are supported in BOTH Volume objects.
  */
 void Volume::setVolume(const Volume &v)
 {
-	setVolume(v, (ChannelMask)(v._chmask&_chmask) );
-}
-
-/**
- * Copy the volume elements contained in v to this Volume object.
- * Only those elments are copied, that are supported in BOTH Volume objects
- * and match the ChannelMask given by chmask.
- */
-void Volume::setVolume(const Volume &v, ChannelMask chmask)
-{
 	foreach (VolumeChannel vc, _volumesL )
 		  {
 		ChannelID chid = vc.chid;
@@ -184,7 +173,7 @@
 	return _volumesL.value(chid).volume;
 }
 
-long Volume::getAvgVolume(ChannelMask chmask)
+qreal Volume::getAvgVolume(ChannelMask chmask)
 {
 	int avgVolumeCounter = 0;
 	long long sumOfActiveVolumes = 0;
@@ -197,21 +186,24 @@
 		}
 	}
 	if (avgVolumeCounter != 0) {
-		sumOfActiveVolumes /= avgVolumeCounter;
+		qreal sumOfActiveVolumesQreal = sumOfActiveVolumes;
+		sumOfActiveVolumesQreal /= avgVolumeCounter;
+		return sumOfActiveVolumesQreal;
 	}
-	// else: just return 0;
-	return (long)sumOfActiveVolumes;
+	else
+		return 0;
 }
 
 
 int Volume::getAvgVolumePercent(ChannelMask chmask)
 {
-	long volume = getAvgVolume(chmask);
+	qreal volume = getAvgVolume(chmask);
 	// min=-100, max=200 => volSpan = 301
 	// volume = -50 =>  volShiftedToZero = -50+min = 50
-	long volSpan = volumeSpan();
-	long volShiftedToZero = volume - _minVolume;
-	int percent = ( volSpan == 0 ) ? 0 : ( 100 * volShiftedToZero ) / ( volSpan - 1);
+	qreal volSpan = volumeSpan();
+	qreal volShiftedToZero = volume - _minVolume;
+	qreal percentReal = ( volSpan == 0 ) ? 0 : ( 100 * volShiftedToZero ) / ( volSpan - \
1); +	int percent = qRound(percentReal);
 	kDebug() << "volSpan=" << volSpan << ", volume=" << volume << ", \
volShiftedToPositive=" << volShiftedToZero << ", percent=" << percent;  
 	return percent;
--- trunk/KDE/kdemultimedia/kmix/core/volume.h #1254101:1254102
@@ -102,14 +102,14 @@
     // Set all volumes to the ones given in vol
     void setVolume(const Volume &vol );
     // Set volumes as specified by the channel mask
-    void setVolume( const Volume &vol, ChannelMask chmask);
+    //void setVolume( const Volume &vol, ChannelMask chmask);
     void setVolume( ChannelID chid, long volume);
 
     // Increase or decrease all volumes by step
     void changeAllVolumes( long step );
     
     long getVolume(ChannelID chid);
-    long getAvgVolume(ChannelMask chmask);
+    qreal getAvgVolume(ChannelMask chmask);
     int getAvgVolumePercent(ChannelMask chmask);
 
     //long operator[](int);
--- trunk/KDE/kdemultimedia/kmix/dbus/dbuscontrolwrapper.cpp #1254101:1254102
@@ -114,7 +114,9 @@
 {
 	// @todo hardcoded
 	Volume& vol = m_md->playbackVolume();
-	return vol.getAvgVolume( Volume::MMAIN );
+	qreal avgVol= vol.getAvgVolume( Volume::MMAIN );
+	long avgVolRounded = avgVol <0 ? avgVol-.5 : avgVol+.5;
+	return avgVolRounded;
 }
 
 void DBusControlWrapper::setMute(bool muted)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic