gusimplewhiteboard
FFTStatus.hpp
Go to the documentation of this file.
1/*
2 * FFTStatus.h
3 * gusimplewhiteboard
4 *
5 * Created by Rene Hexel on 24/06/2014.
6 * Copyright (c) 2014, 2015, 2017 Rene Hexel. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Rene Hexel.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58#ifndef FFTStatus_DEFINED
59#define FFTStatus_DEFINED
60
61#include <cstddef>
62#include <cassert>
63#include <cstdarg>
64#include <cstdlib>
65#include <cstring>
66#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
67#include <sstream>
68#include <gu_util.h>
69#endif
70#include "gusimplewhiteboard.h"
71#include "wb_fft_frequencies.h"
72
73#pragma clang diagnostic push
74#pragma clang diagnostic ignored "-Winvalid-offsetof"
75#pragma clang diagnostic ignored "-Wclass-varargs"
76#pragma clang diagnostic ignored "-Wvarargs"
77
78namespace guWhiteboard
79{
84 {
85 public:
88
90 FFTStatus(int16_t lrms, int16_t rrms, uint16_t hi, uint16_t lo, uint16_t fsk, va_list freqs): fft_dominant_frequency(lrms, rrms, hi, lo, fsk, freqs) {}
91
93 FFTStatus(int16_t lrms, int16_t rrms, uint16_t hi = FSK_DEFAULT_HI, uint16_t lo = FSK_DEFAULT_LO, uint16_t fsk = 0, ...): fft_dominant_frequency(lrms, rrms, hi, lo, fsk, 0)
94 {
95 if (!fsk) return;
96
97 va_list freqs;
98 va_start(freqs, fsk);
99 int16_t freq = static_cast<int16_t>(va_arg(freqs, int));
100 int16_t *freqp = &_frequencies->left();
101 while (freq) { *freqp++ = freq; freq = static_cast<int16_t>(va_arg(freqs, int)); }
102 va_end(freqs);
103 }
104
106 FFTStatus(const FFTStatus &other) { memcpy(static_cast<void *>(this), static_cast<const void *>(&other), GU_SIMPLE_WHITEBOARD_BUFSIZE); }
107
109 FFTStatus &operator=(const FFTStatus &other) { memcpy(static_cast<void *>(this), static_cast<const void *>(&other), GU_SIMPLE_WHITEBOARD_BUFSIZE); return *this; }
110
112 static int num_frequencies() { return FFT_DOMINANT_NUMFREQ; }
113
114#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
116 FFTStatus(const std::string &names) { from_string(names); }
117
119 FFTStatus(const char *names) { from_string(std::string(names)); }
120
122 std::string description()
123 {
124 using namespace std;
125 using namespace guWhiteboard;
126
127 ostringstream ss;
128 ss << rms().left() << "/" << rms().right() << ", ";
129 ss << fsk().hi_freq() << ":" << fsk().lo_freq() << "@" << fsk().hi_percentage();
130 unsigned n = FFTStatus::num_frequencies();
131 for (unsigned i = 0; i < n; i++)
132 {
133 const fft_frequency_level_pair &f = frequencies(i);
134 if (!f.left() && !f.right())
135 break;
136 ss << ", " << f.left() << "+" << f.right();
137 }
138 return ss.str();
139 }
140
142 void from_string(const std::string &str)
143 {
144 using namespace std;
145 using namespace guWhiteboard;
146 vector<string> components = components_of_string_separated(str, ',', /*trim*/ true);
147 size_t n = components.size();
148 if (!n) return;
149
150 /*
151 * get RMS left + right values
152 */
153 vector<string> rmsvals = components_of_string_separated(components[0], '/', /*trim*/ true);
154 size_t k = rmsvals.size();
155 if (!k) return;
156 rms().set_left(static_cast<int16_t>(atoi(rmsvals[0].c_str())));
157 if (k < 2) return;
158 rms().set_right(static_cast<int16_t>(atoi(rmsvals[1].c_str())));
159
160 /*
161 * get FSK high and low frequencies and percentage values
162 */
163 if (n < 2) return;
164 vector<string> fskvals = components_of_string_separated(components[1], ':', /*trim*/ true);
165 k = rmsvals.size();
166 if (!k) return;
167 fsk().set_hi_freq(static_cast<int16_t>(atoi(fskvals[0].c_str())));
168 if (k < 2) return;
169 fsk().set_lo_freq(static_cast<int16_t>(atoi(fskvals[1].c_str())));
170 vector<string> percentvals = components_of_string_separated(fskvals[1], '@', /*trim*/ true);
171 k = percentvals.size();
172 if (k > 1) fsk().set_hi_percentage(static_cast<int16_t>(atoi(percentvals[1].c_str())));
173
174 /*
175 * get dominant frequencies and their levels
176 */
177 for (unsigned i = 2; i < n; i++)
178 {
179 vector<string> freqvals = components_of_string_separated(components[i], '+', /*trim*/ true);
180 k = freqvals.size();
181 if (!k) break;
182 fft_frequency_level_pair &frequency = frequencies(i-2);
183 frequency.set_left(static_cast<int16_t>(atoi(freqvals[0].c_str())));
184 if (k > 1) frequency.set_right(static_cast<int16_t>(atoi(freqvals[1].c_str())));
185 if (!frequency.left() && !frequency.right())
186 break; // if both are zero, we are done
187 }
188 }
189#endif // WHITEBOARD_POSTER_STRING_CONVERSION
190 };
191}
192
193#pragma clang diagnostic pop
194
195#endif // FFTStatus_DEFINED
Container for RMS levels and dominant frequencies.
Definition: FFTStatus.hpp:84
FFTStatus & operator=(const FFTStatus &other)
copy assignment operator
Definition: FFTStatus.hpp:109
FFTStatus()
default constructor
Definition: FFTStatus.hpp:87
FFTStatus(const FFTStatus &other)
copy constructor
Definition: FFTStatus.hpp:106
FFTStatus(const char *names)
const char *constructor
Definition: FFTStatus.hpp:119
FFTStatus(const std::string &names)
string constructor
Definition: FFTStatus.hpp:116
std::string description()
convert to a string
Definition: FFTStatus.hpp:122
FFTStatus(int16_t lrms, int16_t rrms, uint16_t hi=320, uint16_t lo=200, uint16_t fsk=0,...)
alternate constructor
Definition: FFTStatus.hpp:93
static int num_frequencies()
number of frequencies that can be put on the wb
Definition: FFTStatus.hpp:112
void from_string(const std::string &str)
convert from a string
Definition: FFTStatus.hpp:142
FFTStatus(int16_t lrms, int16_t rrms, uint16_t hi, uint16_t lo, uint16_t fsk, va_list freqs)
designated constructor
Definition: FFTStatus.hpp:90
#define GU_SIMPLE_WHITEBOARD_BUFSIZE
message len (max)
/file APM_Interface.h
Main FFT Analysis Structure This structure contains all the components of the FFT analysis,...
fsk int16_t uint16_t uint16_t uint16_t fsk
fsk int16_t uint16_t uint16_t lo
fsk int16_t uint16_t hi
Frequency pair for a stereo channel This struct contains a single frequency pair (in Hz) for a stereo...
gusimplewhiteboard
#define FSK_DEFAULT_HI
default hi frequency for fsk
#define FSK_DEFAULT_LO
default lo frequency for fsk
#define FFT_DOMINANT_NUMFREQ
no wb -> don't register size