write a C program that will generate a.WAV file with DTMF tones based on user input. DTMF tonesare the tones generated by telephone systems, to dial numbers. Eachdigit of a dial-pad has a specific tone, which is generated byadding signals of 2 different frequencies together. The figurebelow shows the 2 frequencies for each of the digits plus* (star)and # (pound). For example, for the number “6”, you would add a1477Hz signal and a 770Hz signal (it’s row and column headers).
In order to “scan in” the arguments from the command line, thefunction header for main should look like this:
int main(int argc, char* argv[]) where argcwill be initialized with the number of arguments (the program name+ the wavefile name + the toneLength + the phone number = 4arguments total), and argv[] is a string array (an array ofstrings) containing pointers to each of the arguments. This meansthat for the example above in 4.1, the value of argv[2] would be apointer to the string containing “0.5”. You can use the atof()standard library function to convert the string to a floating pointnumber.
6. Your code should validate the phone number, to make sure itonly contains numbers between 0-9, #, * or -. The – (dash) wouldsimply insert a tone with no amplitude (quiet) for the duration ofthat tone. If the validation fails, return -1.
7. Your code should validate that the toneLength is between 0.1and 1.0 seconds. If the validation fails,
return -1. create file using the filename from the argumentargv[1].
9. Next, you should allocate enough memory with the mallocfunction, to hold the header of the wave file.
You can use the sizeof operator with the struct of the WAVEFILEheader to figure out the size required. Notice that the structureWAVEFILE is provided in wavefile.h!
10. Next, you should allocate enough memory with the
malloc function to hold all of the audio samples. For this,you’ll need to calculate the total size using
the number of bytes for each sample, the sample rate, the tonelength, and the length of the phone-number string (the number ofdigits to dial).
11. The samples will be the DTMF tones, which are calculated byadding the frequencies from the figure
above, for each of the digits. You can use the following formulato calculate the sample values: sampleValue = AMPLITUDE *(sin(sampleNum * freq1 * 2 * 3.14159 / SAMPLE_RATE)+sin(sampleNum *freq2 * 2 * 3.14159 / SAMPLE_RATE)); where the AMPLITUDE is definedas 16382, the SAMPLE_RATE is defined as 44100, and each sample isstored using 2 bytes. These samples should be gathered in a forloop that has sampleNum going
from 0 to (SAMPLE_RATE * toneLength) – 1. Once each sample iscalculated, it can be added to the
allocated memory.
12. Next, you’ll need to write the header (see appendix) to theoutput wave file, and then afterwards, write the samples. You canuse the fwrite function to write the header and the samples fromthe allocated memories, to the file (the header and the samples canbe done with separate fwrite function calls). Open the file usingthe fopen function, and use the “wb” option (write binary). Then wecan use fwrite with the pointers to the previously allocatedmemories.
13. Finally, close the file. If everything was successful,return 0 from main.
14. Running the program should generate the .wav file with thecorresponding DTMF audio tones.
Expert Answer
Answer to write a C program that will generate a .WAV file with DTMF tones based on user input. DTMF tones are the tones generated…