From 0927bc11a9117d86e9c9a3e2d8fbcf5d4ac1fe8b Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Nov 2017 00:16:18 -0500 Subject: vocoder: fix excess cpu usage --- op25/gr-op25_repeater/lib/vocoder_impl.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'op25') diff --git a/op25/gr-op25_repeater/lib/vocoder_impl.cc b/op25/gr-op25_repeater/lib/vocoder_impl.cc index 3f2032d..967dde4 100644 --- a/op25/gr-op25_repeater/lib/vocoder_impl.cc +++ b/op25/gr-op25_repeater/lib/vocoder_impl.cc @@ -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; -- cgit v1.2.3