pack the client audio processing into its own chain
This commit is contained in:
parent
223c2d1709
commit
99c7093a1a
@ -41,6 +41,7 @@ from csdr.chain.demodulator import DemodulatorChain
|
||||
from csdr.chain.fm import Fm
|
||||
from csdr.chain.am import Am
|
||||
from csdr.chain.ssb import Ssb
|
||||
from csdr.chain.clientaudio import ClientAudioChain
|
||||
|
||||
import logging
|
||||
|
||||
@ -51,6 +52,7 @@ class Dsp(DirewolfConfigSubscriber):
|
||||
def __init__(self, output: Output):
|
||||
self.pycsdr_enabled = True
|
||||
self.pycsdr_chain = None
|
||||
self.pycsdr_client_chain = None
|
||||
self.pycsdr_reader = None
|
||||
self.pycsdr_power_reader = None
|
||||
self.buffer = None
|
||||
@ -732,11 +734,19 @@ class Dsp(DirewolfConfigSubscriber):
|
||||
self.set_squelch_level(self.squelch_level)
|
||||
self.set_bpf(self.low_cut, self.high_cut)
|
||||
self.set_offset_freq(self.offset_freq)
|
||||
|
||||
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.output.send_output("audio", self.pycsdr_reader.read)
|
||||
|
||||
powerBuffer = Buffer(Format.FLOAT)
|
||||
chain.setPowerWriter(powerBuffer)
|
||||
self.pycsdr_power_reader = powerBuffer.getReader()
|
||||
@ -839,6 +849,8 @@ class Dsp(DirewolfConfigSubscriber):
|
||||
self.pycsdr_reader = None
|
||||
self.pycsdr_power_reader.stop()
|
||||
self.pycsdr_power_reader = None
|
||||
self.pycsdr_client_chain.stop()
|
||||
self.pycsdr_client_chain = None
|
||||
if self.process is not None:
|
||||
try:
|
||||
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
|
||||
|
@ -12,7 +12,6 @@ class Am(Chain):
|
||||
AmDemod(),
|
||||
DcBlock(),
|
||||
agc,
|
||||
Convert(Format.FLOAT, Format.SHORT),
|
||||
]
|
||||
|
||||
super().__init__(*workers)
|
||||
|
14
csdr/chain/clientaudio.py
Normal file
14
csdr/chain/clientaudio.py
Normal 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)
|
@ -13,6 +13,5 @@ class Fm(Chain):
|
||||
Limit(),
|
||||
NfmDeemphasis(sampleRate),
|
||||
agc,
|
||||
Convert(Format.FLOAT, Format.SHORT),
|
||||
]
|
||||
super().__init__(*workers)
|
||||
|
@ -10,7 +10,6 @@ class Ssb(Chain):
|
||||
# empty chain as placeholder for the "last decimation"
|
||||
Chain(),
|
||||
Agc(Format.FLOAT),
|
||||
Convert(Format.FLOAT, Format.SHORT),
|
||||
]
|
||||
super().__init__(*workers)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user