// // Programmer: Craig Stuart Sapp // Creation Date: Fri Aug 18 21:51:09 PDT 2000 // Last Modified: Fri Aug 18 21:51:14 PDT 2000 // Filename: ...sig/doc/examples/all/pitchdelac/pitchdelac.cpp // Syntax: C++; sig // // Description: This program is an implementation of a pitch // detection algorithm by Patrico de la Cuadra // // #include "sig.h" // function declarations: void checkOptions (Options& opts); void example (void); void usage (const char* command); void analyze (Array& result, Array* buffer); void fill (Array* buffer, SoundFileIn& insound); void printArray (int frame, const Array& anArray); // global interface variables double srate = 0; // the sampling rate of the input soundfile int framesize = 0; // the number of samples in a primary frame int harmonics = 0; // the number of harmonics to analyze int quietQ = 0; // suppress status printing while program is running //////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv[]) { Options options(argc, argv); checkOptions(options); SoundFileIn insound(options.getArgument(1)); srate = insound.getSrate(); double frames = (double)insound.getSamples() / framesize; int framecount; if ((int)frames - frames == 0.0) { framecount = (int)frames; } else { framecount = (int)frames + 1; } Array buffer[harmonics]; for (int j=0; j result; result.setSize(framesize/harmonics + 1); result.allowGrowth(0); result.zero(); for (int i=0; i* buffer, SoundFileIn& insound) { double sample; for (int i=0; i& result, Array* buffer) { Block signal; Block transform[harmonics]; int i, j; for (i=0; i& anArray) { cout << "\n# FRAME = " << frame << "\n"; for (int i=0; i 10000) { cout << "Error: frame size is too large: " << framesize << endl; exit(1); } if (harmonics < 1) { cout << "Error: harmonic count is too small: " << harmonics << endl; exit(1); } if (harmonics > 30) { cout << "Error: harmonic count is too large: " << harmonics << endl; exit(1); } if (framesize/harmonics < 10) { cout << "Error: too many harmonics for the given framesize" << endl; exit(1); } quietQ = opts.getBoolean("quiet"); } ////////////////////////////// // // example -- example usage of the program. // void example(void) { cout << " To be written. \n" << endl; } ////////////////////////////// // // usage -- explaination about the program and its options. // void usage(const char* command) { cout << "\nUsage: " << command << " [-f framesize][-h harmonics] soundfile\n"; cout << " Determines pitch in a soundfile.\n"; cout << " Options are:\n"; cout << " -f framesize = size of primary analysis frame\n"; cout << " -h harmonics = number of analysis frames per block\n"; cout << " -o frameoverlap = option not active\n"; cout << " --options a list of all options.\n"; cout << endl; }