I'm trying to make a time varying delay. One that will update faster than I can get with probe_signal + function_probe + gr_delay block.
The code is shown below. There's not much to it. It's just a start. The flow graph that tests it is just:
1 kHz triangle waveform -> throttle --> time_varying_delay --> time sink
with a second input on the time sink for the input waveform.
I'm implementing the time delay by updating set_history() with a static counter.
It doesn't work. The time delay doesn't vary. The output waveform just sits there in sync with the input. If I uncomment the consume_each line it almost works, until it crashes. For a few thousand counter cycles the delay bounces around. But it always locks up after anywhere from a few hundred to a few thousand counts.
Why would it be fixed without the consume line and bounce around and crash with it ?
Is updating set_history() the wrong approach ?
Thanks.
/* -*- c++ -*- */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gnuradio/io_signature.h>
#include "time_varying_delay_impl.h"
namespace gr {
namespace howto {
time_varying_delay::sptr time_varying_delay::make()
{
return gnuradio::get_initial_sptr (new time_varying_delay_impl());
}
time_varying_delay_impl::time_varying_delay_impl() :
gr::sync_block("time_varying_delay",
gr::io_signature::make(1, 1, sizeof(float)),
gr::io_signature::make(1, 1, sizeof(float)))
{
set_history(1);
}
time_varying_delay_impl::~time_varying_delay_impl() {}
int time_varying_delay_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
static int counter = 1;
for (int i = 0; i < noutput_items; i++) {
out[i] = in[i] / 2.0;
}
set_history(counter++);
std::cout << counter << std::endl;
// consume_each(noutput_items);
return noutput_items;
}
} /* namespace howto */
} /* namespace gr */