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, 21.06.2019 21:30
You need to write some code that responds to a text change in a jtextfield. how can you do that? create a class that implements the interface actionlistener and override the method textfieldchanged create a class that extends the superclass actionlistener and override the method actionperformed create a class that implements the interface actionlistener and override the method actionperformed create a class that extends the superclass actionlistener and override the method textfieldchanged
Answers: 2
question
Computers and Technology, 22.06.2019 10:30
Auniversity wants to install a client-server network. which feature do you think is important for them as they set up the network? sending email blocking multiple people to use the same file low security low set up cost limited access to files
Answers: 1
question
Computers and Technology, 23.06.2019 06:30
On early television stations, what typically filled the screen from around 11pm until 6am? test dummies test patterns tests testing colors
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
What are some settings you can control when formatting columns?
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
Social Studies, 21.05.2021 19:50
question
Spanish, 21.05.2021 19:50
Questions on the website: 13722363