Background
Audio data from Usb audio device(input)need to be play back by system speaker
Detail
1) audio data format is 8000Hz, 16bits,mono
2) usb audio driver capture the audio datafrom usb audio device
3) usb audio driver transfer the audio datato directshow
4) directshow transfer the audio data toaudio driver
5) audio driver convert the format frommono to stero and convert sampling rate from 8000Hz to 44100Hz by hardware
Issue
1) There is some delay, more than 1s
2) Voice not smoothly
Analyze
1) in the audio path, there are 3 typesbuffers at least.
A: Usb audiodriver has the buffer to fill with the raw data from usb audio device, sizeis512Bytes
B: Directshowhas buffers to fill the raw data for transfer it from usb audio driver to audiodriver, size is 4000Bytes*4
C: Audio driverhas buffer(DMA buffer) to fill the raw data from directshow, size is 0x1000*6
2) buffer size of directshow will generatethe delay, but the total is 4000Bytes = 250ms
3) glitch maybe generated from 2 cases
DMA buffer hasno enough data and filled with 0
DMA buffer wasoverrun, but no more data come and stop, till new data come and run again
Solution
1) reduce the DMA buffer size of audiodriver
Result:fail
Reason:DMA loop start/stop, DMA buffer overrun
2) reduce the directshow buffer size
Result:fail
Reason:there is no API to complete
3) fill directshow buffer with 0 before usbaudio driver start to capture raw data
Result:fail
Reason:DMA loop start/stop, DMA buffer overrun
4) fill directshow buffer with 0 before usbaudio driver satrt to capture raw data, and reduce the DMA buffer size of audiodriver
Result:alwaysOK, some time still fail
Reason:DMA loop start/stop, DMA buffer overrun
5) till now, may be we need to filldirectshow buffer immediately. One method can be immplemented.
Usingsoftware to convert the sampling, wave device can do that, so let directshowusing sample rate 44100, if we do this, usb audio driver will convert samplerate from 8000Hz to 44100Hz, and about 800Bytes raw data will be convert to4000Bytes 44100Hz format data, and audio driver will pass the hard ware convertsample rate.
This solution can solve the 2 issue, thissolution is same as reduce the DMA buffer size to it’s 1/5.5, so no obviousdelay, the software SRC will not stop if there is no enough data, so there isno glitch was heared.
6) redesign, do not using directshow, usbaudio driver transfer the data to audio driver directly.
Directshow inuser mode, and both the drivers in kernel mode, so there will be many timesmode exchange, at the same time, diretshow is a limit source in WINCE system,and we can not makesure it can meet all our requirement.