restore DRM functionality

This commit is contained in:
Jakob Ketterl 2021-09-07 17:31:32 +02:00
parent f3b05c6318
commit 9ca5e0ebd6
5 changed files with 74 additions and 33 deletions

16
csdr/chain/drm.py Normal file
View File

@ -0,0 +1,16 @@
from csdr.chain.demodulator import BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain
from pycsdr.modules import Convert
from pycsdr.types import Format
from owrx.drm import DrmModule
class Drm(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain):
def __init__(self):
workers = [Convert(Format.COMPLEX_FLOAT, Format.COMPLEX_SHORT), DrmModule()]
super().__init__(workers)
def getFixedIfSampleRate(self) -> int:
return 48000
def getFixedAudioRate(self) -> int:
return 48000

View File

@ -4,6 +4,7 @@ from pycsdr.types import Format
from abc import ABCMeta, abstractmethod
from threading import Thread
from io import BytesIO
from subprocess import Popen, PIPE
import pickle
@ -89,3 +90,39 @@ class PickleModule(ThreadModule):
@abstractmethod
def process(self, input):
pass
class PopenModule(AutoStartModule, metaclass=ABCMeta):
def __init__(self):
self.process = None
super().__init__()
@abstractmethod
def getCommand(self):
pass
def start(self):
self.process = Popen(self.getCommand(), stdin=PIPE, stdout=PIPE)
Thread(target=self.pump(self.reader.read, self.process.stdin.write)).start()
Thread(target=self.pump(self.process.stdout.read, self.writer.write)).start()
def stop(self):
if self.process is not None:
self.process.terminate()
self.process.wait()
self.process = None
self.reader.stop()
def pump(self, read, write):
def copy():
while True:
data = None
try:
data = read()
except ValueError:
pass
if data is None or isinstance(data, bytes) and len(data) == 0:
break
write(data)
return copy

14
owrx/drm.py Normal file
View File

@ -0,0 +1,14 @@
from csdr.module import PopenModule
from pycsdr.types import Format
class DrmModule(PopenModule):
def getInputFormat(self) -> Format:
return Format.COMPLEX_FLOAT
def getOutputFormat(self) -> Format:
return Format.SHORT
def getCommand(self):
# dream -c 6 --sigsrate 48000 --audsrate 48000 -I - -O -
return ["dream", "-c", "6", "--sigsrate", "48000", "--audsrate", "48000", "-I", "-", "-O", "-"]

View File

@ -13,6 +13,7 @@ from csdr.chain.clientaudio import ClientAudioChain
from csdr.chain.analog import NFm, WFm, Am, Ssb
from csdr.chain.digiham import DigihamChain, Dmr, Dstar, Nxdn, Ysf
from csdr.chain.m17 import M17Chain
from csdr.chain.drm import Drm
from csdr.chain.fft import FftChain
from csdr.chain.digimodes import AudioChopperDemodulator, PacketDemodulator, PocsagDemodulator
from pycsdr.modules import Buffer, Writer
@ -444,6 +445,8 @@ class DspManager(Output, SdrSourceEventClient):
return Nxdn(self.props["digital_voice_codecserver"])
elif demod == "m17":
return M17Chain()
elif demod == "drm":
return Drm()
def setDemodulator(self, mod):
demodulator = self._getDemodulator(mod)

View File

@ -1,42 +1,13 @@
from csdr.module import AutoStartModule
from csdr.module import PopenModule
from pycsdr.types import Format
from subprocess import Popen, PIPE
import threading
class M17Module(AutoStartModule):
def __init__(self):
self.process = None
super().__init__()
class M17Module(PopenModule):
def getInputFormat(self) -> Format:
return Format.SHORT
def getOutputFormat(self) -> Format:
return Format.SHORT
def start(self):
self.process = Popen(["m17-demod"], stdin=PIPE, stdout=PIPE)
threading.Thread(target=self.pump(self.reader.read, self.process.stdin.write)).start()
threading.Thread(target=self.pump(self.process.stdout.read, self.writer.write)).start()
def stop(self):
if self.process is not None:
self.process.terminate()
self.process.wait()
self.process = None
self.reader.stop()
def pump(self, read, write):
def copy():
while True:
data = None
try:
data = read()
except ValueError:
pass
if data is None or isinstance(data, bytes) and len(data) == 0:
break
write(data)
return copy
def getCommand(self):
return ["m17-demod"]