diff --git a/csdr/chain/analog.py b/csdr/chain/analog.py index 15b8d1b..c890343 100644 --- a/csdr/chain/analog.py +++ b/csdr/chain/analog.py @@ -1,4 +1,4 @@ -from csdr.chain.demodulator import BaseDemodulatorChain +from csdr.chain.demodulator import BaseDemodulatorChain, FixedIfSampleRateChain, HdAudio from pycsdr.modules import AmDemod, DcBlock, FmDemod, Limit, NfmDeemphasis, Agc, WfmDeemphasis, FractionalDecimator, RealPart from pycsdr.types import Format, AgcProfile @@ -31,7 +31,7 @@ class NFm(BaseDemodulatorChain): super().__init__(workers) -class WFm(BaseDemodulatorChain): +class WFm(BaseDemodulatorChain, FixedIfSampleRateChain, HdAudio): def __init__(self, sampleRate: int, tau: float): workers = [ FmDemod(), diff --git a/csdr/chain/demodulator.py b/csdr/chain/demodulator.py index 8ca5556..74373c2 100644 --- a/csdr/chain/demodulator.py +++ b/csdr/chain/demodulator.py @@ -1,12 +1,27 @@ from csdr.chain import Chain +from abc import ABC, abstractmethod class BaseDemodulatorChain(Chain): def getFixedIfSampleRate(self): return None - def getFixedAudioRate(self): - return None - def supportsSquelch(self): return True + + +class FixedAudioRateChain(ABC): + @abstractmethod + def getFixedAudioRate(self): + pass + + +class FixedIfSampleRateChain(ABC): + @abstractmethod + def getFixedIfSampleRate(self): + return self.fixedIfSampleRate + + +# marker interface +class HdAudio: + pass diff --git a/csdr/chain/digiham.py b/csdr/chain/digiham.py index fbf2de8..fa52ead 100644 --- a/csdr/chain/digiham.py +++ b/csdr/chain/digiham.py @@ -1,11 +1,11 @@ -from csdr.chain.demodulator import BaseDemodulatorChain +from csdr.chain.demodulator import BaseDemodulatorChain, FixedAudioRateChain, FixedIfSampleRateChain from pycsdr.modules import FmDemod, Agc, Writer from pycsdr.types import Format from digiham.modules import DstarDecoder, DcBlock, FskDemodulator, GfskDemodulator, DigitalVoiceFilter, MbeSynthesizer, NarrowRrcFilter, NxdnDecoder, DmrDecoder, WideRrcFilter, YsfDecoder from digiham.ambe import Modes -class DigihamChain(BaseDemodulatorChain): +class DigihamChain(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain): def __init__(self, fskDemodulator, decoder, mbeMode, filter=None, codecserver: str = ""): self.decoder = decoder if codecserver is None: diff --git a/owrx/dsp.py b/owrx/dsp.py index 03f0b38..9744ff8 100644 --- a/owrx/dsp.py +++ b/owrx/dsp.py @@ -7,10 +7,9 @@ from owrx.source import SdrSourceEventClient, SdrSourceState, SdrClientClass from owrx.property import PropertyStack, PropertyLayer, PropertyValidator from owrx.property.validators import OrValidator, RegexValidator, BoolValidator from owrx.modes import Modes -from owrx.config.core import CoreConfig from csdr.output import Output from csdr.chain import Chain -from csdr.chain.demodulator import BaseDemodulatorChain +from csdr.chain.demodulator import BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain from csdr.chain.selector import Selector from csdr.chain.clientaudio import ClientAudioChain from csdr.chain.analog import NFm, WFm, Am, Ssb @@ -53,15 +52,13 @@ class ClientDemodulatorChain(Chain): self.demodulator = demodulator - ifRate = self.demodulator.getFixedIfSampleRate() - if ifRate is not None: - self.selector.setOutputRate(ifRate) + if isinstance(self.demodulator, FixedIfSampleRateChain): + self.selector.setOutputRate(self.demodulator.getFixedIfSampleRate()) else: self.selector.setOutputRate(self.outputRate) - audioRate = self.demodulator.getFixedAudioRate() - if audioRate is not None: - self.clientAudioChain.setInputRate(audioRate) + if isinstance(self.demodulator, FixedAudioRateChain): + self.clientAudioChain.setInputRate(self.demodulator.getFixedAudioRate()) else: self.clientAudioChain.setInputRate(self.outputRate) @@ -102,9 +99,9 @@ class ClientDemodulatorChain(Chain): return self.outputRate = outputRate - if self.demodulator.getFixedIfSampleRate() is None: + if not isinstance(self.demodulator, FixedIfSampleRateChain): self.selector.setOutputRate(outputRate) - if self.demodulator.getFixedAudioRate() is None: + if not isinstance(self.demodulator, FixedAudioRateChain): self.clientAudioChain.setClientRate(outputRate) def setPowerWriter(self, writer: Writer) -> None: