2021-09-01 13:58:39 +00:00
|
|
|
from owrx.source import SdrSource
|
|
|
|
from pycsdr.modules import Buffer, FirDecimate, Shift
|
|
|
|
from pycsdr.types import Format
|
|
|
|
from csdr.chain import Chain
|
2019-12-21 19:58:28 +00:00
|
|
|
|
|
|
|
|
2021-09-01 13:58:39 +00:00
|
|
|
class Resampler(SdrSource):
|
2020-12-30 16:18:46 +00:00
|
|
|
def onPropertyChange(self, changes):
|
2022-12-10 18:50:26 +00:00
|
|
|
self.logger.warning("Resampler is unable to handle property changes: {0}".format(changes))
|
2019-12-27 23:26:45 +00:00
|
|
|
|
2019-12-31 14:24:11 +00:00
|
|
|
def __init__(self, props, sdr):
|
2019-12-21 19:58:28 +00:00
|
|
|
sdrProps = sdr.getProps()
|
2021-09-01 13:58:39 +00:00
|
|
|
shift = (sdrProps["center_freq"] - props["center_freq"]) / sdrProps["samp_rate"]
|
|
|
|
decimation = int(float(sdrProps["samp_rate"]) / props["samp_rate"])
|
|
|
|
if_samp_rate = sdrProps["samp_rate"] / decimation
|
|
|
|
transition_bw = 0.15 * (if_samp_rate / float(sdrProps["samp_rate"]))
|
2019-12-21 19:58:28 +00:00
|
|
|
props["samp_rate"] = if_samp_rate
|
|
|
|
|
2021-09-01 13:58:39 +00:00
|
|
|
self.chain = Chain([
|
|
|
|
Shift(shift),
|
|
|
|
FirDecimate(decimation, transition_bw)
|
|
|
|
])
|
|
|
|
|
|
|
|
self.chain.setReader(sdr.getBuffer().getReader())
|
|
|
|
|
2019-12-31 14:24:11 +00:00
|
|
|
super().__init__(None, props)
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2021-09-01 13:58:39 +00:00
|
|
|
def getBuffer(self):
|
|
|
|
if self.buffer is None:
|
|
|
|
self.buffer = Buffer(Format.COMPLEX_FLOAT)
|
|
|
|
self.chain.setWriter(self.buffer)
|
|
|
|
return self.buffer
|
2019-12-21 19:58:28 +00:00
|
|
|
|
2021-09-02 08:53:05 +00:00
|
|
|
def stop(self):
|
|
|
|
self.chain.stop()
|
|
|
|
self.chain = None
|
|
|
|
super().stop()
|
|
|
|
|
2019-12-21 19:58:28 +00:00
|
|
|
def activateProfile(self, profile_id=None):
|
2022-12-10 18:50:26 +00:00
|
|
|
self.logger.warning("Resampler does not support setting profiles")
|
2019-12-21 19:58:28 +00:00
|
|
|
pass
|
2021-01-13 22:44:00 +00:00
|
|
|
|
|
|
|
def validateProfiles(self):
|
|
|
|
# resampler does not support profiles
|
|
|
|
pass
|