Ejemplo n.º 1
0
    def test_001_t(self):
        if os.path.exists("debug/PCM_left.dat") and os.path.exists(
                "debug/PCM_right.dat"):
            self.src_left = blocks.file_source_make(gr.sizeof_float,
                                                    "debug/PCM_left.dat")
            self.src_right = blocks.file_source_make(gr.sizeof_float,
                                                     "debug/PCM_right.dat")
            self.f2s_1 = blocks.float_to_short_make(1, 32767)
            self.f2s_2 = blocks.float_to_short_make(1, 32767)
            self.mp4_encode = dab.mp4_encode_sb_make(14, 2, 32000, 1)
            self.mp4_decode = dab.mp4_decode_bs_make(14)
            self.s2f_1 = blocks.short_to_float_make(1, 32767)
            self.s2f_2 = blocks.short_to_float_make(1, 32767)
            self.audio = audio.sink_make(32000)

            self.tb.connect(self.src_left, self.f2s_1, (self.mp4_encode, 0))
            self.tb.connect(self.src_right, self.f2s_2, (self.mp4_encode, 1))
            self.tb.connect(self.mp4_encode, self.mp4_decode, self.s2f_1,
                            (self.audio, 0))
            self.tb.connect((self.mp4_decode, 1), self.s2f_2, (self.audio, 1))
            self.tb.run()
            # check data
        else:
            log = gr.logger("log")
            log.debug("debug file not found - skipped test")
            log.set_level("WARN")
Ejemplo n.º 2
0
    def __init__(self,
                 dab_params,
                 bit_rate,
                 address,
                 subch_size,
                 protection,
                 output_float,
                 verbose=False,
                 debug=False):
        if output_float:  # map short samples to the range [-1,1] in floats
            gr.hier_block2.__init__(
                self,
                "dab_audio_decoder_ff",
                # Input signature
                gr.io_signature(1, 1,
                                gr.sizeof_float * dab_params.num_carriers * 2),
                # Output signature
                gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_float))
        else:  # output signed 16 bit integers (directly from decoder)
            gr.hier_block2.__init__(
                self,
                "dab_audio_decoder_ff",
                # Input signature
                gr.io_signature(1, 1,
                                gr.sizeof_float * dab_params.num_carriers * 2),
                # Output signature
                gr.io_signature2(2, 2, gr.sizeof_short, gr.sizeof_short))

        self.msc_dec = grdab.msc_decode(dab_params, address, subch_size,
                                        protection)
        self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST)
        self.mp2_dec = grdab.mp2_decode_bs_make(bit_rate / 8)
        self.connect((self, 0), self.msc_dec, self.unpack, self.mp2_dec)

        if output_float:
            # map short samples to the range [-1,1] in floats
            self.s2f_left = blocks.short_to_float_make(1, 32767)
            self.s2f_right = blocks.short_to_float_make(1, 32767)
            self.gain_left = blocks.multiply_const_ff(1, 1)
            self.gain_right = blocks.multiply_const_ff(1, 1)
            self.connect((self.mp2_dec, 0), self.s2f_left, self.gain_left,
                         (self, 0))
            self.connect((self.mp2_dec, 1), self.s2f_right, self.gain_right,
                         (self, 1))
        else:
            # output signed 16 bit integers (directly from decoder)
            self.connect((self.mp2_dec, 0), (self, 0))
            self.connect((self.mp2_dec, 1), (self, 1))
Ejemplo n.º 3
0
    def test_001_t (self):
        if os.path.exists("debug/reed_solomon_repaired.dat"):
            self.src = blocks.file_source_make(gr.sizeof_char, "debug/reed_solomon_repaired.dat")
            self.mp4 = grdab.mp4_decode_bs_make(14)
            self.s2f_left = blocks.short_to_float_make(1, 32767)
            self.s2f_right = blocks.short_to_float_make(1, 32767)
            self.audio = audio.sink_make(32000)

            self.tb.connect(self.src, (self.mp4, 0), self.s2f_left, (self.audio, 0))
            self.tb.connect((self.mp4, 1), self.s2f_right, (self.audio, 1))
            self.tb.run()
        else:
            log = gr.logger("log")
            log.debug("debug file not found - skipped test")
            log.set_level("WARN")
        pass
