fix typo in pcm format args
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 3 Aug 2021 09:08:53 +0000 (11:08 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 3 Aug 2021 09:08:53 +0000 (11:08 +0200)
music_assistant/constants.py
music_assistant/helpers/audio.py
music_assistant/web/stream.py

index c213513bc1c28fe65a7b68c4c7c95dd2362122d0..0009ad74cb88970b51e807b1e6fb5223a741884b 100755 (executable)
@@ -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
index 789dd82c9e7601ba275c04491bb5132c33059773..41f2d72818f36c8c37953d6d27ada77dbe8bb107 100644 (file)
@@ -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)]
index 7dc5020dfdea4fa3a606385725b8e60d087ab4d8..9e6e7c0fbc15b900db02efcffcf2762ac8ddcfa8 100644 (file)
@@ -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,
         ):