/* This program is derived from Chris Vaill's normalize program and has been modified to use the Audio File Library for file reading and audio data conversion. Copyright (C) 2001, Silicon Graphics, Inc. Copyright (C) 1999-2001, Chris Vaill This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* power.c Calculate the power and peak amplitudes of an audio file. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif struct smooth { double *buf; int length, start, n; }; static double get_smoothed_data (struct smooth *s) { int i; double smoothed; smoothed = 0; for (i = 0; i < s->n; i++) smoothed += s->buf[i]; smoothed = smoothed / s->n; return smoothed; } void print_power (char *filename); int main (int argc, char **argv) { int i; if (argc < 2) { fprintf(stderr, "usage: %s filename [more filenames...]\n", argv[0]); exit(EXIT_FAILURE); } for (i=1; i= frameCount) { winEnd = frameCount; lastWindow = TRUE; } afReadFrames(file, AF_DEFAULT_TRACK, frames, windowSize); for (c=0; c maxSample) maxSample = sample; if (sample < minSample) minSample = sample; } } /* Compute power for each channel. */ for (c=0; c maxpow) maxpow = pow; } else { powsmooth[c].n++; } } winStart += windowSize; } while (!lastWindow); for (c = 0; c < channelCount; c++) { pow = get_smoothed_data(&powsmooth[c]); if (pow > maxpow) maxpow = pow; } free(sums); free(frames); for (c=0; c