Ejemplo n.º 4
0
    def __init__(self,
                 dab_params,
                 bit_rate,
                 address,
                 subch_size,
                 protection,
                 output_float,
                 verbose=False,
                 debug=False):
        if output_float:  # map short samples to the range [-1,1] in floats
            gr.hier_block2.__init__(
                self,
                "dabplus_audio_decoder_ff",
                # Input signature
                gr.io_signature2(2, 2,
                                 gr.sizeof_float * dab_params.num_carriers * 2,
                                 gr.sizeof_char),
                # Output signature
                gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_float))
        else:  # output signed 16 bit integers (directly from decoder)
            gr.hier_block2.__init__(
                self,
                "dabplus_audio_decoder_ff",
                # Input signature
                gr.io_signature2(2, 2,
                                 gr.sizeof_float * dab_params.num_carriers * 2,
                                 gr.sizeof_char),
                # Output signature
                gr.io_signature2(2, 2, gr.sizeof_short, gr.sizeof_short))
        self.dp = dab_params
        self.bit_rate_n = bit_rate / 8
        self.address = address
        self.size = subch_size
        self.protection = protection
        self.output_float = output_float
        self.verbose = verbose
        self.debug = debug

        # sanity check
        # if self.bit_rate_n*6 != self.size:
        #     log = gr.logger("log")
        #     log.debug("bit rate and subchannel size are not fitting")
        #     log.set_level("ERROR")
        #     raise ValueError

        # MSC decoder extracts logical frames out of transmission frame and decodes it
        self.msc_decoder = dab.msc_decode(self.dp, self.address, self.size,
                                          self.protection, self.verbose,
                                          self.debug)
        # firecode synchronizes to superframes and checks
        self.firecode = dab.firecode_check_bb_make(self.bit_rate_n)
        # Reed-Solomon error repair
        self.rs = dab.reed_solomon_decode_bb_make(self.bit_rate_n)
        # mp4 decoder
        self.mp4 = dab.mp4_decode_bs_make(self.bit_rate_n)

        self.connect((self, 0), (self.msc_decoder, 0), self.firecode, self.rs,
                     self.mp4)
        self.connect((self, 1), (self.msc_decoder, 1))

        if self.output_float:
            # map short samples to the range [-1,1] in floats
            self.s2f_left = blocks.short_to_float_make(1, 32767)
            self.s2f_right = blocks.short_to_float_make(1, 32767)
            self.gain_left = blocks.multiply_const_ff(1, 1)
            self.gain_right = blocks.multiply_const_ff(1, 1)
            self.connect((self.mp4, 0), self.s2f_left, self.gain_left,
                         (self, 0))
            self.connect((self.mp4, 1), self.s2f_right, self.gain_right,
                         (self, 1))
        else:
            # output signed 16 bit integers (directly from decoder)
            self.connect((self.mp4, 0), (self, 0))
            self.connect((self.mp4, 1), (self, 1))
