2008-05-31 22:26:53 +00:00
|
|
|
/* -*- C++ -*- */
|
2008-11-09 22:41:29 +00:00
|
|
|
|
2008-05-31 22:26:53 +00:00
|
|
|
/*
|
2009-09-08 00:15:52 +00:00
|
|
|
* Copyright 2008, 2009 Steve Glass
|
2008-05-31 22:26:53 +00:00
|
|
|
*
|
|
|
|
* This file is part of OP25.
|
|
|
|
*
|
|
|
|
* OP25 is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* OP25 is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with OP25; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
#include <algorithm>
|
2008-05-31 22:26:53 +00:00
|
|
|
#include <gr_io_signature.h>
|
2008-12-15 07:46:10 +00:00
|
|
|
#include <iostream>
|
2009-06-25 20:27:44 +00:00
|
|
|
#include <itpp/comm/bch.h>
|
|
|
|
#include <logfile_du_handler.h>
|
2009-09-08 00:15:52 +00:00
|
|
|
#include <offline_imbe_decoder.h>
|
2008-12-01 04:24:15 +00:00
|
|
|
#include <op25_decoder_ff.h>
|
2009-06-25 20:27:44 +00:00
|
|
|
#include <snapshot_du_handler.h>
|
2009-09-08 00:15:52 +00:00
|
|
|
#include <voice_du_handler.h>
|
2009-07-07 21:47:54 +00:00
|
|
|
#include <yank.h>
|
2008-05-31 22:26:53 +00:00
|
|
|
|
2008-12-15 07:46:10 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff_sptr
|
2009-01-28 04:50:25 +00:00
|
|
|
op25_make_decoder_ff(gr_msg_queue_sptr msgq)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
2009-01-28 04:50:25 +00:00
|
|
|
return op25_decoder_ff_sptr(new op25_decoder_ff(msgq));
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::~op25_decoder_ff()
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-09 09:03:37 +00:00
|
|
|
void
|
|
|
|
op25_decoder_ff::forecast(int nof_output_items, gr_vector_int &nof_input_items_reqd)
|
|
|
|
{
|
2009-09-10 05:59:25 +00:00
|
|
|
/* This block consumes 4800 symbols/s and produces 8000
|
2009-10-30 00:12:41 +00:00
|
|
|
* samples/s. That's a work rate of 3/5 or 0.6. If no audio output
|
|
|
|
* is available we'll produce silence.
|
2009-09-10 05:59:25 +00:00
|
|
|
*/
|
2008-11-07 10:14:00 +00:00
|
|
|
const size_t nof_inputs = nof_input_items_reqd.size();
|
2009-09-10 05:59:25 +00:00
|
|
|
const int nof_samples_reqd = .6 * nof_output_items;
|
2009-09-10 01:12:22 +00:00
|
|
|
fill(&nof_input_items_reqd[0], &nof_input_items_reqd[nof_inputs], nof_samples_reqd);
|
2008-09-09 09:03:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-10 05:59:25 +00:00
|
|
|
int
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::general_work(int nof_output_items, gr_vector_int& nof_input_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
2008-12-15 07:46:10 +00:00
|
|
|
try {
|
|
|
|
|
2009-09-10 01:12:22 +00:00
|
|
|
// process input
|
2008-12-15 07:46:10 +00:00
|
|
|
const float *in = reinterpret_cast<const float*>(input_items[0]);
|
|
|
|
for(int i = 0; i < nof_input_items[0]; ++i) {
|
|
|
|
dibit d;
|
|
|
|
if(in[i] < -2.0) {
|
|
|
|
d = 3;
|
|
|
|
} else if(in[i] < 0.0) {
|
|
|
|
d = 2;
|
|
|
|
} else if(in[i] < 2.0) {
|
|
|
|
d = 0;
|
|
|
|
} else {
|
|
|
|
d = 1;
|
|
|
|
}
|
|
|
|
receive_symbol(d);
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
2009-09-10 01:12:22 +00:00
|
|
|
consume_each(nof_input_items[0]);
|
2009-09-08 00:15:52 +00:00
|
|
|
|
2009-09-10 01:12:22 +00:00
|
|
|
// produce audio
|
|
|
|
audio_samples *samples = d_imbe->audio();
|
2009-06-21 21:07:55 +00:00
|
|
|
float *out = reinterpret_cast<float*>(output_items[0]);
|
2009-09-10 01:12:22 +00:00
|
|
|
const int n = min(static_cast<int>(samples->size()), nof_output_items);
|
|
|
|
if(0 < n) {
|
|
|
|
copy(samples->begin(), samples->begin() + n, out);
|
|
|
|
samples->erase(samples->begin(), samples->begin() + n);
|
|
|
|
}
|
|
|
|
if(n < nof_output_items) {
|
|
|
|
fill(out + n, out + nof_output_items, 0.0);
|
|
|
|
}
|
2008-12-15 07:46:10 +00:00
|
|
|
return nof_output_items;
|
2009-09-10 05:59:25 +00:00
|
|
|
|
2008-12-15 07:46:10 +00:00
|
|
|
} catch(const std::exception& x) {
|
|
|
|
cerr << x.what() << endl;
|
|
|
|
exit(1);
|
|
|
|
} catch(...) {
|
|
|
|
cerr << "unhandled exception" << endl;
|
2009-01-28 04:50:25 +00:00
|
|
|
exit(2); }
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 10:38:11 +00:00
|
|
|
const char*
|
|
|
|
op25_decoder_ff::device_name() const
|
|
|
|
{
|
2009-06-25 20:27:44 +00:00
|
|
|
return d_sniffer_du_handler->device_name();
|
2008-12-06 10:38:11 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 04:50:25 +00:00
|
|
|
op25_decoder_ff::op25_decoder_ff(gr_msg_queue_sptr msgq) :
|
2008-12-01 04:24:15 +00:00
|
|
|
gr_block("decoder_ff", gr_make_io_signature(1, 1, sizeof(float)), gr_make_io_signature(0, 1, sizeof(float))),
|
2008-05-31 22:26:53 +00:00
|
|
|
d_data_unit(),
|
2009-06-25 20:27:44 +00:00
|
|
|
d_data_unit_handler(),
|
2009-01-28 04:50:25 +00:00
|
|
|
d_frame_hdr(),
|
2009-09-10 01:12:22 +00:00
|
|
|
d_imbe(imbe_decoder::make()),
|
2009-06-25 20:27:44 +00:00
|
|
|
d_state(SYNCHRONIZING),
|
|
|
|
d_sniffer_du_handler(NULL)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
2009-06-25 20:27:44 +00:00
|
|
|
d_sniffer_du_handler = new sniffer_du_handler(d_data_unit_handler);
|
|
|
|
d_data_unit_handler = data_unit_handler_sptr(d_sniffer_du_handler);
|
|
|
|
d_data_unit_handler = data_unit_handler_sptr(new snapshot_du_handler(d_data_unit_handler, msgq));
|
2009-09-08 00:15:52 +00:00
|
|
|
d_data_unit_handler = data_unit_handler_sptr(new voice_du_handler(d_data_unit_handler, d_imbe));
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-01-28 04:50:25 +00:00
|
|
|
op25_decoder_ff::correlated()
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
2009-01-28 04:50:25 +00:00
|
|
|
static const bool FS[] = {
|
|
|
|
0, 1, 0, 1, 0, 1, 0, 1,
|
|
|
|
0, 1, 1, 1, 0, 1, 0, 1,
|
|
|
|
1, 1, 1, 1, 0, 1, 0, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
0, 1, 1, 1, 0, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1
|
|
|
|
};
|
|
|
|
static const size_t FS_SZ = sizeof(FS)/sizeof(FS[0]);
|
|
|
|
|
|
|
|
uint8_t errs = 0;
|
|
|
|
for(size_t i = 0; i < FS_SZ; ++i) {
|
|
|
|
if(d_frame_hdr[i] ^ FS[i]) {
|
2008-12-29 01:26:29 +00:00
|
|
|
++errs;
|
|
|
|
}
|
|
|
|
}
|
2009-07-07 21:47:54 +00:00
|
|
|
return (errs <= 4);
|
2009-01-28 04:50:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-01 23:43:50 +00:00
|
|
|
data_unit_sptr
|
2009-01-28 04:50:25 +00:00
|
|
|
op25_decoder_ff::identified()
|
|
|
|
{
|
|
|
|
static const size_t NID[] = {
|
|
|
|
63, 62, 61, 60, 59, 58, 57, 56,
|
|
|
|
55, 54, 53, 52, 51, 50, 49, 48,
|
|
|
|
112, 111, 110, 109, 108, 107, 106, 105,
|
|
|
|
104, 103, 102, 101, 100, 99, 98, 97,
|
|
|
|
96, 95, 94, 93, 92, 91, 90, 89,
|
|
|
|
88, 87, 86, 85, 84, 83, 82, 81,
|
|
|
|
80, 79, 78, 77, 76, 75, 74, 73,
|
|
|
|
72, 69, 68, 67, 66, 65, 64,
|
|
|
|
};
|
|
|
|
size_t NID_SZ = sizeof(NID) / sizeof(NID[0]);
|
|
|
|
|
|
|
|
itpp::bvec b(63), zeroes(16);
|
2009-09-08 00:15:52 +00:00
|
|
|
itpp::BCH bch(63, 16, 11, "6 3 3 1 1 4 1 3 6 7 2 3 5 4 5 3", true);
|
2009-07-07 21:47:54 +00:00
|
|
|
yank(d_frame_hdr, NID, NID_SZ, b, 0);
|
2009-06-25 20:27:44 +00:00
|
|
|
b = bch.decode(b);
|
2009-08-01 23:43:50 +00:00
|
|
|
if(b != zeroes) {
|
2009-06-25 20:27:44 +00:00
|
|
|
b = bch.encode(b);
|
2009-07-07 21:47:54 +00:00
|
|
|
yank_back(b, 0, d_frame_hdr, NID, NID_SZ);
|
2009-01-28 04:50:25 +00:00
|
|
|
d_data_unit = data_unit::make_data_unit(d_frame_hdr);
|
|
|
|
} else {
|
|
|
|
data_unit_sptr null;
|
|
|
|
d_data_unit = null;
|
|
|
|
}
|
2009-08-01 23:43:50 +00:00
|
|
|
return d_data_unit;
|
2009-01-28 04:50:25 +00:00
|
|
|
}
|
|
|
|
|
2008-05-31 22:26:53 +00:00
|
|
|
void
|
2008-09-09 09:03:37 +00:00
|
|
|
op25_decoder_ff::receive_symbol(dibit d)
|
2008-05-31 22:26:53 +00:00
|
|
|
{
|
2009-01-28 04:50:25 +00:00
|
|
|
d_frame_hdr.push_back(d & 0x2);
|
|
|
|
d_frame_hdr.push_back(d & 0x1);
|
|
|
|
const size_t frame_hdr_sz = d_frame_hdr.size();
|
|
|
|
|
2008-05-31 22:26:53 +00:00
|
|
|
switch(d_state) {
|
|
|
|
case SYNCHRONIZING:
|
2009-01-28 04:50:25 +00:00
|
|
|
if(48 <= frame_hdr_sz) {
|
|
|
|
d_frame_hdr.erase(d_frame_hdr.begin(), d_frame_hdr.begin() + (frame_hdr_sz - 48));
|
|
|
|
if(correlated()) {
|
|
|
|
d_state = IDENTIFYING;
|
|
|
|
}
|
2008-05-31 22:26:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDENTIFYING:
|
2009-06-25 20:27:44 +00:00
|
|
|
if(114 == frame_hdr_sz) {
|
2009-01-28 04:50:25 +00:00
|
|
|
if(identified()) {
|
2008-12-01 04:24:15 +00:00
|
|
|
d_state = READING;
|
2008-05-31 22:26:53 +00:00
|
|
|
} else {
|
|
|
|
d_state = SYNCHRONIZING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-12-01 04:24:15 +00:00
|
|
|
case READING:
|
|
|
|
d_data_unit->extend(d);
|
2008-12-15 07:46:10 +00:00
|
|
|
if(d_data_unit->is_complete()) {
|
2009-07-07 21:47:54 +00:00
|
|
|
d_data_unit->correct_errors();
|
2009-06-25 20:27:44 +00:00
|
|
|
d_data_unit_handler->handle(d_data_unit);
|
2008-05-31 22:26:53 +00:00
|
|
|
data_unit_sptr null;
|
|
|
|
d_data_unit = null;
|
|
|
|
d_state = SYNCHRONIZING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|