Goto: [ Program Documentation ]
// // Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu> // Creation Date: Wed Apr 30 13:01:29 GMT-0800 1997 // Last Modified: Sun May 25 00:09:05 GMT-0800 1997 // Last Modified: Thu Aug 26 15:04:28 PDT 2004 (added Option class) // Filename: ...sig/doc/examples/sig/sigfile/silence/silence.cpp // Syntax: C++; sig // // Description: make a blank soundfile. // #include "sigAudio.h" #ifndef OLDCPP #include <iostream> using namespace std; #else #include <iostream.h> #endif void exitUsage(const char* command); int main(int argc, char* argv[]) { Options options; options.define("s|samples=i:44100", "number of samples to generate"); options.define("sec|seconds=d:1.0", "duration of sound if no -s option"); options.define("r|srate|sr=d:44100", "sampling rate of output sound"); options.define("c|channels|chan=i:1", "number of channels in output sound"); options.process(argc, argv); if (options.getArgCount() != 1) { exitUsage(options.getCommand()); } int srate = (int)options.getDouble("srate"); int numSamples = options.getInteger("samples"); if (!options.getBoolean("samples") && options.getBoolean("seconds")) { double seconds = options.getDouble("seconds"); numSamples = (int)(seconds * srate + 0.5); } if (numSamples < 1) { numSamples = 1000; } int channels = options.getInteger("channels"); if (channels < 1) { channels = 1; } SoundHeader header; header.setHighMono("This is a blank soundfile."); header.setChannels(channels); header.setSrate(srate); // Elements: Constant constant(0); SoundFileOut outsound(options.getArg(1), header); // Connections: int i; for (i=0; i<channels; i++) { outsound.connect(constant, i, 0); } Action action; action.tick(outsound, numSamples); return 0; } void exitUsage(const char* command) { cout << endl; cout << "Generates a blank soundfile with specified length." << endl; cout << endl; cout << "Usage: " << command << " [-s|--sec] [-r] [-c] outsound" << endl; cout << endl; cout << " -s sample_count = make outsound sample_count samples long\n"; cout << " --sec seconds = make outsound specified seconds long\n"; cout << " -r sampling_rate = specify outsound sampling rate\n"; cout << " -c channels = specify outsound channel count\n"; cout << endl; exit(1); } // md5sum: 16ac3d8a48c311055bcc93dfa8029483 silence.cpp [20050403]