can't understand the question on my assignment

The task given is:

You are to write a C++ program that reads in a WAVE file, reverses the audio samples, and writes the
result to a new WAVE file. Specifically, the program should be called reverse, and takes exactly two
command line arguments:
reverse <in file> <out file>
where <in file> is the name of an existing WAVE file to read in, and <out file> is the name of the WAVE

file to write (which may or may not exist - if it does exist, it should be overwritten). For example, if the user
runs the program from a directory that contains the file cs225.wav, then invoking
reverse cs225.wav 522sc.wav
will read in the WAVE file cs225.wav and write the file 522sc.wav, whose audio data is a reverse of the
original file.
In addition, your program should handle failure cases gracefully. There are several cases to consider.
First, if the user specifies no command line arguments:
reverse
then your program should print out the usage message
usage:
reverse <wave in> <wave out>
where:
<wave in> -- input wave file
<wave out>-- output wave file
(exactly in this form). In this case, the program should exit with a return value of 0. Second, if the user
specifies a number of command line arguments other than zero or two, say
reverse cs225.wav
then the program should print out the error message
incorrect number of arguments

Here my doubt
1.Does it mean i need have to do int main(int argc, char** argv)? or use getline or std::cin for the task.

if using int main(int argc, char** argv), the "reverse cs225.wav" is 2 command not 1 command?

if using use getline or std::cin, it is possible to store the input into char** argv, so i can don't need handle tab or multiple space.

2.the reverse <in file> <out file> the "<out file>" is user given or auto reverse the filename?

Last edited on
Yes you need to use command line parameters => int main(int argc, char** argv).
The count of argc should be 3. The first is the name of the program or nullptr, argv[1] and argv[2] contain the file names.

Start by implementing the opening of the files error handling.
the "<out file>" is user given or auto reverse the filename?


takes exactly two command line arguments: reverse <in file> <out file>


The exercise doesn't say how to reverse the audio. Maybe you can ask your teacher.
Well, since WAV PCM is uncompressed, it actually isn't too hard to just read the samples into an std::vector and reverse that. When I manipulated WAV files I would actually split each part (stereo left and right) into their own std::vector, and then recombine them.

If Clarence is doing this from scratch, the hardest part is getting the file format down. WAV is easy enough to decode/encode yourself, but you're still gonna need to do some research as to the exact specifications of the WAV format.
Use the types in <cstdint>.
http://soundfile.sapp.org/doc/WaveFormat/

I have not used it, but this seems like an easy-to-use library if you don't want to write everything from scratch yourself.
https://github.com/adamstark/AudioFile
Last edited on
Topic archived. No new replies allowed.