本文整理汇总了C++中WaveFile::printHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ WaveFile::printHeader方法的具体用法?C++ WaveFile::printHeader怎么用?C++ WaveFile::printHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WaveFile
的用法示例。
在下文中一共展示了WaveFile::printHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Check input arguments
if (argc != 3) {
cout << "Incorrect number of arguments." << endl;
cout << "Usage: " << argv[0] << " <source file> <target file>" << endl;
}
// Store starting time
time_t startTime;
time(&startTime);
// Open the input file
ifstream inputFile(argv[1], ios::in | ios::binary | ios::ate);
WaveFile inputWave;
if (inputFile.is_open())
{
// Read header data
inputWave.read(inputFile);
// Print out the header
inputWave.printHeader();
// Check the header values to make sure they conform to what is expected
int error = inputWave.check();
if (error > 0)
{
// Exit the program if the check failed
return error;
}
// Open the output file, disreguarding the contents of it
ofstream outFile(argv[2], ios::out | ios::binary | ios::trunc);
if (outFile.is_open())
{
// Rewrite the header
inputWave.writeHeader(outFile);
// Find maximum amplitude
cout << "Finding maximum amplitude..." << endl;
short maximumSample = inputWave.getMaxSample(inputFile);
// Output the amplitude of the sine wave that will be added
cout << "Sine Wave Amplitude: " << maximumSample/2 << endl;
// Add sine wave
// Iteration number is number of samples / number of channels
cout << "Adding sine wave..." << endl;
unsigned int iterationNumber = 0;
while (inputWave.hasMoreSamples())
{
// Expicit casting to double for time calculation
double t = ((double)iterationNumber) / ((double)inputWave.header.SampleRate);
// Calculation of sine wave sample, should not overflow
// Half of maximum amplitude * sine wave at 2500 Hz
short sineWave = (maximumSample/2) * sin(2.0*3.14*2500.0*t);
// Loop through the channels
for (int i = 0; i < inputWave.header.NumChannels; i++)
{
// Read new sample in
short sample = inputWave.getNextSample(inputFile);
// Calculation of new sample, can overflow
short newSample = addOverflow(sineWave, sample);
// Write new sample to output file
inputWave.writeSample(newSample, outFile);
}
iterationNumber++;
}
// Close the files
inputFile.close();
outFile.close();
}
else
{
// Could not open output file
cerr << "Unable to open: " << argv[2] << endl;
return 1;
}
}
else
{
// Could not open input file
cerr << "Unable to open: " << argv[1] << "." << endl;
return 1;
}
cout << "Done." << endl;
// Store ending time
time_t endTime;
time(&endTime);
// Calculate time taken
double seconds = difftime(endTime, startTime);
//.........这里部分代码省略.........