[Openal] AL_FORMAT Types and Meanings
Ümit Uzun
umituzun84 at gmail.com
Thu Oct 1 06:17:52 PDT 2009
Hi All,
I have needed to control every channel manually so I have injected
Framework.cpp of OpenAL SDK.
I added
template<typename T> T *LoadData(const T *data, int size, const char
*channels, short channelType)
{
size /= sizeof(T);
T *multData = new T[size * channelType];
for(int i = 0; i < size; i++)
{
for(int k = 0; k < channelType; k++)
{
multData[i * channelType + k] = channels[k] == '1' ? data[i] :
0;
}
}
return multData;
}
const char *channels; // For example 110010
// Find channelType by counting channels value for example 5.1's channelType
== 6
short channelType;
for(channelType = 0; channels[channelType] != NULL; channelType++);
if(fmt.wBitsPerSample == 16) // assumes 16-bit short
{
ALshort *data = LoadData((const ALshort*)pData, iDataSize, channels,
channelType);
switch(channelType)
{
case 2:
alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_MONO16"), data,
iDataSize * channelType, iFrequency);
break;
case 4:
alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_QUAD16"), data,
iDataSize * channelType, iFrequency);
break;
case 6:
alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_51CHN16"), data,
iDataSize * channelType, iFrequency);
break;
case 7:
alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_61CHN16"), data,
iDataSize * channelType, iFrequency);
break;
case 8:
alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_71CHN16"), data,
iDataSize * channelType, iFrequency);
break;
}
delete[] data;
}
instead of
alBufferData(uiBufferID, eBufferFormat, pData, iDataSize, iFrequency);
command.
With this changing I can specify each channel for related buffer's will be
played.
I specify each sounds channel value by;
<!-- Channels Enum for 5.1 123456 -->
<!-- 1 : Front Left Speaker -->
<!-- 2 : Front Right Speaker -->
<!-- 3 : Front Center Speaker -->
<!-- 4 : Low Frequency Speaker -->
<!-- 5 : Back Left Speaker -->
<!-- 6 : Back Right Speaker -->
In LoadData template function I create the multData sound buffer data in
this sequence. I mean for example we have 16 bit sampled 5.1 sound which
will be played only front left(this sound's channels:100000) I send the raw
pData sound buffer to LoadData function and multiplex this sound data for 6
channel in given sequence order. Create new multData array for 6 channel and
start to set this sound array firstly Front Left and Front Right and so on.
So do you think this operation right or now?
With all those changing I want to control channels. Because I have some
sounds which only must played on rear left channel and some sounds only
front right and etc.
Do you think this approach is suitable?
And another question I want to handle 2.0 speaker like 5.1 and as you can
see I use AL_FORMAT_MONO16 for 2 channel. Do you think it's right or not?
Should I use AL_FORMAT_STEREO16? Or which enumeration do I need?
If I am so complex, please ask me question to lead you right direction.
Regards.
Ümit Uzun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://opensource.creative.com/pipermail/openal/attachments/20091001/fc1c1fcf/attachment.html
More information about the Openal
mailing list