Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes to the DSP code. #378

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions owrx/dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ def _updateDialFrequency(self):
if isinstance(self.demodulator, DialFrequencyReceiver):
self.demodulator.setDialFrequency(dialFrequency)
if isinstance(self.secondaryDemodulator, DialFrequencyReceiver):
if self.secondaryFrequencyOffset:
dialFrequency += self.secondaryFrequencyOffset
self.secondaryDemodulator.setDialFrequency(dialFrequency)

def setAudioCompression(self, compression: str) -> None:
Expand Down Expand Up @@ -347,18 +349,23 @@ def setSecondaryFrequencyOffset(self, freq: int) -> None:
if self.secondaryFrequencyOffset == freq:
return
self.secondaryFrequencyOffset = freq
if self.secondarySelector:
self.secondarySelector.setFrequencyOffset(self.secondaryFrequencyOffset)
self._updateDialFrequency()

if self.secondarySelector is None:
return
self.secondarySelector.setFrequencyOffset(self.secondaryFrequencyOffset)

def setSecondaryFftCompression(self, compression: str) -> None:
def setSecondaryFftCompression(self, compression: str) -> bool:
if compression == self.secondaryFftCompression:
return
return False
self.secondaryFftCompression = compression
if not self.secondaryFftChain:
return
self.secondaryFftChain.setCompression(self.secondaryFftCompression)
return False
# compressions may have different formats
try:
self.secondaryFftChain.setCompression(self.secondaryFftCompression)
except ValueError:
return True
# formats matched
return False

def setSecondaryFftOverlapFactor(self, overlap: float) -> None:
if overlap == self.secondaryFftOverlapFactor:
Expand All @@ -377,8 +384,13 @@ def setSecondaryFftFps(self, fps: int) -> None:
self.secondaryFftChain.setFps(self.secondaryFftFps)

def getSecondaryFftOutputFormat(self) -> Format:
if self.secondaryFftCompression == "adpcm":
# if we already have an FFT chain, query its output format
if self.secondaryFftChain is not None:
return self.secondaryFftChain.getOutputFormat()
# ADPCM compression produces chars
elif self.secondaryFftCompression == "adpcm":
return Format.CHAR
# uncompressed FFT uses floats
return Format.FLOAT

def setWfmDeemphasisTau(self, tau: float) -> None:
Expand Down Expand Up @@ -590,7 +602,9 @@ def _getDemodulator(self, demod: Union[str, BaseDemodulatorChain]) -> Optional[B
return Empty()

def setDemodulator(self, mod):
# this kills both primary and secondary demodulators
self.chain.stopDemodulator()

try:
demodulator = self._getDemodulator(mod)
if demodulator is None:
Expand All @@ -605,6 +619,13 @@ def setDemodulator(self, mod):
buffer = Buffer(self.chain.getOutputFormat())
self.chain.setWriter(buffer)
self.wireOutput(self.audioOutput, buffer)

# recreate secondary demodulator, if present
mod2 = self.props["secondary_mod"] if "secondary_mod" in self.props else ""
desc = Modes.findByModulation(mod2)
if hasattr(desc, "underlying") and mod in desc.underlying:
self.setSecondaryDemodulator(mod2)

except DemodulatorError as de:
self.handler.write_demodulator_error(str(de))

Expand Down