// // Programmer: Craig Stuart Sapp // Creation Date: Thu Feb 14 07:20:44 PST 2002 // Last Modified: Thu Feb 14 07:20:48 PST 2002 // Filename: ...soundfile/examples/sndpower.cpp // Syntax: C++ // // Description: Calculate the average signal power for given durations // #include "soundfile.h" #include #include #include #include int main(int argc, char** argv) { Options options; options.define("a|average=i:10000", "Number of samples to average over"); options.define("s|start=i:0", "Starting sample"); options.define("n|count=i:-1", "Number of analyses to make"); options.process(argc, argv); if (options.getArgCount() == 0) { cout << "Usage: " << options.getCommand() << " filename" << endl; exit(1); } SoundFileRead soundfile(options.getArg(1)); int chunk = options.getInteger("average"); int start = options.getInteger("start"); int totalframes = options.getInteger("count"); if (totalframes <= 0) { totalframes = (soundfile.getSamples() - start)/chunk + 1; } cout << "; Filename = " << options.getArg(1) << "\n"; cout << "; Samples = " << soundfile.getSamples() << "\n"; if (start != 0) { cout << "; Starting sample = " << start << "\n"; } cout << "; Averaging size = " << chunk << " samples" << "\n"; cout << "; Total frames = " << totalframes << "\n"; cout << "; frame RMS Db\n"; double sum, value, db, rms; int i, j, channel; for (i=0; i