3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gr_bin_statistics_f.h>
28 #include <gr_io_signature.h>
30 gr_bin_statistics_f_sptr
31 gr_make_bin_statistics_f(unsigned int vlen,
32 gr_msg_queue_sptr msgq,
37 return gr_bin_statistics_f_sptr(new gr_bin_statistics_f(vlen,
44 gr_bin_statistics_f::gr_bin_statistics_f(unsigned int vlen,
45 gr_msg_queue_sptr msgq,
49 : gr_sync_block("bin_statistics_f",
50 gr_make_io_signature(1, 1, sizeof(float) * vlen),
51 gr_make_io_signature(0, 0, 0)),
52 d_vlen(vlen), d_msgq(msgq), d_tune(tune),
53 d_tune_delay(tune_delay), d_dwell_delay(dwell_delay),
54 d_center_freq(0), d_delay(0),
60 gr_bin_statistics_f::~gr_bin_statistics_f()
66 gr_bin_statistics_f::enter_init()
73 gr_bin_statistics_f::enter_tune_delay()
75 d_state = ST_TUNE_DELAY;
76 d_delay = d_tune_delay;
77 d_center_freq = d_tune->calleval(0);
81 gr_bin_statistics_f::enter_dwell_delay()
83 d_state = ST_DWELL_DELAY;
84 d_delay = d_dwell_delay;
89 gr_bin_statistics_f::leave_dwell_delay()
95 gr_bin_statistics_f::work(int noutput_items,
96 gr_vector_const_void_star &input_items,
97 gr_vector_void_star &output_items)
99 const float *input = (const float *) input_items[0];
100 size_t vlen = d_max.size();
105 while (n < noutput_items){
113 t = std::min(noutput_items - n, int(d_delay));
116 assert(d_delay >= 0);
122 t = std::min(noutput_items - n, int(d_delay));
123 for (int i = 0; i < t; i++){
124 accrue_stats(&input[n * vlen]);
128 assert(d_delay >= 0);
140 return noutput_items;
143 //////////////////////////////////////////////////////////////////////////
144 // virtual methods for gathering stats
145 //////////////////////////////////////////////////////////////////////////
148 gr_bin_statistics_f::reset_stats()
150 for (size_t i = 0; i < vlen(); i++){
156 gr_bin_statistics_f::accrue_stats(const float *input)
158 for (size_t i = 0; i < vlen(); i++){
159 d_max[i] = std::max(d_max[i], input[i]); // compute per bin maxima
164 gr_bin_statistics_f::send_stats()
166 if (msgq()->full_p()) // if the queue is full, don't block, drop the data...
169 // build & send a message
170 gr_message_sptr msg = gr_make_message(0, center_freq(), vlen(), vlen() * sizeof(float));
171 memcpy(msg->msg(), &d_max[0], vlen() * sizeof(float));
172 msgq()->insert_tail(msg);