// This looks at a number of periods of a given frequency starting at a certain time in the audio // and returns an intensity value. // No phase adjustment here, so you have to call this twice to get meaningful (complex) results. srecord noeq SumOfVibrations(IAudioSample sample, int channel, double start, double freq, int periods) { double period, end; double rawSum() { period = sample.sampleRate()/freq; double sum = 0, t = start; for p to periods: { // Subtract an expected trough from an expected neighboring peak and add to overall sum. // Nota bene: Trough and peak have the same area (=length), so this is basically a Haar-like feature! // By the use of which we automatically get around nasty complications like DC offsets in the input data. sum += sample.sampleSum(channel, t, t+period/2) - sample.sampleSum(channel, t+period/2, t+period); t += period; } end = t; ret sum; } // alternate calculation adjusted for duration double sumDividedByDuration() { ret rawSum()/(end-start); } }
Began life as a copy of #1032977
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1032979 |
Snippet name: | SumOfVibrations |
Eternal ID of this version: | #1032979/1 |
Text MD5: | ac47bcb9d7459181a1f1bce61f9be28b |
Author: | stefan |
Category: | javax / audio analysis |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-11 07:03:08 |
Source code size: | 1124 bytes / 28 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 139 / 163 |
Referenced in: | [show references] |