mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
Fix the Volume control does not work #1578
This commit is contained in:
@@ -339,39 +339,19 @@ public partial class ViewerPanel : UserControl, IDisposable, INotifyPropertyChan
|
||||
}
|
||||
}
|
||||
|
||||
// Newer .net has Math.Clamp
|
||||
private T Clamp<T>(T val, T min, T max) where T : IComparable<T>
|
||||
{
|
||||
if (val.CompareTo(min) < 0) return min;
|
||||
else if (val.CompareTo(max) > 0) return max;
|
||||
else return val;
|
||||
}
|
||||
|
||||
// A change in amplitude by a factor of 10 corresponds to a 20 dB change
|
||||
private const double DecibelAmplitudeMult = 20.0;
|
||||
|
||||
public double LinearVolume
|
||||
{
|
||||
// mediaElement.Volume returns [0,1] where 0 = -100db, 1 = 0db
|
||||
// Decibel is logarithmic. See amplitude table https://en.wikipedia.org/wiki/Decibel
|
||||
get
|
||||
{
|
||||
var dbVol = 100.0 * (mediaElement.Volume - 1.0);
|
||||
var linearVol = Math.Pow(10, dbVol / DecibelAmplitudeMult);
|
||||
return linearVol;
|
||||
}
|
||||
get => mediaElement.Volume;
|
||||
set
|
||||
{
|
||||
var linearVol = Clamp(value, 0.00001, 1.0);
|
||||
var dbVol = DecibelAmplitudeMult * Math.Log10(linearVol);
|
||||
mediaElement.Volume = dbVol / 100.0 + 1.0;
|
||||
mediaElement.Volume = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void ChangeVolume(double delta)
|
||||
{
|
||||
LinearVolume = LinearVolume + delta; // setter will clamp
|
||||
LinearVolume += delta;
|
||||
}
|
||||
|
||||
private void TogglePlayPause(object sender, EventArgs e)
|
||||
|
Reference in New Issue
Block a user