mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
replaygain: apply review feedback: fixup previous refactor, improve tests
by adding files which are not completely silent, thus hitting a different code path in some calculations The sample files were generated using > sox -n whitenoise.flac synth 00:00:02 whitenoise > ffmpeg -i whitenoise.flac whitenoise.opus > ffmpeg -i whitenoise.flac whitenoise.mp3
This commit is contained in:
parent
b8be2af11d
commit
3965858ac1
6 changed files with 27 additions and 9 deletions
|
|
@ -329,7 +329,7 @@ class FfmpegBackend(Backend):
|
|||
|
||||
def sum_of_track_powers(track_gain, track_n_blocks):
|
||||
# convert `LU to target_level` -> LUFS
|
||||
loudness = target_level_lufs - track_gain
|
||||
loudness = target_level_lufs - track_gain.gain
|
||||
|
||||
# This reverses ITU-R BS.1770-4 p. 6 equation (5) to convert
|
||||
# from loudness to power. The result is the average gating
|
||||
|
|
@ -586,7 +586,7 @@ class CommandBackend(Backend):
|
|||
When computing album gain, the last TrackGain object returned is
|
||||
the album gain
|
||||
"""
|
||||
if len(items) == 0:
|
||||
if not items:
|
||||
self._log.debug('no supported tracks to analyze')
|
||||
return []
|
||||
|
||||
|
|
@ -1375,7 +1375,7 @@ class ReplayGainPlugin(BeetsPlugin):
|
|||
pass
|
||||
|
||||
def close_pool(self):
|
||||
"""Regularly lose the `ThreadPool` instance in `self.pool`.
|
||||
"""Regularly close the `ThreadPool` instance in `self.pool`.
|
||||
"""
|
||||
if self.pool is not None:
|
||||
self.pool.close()
|
||||
|
|
|
|||
|
|
@ -373,11 +373,20 @@ class TestHelper:
|
|||
items.append(item)
|
||||
return items
|
||||
|
||||
def add_album_fixture(self, track_count=1, ext='mp3', disc_count=1):
|
||||
def add_album_fixture(
|
||||
self,
|
||||
track_count=1,
|
||||
fname='full',
|
||||
ext='mp3',
|
||||
disc_count=1,
|
||||
):
|
||||
"""Add an album with files to the database.
|
||||
"""
|
||||
items = []
|
||||
path = os.path.join(_common.RSRC, util.bytestring_path('full.' + ext))
|
||||
path = os.path.join(
|
||||
_common.RSRC,
|
||||
util.bytestring_path(f'{fname}.{ext}'),
|
||||
)
|
||||
for discnumber in range(1, disc_count + 1):
|
||||
for i in range(track_count):
|
||||
item = Item.from_path(path)
|
||||
|
|
|
|||
BIN
test/rsrc/whitenoise.flac
Normal file
BIN
test/rsrc/whitenoise.flac
Normal file
Binary file not shown.
BIN
test/rsrc/whitenoise.mp3
Normal file
BIN
test/rsrc/whitenoise.mp3
Normal file
Binary file not shown.
BIN
test/rsrc/whitenoise.opus
Normal file
BIN
test/rsrc/whitenoise.opus
Normal file
Binary file not shown.
|
|
@ -85,6 +85,8 @@ class FfmpegBackendMixin():
|
|||
|
||||
|
||||
class ReplayGainCliTestBase(TestHelper):
|
||||
FNAME: str
|
||||
|
||||
def setUp(self):
|
||||
# Implemented by Mixins, see above. This may decide to skip the test.
|
||||
self.test_backend()
|
||||
|
|
@ -99,7 +101,8 @@ class ReplayGainCliTestBase(TestHelper):
|
|||
self.unload_plugins()
|
||||
|
||||
def _add_album(self, *args, **kwargs):
|
||||
album = self.add_album_fixture(*args, **kwargs)
|
||||
# Use a file with non-zero volume (most test assets are total silence)
|
||||
album = self.add_album_fixture(*args, fname=self.FNAME, **kwargs)
|
||||
for item in album.items():
|
||||
reset_replaygain(item)
|
||||
|
||||
|
|
@ -305,19 +308,25 @@ class ReplayGainCliTestBase(TestHelper):
|
|||
@unittest.skipIf(not GST_AVAILABLE, 'gstreamer cannot be found')
|
||||
class ReplayGainGstCliTest(ReplayGainCliTestBase, unittest.TestCase,
|
||||
GstBackendMixin):
|
||||
pass
|
||||
FNAME = "full" # file contains only silence
|
||||
|
||||
|
||||
@unittest.skipIf(not GAIN_PROG_AVAILABLE, 'no *gain command found')
|
||||
class ReplayGainCmdCliTest(ReplayGainCliTestBase, unittest.TestCase,
|
||||
CmdBackendMixin):
|
||||
pass
|
||||
FNAME = "full" # file contains only silence
|
||||
|
||||
|
||||
@unittest.skipIf(not FFMPEG_AVAILABLE, 'ffmpeg cannot be found')
|
||||
class ReplayGainFfmpegCliTest(ReplayGainCliTestBase, unittest.TestCase,
|
||||
FfmpegBackendMixin):
|
||||
pass
|
||||
FNAME = "full" # file contains only silence
|
||||
|
||||
|
||||
@unittest.skipIf(not FFMPEG_AVAILABLE, 'ffmpeg cannot be found')
|
||||
class ReplayGainFfmpegNoiseCliTest(ReplayGainCliTestBase, unittest.TestCase,
|
||||
FfmpegBackendMixin):
|
||||
FNAME = "whitenoise"
|
||||
|
||||
|
||||
class ImportTest(TestHelper):
|
||||
|
|
|
|||
Loading…
Reference in a new issue