mono/mono — pull request #486 by fvalette (2012-10-26 08:02:31+00:00)
Title: Fix System.Media.SoundPlayer on Linux

Hi.

I fix the System.Media.SoundPlayer on linux.
There were three major problems in the original implementation:

- Wave header's file was badly parsed. Wave file may have a 'fact' sub chunk before the 'data' sub chunk. This sub chunk is for Non-PCM file but some PCM can have it. [see http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html]. If a PCM wave file had this sub chunk, it was not played at all ....

- Alsa layer was badly initialize. The Alsa layer is now initialize with the best ring-buffer and period size according to the format, sampling rate of the sound file AND the sound card properties. Now, the chunk of sound played by Alsa, is always at the best size for the hardware. This is better than the previous 4kB sample, which can be good for a particular sound but played very bad on another.

- The played method which send sound chunk to alsa was buggy too. The size pass to the alsa layer is in fragment, a fragment is a sample per channel, so the size of the chunk (in bytes) must be divide by the size of one sample (in bytes) and by the number of channel, the previous method works only for mono audio file and performing extremely badly with stereo audio file ! I also fix the FIXME in that play method.

With these fixes, the System.Media.SoundPlayer will play wave file well on every linux system.

I'm happy to participate to the Mono project.

cheers