Merge pull request #528 from adamcik/fix/bug-525-mixer-divide-by-zero
audio: Handle min=max when scaling volumes (fixes: #525)
This commit is contained in:
commit
fd6bb4ba43
@ -15,6 +15,10 @@ v0.16.0 (UNRELEASED)
|
||||
Currently we support M3U, PLS, XSPF and ASX files, also note that we can
|
||||
currently only play the first stream in the playlist.
|
||||
|
||||
- We now handle the rare case where an audio track has max volume equal to min.
|
||||
This was causing divide by zero errors when scaling volumes to a zero to
|
||||
hundred scale. (Fixes: :issue:`525`)
|
||||
|
||||
|
||||
v0.15.0 (2013-09-19)
|
||||
====================
|
||||
|
||||
@ -544,6 +544,8 @@ class Audio(pykka.ThreadingActor):
|
||||
"""Convert value between scales."""
|
||||
new_min, new_max = new
|
||||
old_min, old_max = old
|
||||
if old_min == old_max:
|
||||
return old_max
|
||||
scaling = float(new_max - new_min) / (old_max - old_min)
|
||||
return int(round(scaling * (value - old_min) + new_min))
|
||||
|
||||
|
||||
@ -6,6 +6,9 @@ import pygst
|
||||
pygst.require('0.10')
|
||||
import gst
|
||||
|
||||
import gobject
|
||||
gobject.threads_init()
|
||||
|
||||
import pykka
|
||||
|
||||
from mopidy import audio
|
||||
@ -80,6 +83,18 @@ class AudioTest(unittest.TestCase):
|
||||
self.assertTrue(self.audio.set_volume(value).get())
|
||||
self.assertEqual(value, self.audio.get_volume().get())
|
||||
|
||||
def test_set_volume_with_mixer_min_equal_max(self):
|
||||
config = {
|
||||
'audio': {
|
||||
'mixer': 'fakemixer track_max_volume=0',
|
||||
'mixer_track': None,
|
||||
'output': 'fakesink',
|
||||
'visualizer': None,
|
||||
}
|
||||
}
|
||||
self.audio = audio.Audio.start(config=config).proxy()
|
||||
self.assertEqual(0, self.audio.get_volume().get())
|
||||
|
||||
@unittest.SkipTest
|
||||
def test_set_state_encapsulation(self):
|
||||
pass # TODO
|
||||
|
||||
Loading…
Reference in New Issue
Block a user