p25p2 integration
This commit is contained in:
parent
9ed0eb501a
commit
fdacb9d1fe
|
@ -0,0 +1,155 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* GNU Radio interface for Pavel Yazev's Project 25 IMBE Encoder/Decoder
|
||||
*
|
||||
* Copyright 2009 Pavel Yazev E-mail: pyazev@gmail.com
|
||||
* Copyright 2009, 2010, 2011, 2012, 2013, 2014 KA1RBI
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; 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
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include "p25p1_voice_decode.h"
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "imbe_vocoder/imbe_vocoder.h"
|
||||
#include "p25_frame.h"
|
||||
#include "op25_imbe_frame.h"
|
||||
|
||||
namespace gr {
|
||||
namespace op25_repeater {
|
||||
|
||||
static void clear_bits(bit_vector& v) {
|
||||
for (size_t i=0; i<v.size(); i++) {
|
||||
v[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
p25p1_voice_decode::p25p1_voice_decode(bool verbose_flag, const char* udp_host, int udp_port, std::deque<int16_t> &_output_queue) :
|
||||
write_sock(0),
|
||||
write_bufp(0),
|
||||
rxbufp(0),
|
||||
output_queue(_output_queue),
|
||||
opt_verbose(verbose_flag),
|
||||
opt_udp_port(udp_port)
|
||||
{
|
||||
if (opt_udp_port != 0)
|
||||
// remote UDP output
|
||||
init_sock(udp_host, opt_udp_port);
|
||||
|
||||
const char *p = getenv("IMBE");
|
||||
if (p && strcasecmp(p, "soft") == 0)
|
||||
d_software_imbe_decoder = true;
|
||||
else
|
||||
d_software_imbe_decoder = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Our virtual destructor.
|
||||
*/
|
||||
p25p1_voice_decode::~p25p1_voice_decode()
|
||||
{
|
||||
}
|
||||
|
||||
void p25p1_voice_decode::rxframe(const uint32_t u[])
|
||||
{
|
||||
int16_t snd[FRAME];
|
||||
int16_t frame_vector[8];
|
||||
// decode 88 bits, outputs 160 sound samples (8000 rate)
|
||||
if (d_software_imbe_decoder) {
|
||||
voice_codeword cw(voice_codeword_sz);
|
||||
imbe_header_encode(cw, u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7]);
|
||||
software_decoder.decode(cw);
|
||||
audio_samples *samples = software_decoder.audio();
|
||||
for (int i=0; i < FRAME; i++) {
|
||||
if (samples->size() > 0) {
|
||||
snd[i] = (int16_t)(samples->front() * 32768.0);
|
||||
samples->pop_front();
|
||||
} else {
|
||||
snd[i] = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i=0; i < 8; i++) {
|
||||
frame_vector[i] = u[i];
|
||||
}
|
||||
/* TEST*/ frame_vector[7] >>= 1;
|
||||
vocoder.imbe_decode(frame_vector, snd);
|
||||
}
|
||||
if (opt_udp_port > 0) {
|
||||
sendto(write_sock, snd, FRAME * sizeof(int16_t), 0, (struct sockaddr*)&write_sock_addr, sizeof(write_sock_addr));
|
||||
} else {
|
||||
// add generated samples to output queue
|
||||
for (int i = 0; i < FRAME; i++) {
|
||||
output_queue.push_back(snd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void p25p1_voice_decode::rxchar(const char* c, int len)
|
||||
{
|
||||
uint32_t u[8];
|
||||
|
||||
for (int i = 0; i < len; i++ ) {
|
||||
if (c[i] < ' ') {
|
||||
if (c[i] == '\n') {
|
||||
rxbuf[rxbufp] = 0;
|
||||
sscanf(rxbuf, "%x %x %x %x %x %x %x %x", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5], &u[6], &u[7]);
|
||||
rxbufp = 0;
|
||||
rxframe(u);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
rxbuf[rxbufp++] = c[i];
|
||||
if (rxbufp >= RXBUF_MAX) {
|
||||
rxbufp = RXBUF_MAX - 1;
|
||||
}
|
||||
} /* end of for() */
|
||||
}
|
||||
|
||||
void p25p1_voice_decode::init_sock(const char* udp_host, int udp_port)
|
||||
{
|
||||
memset (&write_sock_addr, 0, sizeof(write_sock_addr));
|
||||
write_sock = socket(PF_INET, SOCK_DGRAM, 17); // UDP socket
|
||||
if (write_sock < 0) {
|
||||
fprintf(stderr, "vocoder: socket: %d\n", errno);
|
||||
write_sock = 0;
|
||||
return;
|
||||
}
|
||||
if (!inet_aton(udp_host, &write_sock_addr.sin_addr)) {
|
||||
fprintf(stderr, "vocoder: bad IP address\n");
|
||||
close(write_sock);
|
||||
write_sock = 0;
|
||||
return;
|
||||
}
|
||||
write_sock_addr.sin_family = AF_INET;
|
||||
write_sock_addr.sin_port = htons(udp_port);
|
||||
}
|
||||
|
||||
} /* namespace op25_repeater */
|
||||
} /* namespace gr */
|
|
@ -0,0 +1,75 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2009, 2010, 2011, 2012, 2013, 2014 Max H. Parke KA1RBI
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_OP25_REPEATER_P25P1_VOICE_DECODE_H
|
||||
#define INCLUDED_OP25_REPEATER_P25P1_VOICE_DECODE_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#include "imbe_vocoder/imbe_vocoder.h"
|
||||
|
||||
#include "imbe_decoder.h"
|
||||
#include "software_imbe_decoder.h"
|
||||
|
||||
namespace gr {
|
||||
namespace op25_repeater {
|
||||
|
||||
typedef std::vector<bool> bit_vector;
|
||||
class p25p1_voice_decode
|
||||
{
|
||||
private:
|
||||
// Nothing to declare in this block.
|
||||
|
||||
public:
|
||||
p25p1_voice_decode(bool verbose_flag, const char* udp_host, int udp_port, std::deque<int16_t> &_output_queue);
|
||||
~p25p1_voice_decode();
|
||||
void rxframe(const uint32_t u[]);
|
||||
void rxchar(const char* c, int len);
|
||||
|
||||
private:
|
||||
static const int RXBUF_MAX = 80;
|
||||
|
||||
/* data items */
|
||||
int write_sock;
|
||||
struct sockaddr_in write_sock_addr;
|
||||
int write_bufp;
|
||||
char write_buf[512];
|
||||
char rxbuf[RXBUF_MAX];
|
||||
int rxbufp ;
|
||||
imbe_vocoder vocoder;
|
||||
software_imbe_decoder software_decoder;
|
||||
bool d_software_imbe_decoder;
|
||||
|
||||
std::deque<int16_t> &output_queue;
|
||||
|
||||
bool opt_verbose;
|
||||
int opt_udp_port;
|
||||
/* local methods */
|
||||
void init_sock(const char* udp_host, int udp_port);
|
||||
};
|
||||
|
||||
} // namespace op25_repeater
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_OP25_REPEATER_P25P1_VOICE_DECODE_H */
|
|
@ -0,0 +1,347 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* GNU Radio interface for Pavel Yazev's Project 25 IMBE Encoder/Decoder
|
||||
*
|
||||
* Copyright 2009 Pavel Yazev E-mail: pyazev@gmail.com
|
||||
* Copyright 2009, 2010, 2011, 2012, 2013, 2014 KA1RBI
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; 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
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include "p25p1_voice_encode.h"
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "imbe_vocoder/imbe_vocoder.h"
|
||||
#include "p25_frame.h"
|
||||
#include "op25_imbe_frame.h"
|
||||
|
||||
namespace gr {
|
||||
namespace op25_repeater {
|
||||
|
||||
/* bits to be preset to 1 for all transmitted frames */
|
||||
static const bool ldu1_preset[] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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*/
|
||||
};
|
||||
|
||||
static const bool ldu2_preset[] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0-35 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1, /* 36-71 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 72-107 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* 108-143 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-179 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* 180-215 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 216-251 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* 252-287 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 288-323 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* 324-359 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 360-395 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0, /* 1656-1691 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, /* 1692-1727 */
|
||||
};
|
||||
|
||||
static void clear_bits(bit_vector& v) {
|
||||
for (size_t i=0; i<v.size(); i++) {
|
||||
v[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
p25p1_voice_encode::p25p1_voice_encode(bool verbose_flag, int stretch_amt, char* udp_host, int udp_port, bool raw_vectors_flag, std::deque<uint8_t> &_output_queue) :
|
||||
frame_cnt(0),
|
||||
write_sock(0),
|
||||
write_bufp(0),
|
||||
peak_amplitude(0),
|
||||
peak(0),
|
||||
samp_ct(0),
|
||||
codeword_ct(0),
|
||||
sampbuf_ct(0),
|
||||
stretch_count(0),
|
||||
output_queue(_output_queue),
|
||||
f_body(P25_VOICE_FRAME_SIZE),
|
||||
opt_dump_raw_vectors(raw_vectors_flag),
|
||||
opt_verbose(verbose_flag),
|
||||
opt_udp_port(udp_port)
|
||||
{
|
||||
opt_stretch_amt = 0;
|
||||
if (stretch_amt < 0) {
|
||||
opt_stretch_sign = -1;
|
||||
opt_stretch_amt = 0 - stretch_amt;
|
||||
} else {
|
||||
opt_stretch_sign = 1;
|
||||
opt_stretch_amt = stretch_amt;
|
||||
}
|
||||
|
||||
if (opt_udp_port != 0)
|
||||
// remote UDP output
|
||||
init_sock(udp_host, opt_udp_port);
|
||||
|
||||
clear_bits(f_body);
|
||||
}
|
||||
|
||||
/*
|
||||
* Our virtual destructor.
|
||||
*/
|
||||
p25p1_voice_encode::~p25p1_voice_encode()
|
||||
{
|
||||
}
|
||||
|
||||
static const int STATS_INTERVAL = 20;
|
||||
static const int SAMP_INTERVAL = 8192;
|
||||
|
||||
void p25p1_voice_encode::append_imbe_codeword(bit_vector& frame_body, int16_t frame_vector[], unsigned int& codeword_ct)
|
||||
{
|
||||
voice_codeword cw(voice_codeword_sz);
|
||||
uint8_t obuf[P25_VOICE_FRAME_SIZE/2];
|
||||
// construct 144-bit codeword from 88 bits of parameters
|
||||
imbe_header_encode(cw, frame_vector[0], frame_vector[1], frame_vector[2], frame_vector[3], frame_vector[4], frame_vector[5], frame_vector[6], frame_vector[7]);
|
||||
|
||||
// add codeword to voice data unit
|
||||
imbe_interleave(frame_body, cw, codeword_ct);
|
||||
|
||||
// after the ninth and final codeword added, dispose of frame
|
||||
if (++codeword_ct >= nof_voice_codewords) {
|
||||
static const uint64_t hws[2] = { 0x293555ef2c653437LL, 0x293aba93bec26a2bLL };
|
||||
int ldu_type = frame_cnt & 1; // set ldu_type = 0(LDU1) or 1(LDU2)
|
||||
const bool* ldu_preset = (ldu_type == 0) ? ldu1_preset : ldu2_preset;
|
||||
|
||||
p25_setup_frame_header(frame_body, hws[ldu_type]);
|
||||
for (size_t i = 0; i < frame_body.size(); i++) {
|
||||
frame_body[i] = frame_body[i] | ldu_preset[i];
|
||||
}
|
||||
// finally, output the frame
|
||||
if (opt_udp_port > 0) {
|
||||
// pack the bits into bytes, MSB first
|
||||
size_t obuf_ct = 0;
|
||||
for (uint32_t i = 0; i < P25_VOICE_FRAME_SIZE; i += 8) {
|
||||
uint8_t b =
|
||||
(frame_body[i+0] << 7) +
|
||||
(frame_body[i+1] << 6) +
|
||||
(frame_body[i+2] << 5) +
|
||||
(frame_body[i+3] << 4) +
|
||||
(frame_body[i+4] << 3) +
|
||||
(frame_body[i+5] << 2) +
|
||||
(frame_body[i+6] << 1) +
|
||||
(frame_body[i+7] );
|
||||
obuf[obuf_ct++] = b;
|
||||
}
|
||||
sendto(write_sock, obuf, obuf_ct, 0, (struct sockaddr*)&write_sock_addr, sizeof(write_sock_addr));
|
||||
} else {
|
||||
for (uint32_t i = 0; i < P25_VOICE_FRAME_SIZE; i += 2) {
|
||||
uint8_t dibit =
|
||||
(frame_body[i+0] << 1) +
|
||||
(frame_body[i+1] );
|
||||
output_queue.push_back(dibit);
|
||||
}
|
||||
}
|
||||
codeword_ct = 0;
|
||||
frame_cnt++;
|
||||
if (opt_verbose && (frame_cnt % STATS_INTERVAL) == 0) {
|
||||
gettimeofday(&tv, &tz);
|
||||
int s = tv.tv_sec - oldtv.tv_sec;
|
||||
int us = tv.tv_usec - oldtv.tv_usec;
|
||||
if (us < 0) {
|
||||
us = us + 1000000;
|
||||
s = s - 1;
|
||||
}
|
||||
float f = us;
|
||||
f /= 1000000;
|
||||
f += s;
|
||||
fprintf (stderr, "time %f peak %5d\n", f / STATS_INTERVAL, peak_amplitude);
|
||||
oldtv = tv;
|
||||
}
|
||||
clear_bits(f_body);
|
||||
}
|
||||
}
|
||||
|
||||
void p25p1_voice_encode::compress_frame(int16_t snd[])
|
||||
{
|
||||
int16_t frame_vector[8];
|
||||
|
||||
// encode 160 audio samples into 88 bits (u0-u7)
|
||||
vocoder.imbe_encode(frame_vector, snd);
|
||||
|
||||
// if dump option, dump u0-u7 to output
|
||||
if (opt_dump_raw_vectors) {
|
||||
char s[128];
|
||||
sprintf(s, "%03x %03x %03x %03x %03x %03x %03x %03x\n", frame_vector[0], frame_vector[1], frame_vector[2], frame_vector[3], frame_vector[4], frame_vector[5], frame_vector[6], frame_vector[7]);
|
||||
memcpy(&write_buf[write_bufp], s, strlen(s));
|
||||
write_bufp += strlen(s);
|
||||
if (write_bufp >= 288) {
|
||||
sendto(write_sock, write_buf, 288, 0, (struct sockaddr*)&write_sock_addr, sizeof(write_sock_addr));
|
||||
write_bufp = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
append_imbe_codeword(f_body, frame_vector, codeword_ct);
|
||||
}
|
||||
|
||||
void p25p1_voice_encode::add_sample(int16_t samp)
|
||||
{
|
||||
// add one sample to 160-sample frame buffer and process if filled
|
||||
sampbuf[sampbuf_ct++] = samp;
|
||||
if (sampbuf_ct >= FRAME) {
|
||||
compress_frame(sampbuf);
|
||||
sampbuf_ct = 0;
|
||||
}
|
||||
|
||||
// track signal amplitudes
|
||||
int16_t asamp = (samp < 0) ? 0 - samp : samp;
|
||||
peak = (asamp > peak) ? asamp : peak;
|
||||
if (++samp_ct >= SAMP_INTERVAL) {
|
||||
peak_amplitude = peak;
|
||||
peak = 0;
|
||||
samp_ct = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void p25p1_voice_encode::compress_samp(const int16_t * samp, int len)
|
||||
{
|
||||
// Apply sample rate slew to accomodate sound card rate discrepancy -
|
||||
// workaround for USRP underrun problem occurring when sound card
|
||||
// capture rate is slower than the correct rate
|
||||
|
||||
// FIXME: autodetect proper value for opt_stretch_amt
|
||||
// perhaps by steering the LDU output rate to a 180.0 msec. rate
|
||||
|
||||
for (int i = 0; i < len; i++ ) {
|
||||
stretch_count++;
|
||||
if (opt_stretch_amt != 0 && stretch_count >= opt_stretch_amt) {
|
||||
stretch_count = 0;
|
||||
if (opt_stretch_sign < 0)
|
||||
// spill this samp
|
||||
continue;
|
||||
// repeat this samp
|
||||
add_sample(samp[i]);
|
||||
}
|
||||
add_sample(samp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void p25p1_voice_encode::init_sock(char* udp_host, int udp_port)
|
||||
{
|
||||
memset (&write_sock_addr, 0, sizeof(write_sock_addr));
|
||||
write_sock = socket(PF_INET, SOCK_DGRAM, 17); // UDP socket
|
||||
if (write_sock < 0) {
|
||||
fprintf(stderr, "vocoder: socket: %d\n", errno);
|
||||
write_sock = 0;
|
||||
return;
|
||||
}
|
||||
if (!inet_aton(udp_host, &write_sock_addr.sin_addr)) {
|
||||
fprintf(stderr, "vocoder: bad IP address\n");
|
||||
close(write_sock);
|
||||
write_sock = 0;
|
||||
return;
|
||||
}
|
||||
write_sock_addr.sin_family = AF_INET;
|
||||
write_sock_addr.sin_port = htons(udp_port);
|
||||
}
|
||||
|
||||
} /* namespace op25_repeater */
|
||||
} /* namespace gr */
|
|
@ -0,0 +1,89 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2009, 2010, 2011, 2012, 2013, 2014 Max H. Parke KA1RBI
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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 this software; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_OP25_REPEATER_P25P1_VOICE_ENCODE_H
|
||||
#define INCLUDED_OP25_REPEATER_P25P1_VOICE_ENCODE_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#include "imbe_vocoder/imbe_vocoder.h"
|
||||
|
||||
#include "imbe_decoder.h"
|
||||
#include "software_imbe_decoder.h"
|
||||
|
||||
namespace gr {
|
||||
namespace op25_repeater {
|
||||
|
||||
typedef std::vector<bool> bit_vector;
|
||||
class p25p1_voice_encode
|
||||
{
|
||||
private:
|
||||
// Nothing to declare in this block.
|
||||
|
||||
public:
|
||||
p25p1_voice_encode(bool verbose_flag, int stretch_amt, char* udp_host, int udp_port, bool raw_vectors_flag, std::deque<uint8_t> &_output_queue);
|
||||
~p25p1_voice_encode();
|
||||
void compress_samp(const int16_t * samp, int len);
|
||||
|
||||
private:
|
||||
static const int RXBUF_MAX = 80;
|
||||
|
||||
/* data items */
|
||||
int frame_cnt ;
|
||||
int write_sock;
|
||||
struct sockaddr_in write_sock_addr;
|
||||
int write_bufp;
|
||||
char write_buf[512];
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
struct timeval oldtv;
|
||||
int peak_amplitude;
|
||||
int peak;
|
||||
int samp_ct;
|
||||
char rxbuf[RXBUF_MAX];
|
||||
unsigned int codeword_ct ;
|
||||
int16_t sampbuf[FRAME];
|
||||
size_t sampbuf_ct ;
|
||||
int stretch_count ;
|
||||
bit_vector f_body;
|
||||
imbe_vocoder vocoder;
|
||||
|
||||
std::deque<uint8_t> &output_queue;
|
||||
|
||||
bool opt_dump_raw_vectors;
|
||||
bool opt_verbose;
|
||||
int opt_stretch_amt;
|
||||
int opt_stretch_sign;
|
||||
int opt_udp_port;
|
||||
/* local methods */
|
||||
void append_imbe_codeword(bit_vector& frame_body, int16_t frame_vector[], unsigned int& codeword_ct);
|
||||
void compress_frame(int16_t snd[]);
|
||||
void add_sample(int16_t samp);
|
||||
void init_sock(char* udp_host, int udp_port);
|
||||
};
|
||||
|
||||
} // namespace op25_repeater
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_OP25_REPEATER_P25P1_VOICE_ENCODE_H */
|
Loading…
Reference in New Issue