updates
- bump up libm17 - scheduler tweaks (Codec2 blocks) - "reset" message input in C2 decoderdev
parent
4d375bf461
commit
e4f4d845cc
|
|
@ -19,7 +19,9 @@ inputs:
|
|||
dtype: byte
|
||||
vlen: 1
|
||||
optional: 0
|
||||
|
||||
- label: state_reset
|
||||
domain: message
|
||||
optional: 1
|
||||
|
||||
outputs:
|
||||
- label: out
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ install(FILES
|
|||
api.h
|
||||
codec2_encoder.h
|
||||
codec2_decoder.h
|
||||
symbol_sync.h
|
||||
#symbol_sync.h
|
||||
m17_coder.h
|
||||
m17_decoder.h DESTINATION include/gnuradio/m17
|
||||
)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,45 @@ namespace gr
|
|||
codec2_decoder_impl::codec2_decoder_impl() : gr::block("codec2_decoder", gr::io_signature::make(1, 1, sizeof(uint8_t)),
|
||||
gr::io_signature::make(1, 1, sizeof(int16_t)))
|
||||
{
|
||||
set_output_multiple(CODEC2_SAMPLES_PER_FRAME);
|
||||
|
||||
init_state();
|
||||
|
||||
message_port_register_in(pmt::mp("state_reset"));
|
||||
|
||||
set_msg_handler(
|
||||
pmt::mp("state_reset"),
|
||||
boost::bind(&codec2_decoder_impl::reset, this,
|
||||
boost::placeholders::_1));
|
||||
}
|
||||
|
||||
// TODO: fix this function!
|
||||
void codec2_decoder_impl::reset(const pmt::pmt_t &msg)
|
||||
{
|
||||
std::string cmd = "";
|
||||
|
||||
if (pmt::is_symbol(msg))
|
||||
{
|
||||
cmd = pmt::symbol_to_string(msg);
|
||||
}
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm t;
|
||||
localtime_r(&now, &t);
|
||||
|
||||
if (cmd == "SOT")
|
||||
{
|
||||
;
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd == "EOT")
|
||||
{
|
||||
codec2_init(&c2); // i hope this is the right place to put it
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "[%02d:%02d:%02d] Strange message received\n", t.tm_hour, t.tm_min, t.tm_sec);
|
||||
}
|
||||
|
||||
void codec2_decoder_impl::init_state(void)
|
||||
|
|
@ -62,7 +99,7 @@ namespace gr
|
|||
codec2_decoder_impl::forecast(int noutput_items,
|
||||
gr_vector_int &ninput_items_required)
|
||||
{
|
||||
ninput_items_required[0] = CODEC2_BYTES_PER_FRAME;
|
||||
ninput_items_required[0] = (noutput_items / CODEC2_SAMPLES_PER_FRAME) * CODEC2_BYTES_PER_FRAME;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -72,7 +109,6 @@ namespace gr
|
|||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const uint8_t *bits = static_cast<const uint8_t *>(input_items[0]);
|
||||
|
||||
int16_t *speech = static_cast<int16_t *>(output_items[0]);
|
||||
|
||||
if (ninput_items[0] < CODEC2_BYTES_PER_FRAME)
|
||||
|
|
@ -81,11 +117,20 @@ namespace gr
|
|||
if (noutput_items < CODEC2_SAMPLES_PER_FRAME)
|
||||
return 0;
|
||||
|
||||
codec2_decode(&c2, speech, bits);
|
||||
int frames = std::min(
|
||||
ninput_items[0] / CODEC2_BYTES_PER_FRAME,
|
||||
noutput_items / CODEC2_SAMPLES_PER_FRAME);
|
||||
|
||||
consume_each(CODEC2_BYTES_PER_FRAME);
|
||||
for (int i = 0; i < frames; i++)
|
||||
{
|
||||
codec2_decode(&c2,
|
||||
speech + i * CODEC2_SAMPLES_PER_FRAME,
|
||||
bits + i * CODEC2_BYTES_PER_FRAME);
|
||||
}
|
||||
|
||||
return CODEC2_SAMPLES_PER_FRAME;
|
||||
consume_each(frames * CODEC2_BYTES_PER_FRAME);
|
||||
|
||||
return frames * CODEC2_SAMPLES_PER_FRAME;
|
||||
}
|
||||
} /* namespace m17 */
|
||||
} /* namespace gr */
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace gr
|
|||
private:
|
||||
codec2_t c2;
|
||||
|
||||
void reset(const pmt::pmt_t &msg);
|
||||
void init_state(void);
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ namespace gr
|
|||
codec2_encoder_impl::codec2_encoder_impl() : gr::block("codec2_encoder", gr::io_signature::make(1, 1, sizeof(int16_t)),
|
||||
gr::io_signature::make(1, 1, sizeof(uint8_t)))
|
||||
{
|
||||
set_output_multiple(CODEC2_BYTES_PER_FRAME);
|
||||
|
||||
init_state();
|
||||
|
||||
message_port_register_in(pmt::mp("state_reset"));
|
||||
|
|
@ -50,8 +52,6 @@ namespace gr
|
|||
pmt::mp("state_reset"),
|
||||
boost::bind(&codec2_encoder_impl::reset, this,
|
||||
boost::placeholders::_1));
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
// TODO: fix this function!
|
||||
|
|
@ -99,7 +99,7 @@ namespace gr
|
|||
codec2_encoder_impl::forecast(int noutput_items,
|
||||
gr_vector_int &ninput_items_required)
|
||||
{
|
||||
ninput_items_required[0] = CODEC2_SAMPLES_PER_FRAME; // 160 samples
|
||||
ninput_items_required[0] = (noutput_items / CODEC2_BYTES_PER_FRAME) * CODEC2_SAMPLES_PER_FRAME;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -109,7 +109,6 @@ namespace gr
|
|||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const int16_t *speech = static_cast<const int16_t *>(input_items[0]);
|
||||
|
||||
uint8_t *bits = static_cast<uint8_t *>(output_items[0]);
|
||||
|
||||
// we need one full speech frame
|
||||
|
|
@ -120,14 +119,19 @@ namespace gr
|
|||
if (noutput_items < CODEC2_BYTES_PER_FRAME)
|
||||
return 0;
|
||||
|
||||
// encode exactly one frame
|
||||
codec2_encode(&c2, bits, const_cast<int16_t *>(speech));
|
||||
int frames = std::min(
|
||||
ninput_items[0] / CODEC2_SAMPLES_PER_FRAME,
|
||||
noutput_items / CODEC2_BYTES_PER_FRAME);
|
||||
|
||||
// consume 160 samples
|
||||
consume_each(CODEC2_SAMPLES_PER_FRAME);
|
||||
for (int i = 0; i < frames; i++)
|
||||
{
|
||||
codec2_encode(&c2,
|
||||
bits + i * CODEC2_BYTES_PER_FRAME,
|
||||
speech + i * CODEC2_SAMPLES_PER_FRAME);
|
||||
}
|
||||
|
||||
// produce 8 bytes
|
||||
return CODEC2_BYTES_PER_FRAME;
|
||||
consume_each(frames * CODEC2_SAMPLES_PER_FRAME);
|
||||
return frames * CODEC2_BYTES_PER_FRAME;
|
||||
}
|
||||
} /* namespace m17 */
|
||||
} /* namespace gr */
|
||||
|
|
|
|||
2
libm17
2
libm17
|
|
@ -1 +1 @@
|
|||
Subproject commit 0f84226f5a284610d565d52447867f26c6ca4da7
|
||||
Subproject commit 07926d08ade8509f1ce55d0289f229ab44cbcf51
|
||||
Loading…
Reference in New Issue