From d33deb3cae1f231000745dd077d339dcb004e97b Mon Sep 17 00:00:00 2001 From: Lars Amsel Date: Mon, 3 Jan 2022 11:54:27 +0100 Subject: uhd: Allow pass raw IQ data array to tone generator Instead of calculating a tone from its parameter it is also useful to pass an precalculated signal to be played. This change modifies the __init__ to take an iq_data as parameter for the internal buffer and moves the generation of the tone from rate, frequency and amplitude into a class method. The streamer parameter was deleted (never used). --- host/python/uhd/usrp/cal/tone_gen.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'host/python') diff --git a/host/python/uhd/usrp/cal/tone_gen.py b/host/python/uhd/usrp/cal/tone_gen.py index b9d986132..3234e5bf1 100644 --- a/host/python/uhd/usrp/cal/tone_gen.py +++ b/host/python/uhd/usrp/cal/tone_gen.py @@ -11,13 +11,14 @@ import threading import numpy import uhd -class ToneGenerator: +class WaveformGenerator: """ - Class that can output a tone from a different thread until told to stop + Class that can output arbitrary waveform + from a different thread until told to stop """ - def __init__(self, rate, freq, ampl, streamer=None): + def __init__(self, iq_data, streamer=None): + self._buffer = iq_data self._streamer = streamer - self._buffer = uhd.dsp.signals.get_continuous_tone(rate, freq, ampl) self._run = False self._thread = None @@ -59,3 +60,13 @@ class ToneGenerator: metadata.end_of_burst = True self._streamer.send( numpy.array([0], dtype=numpy.complex64), metadata, 0.1) + + +class ToneGenerator(WaveformGenerator): + """ + Class that can output a tone based on WaveformGenerator + """ + def __init__(rate, freq, ampl, streamer=None): + super().__init__( + uhd.dsp.signals.get_continuous_tone(rate, freq, ampl), + streamer) -- cgit v1.2.3