[Openal] Split wav channel
Daniel PEACOCK
dpeacock at creativelabs.com
Tue Jul 28 08:52:42 PDT 2009
Hi,
Stereo wave files have interleaved data i.e a Left Channel Sample followed
by a Right Channel Sample followed by Left, Right etc ... If you want to
split the file into two monos then you would do something like this
(assuming 16bit samples and that the pointers are all valid and point to
enough storage space, etc ...)
ALvoid SplitStereo(ALshort *pStereoData, ALshort *pLeft, ALshort *pRight,
ALuint uiNumSamples)
{
ALuint i;
for (i = 0; i < uiNumSamples; i++)
{
pLeft[ i ] = pStereoData[i*2];
pRight[ i ] = pStereoData[i*2+1];
}
}
If you just want to create a single mono stream from a stereo file, then
you need to mix the Left and Right samples together (and watch out for
overflows).
ALvoid StereoToMono(ALshort *pStereoData, ALshort *pMonoData, ALuint
uiNumSamples)
{
ALuint i;
ALint result;
for (i = 0; i< uiNumSamples; i++)
{
result = (ALint)pStereoData[i*2] + (ALint)pStereoData[i*2+1];
if (result > 32767)
result = 32767;
else if (result < -32768)
result = -32768;
pMonoData[i] = (ALshort)result;
}
}
NOTE : uiNumSamples is the number of 'blocks' or 'frames' and not the
count of all the samples in all the channels. e.g. For 16bit stereo data,
uiNumSamples = DataSizeInBytes / 4. (divide by 2 because it is 16bit
shorts, and divide by 2 again because there are 2 channels).
If you intend to play both mono parts of the stereo file then you should
use the vector play call (alSourcePlayv) to keep the parts in sync
otherwise you might hear some strange artifacts.
Dan
Creative Labs (UK) Ltd.
Notice
The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
message by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying or distribution of the message, or
any action taken by you in reliance on it, is prohibited and may be
unlawful. If you have received this message in error, please delete it
and contact the sender immediately. Thank you.
Creative Labs UK Ltd company number 2658256 registered in England and Wales
at Belmont Road, Belmont Place, Maidenhead, Berkshire, SL6 6TB
Andrea Mannarà
<andrea.mannara at t
hesis.seac02.it> To
Sent by: openal at opensource.creative.com
openal-bounces at op cc
ensource.creative
.com Subject
[Openal] Split wav channel
07/28/2009 02:00
PM
Hello,
I'm new user of OpenAl and i need to make spatial a wave with stereo
channel.
I thought I can split it in two separated sources and make these spatial.
But How can I split the 2 channel?
Thanks, Huvber
_______________________________________________
Openal mailing list
Openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal
ForwardSourceID:NT0006E24A
More information about the Openal
mailing list