3
* Copyright 2005,2011 Free Software Foundation, Inc.
5
* This file is part of GNU Radio
7
* GNU Radio is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3, or (at your option)
12
* GNU Radio is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Radio; see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 51 Franklin Street,
20
* Boston, MA 02110-1301, USA.
27
#include "codec2_encode_sp_impl.h"
30
#include "codec2/codec2.h"
33
#include <gnuradio/io_signature.h>
39
codec2_encode_sp::sptr
40
codec2_encode_sp::make()
42
return gnuradio::get_initial_sptr
43
(new codec2_encode_sp_impl());
46
codec2_encode_sp_impl::codec2_encode_sp_impl()
47
: sync_decimator("vocoder_codec2_encode_sp",
48
io_signature::make(1, 1, sizeof(short)),
49
io_signature::make(1, 1, CODEC2_BITS_PER_FRAME * sizeof(char)),
50
CODEC2_SAMPLES_PER_FRAME)
52
if((d_codec2 = codec2_create()) == 0)
53
throw std::runtime_error("codec2_encode_sp_impl: codec2_create failed");
56
codec2_encode_sp_impl::~codec2_encode_sp_impl()
58
codec2_destroy(d_codec2);
62
codec2_encode_sp_impl::work(int noutput_items,
63
gr_vector_const_void_star &input_items,
64
gr_vector_void_star &output_items)
66
const short *in = (const short*)input_items[0];
67
unsigned char *out = (unsigned char*)output_items[0];
69
for(int i = 0; i < noutput_items; i++) {
70
codec2_encode(d_codec2, out, const_cast<short*>(in));
71
in += CODEC2_SAMPLES_PER_FRAME;
72
out += CODEC2_BITS_PER_FRAME * sizeof(char);
78
} /* namespace vocoder */