Enable >16bit output sample widths using DirectSound API
Multichannel support is complete in DirectSound. This has been quite extensively tested. The remaining work pertains to >16 bit sample formats. Progress on this issue was made in changesets r1268 r1258. See the checkin comments there.
At the moment input and output sample formats are hardwired to 16 bit in the two lines in pa_win_ds.c reading:
PaSampleFormat nativeInputFormats = paInt16;
It is possible to uncomment the following lines to support other sample formats:
PaSampleFormat nativeFormats = paUInt8 | paInt16 | paInt24 | paInt32 | paFloat32;
However this will make use of DS converters rather than using PortAudio converters to map to the best supported sample format. The main work left to do is to handle renegotiation of sample format if the requested format fails (ie if 24 bit is requested, but dsound fails, we need to fall back to 16 bit).
The issue has been discussed on the mailing list:
http://techweb.rfa.org/pipermail/portaudio/2008-January/008175.html
http://techweb.rfa.org/pipermail/portaudio/2008-February/008195.html
There have been other discussions here on when/why to use WAVEFORMATEX instead of WAVEFORMATEXTENSIBLE:
For example, there are some very popular soundcards with bugs in their WAVEFORMATEXTENSIBLE support:
http://techweb.rfa.org/pipermail/portaudio/2008-February/008237.html
Alec originally wrote:
I have attached a modified version of portaudio/src/hostapi/dsound/pa_win_ds.c, which has been patched to allow multiple (more than two) channels, and sample formats other than paInt16. This is achieved through the use of the WAVEFORMATEXTENSIBLE structure.
Of note:
At the moment input and output sample formats are hardwired to 16 bit in the two lines in pa_win_ds.c reading:
PaSampleFormat nativeInputFormats = paInt16;
It is possible to uncomment the following lines to support other sample formats:
PaSampleFormat nativeFormats = paUInt8 | paInt16 | paInt24 | paInt32 | paFloat32;
However this will make use of DS converters rather than using PortAudio converters to map to the best supported sample format. The main work left to do is to handle renegotiation of sample format if the requested format fails (ie if 24 bit is requested, but dsound fails, we need to fall back to 16 bit).
The issue has been discussed on the mailing list:
http://techweb.rfa.org/pipermail/portaudio/2008-January/008175.html
http://techweb.rfa.org/pipermail/portaudio/2008-February/008195.html
There have been other discussions here on when/why to use WAVEFORMATEX instead of WAVEFORMATEXTENSIBLE:
For example, there are some very popular soundcards with bugs in their WAVEFORMATEXTENSIBLE support:
http://techweb.rfa.org/pipermail/portaudio/2008-February/008237.html
Alec originally wrote:
I have attached a modified version of portaudio/src/hostapi/dsound/pa_win_ds.c, which has been patched to allow multiple (more than two) channels, and sample formats other than paInt16. This is achieved through the use of the WAVEFORMATEXTENSIBLE structure.
Of note:
- I have coded away the PA sample format conversion, which is probably not in model for PortAudio. This can be re-introduced by specifying desired sample formats in the call to PaUtil_SelectClosestAvailableFormat().
- The use of WAVEFORMATEXTENSIBLE requires us to define a channel mapping. I have used the technique of 1 channel -> FrontCenterSpeaker, N channels -> FirstNSpeakers. This makes sense to me, but be aware of the choice.
Leave a comment