subject

The sample rate will be 44100 samples per second, 16 bits per sample, stereo. You will allocate a 2-D array to hold the stereo data; the 2-D array will have 2 columns (1 for the left channel, and 1 for the right channel) and enough rows to hold the audio samples for left and right channeles. Your program will use the pointer-to-pointer-to short int from the alloc()'d memory as an argument to a subroutine to fill in the audio data in the 2-D array. Your program will use a structure for the wav file header and fill in the appropriate header values. Your program will write out the header using a single fwrite(), and then write out the audio data using a loop. If your program is correct, when you double-click on the WAVE file created by your program, your computer's default audio app will open the file and play it through your computer's speakers. 1) Define a structure that will hold a wav file header. struct header char chunkid[4]; unsigned int chunksize; char format[4]; char subchunklid[4]; unsigned int subchunklsize; unsigned short int audioformat; unsigned short int numchannels; unsigned int samplerate; unsigned int byterate; unsigned short int blockalign; unsigned short int bitspersample; etc.. etc.. Be careful to use the data types with the exact number of bytes in each field of the header 2) Declare a variable of type struct header, e. g. struct header wh. 3) In your main program, prompt the user for a length (float) of audio in seconds, and for the frequencies in Hz for the left and right channels. Audio data is signed, not unsigned. 4) Now fill-in all of the fields of the way header wh. You have all the info that you will need, The wh. chunkid[ ] should hold 'R' T'F''F. There are many correct ways to fill in the characters in the header. For example, to write RIFF into the field wh. chunkid, you could use sprintf(wh. chunkid,"%s","RIFF"); but this actually writes 5 bytes into wh. chunkid, the 5th character being the string termination character. So you should use strncpy(wh. chunkid,"RIFF",4). When you write "fmt" (important: this must have the blank space after fmt) to wh. subchunklid, you could also use strncpy(wh. subchunklid,"fmt".4); . The wav file will contain 16-bit audio data (short int), and it will be a stereo audio file at 44100 samples per second. So wh. bitspersample=16; blockalign=etc. etc... 5) Construct a 2-D array of short int variables of dimension sufficient to hold all of the left channel of the stereo audio data, and all of the right-channel of audio data. The number of rows will be the number of audio samples required for the audio length selected by the user. The number of columns will be 2, one for the left channel value and one for the right channel value. Make sure that you correctly calculate how many audio samples are required in the left and right channel vectors. To construct the 2-D array, follow the steps in the book in Chapter 11 and in the lectures. It is a 3-step process. Declare a pntr-pntr-short int. Malloc() a 1-D array of pntr- short int's to hold the memory addresses of the rows of the matrix. Then use a loop to malloc(the memory for each row of the matrix 6) Your main program will then call a subroutine that fills in the audio data with sinusoid waves whose frequencies are those selected by the user. This subroutine will receive (as an argument) the pointer-to-pointer to short int audio-data array. (Note: you calloc()'d a ep 3). The name of this array is a pointer-to-pointer-to-short int. It holds the memory address of the start of the cell of the 1-D array of pointers to the rows of the 2-D array. Therefore, your subroutine can access the pointers to the start of each row, and therefore access the values in each row. See previous programming assignments for more information. 7) Open a file called tones2.wav in the directory from which your program is executed. Open it in mode "wb". 8) Write out the wav file header using a single fwrite(). 9) Finally, write out the audio data. In a stereo wav file, the data from the left and right channels are interleaved; first one 2-byte sample for the left channel, then one 2-byte for the right channel, then one 2-byte for the left channel, etc.. Use a for-loop to write out these interleaved 2-byte samples from the 2-D array. 10) fclose() the wav file. 11) free the allocated memory

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:20
Amedian in the road will be marked with a white sign that has a black arrow going to the left of the median. true false
Answers: 1
question
Computers and Technology, 22.06.2019 21:40
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
Companies that implement and apply an information system effectively can create
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Into what form does the barcode reader convert individual bar patterns?
Answers: 1
You know the right answer?
The sample rate will be 44100 samples per second, 16 bits per sample, stereo. You will allocate a 2-...
Questions
question
Physics, 30.11.2021 05:30
question
Mathematics, 30.11.2021 05:30
question
Computers and Technology, 30.11.2021 05:30
Questions on the website: 13722362