I have a audio card that supports multiple speakers (Creative SB X-Fi). What I am trying to do is write a program in C++ (Windows 7 Environment, Visual Studio IDE) that will play a given mono wav file to one of the 4 speakers I have hooked up. 开发者_运维百科 Can anybody point me in the correct direction as to specific functions that will accomplish this aim? My attempt to google a solution has not yielded fruit. Thanks.
You can play sound through a set of surround sound speakers using DirectSound. See the MSDN page "Sounds in 3-D".
I suggest trying Ben Voigt's answer first, since if that works out it will probably be easier and more flexible.
But if for some reason it doesn't, another alternative is as follows.
Basically, when you want to play the mono .wav out of a particular speaker, convert it to a 6-channel .wav that's silent on five of the channels, but contains the data from the mono .wav on the channel for the speaker you want it to play on.
This should be fairly easy to do, because the .wav file format is very simple. The basic idea is that the sound data in your mono .wav file will consist of (typically) two-byte pairs for each audio sample, for example:
1234 2ab3 def0 ce18 ....
To convert that data to multi-channel you need to insert silence (zero) for the other channels. For example, for channel 0 (front-left) you'd use:
1234 0000 0000 0000 0000 0000 2ab3 0000 0000 0000 0000 0000 def0 0000 0000 0000 0000 0000 (etc)
whereas for front-right you'd use:
0000 1234 0000 0000 0000 0000 0000 2ab3 0000 0000 0000 0000 0000 def0 0000 0000 0000 0000 (etc)
(Consult this list of speaker assignments for the order.)
You also need to deal with the file's header, but the wave file header format is very simple; you'd need to change NumChannels
from 1 to 6, ByteRate
from whatever it is to the same value times 6, similarly for BlockAlign
and Subchunk2Size
.
NB I haven't actually tested any of the above, but it shouldn't take too much time to experiment. If it doesn't work, it may be necessary to add the newer WAVE_FORMAT_EXTENSIBLE data to the file - more fiddly but still not too hard; here is a useful page describing these extensions to the .wav format.
Have you been trying BASS library?
http://www.un4seen.com/
Multiple outputs Simultaneously use multiple soundcards, and move channels between them
精彩评论