Debugging HDRadio.
This commit is contained in:
parent
a22e6f3c74
commit
af9ed9c563
|
|
@ -1,10 +1,16 @@
|
|||
from csdr.chain.demodulator import FixedIfSampleRateChain, BaseDemodulatorChain, FixedAudioRateChain, DialFrequencyReceiver
|
||||
from csdr.chain.demodulator import FixedIfSampleRateChain, BaseDemodulatorChain, FixedAudioRateChain, DialFrequencyReceiver, HdAudio
|
||||
from csdr.module.hdradio import HdRadioModule
|
||||
from pycsdr.modules import Convert, Agc, Downmix, Writer
|
||||
from pycsdr.modules import Convert, Agc, Downmix, Writer, Buffer
|
||||
from pycsdr.types import Format
|
||||
from typing import Optional
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
class HdRadio(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, DialFrequencyReceiver):
|
||||
class HdRadio(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain, HdAudio, DialFrequencyReceiver):
|
||||
def __init__(self, program: int = 0):
|
||||
self.hdradio = HdRadioModule(program = program)
|
||||
workers = [
|
||||
|
|
@ -15,12 +21,15 @@ class HdRadio(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain,
|
|||
]
|
||||
super().__init__(workers)
|
||||
|
||||
def getFixedIfSampleRate(self):
|
||||
def getFixedIfSampleRate(self) -> int:
|
||||
return self.hdradio.getFixedAudioRate()
|
||||
|
||||
def getFixedAudioRate(self):
|
||||
def getFixedAudioRate(self) -> int:
|
||||
return 44100
|
||||
|
||||
def supportsSquelch(self) -> bool:
|
||||
return False
|
||||
|
||||
# Set metadata consumer
|
||||
def setMetaWriter(self, writer: Writer) -> None:
|
||||
self.hdradio.setMetaWriter(writer)
|
||||
|
|
@ -32,3 +41,16 @@ class HdRadio(BaseDemodulatorChain, FixedIfSampleRateChain, FixedAudioRateChain,
|
|||
def setDialFrequency(self, frequency: int) -> None:
|
||||
# Clear station metadata when changing frequency
|
||||
pass
|
||||
|
||||
#def _connect(self, w1, w2, buffer: Optional[Buffer] = None) -> None:
|
||||
# # Buffering 2 seconds of input stream
|
||||
# if isinstance(w2, HdRadioModule):
|
||||
# size = self.getFixedIfSampleRate() * 2 * 2 * 2
|
||||
# buffer = Buffer(w1.getOutputFormat(), size=size)
|
||||
# logger.info("%d bytes => HdRadioModule", size)
|
||||
# # Buffering 10 seconds of output audio
|
||||
# if isinstance(w1, HdRadioModule):
|
||||
# size = self.getFixedAudioRate() * 2 * 2
|
||||
# buffer = Buffer(w1.getOutputFormat(), size=size)
|
||||
# logger.info("HdRadioModule => %d bytes", size)
|
||||
# super()._connect(w1, w2, buffer)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from pycsdr.types import Format
|
|||
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
|
@ -46,12 +47,14 @@ class HdRadioModule(ThreadModule):
|
|||
logger.debug("Starting NRSC5 decoder...")
|
||||
self.radio.open_pipe()
|
||||
self.radio.start()
|
||||
self.ts = time.time()
|
||||
self.cnt = 0
|
||||
|
||||
# Main loop
|
||||
logger.debug("Running the loop...")
|
||||
while self.doRun:
|
||||
data = self.reader.read()
|
||||
if data is None:
|
||||
if data is None or len(data) == 0:
|
||||
self.doRun = False
|
||||
break
|
||||
try:
|
||||
|
|
@ -66,17 +69,21 @@ class HdRadioModule(ThreadModule):
|
|||
logger.debug("DONE.")
|
||||
|
||||
def callback(self, evt_type, evt):
|
||||
if evt_type == EventType.AUDIO:
|
||||
if evt_type == EventType.LOST_DEVICE:
|
||||
logger.info("Lost device")
|
||||
self.doRun = False
|
||||
elif evt_type == EventType.AUDIO:
|
||||
if evt.program == self.program:
|
||||
#logger.info("Audio data for program %d", evt.program)
|
||||
sz = len(evt.data) / 2 / 2
|
||||
self.cnt += sz
|
||||
ts = self.ts + self.cnt / 44100
|
||||
#logger.info("DIFF: {0}, SIZE: {1}".format(time.time() - ts, sz))
|
||||
self.writer.write(evt.data)
|
||||
elif evt_type == EventType.HDC:
|
||||
if evt.program == self.program:
|
||||
#logger.info("HDC data for program %d", evt.program)
|
||||
pass
|
||||
elif evt_type == EventType.LOST_DEVICE:
|
||||
logger.info("Lost device")
|
||||
self.doRun = False
|
||||
elif evt_type == EventType.IQ:
|
||||
logger.info("IQ data")
|
||||
elif evt_type == EventType.SYNC:
|
||||
|
|
|
|||
Loading…
Reference in New Issue