3 * Copyright 2004,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 2, 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_ctcss_squelch_ff.h>
29 static float ctcss_tones[] = {
30 67.0, 71.9, 74.4, 77.0, 79.7, 82.5, 85.4, 88.5, 91.5, 94.8,
31 97.4, 100.0, 103.5, 107.2, 110.9, 114.8, 118.8, 123.0, 127.3, 131.8,
32 136.5, 141.3, 146.2, 151.4, 156.7, 162.2, 167.9, 173.8, 179.9, 186.2,
33 192.8, 203.5, 210.7, 218.1, 225.7, 233.6, 241.8, 250.3
36 static int max_tone_index = 37;
38 gr_ctcss_squelch_ff_sptr
39 gr_make_ctcss_squelch_ff(int rate, float freq, float level, int len, int ramp, bool gate)
41 return gr_ctcss_squelch_ff_sptr(new gr_ctcss_squelch_ff(rate, freq, level, len, ramp, gate));
44 int gr_ctcss_squelch_ff::find_tone(float freq)
46 for (int i = 0; i <= max_tone_index; i++)
47 if (ctcss_tones[i] == freq) // FIXME: make almost equal
53 gr_ctcss_squelch_ff::gr_ctcss_squelch_ff(int rate, float freq, float level, int len, int ramp, bool gate) :
54 gr_squelch_base_ff("ctcss_squelch_ff", ramp, gate)
59 // Default is 100 ms detection time
61 d_len = (int)(rate/10.0);
65 int i = find_tone(freq);
67 // Non-standard tones or edge tones get 2% guard band, otherwise
68 // guards are set at adjacent ctcss tone frequencies
70 if (i == -1 || i == 0)
73 f_l = ctcss_tones[i-1];
75 if (i == -1 || i == max_tone_index)
78 f_r = ctcss_tones[i+1];
80 d_goertzel_l = gri_goertzel(rate, d_len, f_l);
81 d_goertzel_c = gri_goertzel(rate, d_len, freq);
82 d_goertzel_r = gri_goertzel(rate, d_len, f_r);
87 std::vector<float> gr_ctcss_squelch_ff::squelch_range() const
89 std::vector<float> r(3);
92 r[2] = (r[1]-r[0])/100; // step size
97 void gr_ctcss_squelch_ff::update_state(const float &in)
99 d_goertzel_l.input(in);
100 d_goertzel_c.input(in);
101 d_goertzel_r.input(in);
103 float d_out_l, d_out_c, d_out_r;
104 if (d_goertzel_c.ready()) {
105 d_out_l = abs(d_goertzel_l.output());
106 d_out_c = abs(d_goertzel_c.output());
107 d_out_r = abs(d_goertzel_r.output());
109 //printf("d_out_l=%f d_out_c=%f d_out_r=%f\n", d_out_l, d_out_c, d_out_r);
110 d_mute = (d_out_c < d_level || d_out_c < d_out_l || d_out_c < d_out_r);