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 16:00
Why should characters such as / \ " ' * ; - ? [ ] ( ) ~ ! $ { } < > # @ & | space, tab, and newline be avoided in file names?
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Match the following. 1. show grouping of word processing tasks that can be performed quick access toolbar 2. shortcut location for commonly used elements scroll bars 3. organized commands used to modify documents ribbon 4. used to align and measure content in a word screen zoom bar 5. vertical and horizontal bars that are used to navigate through a document contextual tabs 6. displays the name of the document in use ruler 7. allows users to enlarge or shrink a visual of a word document title bar
Answers: 2
question
Computers and Technology, 23.06.2019 00:10
Write a function so that the main0 code below can be replaced by the simpler code that calls function mphandminutes tomiles0. original main0 int main) l double milesperhour-70.0; double minutestraveled = 100.0; double hourstraveled; double milestraveled; hourstraveled = minutestraveled / 60.0; milestraveled = hourstraveled * milesperhour; cout < "miles" 2 using namespace std; 4 /* your solution goes here/ 6 int maino 1 test passed 7 double milesperhour 70.0 all tests passed 8 double minutestraveled 100.0; 10 cout < < "miles: " < < mphandminutestomiles(milesper-hour, minutestraveled) < < endl; 12 return 0; 13
Answers: 1
question
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
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
Mathematics, 11.02.2021 21:50
Questions on the website: 13722359