Integrating Throttle changes from Jakob.

This commit is contained in:
Marat Fayzullin 2024-07-10 18:50:39 -04:00
parent abf88acf95
commit 3bf1fedd2e
1 changed files with 8 additions and 13 deletions

View File

@ -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)