From 3bf1fedd2e524bc927e4801ab79bd51ea4e4dd1f Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Wed, 10 Jul 2024 18:50:39 -0400 Subject: [PATCH] Integrating Throttle changes from Jakob. --- csdr/chain/hdradio.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/csdr/chain/hdradio.py b/csdr/chain/hdradio.py index 5cefe36c..9727a433 100644 --- a/csdr/chain/hdradio.py +++ b/csdr/chain/hdradio.py @@ -1,6 +1,6 @@ from csdr.chain.demodulator import FixedIfSampleRateChain, BaseDemodulatorChain, FixedAudioRateChain, DialFrequencyReceiver, HdAudio from csdr.module.hdradio import HdRadioModule -from pycsdr.modules import Convert, Agc, Downmix, Writer, Buffer +from pycsdr.modules import Convert, Agc, Downmix, Writer, Buffer, Throttle from pycsdr.types import Format from typing import Optional @@ -17,6 +17,7 @@ class HdRadio(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, Agc(Format.COMPLEX_FLOAT), Convert(Format.COMPLEX_FLOAT, Format.COMPLEX_SHORT), self.hdradio, + Throttle(Format.SHORT, 44100 * 2), Downmix(Format.SHORT), ] super().__init__(workers) @@ -42,15 +43,9 @@ class HdRadio(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, # Clear station metadata when changing frequency pass - #def _connect(self, w1, w2, buffer: Optional[Buffer] = None) -> None: - # # Buffering 2 seconds of input stream - # if isinstance(w2, HdRadioModule): - # size = self.getFixedIfSampleRate() * 2 * 2 * 2 - # buffer = Buffer(w1.getOutputFormat(), size=size) - # logger.info("%d bytes => HdRadioModule", size) - # # Buffering 10 seconds of output audio - # if isinstance(w1, HdRadioModule): - # size = self.getFixedAudioRate() * 2 * 2 - # buffer = Buffer(w1.getOutputFormat(), size=size) - # logger.info("HdRadioModule => %d bytes", size) - # super()._connect(w1, w2, buffer) + def _connect(self, w1, w2, buffer: Optional[Buffer] = None) -> None: + if isinstance(w2, Throttle): + # Audio data comes in in bursts, so we use a throttle + # and 10x the default buffer size here + buffer = Buffer(Format.SHORT, 2621440) + return super()._connect(w1, w2, buffer)