return to the simpler API
This commit is contained in:
parent
be6f533437
commit
0f1feb9d47
@ -117,7 +117,7 @@ class Dsp(DirewolfConfigSubscriber):
|
|||||||
def setBuffer(self, buffer):
|
def setBuffer(self, buffer):
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
if self.pycsdr_chain is not None:
|
if self.pycsdr_chain is not None:
|
||||||
self.pycsdr_chain.setInput(buffer)
|
self.pycsdr_chain.setReader(buffer.getReader())
|
||||||
|
|
||||||
def set_service(self, flag=True):
|
def set_service(self, flag=True):
|
||||||
self.is_service = flag
|
self.is_service = flag
|
||||||
@ -754,14 +754,14 @@ class Dsp(DirewolfConfigSubscriber):
|
|||||||
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.setReader(self.buffer.getReader())
|
||||||
|
|
||||||
output_rate = self.get_hd_output_rate() if self.isHdAudio() else self.get_output_rate()
|
output_rate = self.get_hd_output_rate() if self.isHdAudio() else self.get_output_rate()
|
||||||
audio_rate = 8000 if self.isDigitalVoice() else self.get_audio_rate()
|
audio_rate = 8000 if self.isDigitalVoice() else self.get_audio_rate()
|
||||||
self.pycsdr_client_chain = ClientAudioChain(chain.getOutputFormat(), audio_rate, output_rate, self.audio_compression)
|
self.pycsdr_client_chain = ClientAudioChain(chain.getOutputFormat(), audio_rate, output_rate, self.audio_compression)
|
||||||
buffer = Buffer(chain.getOutputFormat())
|
buffer = Buffer(chain.getOutputFormat())
|
||||||
chain.setWriter(buffer)
|
chain.setWriter(buffer)
|
||||||
self.pycsdr_client_chain.setInput(buffer)
|
self.pycsdr_client_chain.setReader(buffer.getReader())
|
||||||
|
|
||||||
outputBuffer = Buffer(self.pycsdr_client_chain.getOutputFormat())
|
outputBuffer = Buffer(self.pycsdr_client_chain.getOutputFormat())
|
||||||
self.pycsdr_client_chain.setWriter(outputBuffer)
|
self.pycsdr_client_chain.setWriter(outputBuffer)
|
||||||
|
@ -3,57 +3,39 @@ from pycsdr.modules import Buffer, Writer
|
|||||||
|
|
||||||
class Chain:
|
class Chain:
|
||||||
def __init__(self, *workers):
|
def __init__(self, *workers):
|
||||||
self.input = None
|
|
||||||
self.output = None
|
|
||||||
self.reader = None
|
self.reader = None
|
||||||
|
self.writer = None
|
||||||
|
self.clientReader = None
|
||||||
self.workers = list(workers)
|
self.workers = list(workers)
|
||||||
filtered = self._filterWorkers()
|
for i in range(1, len(self.workers)):
|
||||||
for i in range(1, len(filtered)):
|
self._connect(self.workers[i - 1], self.workers[i])
|
||||||
self._connect(filtered[i - 1], filtered[i])
|
|
||||||
|
|
||||||
def _filterWorkers(self):
|
|
||||||
return [w for w in self.workers if not isinstance(w, Chain) or not w.empty()]
|
|
||||||
|
|
||||||
def empty(self):
|
|
||||||
return len(self.workers) <= 0
|
|
||||||
|
|
||||||
def _connect(self, w1, w2):
|
def _connect(self, w1, w2):
|
||||||
writer = Buffer(w1.getOutputFormat())
|
writer = Buffer(w1.getOutputFormat())
|
||||||
w1.setWriter(writer)
|
w1.setWriter(writer)
|
||||||
if isinstance(w2, Chain):
|
w2.setReader(writer.getReader())
|
||||||
w2.setInput(writer)
|
|
||||||
else:
|
def setReader(self, reader):
|
||||||
w2.setReader(writer.getReader())
|
if self.reader is reader:
|
||||||
|
return
|
||||||
|
self.reader = reader
|
||||||
|
if self.workers:
|
||||||
|
self.workers[0].setReader(reader)
|
||||||
|
|
||||||
|
def setWriter(self, writer):
|
||||||
|
if self.writer is writer:
|
||||||
|
return
|
||||||
|
self.writer = writer
|
||||||
|
if self.workers:
|
||||||
|
self.workers[-1].setWriter(writer)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
for w in self.workers:
|
for w in self.workers:
|
||||||
w.stop()
|
w.stop()
|
||||||
if self.reader is not None:
|
if self.clientReader is not None:
|
||||||
self.reader.stop()
|
# TODO should be covered by finalize
|
||||||
self.reader = None
|
self.clientReader.stop()
|
||||||
|
self.clientReader = None
|
||||||
def setInput(self, buffer: Buffer):
|
|
||||||
if self.input == buffer:
|
|
||||||
return
|
|
||||||
self.input = buffer
|
|
||||||
if self.workers:
|
|
||||||
firstWorker = self.workers[0]
|
|
||||||
if isinstance(firstWorker, Chain):
|
|
||||||
firstWorker.setInput(buffer)
|
|
||||||
else:
|
|
||||||
firstWorker.setReader(buffer.getReader())
|
|
||||||
else:
|
|
||||||
self.output = self.input
|
|
||||||
|
|
||||||
def setWriter(self, writer: Writer):
|
|
||||||
if self.output == writer:
|
|
||||||
return
|
|
||||||
self.output = writer
|
|
||||||
if self.workers:
|
|
||||||
lastWorker = self.workers[-1]
|
|
||||||
lastWorker.setWriter(self.output)
|
|
||||||
else:
|
|
||||||
raise BufferError("setOutput on empty chain")
|
|
||||||
|
|
||||||
def getOutputFormat(self):
|
def getOutputFormat(self):
|
||||||
if self.workers:
|
if self.workers:
|
||||||
@ -69,41 +51,34 @@ class Chain:
|
|||||||
self.workers[index] = newWorker
|
self.workers[index] = newWorker
|
||||||
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
writer = self.input
|
if self.reader is not None:
|
||||||
|
newWorker.setReader(self.reader)
|
||||||
else:
|
else:
|
||||||
previousWorker = self.workers[index - 1]
|
previousWorker = self.workers[index - 1]
|
||||||
writer = Buffer(previousWorker.getOutputFormat())
|
buffer = Buffer(previousWorker.getOutputFormat())
|
||||||
previousWorker.setWriter(writer)
|
previousWorker.setWriter(buffer)
|
||||||
|
newWorker.setReader(buffer.getReader())
|
||||||
|
|
||||||
if writer is not None:
|
if index == len(self.workers) - 1:
|
||||||
if isinstance(newWorker, Chain):
|
if self.writer is not None:
|
||||||
newWorker.setInput(writer)
|
newWorker.setWriter(self.writer)
|
||||||
else:
|
|
||||||
newWorker.setReader(writer.getReader())
|
|
||||||
|
|
||||||
if index < len(self.workers) - 1:
|
|
||||||
nextWorker = self.workers[index + 1]
|
|
||||||
writer = Buffer(newWorker.getOutputFormat())
|
|
||||||
newWorker.setWriter(writer)
|
|
||||||
if isinstance(nextWorker, Chain):
|
|
||||||
nextWorker.setInput(writer)
|
|
||||||
else:
|
|
||||||
nextWorker.setReader(writer.getReader())
|
|
||||||
else:
|
else:
|
||||||
if self.output is not None:
|
nextWorker = self.workers[index + 1]
|
||||||
newWorker.setWriter(self.output)
|
buffer = Buffer(newWorker.getOutputFormat())
|
||||||
|
newWorker.setWriter(buffer)
|
||||||
|
nextWorker.setReader(buffer.getReader())
|
||||||
|
|
||||||
def pump(self, write):
|
def pump(self, write):
|
||||||
if self.output is None:
|
if self.writer is None:
|
||||||
self.setWriter(Buffer(self.getOutputFormat()))
|
self.setWriter(Buffer(self.getOutputFormat()))
|
||||||
self.reader = self.output.getReader()
|
self.clientReader = self.writer.getReader()
|
||||||
|
|
||||||
def copy():
|
def copy():
|
||||||
run = True
|
run = True
|
||||||
while run:
|
while run:
|
||||||
data = None
|
data = None
|
||||||
try:
|
try:
|
||||||
data = self.reader.read()
|
data = self.clientReader.read()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if data is None:
|
if data is None:
|
||||||
|
@ -7,11 +7,6 @@ class Ssb(Chain):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
workers = [
|
workers = [
|
||||||
RealPart(),
|
RealPart(),
|
||||||
# empty chain as placeholder for the "last decimation"
|
|
||||||
Chain(),
|
|
||||||
Agc(Format.FLOAT),
|
Agc(Format.FLOAT),
|
||||||
]
|
]
|
||||||
super().__init__(*workers)
|
super().__init__(*workers)
|
||||||
|
|
||||||
def setLastDecimation(self, decimation: Chain):
|
|
||||||
self.replace(1, decimation)
|
|
||||||
|
@ -56,7 +56,7 @@ class SpectrumThread(SdrSourceEventClient):
|
|||||||
threading.Thread(target=self.dsp.pump(self.sdrSource.writeSpectrumData)).start()
|
threading.Thread(target=self.dsp.pump(self.sdrSource.writeSpectrumData)).start()
|
||||||
|
|
||||||
if self.sdrSource.isAvailable():
|
if self.sdrSource.isAvailable():
|
||||||
self.dsp.setInput(self.sdrSource.getBuffer())
|
self.dsp.setReader(self.sdrSource.getBuffer().getReader())
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.dsp is None:
|
if self.dsp is None:
|
||||||
@ -81,7 +81,7 @@ class SpectrumThread(SdrSourceEventClient):
|
|||||||
if self.dsp is None:
|
if self.dsp is None:
|
||||||
self.start()
|
self.start()
|
||||||
else:
|
else:
|
||||||
self.dsp.setInput(self.sdrSource.getBuffer())
|
self.dsp.setReader(self.sdrSource.getBuffer().getReader())
|
||||||
|
|
||||||
def onFail(self):
|
def onFail(self):
|
||||||
self.dsp.stop()
|
self.dsp.stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user