From be6f533437af761e555a05327fa1d112e442126d Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 12 Aug 2021 18:01:03 +0200 Subject: [PATCH] re-structure client audio conversion --- csdr/chain/clientaudio.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/csdr/chain/clientaudio.py b/csdr/chain/clientaudio.py index 5441bc8..b67ace5 100644 --- a/csdr/chain/clientaudio.py +++ b/csdr/chain/clientaudio.py @@ -1,16 +1,18 @@ from csdr.chain import Chain -from pycsdr.modules import AudioResampler, Convert, AdpcmEncoder +from pycsdr.modules import AudioResampler, Convert, AdpcmEncoder, Limit from pycsdr.types import Format class ClientAudioChain(Chain): def __init__(self, format: Format, inputRate: int, clientRate: int, compression: str): workers = [] - if format != Format.FLOAT: - workers += [Convert(format, Format.FLOAT)] if inputRate != clientRate: - workers += [AudioResampler(inputRate, clientRate)] - workers += [Convert(Format.FLOAT, Format.SHORT)] + # we only have an audio resampler for float ATM so if we need to resample, we need to convert + if format != Format.FLOAT: + workers += [Convert(format, Format.FLOAT)] + workers += [AudioResampler(inputRate, clientRate), Limit(), Convert(Format.FLOAT, Format.SHORT)] + elif format != Format.SHORT: + workers += [Convert(format, Format.SHORT)] if compression == "adpcm": workers += [AdpcmEncoder(sync=True)] super().__init__(*workers)