// // Programmer: Craig Stuart Sapp // Creation Date: Wed Jan 23 21:10:32 PST 2002 // Last Modified: Sun Feb 3 11:08:04 PST 2002 (updated for soundfile 2.0) // Filename: ...soundfile/examples/multi2mono.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 amp = options.getDouble("amp"); double clickamp = options.getDouble("click-amp"); const char* inputname = options.getArg(1); const char* clicktrack = options.getArg(2); const char* outputname = options.getArg(3); Array clicktimes; getClickTimes(clicktimes, clicktrack); SoundFileRead insound(inputname); SoundHeader header = insound; header.setChannels(2); SoundFileWrite outsound(outputname, header); int i, channel; double newsample; double clicksample; for (i=0; i 44) { clickstatus = 0; } } else { clicksample = 0.0; } outsound.writeSampleDouble(clicksample); outsound.writeSampleDouble(amp * newsample/insound.getChannels()); insound.incrementSample(); } 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; } }