| 189 | } |
| 190 | |
| 191 | bool 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 |
no test coverage detected