From: Marcel van der Veldt Date: Tue, 3 Aug 2021 09:08:53 +0000 (+0200) Subject: fix typo in pcm format args X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=1cfca2ca691037815f4676dc9501b4317540657d;p=music-assistant-server.git fix typo in pcm format args --- diff --git a/music_assistant/constants.py b/music_assistant/constants.py index c213513b..0009ad74 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -1,6 +1,6 @@ """All constants for Music Assistant.""" -__version__ = "0.2.3" +__version__ = "0.2.4" REQUIRED_PYTHON_VER = "3.8" # configuration keys/attributes diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index 789dd82c..41f2d728 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -313,7 +313,8 @@ def get_sox_args( filter_args = [] if streamdetails.gain_correct: filter_args += ["vol", str(streamdetails.gain_correct), "dB"] - if resample and resample > 48000: + if resample and streamdetails.content_type == ContentType.FLAC: + # use extra high quality resampler only if it makes sense filter_args += ["rate", "-v", str(resample)] elif resample: filter_args += ["rate", str(resample)] diff --git a/music_assistant/web/stream.py b/music_assistant/web/stream.py index 7dc5020d..9e6e7c0f 100644 --- a/music_assistant/web/stream.py +++ b/music_assistant/web/stream.py @@ -61,18 +61,18 @@ async def stream_queue(request: Request): # assume that highest possible quality is needed # if player supports sample rates > 96000 # we use float64 PCM format internally which is heavy on CPU - pcm_format = "f64" + pcm_format = ContentType.PCM_F64LE elif sample_rate > 48000: # prefer internal PCM_S32LE format - pcm_format = "s32" + pcm_format = ContentType.PCM_S32LE else: # fallback to 24 bits - pcm_format = "s24" + pcm_format = ContentType.PCM_S24LE args = [ "sox", "-t", - pcm_format, + pcm_format.sox_format(), "-c", "2", "-r", @@ -250,8 +250,8 @@ async def get_media_stream( async def get_pcm_queue_stream( mass: MusicAssistant, player_queue: PlayerQueue, - sample_rate=96000, - pcm_format: str = "f64", + sample_rate, + pcm_format: ContentType, channels: int = 2, ) -> AsyncGenerator[bytes, None]: """Stream the PlayerQueue's tracks as constant feed in PCM raw audio.""" @@ -259,15 +259,15 @@ async def get_pcm_queue_stream( queue_index = None # get crossfade details fade_length = player_queue.crossfade_duration - if "64" in pcm_format: + if pcm_format == ContentType.PCM_F64LE: bit_depth = 64 - elif "32" in pcm_format: + elif pcm_format in [ContentType.PCM_F32LE, ContentType.PCM_S32LE]: bit_depth = 32 - elif "24" in pcm_format: + elif pcm_format == ContentType.PCM_S24LE: bit_depth = 24 else: bit_depth = 16 - pcm_args = [pcm_format, "-c", "2", "-r", str(sample_rate)] + pcm_args = [pcm_format.sox_format(), "-c", "2", "-r", str(sample_rate)] sample_size = int(sample_rate * (bit_depth / 8) * channels) # 1 second buffer_size = sample_size * fade_length if fade_length else sample_size * 10 # stream queue tracks one by one @@ -302,7 +302,7 @@ async def get_pcm_queue_stream( async for is_last_chunk, chunk in get_media_stream( mass, streamdetails, - ContentType.PCM_F64LE, + pcm_format, resample=sample_rate, chunk_size=buffer_size, ):