fix sample rate updates for secondary demods

This commit is contained in:
Jakob Ketterl 2021-11-08 17:52:37 +01:00
parent 6d414698e8
commit dcdfe7969a

View File

@ -103,22 +103,11 @@ class ClientDemodulatorChain(Chain):
self.demodulator = demodulator self.demodulator = demodulator
outputRate = self.hdOutputRate if isinstance(self.demodulator, HdAudio) else self.outputRate self.selector.setOutputRate(self._getSelectorOutputRate())
if isinstance(self.demodulator, FixedIfSampleRateChain): clientRate = self._getClientAudioInputRate()
self.selector.setOutputRate(self.demodulator.getFixedIfSampleRate()) self.clientAudioChain.setInputRate(clientRate)
elif isinstance(self.secondaryDemodulator, FixedAudioRateChain): self.demodulator.setSampleRate(clientRate)
self.selector.setOutputRate(self.secondaryDemodulator.getFixedAudioRate())
else:
self.selector.setOutputRate(outputRate)
self.demodulator.setSampleRate(outputRate)
if isinstance(self.demodulator, FixedAudioRateChain):
self.clientAudioChain.setInputRate(self.demodulator.getFixedAudioRate())
elif isinstance(self.secondaryDemodulator, FixedAudioRateChain):
self.clientAudioChain.setInputRate(self.secondaryDemodulator.getFixedAudioRate())
else:
self.clientAudioChain.setInputRate(outputRate)
if isinstance(self.demodulator, DeemphasisTauChain): if isinstance(self.demodulator, DeemphasisTauChain):
self.demodulator.setDeemphasisTau(self.wfmDeemphasisTau) self.demodulator.setDeemphasisTau(self.wfmDeemphasisTau)
@ -126,17 +115,29 @@ class ClientDemodulatorChain(Chain):
self._updateDialFrequency() self._updateDialFrequency()
self._syncSquelch() self._syncSquelch()
outputRate = self.hdOutputRate if isinstance(self.demodulator, HdAudio) else self.outputRate
self.clientAudioChain.setClientRate(outputRate) self.clientAudioChain.setClientRate(outputRate)
if self.metaWriter is not None and isinstance(demodulator, MetaProvider): if self.metaWriter is not None and isinstance(demodulator, MetaProvider):
demodulator.setMetaWriter(self.metaWriter) demodulator.setMetaWriter(self.metaWriter)
def _getSelectorOutputRate(self): def _getSelectorOutputRate(self):
if isinstance(self.secondaryDemodulator, FixedAudioRateChain): if isinstance(self.demodulator, FixedIfSampleRateChain):
return self.demodulator.getFixedIfSampleRate()
elif isinstance(self.secondaryDemodulator, FixedAudioRateChain):
if isinstance(self.demodulator, FixedAudioRateChain) and self.demodulator.getFixedAudioRate() != self.secondaryDemodulator.getFixedAudioRate(): if isinstance(self.demodulator, FixedAudioRateChain) and self.demodulator.getFixedAudioRate() != self.secondaryDemodulator.getFixedAudioRate():
raise ValueError("secondary and primary demodulator chain audio rates do not match!") raise ValueError("secondary and primary demodulator chain audio rates do not match!")
return self.secondaryDemodulator.getFixedAudioRate() return self.secondaryDemodulator.getFixedAudioRate()
return self.outputRate else:
return self.hdOutputRate if isinstance(self.demodulator, HdAudio) else self.outputRate
def _getClientAudioInputRate(self):
if isinstance(self.demodulator, FixedAudioRateChain):
return self.demodulator.getFixedAudioRate()
elif isinstance(self.secondaryDemodulator, FixedAudioRateChain):
return self.secondaryDemodulator.getFixedAudioRate()
else:
return self.hdOutputRate if isinstance(self.demodulator, HdAudio) else self.outputRate
def setSecondaryDemodulator(self, demod: Optional[SecondaryDemodulator]): def setSecondaryDemodulator(self, demod: Optional[SecondaryDemodulator]):
if demod is self.secondaryDemodulator: if demod is self.secondaryDemodulator:
@ -149,8 +150,11 @@ class ClientDemodulatorChain(Chain):
rate = self._getSelectorOutputRate() rate = self._getSelectorOutputRate()
self.selector.setOutputRate(rate) self.selector.setOutputRate(rate)
self.clientAudioChain.setInputRate(rate)
self.demodulator.setSampleRate(rate) clientRate = self._getClientAudioInputRate()
self.clientAudioChain.setInputRate(clientRate)
self.demodulator.setSampleRate(clientRate)
self._updateDialFrequency() self._updateDialFrequency()
self._syncSquelch() self._syncSquelch()