// // Programmer: Craig Stuart Sapp // Creation Date: Thu Mar 30 23:37:15 GMTDT 2006 // Last Modified: Thu Mar 30 23:37:21 GMTDT 2006 // Filename: ...soundfile/examples/monoclick.cpp // Syntax: C++ // // Description: Adds all channels in the input sound file and writes // a sound file with the summation of all channels. // Amplitude scaling factor can be given to prevent // clipping if necessary. // #include "soundfile.h" #include #ifndef OLDCPP #include #include using namespace std; #else #include #include #endif void getClickTimes(Array& clicktimes, const char* filename); ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { Options options; options.define("a|amp=d:1.0", "amplitude scaling factor"); options.define("c|click-amp=d:0.15","click track amplitude scaling factor"); options.process(argc, argv); double clickamp = options.getDouble("click-amp"); const char* clicktrack = options.getArg(1); const char* outputname = options.getArg(2); Array clicktimes; getClickTimes(clicktimes, clicktrack); SoundHeader header; header.setHighMono(); SoundFileWrite outsound(outputname, header); int i; double clicksample; for (i=0; i 44) { clickstatus = 0; } } else { clicksample = 0.0; } outsound.writeSampleDouble(clicksample); } return 0; } ////////////////////////////// // // getClickTimes -- // void getClickTimes(Array& clicktimes, const char* filename) { ifstream clickfile(filename); if (!clickfile.is_open()) { cerr << "Error: cannot open file " << filename << endl; } long input; clicktimes.setSize(100000); clicktimes.setGrowth(100000); clicktimes.setSize(0); clickfile >> input; while (!clickfile.eof()) { clicktimes.append(input); clickfile >> input; } }