rebuilt the resampler using pycsdr

This commit is contained in:
Jakob Ketterl 2021-09-01 15:58:39 +02:00
parent 01260d66c8
commit f9df35ffd4
2 changed files with 23 additions and 21 deletions

View File

@ -6,7 +6,6 @@ from csdr.output import Output
from owrx.wsjt import WsjtParser from owrx.wsjt import WsjtParser
from owrx.aprs import AprsParser from owrx.aprs import AprsParser
from owrx.js8 import Js8Parser from owrx.js8 import Js8Parser
from owrx.config.core import CoreConfig
from owrx.config import Config from owrx.config import Config
from owrx.source.resampler import Resampler from owrx.source.resampler import Resampler
from owrx.property import PropertyLayer, PropertyDeleted from owrx.property import PropertyLayer, PropertyDeleted
@ -200,12 +199,9 @@ class ServiceHandler(SdrSourceEventClient):
if len(group) > 1: if len(group) > 1:
cf = self.get_center_frequency(group) cf = self.get_center_frequency(group)
bw = self.get_bandwidth(group) bw = self.get_bandwidth(group)
logger.debug("group center frequency: {0}, bandwidth: {1}".format(cf, bw)) logger.debug("setting up resampler on center frequency: {0}, bandwidth: {1}".format(cf, bw))
resampler_props = PropertyLayer() resampler_props = PropertyLayer(center_freq=cf, samp_rate=bw)
resampler_props["center_freq"] = cf
resampler_props["samp_rate"] = bw
resampler = Resampler(resampler_props, self.source) resampler = Resampler(resampler_props, self.source)
resampler.start()
for dial in group: for dial in group:
self.services.append(self.setupService(dial["mode"], dial["frequency"], resampler)) self.services.append(self.setupService(dial["mode"], dial["frequency"], resampler))

View File

@ -1,33 +1,39 @@
from .direct import DirectSource from owrx.source import SdrSource
from pycsdr.modules import Buffer, FirDecimate, Shift
from pycsdr.types import Format
from csdr.chain import Chain
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class Resampler(DirectSource): class Resampler(SdrSource):
def onPropertyChange(self, changes): def onPropertyChange(self, changes):
logger.warning("Resampler is unable to handle property changes: {0}".format(changes)) logger.warning("Resampler is unable to handle property changes: {0}".format(changes))
def __init__(self, props, sdr): def __init__(self, props, sdr):
sdrProps = sdr.getProps() sdrProps = sdr.getProps()
self.shift = (sdrProps["center_freq"] - props["center_freq"]) / sdrProps["samp_rate"] shift = (sdrProps["center_freq"] - props["center_freq"]) / sdrProps["samp_rate"]
self.decimation = int(float(sdrProps["samp_rate"]) / props["samp_rate"]) decimation = int(float(sdrProps["samp_rate"]) / props["samp_rate"])
if_samp_rate = sdrProps["samp_rate"] / self.decimation if_samp_rate = sdrProps["samp_rate"] / decimation
self.transition_bw = 0.15 * (if_samp_rate / float(sdrProps["samp_rate"])) transition_bw = 0.15 * (if_samp_rate / float(sdrProps["samp_rate"]))
props["samp_rate"] = if_samp_rate props["samp_rate"] = if_samp_rate
self.sdr = sdr self.chain = Chain([
Shift(shift),
FirDecimate(decimation, transition_bw)
])
self.chain.setReader(sdr.getBuffer().getReader())
super().__init__(None, props) super().__init__(None, props)
def getCommand(self): def getBuffer(self):
return [ if self.buffer is None:
"nc -v 127.0.0.1 {nc_port}".format(nc_port=self.sdr.getPort()), self.buffer = Buffer(Format.COMPLEX_FLOAT)
"csdr shift_addfast_cc {shift}".format(shift=self.shift), self.chain.setWriter(self.buffer)
"csdr fir_decimate_cc {decimation} {ddc_transition_bw} HAMMING".format( return self.buffer
decimation=self.decimation, ddc_transition_bw=self.transition_bw
),
] + self.getNmuxCommand()
def activateProfile(self, profile_id=None): def activateProfile(self, profile_id=None):
logger.warning("Resampler does not support setting profiles") logger.warning("Resampler does not support setting profiles")