Ejemplo n.º 5
0
    def __init__(self,
                 dab_mode,
                 frequency,
                 bit_rate,
                 address,
                 size,
                 protection,
                 audio_bit_rate,
                 dabplus,
                 use_usrp,
                 src_path,
                 sink_path="None"):
        gr.top_block.__init__(self)

        self.dab_mode = dab_mode
        self.verbose = False
        self.sample_rate = 2e6
        self.dabplus = dabplus
        self.use_usrp = use_usrp
        self.src_path = src_path
        self.sink_path = sink_path
        gr.log.set_level("warn")

        ########################
        # source
        ########################
        if self.use_usrp:
            self.src = uhd.usrp_source("", uhd.io_type.COMPLEX_FLOAT32, 1)
            self.src.set_samp_rate(self.sample_rate)
            self.src.set_antenna("TX/RX")
        else:
            print "using file source"
            self.src = blocks.file_source_make(gr.sizeof_gr_complex,
                                               self.src_path, False)

        # set paramters to default mode
        self.softbits = True
        self.filter_input = True
        self.autocorrect_sample_rate = False
        self.resample_fixed = 1
        self.correct_ffe = True
        self.equalize_magnitude = True
        self.frequency = frequency
        self.dab_params = dab.parameters.dab_parameters(
            self.dab_mode, self.sample_rate, self.verbose)
        self.rx_params = dab.parameters.receiver_parameters(
            self.dab_mode, self.softbits, self.filter_input,
            self.autocorrect_sample_rate, self.resample_fixed, self.verbose,
            self.correct_ffe, self.equalize_magnitude)
        ########################
        # FFT and waterfall plot
        ########################
        self.fft_plot = qtgui.freq_sink_c_make(1024,
                                               fft.window.WIN_BLACKMAN_HARRIS,
                                               self.frequency, 2e6, "FFT")
        self.waterfall_plot = qtgui.waterfall_sink_c_make(
            1024, fft.window.WIN_BLACKMAN_HARRIS, self.frequency, 2e6,
            "Waterfall")
        #self.time_plot = qtgui.time_sink_c_make(1024, 2e6, "Time")

        ########################
        # OFDM demod
        ########################
        self.demod = dab.ofdm_demod(self.dab_params, self.rx_params,
                                    self.verbose)

        ########################
        # SNR measurement
        ########################
        self.v2s_snr = blocks.vector_to_stream_make(
            gr.sizeof_gr_complex, self.dab_params.num_carriers)
        self.snr_measurement = digital.mpsk_snr_est_cc_make(
            digital.SNR_EST_SIMPLE, 10000)
        self.constellation_plot = qtgui.const_sink_c_make(1024, "", 1)

        ########################
        # FIC decoder
        ########################
        self.fic_dec = dab.fic_decode(self.dab_params)

        ########################
        # MSC decoder
        ########################
        if self.dabplus:
            self.dabplus = dab.dabplus_audio_decoder_ff(
                self.dab_params, bit_rate, address, size, protection, True)
        else:
            self.msc_dec = dab.msc_decode(self.dab_params, address, size,
                                          protection)
            self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST)
            self.mp2_dec = dab.mp2_decode_bs_make(bit_rate / 8)
            self.s2f_left = blocks.short_to_float_make(1, 32767)
            self.s2f_right = blocks.short_to_float_make(1, 32767)
            self.gain_left = blocks.multiply_const_ff(1, 1)
            self.gain_right = blocks.multiply_const_ff(1, 1)

        ########################
        # audio sink
        ########################
        self.valve_left = dab.valve_ff_make(True)
        self.valve_right = dab.valve_ff_make(True)
        self.audio = audio.sink_make(audio_bit_rate)
        self.wav_sink = blocks.wavfile_sink_make("dab_audio.wav", 2,
                                                 audio_bit_rate)

        ########################
        # Connections
        ########################
        self.connect(self.src, self.fft_plot)
        self.connect(self.src, self.waterfall_plot)
        self.connect(self.src, self.demod, (self.fic_dec, 0))
        self.connect((self.demod, 1), (self.fic_dec, 1))
        if self.dabplus:
            self.connect((self.demod, 0), (self.dabplus, 0))
            self.connect((self.demod, 1), (self.dabplus, 1))
        else:
            self.connect((self.demod, 0), (self.msc_dec, 0), self.unpack,
                         self.mp2_dec)
            self.connect((self.demod, 1), (self.msc_dec, 1))
            self.connect((self.mp2_dec, 0), self.s2f_left, self.gain_left)
            self.connect((self.mp2_dec, 1), self.s2f_right, self.gain_right)
        self.connect((self.demod, 0), self.v2s_snr, self.snr_measurement,
                     self.constellation_plot)
        # connect audio to sound card and file sink
        if self.dabplus:
            self.connect((self.dabplus, 0), (self.audio, 0))
            self.connect((self.dabplus, 1), (self.audio, 1))
            self.connect((self.dabplus, 0), self.valve_left,
                         (self.wav_sink, 0))
            self.connect((self.dabplus, 1), self.valve_right,
                         (self.wav_sink, 1))
        else:
            self.connect(self.gain_left, (self.audio, 0))
            self.connect(self.gain_right, (self.audio, 1))
            self.connect(self.gain_left, self.valve_left, (self.wav_sink, 0))
            self.connect(self.gain_right, self.valve_right, (self.wav_sink, 1))

        # tune USRP frequency
        if self.use_usrp:
            self.set_freq(self.frequency)
            # set gain
            # if no gain was specified, use the mid-point in dB
            g = self.src.get_gain_range()
            self.rx_gain = float(g.start() + g.stop()) / 2
            self.src.set_gain(self.rx_gain)
