gusimplewhiteboard
wb_fft_frequencies.h
Go to the documentation of this file.
1
60#ifndef wb_fft_frequencies_h_
61#define wb_fft_frequencies_h_
62
63#ifdef __cplusplus
64#include <cstdarg>
65#endif
66
67#include <gu_util.h>
68
69#pragma clang diagnostic push
70#pragma clang diagnostic ignored "-Wvarargs"
71
72#ifdef GU_SIMPLE_WHITEBOARD_BUFSIZE
74#define FFT_DOMINANT_NUMFREQ ((GU_SIMPLE_WHITEBOARD_BUFSIZE - sizeof(struct rms_strength) - sizeof(struct fsk_frequencies)) / sizeof(struct fft_frequency_level_pair))
75#else
76#define FFT_DOMINANT_NUMFREQ 0
77#endif
78
79#define FSK_DEFAULT_HI 320
80#define FSK_DEFAULT_LO 200
81
88{
90 PROPERTY(int16_t, left)
92 PROPERTY(int16_t, right)
93
94#ifdef __cplusplus
96 fft_frequency_level_pair(int16_t l = 0, int16_t r = 0): _left(l), _right(r) {}
97#endif
98};
99
106{
108 PROPERTY(int16_t, left)
110 PROPERTY(int16_t, right)
111
112#ifdef __cplusplus
114 rms_strength(int16_t l = 0, int16_t r = 0): _left(l), _right(r) {}
115#endif
116};
117
126{
127 unsigned _hi_freq: 12;
128 unsigned _lo_freq: 12;
129 unsigned _hi_percentage: 7;
130 unsigned _unused_pad: 1;
131
132#ifdef __cplusplus
134 fsk_frequencies(uint16_t hi = FSK_DEFAULT_HI, uint16_t lo = FSK_DEFAULT_LO, uint16_t fsk = 0): _hi_freq(hi/2), _lo_freq(lo/2), _hi_percentage(fsk), _unused_pad(0) {}
135
137 uint16_t hi_freq() const { return _hi_freq * 2; }
138
140 uint16_t lo_freq() const { return _lo_freq * 2; }
141
143 uint16_t hi_percentage() const { return _hi_percentage; }
144
146 float hi_ratio() const { return static_cast<float>(_hi_percentage) / 100.f; }
147
149 void set_hi_freq(uint16_t hi = FSK_DEFAULT_HI) { _hi_freq = hi/2; }
150
152 void set_lo_freq(uint16_t lo = FSK_DEFAULT_LO) { _lo_freq = lo/2; }
153
155 void set_hi_percentage(uint16_t percent = 0) { _hi_percentage = percent; }
156
158 void set_hi_ratio(float r) { _hi_percentage = static_cast<unsigned>(100.f * r); }
159#endif
160};
161
162
171{
174
175
177
178
180
181#ifdef __cplusplus
182#if 0
192 fft_dominant_frequency(int16_t lrms, int16_t rrms, uint16_t hi, uint16_t lo, uint16_t fsk, va_list freqs): _rms(lrms, rrms), _fsk(hi, lo, fsk)
193 {
194 int16_t *freqp = &_frequencies->left();
195 const int16_t * const start = freqp;
196 int16_t freq = static_cast<int16_t>(va_arg(freqs, int));
197 while (freq) { *freqp++ = freq; freq = static_cast<int16_t>(va_arg(freqs, int)); }
198 const size_t n = static_cast<const size_t>(freqp - start);
199 if (n < FFT_DOMINANT_NUMFREQ/2)
200 {
201 freqp[0] = 0;
202 freqp[1] = 0;
203 }
204 }
205#endif
218 fft_dominant_frequency(int16_t lrms = 0, int16_t rrms = 0, uint16_t hi = FSK_DEFAULT_HI, uint16_t lo = FSK_DEFAULT_LO, uint16_t fsk = 0, ...): _rms(lrms, rrms), _fsk(hi, lo, fsk)
219 {
220 if (!rrms) return;
221
222 va_list freqs;
223 va_start(freqs, fsk);
224 int16_t freq = static_cast<int16_t>(va_arg(freqs, int));
225 int16_t *freqp = &_frequencies->left();
226 while (freq) { *freqp++ = freq; freq = static_cast<int16_t>(va_arg(freqs, int)); }
227 va_end(freqs);
228 }
229#endif
230};
231
232#pragma clang diagnostic pop
233
234#endif //#_wb_fft_frequencies_h_
Main FFT Analysis Structure This structure contains all the components of the FFT analysis,...
PROPERTY(struct rms_strength, rms) PROPERTY(struct fsk_frequencies
overall RMS levels
fsk int16_t uint16_t uint16_t uint16_t fsk
fsk int16_t uint16_t uint16_t lo
fsk int16_t uint16_t hi
fsk ARRAY_PROPERTY(struct fft_frequency_level_pair, frequencies, 0) fft_dominant_frequency(int16_t lrms=0
Array of frequency pairs ordered by level (strongest first.
fsk int16_t uint16_t uint16_t uint16_t _fsk(hi, lo, fsk)
Frequency pair for a stereo channel This struct contains a single frequency pair (in Hz) for a stereo...
PROPERTY(int16_t, left) PROPERTY(int16_t
left frequency in Hz (0 means not measured)
right fft_frequency_level_pair(int16_t l=0, int16_t r=0)
constructor with 0 Hz default values (C++ only)
FSK frequency pair and keying values This struct contains the main components of the FSK analysis.
uint16_t lo_freq() const
getter for the low frequency (C++ only)
unsigned _unused_pad
reserved for future use
float hi_ratio() const
convenience getter for the high to low FSK ratio (C++ only)
unsigned _lo_freq
low frequency (0..8191 Hz) divided by 2
void set_lo_freq(uint16_t lo=200)
setter for the low frequency FSK percentage (C++ only)
unsigned _hi_freq
high frequency (0..8191 Hz) divided by 2
unsigned _hi_percentage
FSK hi percentage (0..100 %)
uint16_t hi_freq() const
getter for the high frequency (C++ only)
uint16_t hi_percentage() const
getter for the high frequency FSK percentage (C++ only)
void set_hi_freq(uint16_t hi=320)
setter for the high frequency FSK percentage (C++ only)
void set_hi_ratio(float r)
convenience setter for the high to low FSK ratio (C++ only)
void set_hi_percentage(uint16_t percent=0)
setter for the high frequency FSK percentage (C++ only)
fsk_frequencies(uint16_t hi=320, uint16_t lo=200, uint16_t fsk=0)
constructor with default hi and low frequencies (C++ only)
RMS levels for a stereo channel pair This struct contains the RMS (root mean square) level measured f...
right rms_strength(int16_t l=0, int16_t r=0)
constructor with zero strength default values (C++ only)
PROPERTY(int16_t, left) PROPERTY(int16_t
RMS level for the left channel.
#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