Processing the Audio Data
The default implementation of DoProcessOutput begins by retrieving a pointer to a valid WAVEFORMATEX structure, exactly like was done in AllocateStreamingResources. It then uses the information in that structure to calculate the number of samples in the input buffer waiting to be processed. The following code is from the default implementation:
// Get a pointer to the valid WAVEFORMATEX structure // for the current media type. WAVEFORMATEX *pWave = ( WAVEFORMATEX * ) m_mtInput.pbFormat; // Calculate the number of samples to process. DWORD dwSamplesToProcess = (*cbBytesProcessed / pWave->nBlockAlign) * pWave->nChannels;
Then, the code inspects the wBitsPerSample member to determine the bit depth of the audio. This value is used in a switch statement to provide separate processing for 8-bit and 16-bit audio.
Differences Between 8-bit and 16-bit Audio
There are important differences between 8-bit and 16-bit audio. Therefore, the processing routines to create the echo effect are different. The two formats differ in the following ways:
- Each format has a different sample size: 8-bit samples each occupy one byte of memory, while 16-bit samples each occupy two bytes.
- Each format represents the audio amplitude differently. 8-bit audio is represented by an unsigned integer with a range from 0 to 255; a value of 128 represents silence. 16-bit audio is represented by a signed integer with a range from -32768 to 32767; a value of zero represents silence.
While the process of creating the echo effect is fundamentally identical for each format, the details must differ slightly.