Ejemplo n.º 6
0
    def __init__(self,
                 dab_mode,
                 frequency,
                 num_subch,
                 ensemble_label,
                 service_label,
                 language,
                 country_ID,
                 protections,
                 data_rates_n,
                 stereo_flags,
                 audio_sampling_rates,
                 src_paths,
                 selected_audio,
                 use_usrp,
                 dabplus_types,
                 sink_path="dab_iq_generated.dat"):
        gr.top_block.__init__(self)

        self.dab_mode = dab_mode
        self.frequency = frequency
        interp = 64
        self.sample_rate = 128e6 / interp
        self.dp = dab.parameters.dab_parameters(self.dab_mode, 2000000, False)
        self.num_subch = num_subch
        self.ensemble_label = ensemble_label
        self.service_label = service_label
        self.language = language
        self.protections = protections
        self.data_rates_n = data_rates_n
        self.src_paths = src_paths
        self.use_usrp = use_usrp
        self.dabplus_types = dabplus_types
        self.sink_path = sink_path
        self.selected_audio = selected_audio
        self.volume = 80
        sizes = {0: 12, 1: 8, 2: 6, 3: 4}
        self.subch_sizes = [None] * len(self.data_rates_n)
        for i in range(0, len(self.data_rates_n)):
            self.subch_sizes[i] = self.data_rates_n[i] * sizes[protections[i]]

        ########################
        # FIC
        ########################
        # source
        self.fic_src = dab.fib_source_b_make(
            self.dab_mode, country_ID, self.num_subch, self.ensemble_label,
            self.service_label, "", self.language, self.protections,
            self.data_rates_n, self.dabplus_types)
        # encoder
        self.fic_enc = dab.fic_encode(self.dp)

        ########################
        # MSC
        ########################
        self.recorder = audio.source_make(32000)
        self.msc_sources = [None] * self.num_subch
        self.f2s_left_converters = [None] * self.num_subch
        self.f2s_right_converters = [None] * self.num_subch
        self.mp4_encoders = [None] * self.num_subch
        self.mp2_encoders = [None] * self.num_subch
        self.rs_encoders = [None] * self.num_subch
        self.msc_encoders = [None] * self.num_subch
        for i in range(0, self.num_subch):
            if not self.src_paths[i] is "mic":
                # source
                self.msc_sources[i] = blocks.wavfile_source_make(
                    self.src_paths[i], True)
            # float to short
            self.f2s_left_converters[i] = blocks.float_to_short_make(1, 32767)
            self.f2s_right_converters[i] = blocks.float_to_short_make(1, 32767)
            if self.dabplus_types[i] is 1:
                # mp4 encoder and Reed-Solomon encoder
                self.mp4_encoders[i] = dab.mp4_encode_sb_make(
                    self.data_rates_n[i], 2, audio_sampling_rates[i], 1)
                self.rs_encoders[i] = dab.reed_solomon_encode_bb_make(
                    self.data_rates_n[i])
            else:
                # mp2 encoder
                self.mp2_encoders[i] = dab.mp2_encode_sb_make(
                    self.data_rates_n[i], 2, audio_sampling_rates[i])
            # encoder
            self.msc_encoders[i] = dab.msc_encode(self.dp,
                                                  self.data_rates_n[i],
                                                  self.protections[i])

        ########################
        # MUX
        ########################
        self.mux = dab.dab_transmission_frame_mux_bb_make(
            self.dab_mode, self.num_subch, self.subch_sizes)
        self.trigsrc = blocks.vector_source_b(
            [1] + [0] * (self.dp.symbols_per_frame - 2), True)

        ########################
        # Modulator
        ########################
        self.s2v_mod = blocks.stream_to_vector(gr.sizeof_char,
                                               self.dp.num_carriers / 4)
        self.mod = dab.ofdm_mod(self.dp)

        ########################
        # Sink
        ########################
        if self.use_usrp:
            self.sink = uhd.usrp_sink("", uhd.io_type.COMPLEX_FLOAT32, 1)
            self.sink.set_samp_rate(self.sample_rate)
            self.sink.set_antenna("TX/RX")
            self.sink.set_center_freq(self.frequency)
        else:
            self.sink = blocks.file_sink_make(gr.sizeof_gr_complex,
                                              self.sink_path)
        # audio sink
        self.audio = audio.sink_make(32000)

        self.gain_left = blocks.multiply_const_ff_make(1, 1)
        self.gain_right = blocks.multiply_const_ff_make(1, 1)
        self.s2f_left = blocks.short_to_float_make(1, 32767)
        self.s2f_right = blocks.short_to_float_make(1, 32767)

        ########################
        # Connections
        ########################
        self.connect(self.fic_src, self.fic_enc, (self.mux, 0))
        for i in range(0, self.num_subch):
            if self.dabplus_types[i] is 1:
                if self.src_paths[i] is "mic":
                    self.connect(
                        (self.recorder, 0), self.f2s_left_converters[i],
                        (self.mp4_encoders[i], 0), self.rs_encoders[i],
                        self.msc_encoders[i], (self.mux, i + 1))
                    if stereo_flags[i] == 0:
                        self.connect((self.recorder, 1),
                                     self.f2s_right_converters[i],
                                     (self.mp4_encoders[i], 1))
                    else:
                        self.connect(self.f2s_left_converters[i],
                                     (self.mp4_encoders[i], 1))
                else:
                    self.connect(
                        (self.msc_sources[i], 0), self.f2s_left_converters[i],
                        (self.mp4_encoders[i], 0), self.rs_encoders[i],
                        self.msc_encoders[i], (self.mux, i + 1))
                    if stereo_flags[i] == 0:
                        self.connect((self.msc_sources[i], 1),
                                     self.f2s_right_converters[i],
                                     (self.mp4_encoders[i], 1))
                    else:
                        self.connect(self.f2s_left_converters[i],
                                     (self.mp4_encoders[i], 1))
            else:
                self.connect((self.msc_sources[i], 0),
                             self.f2s_left_converters[i],
                             (self.mp2_encoders[i], 0), self.msc_encoders[i],
                             (self.mux, i + 1))
                if stereo_flags[i] == 0:
                    self.connect((self.msc_sources[i], 1),
                                 self.f2s_right_converters[i],
                                 (self.mp2_encoders[i], 1))
                else:
                    self.connect(self.f2s_left_converters[i],
                                 (self.mp2_encoders[i], 1))
        self.connect((self.mux, 0), self.s2v_mod, (self.mod, 0))
        self.connect(self.trigsrc, (self.mod, 1))
        if use_usrp:
            self.connect(self.mod, self.sink)
        else:
            self.connect(self.mod,
                         blocks.throttle_make(gr.sizeof_gr_complex, 2e6),
                         self.sink)