Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // read a bunch of samples:
- int samples[SAMPLES];
- for (int i=0; i<SAMPLES; i++) {
- int sample = 0;
- while ((sample == 0) || (sample == -1) ) {
- sample = I2S.read();
- }
- // convert to 18 bit signed
- sample >>= 14;
- samples[i] = sample;
- }
- // ok we hvae the samples, get the mean (avg)
- float meanval = 0;
- for (int i=0; i<SAMPLES; i++) {
- meanval += samples[i];
- }
- meanval /= SAMPLES;
- //Serial.print("# average: " ); Serial.println(meanval);
- // subtract it from all sapmles to get a 'normalized' output
- for (int i=0; i<SAMPLES; i++) {
- samples[i] -= meanval;
- //Serial.println(samples[i]);
- }
- // find the 'peak to peak' max
- float maxsample, minsample;
- minsample = 100000;
- maxsample = -100000;
- for (int i=0; i<SAMPLES; i++) {
- minsample = min(minsample, samples[i]);
- maxsample = max(maxsample, samples[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement