diff --git a/owrx/source/direct.py b/owrx/source/direct.py index d11d83b..e4a5eaf 100644 --- a/owrx/source/direct.py +++ b/owrx/source/direct.py @@ -1,5 +1,9 @@ from abc import ABCMeta from owrx.source import SdrSource, SdrDeviceDescription +from csdr.chain import Chain +from typing import Optional +from pycsdr.modules import Buffer +from pycsdr.types import Format import logging @@ -38,16 +42,30 @@ class DirectSource(SdrSource, metaclass=ABCMeta): ] def getCommand(self): - return super().getCommand() + self.getFormatConversion() + self.getNmuxCommand() + return super().getCommand() + self.getNmuxCommand() # override this in subclasses, if necessary - def getFormatConversion(self): - return [] + def getFormatConversion(self) -> Optional[Chain]: + return None # override this in subclasses, if necessary def sleepOnRestart(self): pass + def getBuffer(self): + if self.buffer is None: + source = self._getTcpSource() + buffer = Buffer(source.getOutputFormat()) + source.setWriter(buffer) + conversion = self.getFormatConversion() + if conversion is not None: + conversion.setReader(buffer.getReader()) + # this one must be COMPLEX_FLOAT + buffer = Buffer(Format.COMPLEX_FLOAT) + conversion.setWriter(buffer) + self.buffer = buffer + return self.buffer + class DirectSourceDeviceDescription(SdrDeviceDescription): pass diff --git a/owrx/source/fifi_sdr.py b/owrx/source/fifi_sdr.py index cf6e3e7..4bf3bdd 100644 --- a/owrx/source/fifi_sdr.py +++ b/owrx/source/fifi_sdr.py @@ -1,6 +1,9 @@ from owrx.command import Option from owrx.source.direct import DirectSource, DirectSourceDeviceDescription from subprocess import Popen +from csdr.chain import Chain +from pycsdr.modules import Convert, Gain +from pycsdr.types import Format import logging @@ -20,8 +23,8 @@ class FifiSdrSource(DirectSource): def getEventNames(self): return super().getEventNames() + ["device"] - def getFormatConversion(self): - return ["csdr convert_s16_f", "csdr gain_ff 5"] + def getFormatConversion(self) -> Chain: + return Chain([Convert(Format.COMPLEX_SHORT, Format.COMPLEX_FLOAT), Gain(Format.COMPLEX_FLOAT, 5.0)]) def sendRockProgFrequency(self, frequency): process = Popen(["rockprog", "--vco", "-w", "--freq={}".format(frequency / 1e6)])