MCPcopy Create free account
hub / github.com/awawa-dev/HyperHDR / analyzeSpectrum

Method analyzeSpectrum

sources/base/SoundCapture.cpp:191–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191bool SoundCapture::analyzeSpectrum(int16_t soundBuffer[], int sizeP)
192{
193 if (!_isRunning)
194 return false;
195
196 QMutexLocker locker(&soundBufferGuard);
197
198 int16_t resolutionP = 10;
199 int16_t sec[SOUNDCAP_RESULT_RES] = {
200 2 * 2, // 0-86
201 4 * 2, // 86-258
202 6 * 2, // 258-516
203 12 * 2, // 516-1032
204 24 * 2, // 1032-2064
205 48 * 2, // 2064-4128
206 48 * 2, // 4128-6192
207 512 // 6192-11025
208 };
209
210 int noSound = 0;
211 for (noSound = 0; noSound < pow(2, resolutionP); noSound++)
212 if (soundBuffer[noSound] < -8 || soundBuffer[noSound] > 8)
213 break;
214
215 if (noSound >= pow(2, resolutionP))
216 noSound = 1;
217 else
218 noSound = 0;
219
220 if ((1 << sizeP) > SOUNDCAP_N_WAVE)
221 return false;
222
223 memset(imgBuffer, 0, sizeof(imgBuffer));
224 resultFFT.ClearResult();
225
226 if (noSound == 0)
227 {
228 if (fix_fft(soundBuffer, imgBuffer, resolutionP, 0) < 0)
229 return false;
230
231 for (int i = 0, limit = pow(2, resolutionP - 1), samplerIndex = 0, samplerCount = 0; i < limit; i++)
232 {
233 uint32_t res = std::sqrt(((int32_t)soundBuffer[i]) * soundBuffer[i] + ((int32_t)imgBuffer[i]) * imgBuffer[i]);
234
235 resultFFT.AddResult(samplerIndex, res);
236 samplerCount++;
237
238 if (samplerIndex < SOUNDCAP_RESULT_RES - 1)
239 {
240 if (samplerCount >= sec[samplerIndex])
241 {
242 samplerCount = 0;
243 samplerIndex++;
244 }
245 }
246 }
247 }
248

Callers 2

runMethod · 0.80
runMethod · 0.80

Calls 3

ClearResultMethod · 0.80
AddResultMethod · 0.80
SmoothMethod · 0.80

Tested by

no test coverage detected