ambe_encoder_sb block

This commit is contained in:
Max 2017-01-20 13:47:25 -05:00
parent 7214bc2614
commit a83fbd8c86
6 changed files with 254 additions and 0 deletions

View File

@ -25,5 +25,6 @@ install(FILES
vocoder.h
gardner_costas_cc.h
p25_frame_assembler.h
ambe_encoder_sb.h
fsk4_slicer_fb.h DESTINATION include/op25_repeater
)

View File

@ -0,0 +1,56 @@
/* -*- c++ -*- */
/*
* (C) Copyright 2016 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_AMBE_ENCODER_SB_H
#define INCLUDED_OP25_REPEATER_AMBE_ENCODER_SB_H
#include <op25_repeater/api.h>
#include <gnuradio/block.h>
namespace gr {
namespace op25_repeater {
/*!
* \brief <+description of block+>
* \ingroup op25_repeater
*
*/
class OP25_REPEATER_API ambe_encoder_sb : virtual public gr::block
{
public:
typedef boost::shared_ptr<ambe_encoder_sb> sptr;
/*!
* \brief Return a shared_ptr to a new instance of op25_repeater::ambe_encoder_sb.
*
* To avoid accidental use of raw pointers, op25_repeater::ambe_encoder_sb's
* constructor is in a private implementation
* class. op25_repeater::ambe_encoder_sb::make is the public interface for
* creating new instances.
*/
static sptr make(int versbose_flag);
};
} // namespace op25_repeater
} // namespace gr
#endif /* INCLUDED_OP25_REPEATER_AMBE_ENCODER_SB_H */

View File

@ -25,6 +25,7 @@ include(GrPlatform) #define LIB_SUFFIX
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
list(APPEND op25_repeater_sources
ambe_encoder_sb_impl.cc
vocoder_impl.cc
gardner_costas_cc_impl.cc
p25_frame_assembler_impl.cc
@ -47,6 +48,7 @@ list(APPEND op25_repeater_sources
software_imbe_decoder.cc
ambe.c
mbelib.c
ambe_encoder.cc
)
add_library(gnuradio-op25_repeater SHARED ${op25_repeater_sources})

View File

@ -0,0 +1,114 @@
/* -*- c++ -*- */
/*
* GNU Radio interface for halfrate ambe encoder
*
* (C) Copyright 2016 Max H. Parke KA1RBI
*
* This file is part of OP25
*
* 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 "ambe_encoder_sb_impl.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>
namespace gr {
namespace op25_repeater {
ambe_encoder_sb::sptr
ambe_encoder_sb::make(int verbose_flag)
{
return gnuradio::get_initial_sptr
(new ambe_encoder_sb_impl(verbose_flag));
}
//////////////////////////////////////////////////////////////////////////
// accepts buffers of 160 samples (short format)
// outputs one ambe codeword per 160 samples (36 dibits, char format)
static const int MIN_IN = 1;
static const int MIN_OUT = 1;
static const int MAX_IN = 1;
static const int MAX_OUT = 1;
/*
* The private constructor
*/
ambe_encoder_sb_impl::ambe_encoder_sb_impl(int verbose_flag)
: gr::block("ambe_encoder_sb",
gr::io_signature::make (MIN_IN, MAX_IN, sizeof(short)),
gr::io_signature::make (MAX_IN, MAX_OUT, sizeof(char)))
{
set_output_multiple(36);
set_history(160);
}
/*
* Our virtual destructor.
*/
ambe_encoder_sb_impl::~ambe_encoder_sb_impl()
{
}
void
ambe_encoder_sb_impl::forecast(int nof_output_items, gr_vector_int &nof_input_items_reqd)
{
/* produces 36 samples per 160 samples input
*/
const size_t nof_inputs = nof_input_items_reqd.size();
const int nof_samples_reqd = 160.0 * (nof_output_items / 36.0);
std::fill(&nof_input_items_reqd[0], &nof_input_items_reqd[nof_inputs], nof_samples_reqd);
}
int
ambe_encoder_sb_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
int nframes = ninput_items[0] / 160;
nframes = std::min(nframes, noutput_items / 36);
if (nframes < 1) return 0;
short *in = (short *) input_items[0];
uint8_t *out = reinterpret_cast<uint8_t*>(output_items[0]);
for (int n=0; n<nframes; n++) {
d_encoder.encode(&in[n*160], &out[n*36]);
}
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (nframes * 160);
// Tell runtime system how many output items we produced.
return (nframes * 36);
}
} /* namespace op25_repeater */
} /* namespace gr */

View File

@ -0,0 +1,77 @@
/* -*- c++ -*- */
/*
* (C) Copyright 2016 Max H. Parke KA1RBI
*
* This file is part of OP25
*
* 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_AMBE_ENCODER_SB_IMPL_H
#define INCLUDED_OP25_REPEATER_AMBE_ENCODER_SB_IMPL_H
#include <op25_repeater/ambe_encoder_sb.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <stdint.h>
#include <vector>
#include <deque>
#include "ambe3600x2250_const.h"
#include "mbelib.h"
#include "ambe.h"
#include "p25p2_vf.h"
#include "imbe_vocoder/imbe_vocoder.h"
#include "ambe_encoder.h"
namespace gr {
namespace op25_repeater {
class ambe_encoder_sb_impl : public ambe_encoder_sb
{
private:
// Nothing to declare in this block.
public:
ambe_encoder_sb_impl(int verbose_flag);
~ambe_encoder_sb_impl();
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
int general_work(int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
int general_work_encode (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
int general_work_decode (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
private:
int d_verbose_flag;
ambe_encoder d_encoder;
};
} // namespace op25_repeater
} // namespace gr
#endif /* INCLUDED_OP25_REPEATER_AMBE_ENCODER_SB_IMPL_H */

View File

@ -12,8 +12,12 @@
#include "op25_repeater/gardner_costas_cc.h"
#include "op25_repeater/p25_frame_assembler.h"
#include "op25_repeater/fsk4_slicer_fb.h"
#include "op25_repeater/ambe_encoder_sb.h"
%}
%include "op25_repeater/ambe_encoder_sb.h"
GR_SWIG_BLOCK_MAGIC2(op25_repeater, ambe_encoder_sb);
%include "op25_repeater/vocoder.h"
GR_SWIG_BLOCK_MAGIC2(op25_repeater, vocoder);