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>
31 gr_bin_statistics_f_sptr
32 gr_make_bin_statistics_f(unsigned int vlen,
33 gr_msg_queue_sptr msgq,
38 return gr_bin_statistics_f_sptr(new gr_bin_statistics_f(vlen,
45 gr_bin_statistics_f::gr_bin_statistics_f(unsigned int vlen,
46 gr_msg_queue_sptr msgq,
50 : gr_sync_block("bin_statistics_f",
51 gr_make_io_signature(1, 1, sizeof(float) * vlen),
52 gr_make_io_signature(0, 0, 0)),
53 d_vlen(vlen), d_msgq(msgq), d_tune(tune),
54 d_tune_delay(tune_delay), d_dwell_delay(dwell_delay),
55 d_center_freq(0), d_delay(0),
61 gr_bin_statistics_f::~gr_bin_statistics_f()
67 gr_bin_statistics_f::enter_init()
74 gr_bin_statistics_f::enter_tune_delay()
76 d_state = ST_TUNE_DELAY;
77 d_delay = d_tune_delay;
78 d_center_freq = d_tune->calleval(0);
82 gr_bin_statistics_f::enter_dwell_delay()
84 d_state = ST_DWELL_DELAY;
85 d_delay = d_dwell_delay;
90 gr_bin_statistics_f::leave_dwell_delay()
96 gr_bin_statistics_f::work(int noutput_items,
97 gr_vector_const_void_star &input_items,
98 gr_vector_void_star &output_items)
100 const float *input = (const float *) input_items[0];
101 size_t vlen = d_max.size();
106 while (n < noutput_items){
114 t = std::min(noutput_items - n, int(d_delay));
117 assert(d_delay >= 0);
123 t = std::min(noutput_items - n, int(d_delay));
124 for (int i = 0; i < t; i++){
125 accrue_stats(&input[n * vlen]);
129 assert(d_delay >= 0);
141 return noutput_items;
144 //////////////////////////////////////////////////////////////////////////
145 // virtual methods for gathering stats
146 //////////////////////////////////////////////////////////////////////////
149 gr_bin_statistics_f::reset_stats()
151 for (size_t i = 0; i < vlen(); i++){
157 gr_bin_statistics_f::accrue_stats(const float *input)
159 for (size_t i = 0; i < vlen(); i++){
160 d_max[i] = std::max(d_max[i], input[i]); // compute per bin maxima
165 gr_bin_statistics_f::send_stats()
167 if (msgq()->full_p()) // if the queue is full, don't block, drop the data...
170 // build & send a message
171 gr_message_sptr msg = gr_make_message(0, center_freq(), vlen(), vlen() * sizeof(float));
172 memcpy(msg->msg(), &d_max[0], vlen() * sizeof(float));
173 msgq()->insert_tail(msg);