[Solved] How to detect audio transients in iOS


There are a couple of simple basic ideas you can put to work here.

First, take the input audio and divide into small sized buckets (on the order of 10’s on milliseconds). For each bucket compute the power of the samples in it by summing the squares of each sample value.

For example say you had 16 bit samples at 44.1 kHz, in array called s. One second’s worth of data would be 44100 samples. A 10 msec bucket size would give you 441 samples per bucket. To compute the power you could do this:

float power = 0;
for (int i = 0; i < 441; i++) {
  float normalized = (float)s[i] / 32768.0f;
  power = power + (normalized * normalized);
}

Once you build an array of power values, you can look at relative changes in power from bucket to bucket to do basic signal detection.

Good luck!

1

solved How to detect audio transients in iOS