#include <gr_block.h>
Blocks have a set of input streams and output streams. The input_signature and output_signature define the number of input streams and output streams respectively, and the type of the data items in each stream.
Although blocks may consume data on each input stream at a different rate, all outputs streams must produce data at the same rate. That rate may be different from any of the input rates.
User derived blocks override two methods, forecast and general_work, to implement their signal processing behavior. forecast is called by the system scheduler to determine how many items are required on each input stream in order to produce a given number of output items.
general_work is called to perform the signal processing in the block. It reads the input items and writes the output items.
Public Member Functions | |
virtual | ~gr_block () |
std::string | name () const |
gr_io_signature_sptr | input_signature () const |
gr_io_signature_sptr | output_signature () const |
long | unique_id () const |
unsigned | history () const |
void | set_history (unsigned history) |
bool | fixed_rate () const |
return true if this block has a fixed input to output rate | |
virtual void | forecast (int noutput_items, gr_vector_int &ninput_items_required) |
Estimate input requirements given output request. | |
virtual int | general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)=0 |
compute output items from input items | |
virtual bool | check_topology (int ninputs, int noutputs) |
Confirm that ninputs and noutputs is an acceptable combination. | |
virtual bool | start () |
Called to enable drivers, etc for i/o devices. | |
virtual bool | stop () |
Called to disable drivers, etc for i/o devices. | |
void | set_output_multiple (int multiple) |
Constrain the noutput_items argument passed to forecast and general_work. | |
int | output_multiple () const |
void | consume (int which_input, int how_many_items) |
Tell the scheduler how_many_items of input stream which_input were consumed. | |
void | consume_each (int how_many_items) |
Tell the scheduler how_many_items were consumed on each input stream. | |
void | set_relative_rate (double relative_rate) |
Set the approximate output rate / input rate. | |
double | relative_rate () const |
return the approximate output rate / input rate | |
virtual int | fixed_rate_ninput_to_noutput (int ninput) |
Given ninput samples, return number of output samples that will be produced. N.B. this is only defined if fixed_rate returns true. Generally speaking, you don't need to override this. | |
virtual int | fixed_rate_noutput_to_ninput (int noutput) |
Given noutput samples, return number of input samples required to produce noutput. N.B. this is only defined if fixed_rate returns true. Generally speaking, you don't need to override this. | |
gr_block_detail_sptr | detail () const |
void | set_detail (gr_block_detail_sptr detail) |
Protected Member Functions | |
gr_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature) | |
void | set_input_signature (gr_io_signature_sptr iosig) |
may only be called during constructor | |
void | set_output_signature (gr_io_signature_sptr iosig) |
may only be called during constructor | |
void | set_fixed_rate (bool fixed_rate) |
gr_block::~gr_block | ( | ) | [virtual] |
gr_block::gr_block | ( | const std::string & | name, | |
gr_io_signature_sptr | input_signature, | |||
gr_io_signature_sptr | output_signature | |||
) | [protected] |
std::string gr_block::name | ( | ) | const [inline] |
Referenced by _wrap_gr_block_name(), and operator<<().
gr_io_signature_sptr gr_block::input_signature | ( | ) | const [inline] |
gr_io_signature_sptr gr_block::output_signature | ( | ) | const [inline] |
Referenced by gr_align_on_samplenumbers_ss::general_work(), gr_vector_to_streams::work(), gr_vector_to_stream::work(), gr_streams_to_stream::work(), gr_stream_to_vector::work(), gr_stream_to_streams::work(), gr_null_source::work(), gr_multiply_vss::work(), gr_multiply_vii::work(), gr_multiply_vff::work(), gr_multiply_vcc::work(), gr_multiply_const_vss::work(), gr_multiply_const_vii::work(), gr_multiply_const_vff::work(), gr_multiply_const_vcc::work(), gr_fft_vfc::work(), gr_fft_vcc::work(), gr_add_vss::work(), gr_add_vii::work(), gr_add_vff::work(), gr_add_vcc::work(), gr_add_const_vss::work(), gr_add_const_vii::work(), gr_add_const_vff::work(), and gr_add_const_vcc::work().
long gr_block::unique_id | ( | ) | const [inline] |
Referenced by operator<<().
unsigned gr_block::history | ( | ) | const [inline] |
Assume block computes y_i = f(x_i, x_i-1, x_i-2, x_i-3...) History is the number of x_i's that are examined to produce one y_i. This comes in handy for FIR filters, where we use history to ensure that our input contains the appropriate "history" for the filter. History should be equal to the number of filter taps.
Reimplemented in gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, and gr_rational_resampler_base_scc.
Referenced by gr_sync_interpolator::fixed_rate_ninput_to_noutout(), gr_sync_decimator::fixed_rate_ninput_to_noutput(), gr_sync_block::fixed_rate_ninput_to_noutput(), gr_sync_interpolator::fixed_rate_noutput_to_ninput(), gr_sync_decimator::fixed_rate_noutput_to_ninput(), gr_sync_block::fixed_rate_noutput_to_ninput(), gr_test::forecast(), gr_align_on_samplenumbers_ss::forecast(), and gr_test::general_work().
void gr_block::set_history | ( | unsigned | history | ) | [inline] |
Reimplemented in gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, and gr_rational_resampler_base_scc.
Referenced by gr_adaptive_fir_ccf::gr_adaptive_fir_ccf(), gr_clock_recovery_mm_cc::gr_clock_recovery_mm_cc(), gr_filter_delay_fc::gr_filter_delay_fc(), gr_freq_xlating_fir_filter_ccc::gr_freq_xlating_fir_filter_ccc(), gr_freq_xlating_fir_filter_ccf::gr_freq_xlating_fir_filter_ccf(), gr_freq_xlating_fir_filter_fcc::gr_freq_xlating_fir_filter_fcc(), gr_freq_xlating_fir_filter_fcf::gr_freq_xlating_fir_filter_fcf(), gr_freq_xlating_fir_filter_scc::gr_freq_xlating_fir_filter_scc(), gr_freq_xlating_fir_filter_scf::gr_freq_xlating_fir_filter_scf(), gr_hilbert_fc::gr_hilbert_fc(), gr_test::gr_test(), gr_freq_xlating_fir_filter_scf::work(), gr_freq_xlating_fir_filter_scc::work(), gr_freq_xlating_fir_filter_fcf::work(), gr_freq_xlating_fir_filter_fcc::work(), gr_freq_xlating_fir_filter_ccf::work(), gr_freq_xlating_fir_filter_ccc::work(), gr_fir_filter_scc::work(), gr_fir_filter_fsf::work(), gr_fir_filter_fff::work(), gr_fir_filter_fcc::work(), gr_fir_filter_ccf::work(), gr_fir_filter_ccc::work(), and gr_adaptive_fir_ccf::work().
bool gr_block::fixed_rate | ( | ) | const [inline] |
return true if this block has a fixed input to output rate
If true, then fixed_rate_in_to_out and fixed_rate_out_to_in may be called.
void gr_block::forecast | ( | int | noutput_items, | |
gr_vector_int & | ninput_items_required | |||
) | [virtual] |
Estimate input requirements given output request.
noutput_items | number of output items to produce | |
ninput_items_required | number of input items required on each input stream |
noutput_items
, estimate the number of data items required on each input stream. The estimate doesn't have to be exact, but should be close.
Reimplemented in gr_fractional_interpolator, gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, gr_rational_resampler_base_scc, gr_align_on_samplenumbers_ss, gr_clock_recovery_mm_cc, gr_clock_recovery_mm_ff, gr_dd_mpsk_sync_cc, gr_packed_to_unpacked_bb, gr_packed_to_unpacked_ii, gr_packed_to_unpacked_ss, gr_simple_framer, gr_sync_block, gr_sync_decimator, gr_sync_interpolator, gr_test, gr_unpacked_to_packed_bb, gr_unpacked_to_packed_ii, gr_unpacked_to_packed_ss, trellis_metrics_c, trellis_metrics_f, trellis_metrics_i, trellis_metrics_s, trellis_siso_combined_f, trellis_siso_f, trellis_viterbi_b, trellis_viterbi_combined_b, trellis_viterbi_combined_i, trellis_viterbi_combined_s, trellis_viterbi_i, and trellis_viterbi_s.
virtual int gr_block::general_work | ( | int | noutput_items, | |
gr_vector_int & | ninput_items, | |||
gr_vector_const_void_star & | input_items, | |||
gr_vector_void_star & | output_items | |||
) | [pure virtual] |
compute output items from input items
noutput_items | number of output items to write on each output stream | |
ninput_items | number of input items available on each input stream | |
input_items | vector of pointers to the input items, one entry per input stream | |
output_items | vector of pointers to the output items, one entry per output stream |
Implemented in gr_fractional_interpolator, gr_rational_resampler_base_ccc, gr_rational_resampler_base_ccf, gr_rational_resampler_base_fcc, gr_rational_resampler_base_fff, gr_rational_resampler_base_fsf, gr_rational_resampler_base_scc, gr_align_on_samplenumbers_ss, gr_clock_recovery_mm_cc, gr_clock_recovery_mm_ff, gr_dd_mpsk_sync_cc, gr_keep_one_in_n, gr_nop, gr_packed_to_unpacked_bb, gr_packed_to_unpacked_ii, gr_packed_to_unpacked_ss, gr_simple_correlator, gr_simple_framer, gr_squelch_base_cc, gr_squelch_base_ff, gr_sync_block, gr_sync_decimator, gr_sync_interpolator, gr_test, gr_unpacked_to_packed_bb, gr_unpacked_to_packed_ii, gr_unpacked_to_packed_ss, trellis_metrics_c, trellis_metrics_f, trellis_metrics_i, trellis_metrics_s, trellis_siso_combined_f, trellis_siso_f, trellis_viterbi_b, trellis_viterbi_combined_b, trellis_viterbi_combined_i, trellis_viterbi_combined_s, trellis_viterbi_i, and trellis_viterbi_s.
bool gr_block::check_topology | ( | int | ninputs, | |
int | noutputs | |||
) | [virtual] |
Confirm that ninputs and noutputs is an acceptable combination.
ninputs | number of input streams connected | |
noutputs | number of output streams connected |
Reimplemented in gr_align_on_samplenumbers_ss, gr_chunks_to_symbols_bc, gr_chunks_to_symbols_bf, gr_chunks_to_symbols_ic, gr_chunks_to_symbols_if, gr_chunks_to_symbols_sc, gr_chunks_to_symbols_sf, gr_deinterleave, gr_interleave, gr_kludge_copy, gr_packed_to_unpacked_bb, gr_packed_to_unpacked_ii, gr_packed_to_unpacked_ss, gr_test, gr_unpacked_to_packed_bb, gr_unpacked_to_packed_ii, gr_unpacked_to_packed_ss, gr_oscope_sink_f, audio_alsa_sink, audio_alsa_source, audio_jack_sink, audio_jack_source, audio_osx_source, audio_portaudio_sink, and audio_portaudio_source.
bool gr_block::start | ( | void | ) | [virtual] |
Called to enable drivers, etc for i/o devices.
This allows a block to enable an associated driver to begin transfering data just before we start to execute the scheduler. The end result is that this reduces latency in the pipeline when dealing with audio devices, usrps, etc.
Reimplemented in audio_osx_sink, audio_osx_source, usrp1_sink_base, and usrp1_source_base.
Referenced by _wrap_gr_block_start().
bool gr_block::stop | ( | ) | [virtual] |
Called to disable drivers, etc for i/o devices.
Reimplemented in audio_osx_sink, audio_osx_source, usrp1_sink_base, and usrp1_source_base.
Referenced by _wrap_gr_block_stop().
void gr_block::set_output_multiple | ( | int | multiple | ) |
Constrain the noutput_items argument passed to forecast and general_work.
set_output_multiple causes the scheduler to ensure that the noutput_items argument passed to forecast and general_work will be an integer multiple of
multiple | The default value of output multiple is 1. |
Referenced by audio_alsa_sink::audio_alsa_sink(), audio_alsa_source::audio_alsa_source(), audio_jack_sink::audio_jack_sink(), audio_jack_source::audio_jack_source(), audio_oss_sink::audio_oss_sink(), audio_oss_source::audio_oss_source(), gr_test::gr_test(), gr_sync_interpolator::set_interpolation(), video_sdl_sink_s::video_sdl_sink_s(), and video_sdl_sink_uc::video_sdl_sink_uc().
int gr_block::output_multiple | ( | ) | const [inline] |
void gr_block::consume | ( | int | which_input, | |
int | how_many_items | |||
) |
Tell the scheduler how_many_items
of input stream which_input
were consumed.
Referenced by trellis_siso_f::general_work(), trellis_siso_combined_f::general_work(), gr_test::general_work(), gr_nop::general_work(), and gr_align_on_samplenumbers_ss::general_work().
void gr_block::consume_each | ( | int | how_many_items | ) |
Tell the scheduler how_many_items
were consumed on each input stream.
Referenced by trellis_viterbi_s::general_work(), trellis_viterbi_i::general_work(), trellis_viterbi_combined_s::general_work(), trellis_viterbi_combined_i::general_work(), trellis_viterbi_combined_b::general_work(), trellis_viterbi_b::general_work(), trellis_metrics_s::general_work(), trellis_metrics_i::general_work(), trellis_metrics_f::general_work(), trellis_metrics_c::general_work(), gr_unpacked_to_packed_ss::general_work(), gr_unpacked_to_packed_ii::general_work(), gr_unpacked_to_packed_bb::general_work(), gr_sync_interpolator::general_work(), gr_sync_decimator::general_work(), gr_sync_block::general_work(), gr_squelch_base_ff::general_work(), gr_squelch_base_cc::general_work(), gr_simple_framer::general_work(), gr_simple_correlator::general_work(), gr_rational_resampler_base_scc::general_work(), gr_rational_resampler_base_fsf::general_work(), gr_rational_resampler_base_fff::general_work(), gr_rational_resampler_base_fcc::general_work(), gr_rational_resampler_base_ccf::general_work(), gr_rational_resampler_base_ccc::general_work(), gr_packed_to_unpacked_ss::general_work(), gr_packed_to_unpacked_ii::general_work(), gr_packed_to_unpacked_bb::general_work(), gr_keep_one_in_n::general_work(), gr_fractional_interpolator::general_work(), gr_dd_mpsk_sync_cc::general_work(), gr_clock_recovery_mm_ff::general_work(), gr_clock_recovery_mm_cc::general_work(), and gr_skiphead::work().
void gr_block::set_relative_rate | ( | double | relative_rate | ) |
Set the approximate output rate / input rate.
Provide a hint to the buffer allocator and scheduler. The default relative_rate is 1.0
decimators have relative_rates < 1.0 interpolators have relative_rates > 1.0
Referenced by gr_clock_recovery_mm_cc::gr_clock_recovery_mm_cc(), gr_clock_recovery_mm_ff::gr_clock_recovery_mm_ff(), gr_fractional_interpolator::gr_fractional_interpolator(), gr_test::gr_test(), gr_sync_decimator::set_decimation(), and gr_sync_interpolator::set_interpolation().
double gr_block::relative_rate | ( | ) | const [inline] |
return the approximate output rate / input rate
Referenced by gr_test::fixed_rate_ninput_to_noutput(), gr_test::fixed_rate_noutput_to_ninput(), and gr_test::forecast().
int gr_block::fixed_rate_ninput_to_noutput | ( | int | ninput | ) | [virtual] |
Given ninput samples, return number of output samples that will be produced. N.B. this is only defined if fixed_rate returns true. Generally speaking, you don't need to override this.
Reimplemented in gr_sync_block, gr_sync_decimator, and gr_test.
int gr_block::fixed_rate_noutput_to_ninput | ( | int | noutput | ) | [virtual] |
Given noutput samples, return number of input samples required to produce noutput. N.B. this is only defined if fixed_rate returns true. Generally speaking, you don't need to override this.
Reimplemented in gr_sync_block, gr_sync_decimator, gr_sync_interpolator, and gr_test.
void gr_block::set_input_signature | ( | gr_io_signature_sptr | iosig | ) | [inline, protected] |
may only be called during constructor
Referenced by audio_alsa_sink::audio_alsa_sink(), audio_jack_sink::audio_jack_sink(), audio_osx_sink::audio_osx_sink(), and audio_portaudio_sink::audio_portaudio_sink().
void gr_block::set_output_signature | ( | gr_io_signature_sptr | iosig | ) | [inline, protected] |
may only be called during constructor
Referenced by audio_alsa_source::audio_alsa_source(), audio_jack_source::audio_jack_source(), audio_osx_source::audio_osx_source(), and audio_portaudio_source::audio_portaudio_source().
void gr_block::set_fixed_rate | ( | bool | fixed_rate | ) | [inline, protected] |
Referenced by gr_sync_block::gr_sync_block(), gr_test::gr_test(), and gr_test::set_fixed_rate_public().
gr_block_detail_sptr gr_block::detail | ( | ) | const [inline] |
void gr_block::set_detail | ( | gr_block_detail_sptr | detail | ) | [inline] |