pack the client audio processing into its own chain

This commit is contained in:
Jakob Ketterl 2021-07-25 19:31:56 +02:00
parent 223c2d1709
commit 99c7093a1a
5 changed files with 28 additions and 5 deletions

View File

@ -41,6 +41,7 @@ from csdr.chain.demodulator import DemodulatorChain
from csdr.chain.fm import Fm from csdr.chain.fm import Fm
from csdr.chain.am import Am from csdr.chain.am import Am
from csdr.chain.ssb import Ssb from csdr.chain.ssb import Ssb
from csdr.chain.clientaudio import ClientAudioChain
import logging import logging
@ -51,6 +52,7 @@ class Dsp(DirewolfConfigSubscriber):
def __init__(self, output: Output): def __init__(self, output: Output):
self.pycsdr_enabled = True self.pycsdr_enabled = True
self.pycsdr_chain = None self.pycsdr_chain = None
self.pycsdr_client_chain = None
self.pycsdr_reader = None self.pycsdr_reader = None
self.pycsdr_power_reader = None self.pycsdr_power_reader = None
self.buffer = None self.buffer = None
@ -732,11 +734,19 @@ class Dsp(DirewolfConfigSubscriber):
self.set_squelch_level(self.squelch_level) self.set_squelch_level(self.squelch_level)
self.set_bpf(self.low_cut, self.high_cut) self.set_bpf(self.low_cut, self.high_cut)
self.set_offset_freq(self.offset_freq) self.set_offset_freq(self.offset_freq)
chain.setInput(self.buffer) chain.setInput(self.buffer)
outputBuffer = Buffer(chain.getOutputFormat())
chain.setWriter(outputBuffer) self.pycsdr_client_chain = ClientAudioChain(self.get_audio_rate(), self.get_output_rate(), self.audio_compression)
buffer = Buffer(chain.getOutputFormat())
chain.setWriter(buffer)
self.pycsdr_client_chain.setInput(buffer)
outputBuffer = Buffer(self.pycsdr_client_chain.getOutputFormat())
self.pycsdr_client_chain.setWriter(outputBuffer)
self.pycsdr_reader = outputBuffer.getReader() self.pycsdr_reader = outputBuffer.getReader()
self.output.send_output("audio", self.pycsdr_reader.read) self.output.send_output("audio", self.pycsdr_reader.read)
powerBuffer = Buffer(Format.FLOAT) powerBuffer = Buffer(Format.FLOAT)
chain.setPowerWriter(powerBuffer) chain.setPowerWriter(powerBuffer)
self.pycsdr_power_reader = powerBuffer.getReader() self.pycsdr_power_reader = powerBuffer.getReader()
@ -839,6 +849,8 @@ class Dsp(DirewolfConfigSubscriber):
self.pycsdr_reader = None self.pycsdr_reader = None
self.pycsdr_power_reader.stop() self.pycsdr_power_reader.stop()
self.pycsdr_power_reader = None self.pycsdr_power_reader = None
self.pycsdr_client_chain.stop()
self.pycsdr_client_chain = None
if self.process is not None: if self.process is not None:
try: try:
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)

View File

@ -12,7 +12,6 @@ class Am(Chain):
AmDemod(), AmDemod(),
DcBlock(), DcBlock(),
agc, agc,
Convert(Format.FLOAT, Format.SHORT),
] ]
super().__init__(*workers) super().__init__(*workers)

14
csdr/chain/clientaudio.py Normal file
View File

@ -0,0 +1,14 @@
from csdr.chain import Chain
from pycsdr.modules import AudioResampler, Convert, AdpcmEncoder
from pycsdr.types import Format
class ClientAudioChain(Chain):
def __init__(self, inputRate: int, clientRate: int, compression: str):
workers = []
if inputRate != clientRate:
workers += [AudioResampler(inputRate, clientRate)]
workers += [Convert(Format.FLOAT, Format.SHORT)]
if compression == "adpcm":
workers += [AdpcmEncoder()]
super().__init__(*workers)

View File

@ -13,6 +13,5 @@ class Fm(Chain):
Limit(), Limit(),
NfmDeemphasis(sampleRate), NfmDeemphasis(sampleRate),
agc, agc,
Convert(Format.FLOAT, Format.SHORT),
] ]
super().__init__(*workers) super().__init__(*workers)

View File

@ -10,7 +10,6 @@ class Ssb(Chain):
# empty chain as placeholder for the "last decimation" # empty chain as placeholder for the "last decimation"
Chain(), Chain(),
Agc(Format.FLOAT), Agc(Format.FLOAT),
Convert(Format.FLOAT, Format.SHORT),
] ]
super().__init__(*workers) super().__init__(*workers)