vocoder: fix excess cpu usage

This commit is contained in:
Max 2017-11-29 00:16:18 -05:00
parent 796c81f219
commit 0927bc11a9
1 changed files with 10 additions and 2 deletions

View File

@ -40,6 +40,8 @@
namespace gr {
namespace op25_repeater {
static const int FRAGMENT_SIZE = 864;
vocoder::sptr
vocoder::make(bool encode_flag, bool verbose_flag, int stretch_amt, char* udp_host, int udp_port, bool raw_vectors_flag)
{
@ -73,6 +75,8 @@ namespace gr {
p1voice_encode(verbose_flag, stretch_amt, udp_host, udp_port, raw_vectors_flag, output_queue),
p1voice_decode(verbose_flag, udp_host, udp_port, output_queue_decode)
{
if (opt_encode_flag)
set_output_multiple(FRAGMENT_SIZE);
}
/*
@ -131,13 +135,17 @@ vocoder_impl::general_work_encode (int noutput_items,
gr_vector_void_star &output_items)
{
const short *in = (const short *) input_items[0];
const int noutput_fragments = noutput_items / FRAGMENT_SIZE;
const int fragments_available = output_queue.size() / FRAGMENT_SIZE;
const int nsamples_consume = std::min(ninput_items[0], std::max(0,(noutput_fragments - fragments_available) * 9 * 160));
p1voice_encode.compress_samp(in, ninput_items[0]);
if (nsamples_consume > 0)
p1voice_encode.compress_samp(in, nsamples_consume);
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (ninput_items[0]);
consume_each (nsamples_consume);
if (opt_udp_port > 0) // in udp option, we are a gr sink only
return 0;