[Openal] Play mono as "stereo"
Carlo VOGELSANG
CVOGELSANG at creativelabs.com
Fri Oct 19 10:39:49 PDT 2007
Hi Andrew;
When creating the stereo buffer, you actually need to interleave the data
(i.e. L R L R L R instead of the LLLLLLLLL RRRRRRRRRR that you are doing
now):
if (eFormat == AL_FORMAT_MONO8)
{
char* c = new char[file.GetDataSize()*2];
for (int i=0; i < file.GetDataSize(); i++)
{
c[i*2]=file.GetData()[i]; // left chan
c[I*2+1]=file.GetData()[i]; // right chan
}
alBufferData(m_uiBuffer, AL_FORMAT_STEREO8, c, file.GetDataSize()*2,
file.GetFrequency()/2);
delete[] c;
}
you could also try setting the mono source to head relative that way it'll
come out of all speakers and won't move when the listener moves.
alSourcei(sid, AL_SOURCE_RELATIVE, TRUE);
alSource3f(sid, AL_POSITION, 0.0f, 0.0f, 0.0f);
-Carlo
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.
"Andrew Kerkel"
<andrew.kerkel at b-
alive.de> To
Sent by: "OpenAL"
openal-bounces at op <openal at opensource.creative.com>
ensource.creative cc
.com
Subject
[Openal] Play mono as "stereo"
10/19/2007 09:50
AM
Hi,
According to the programming guide the number of channels in buffer > 1 is
valid but it won't be positioned when played. That's ok so far but in a
special (inverse) case (exactly: speech - which is mono in our project) I
need to use a mono sound as a non 3D sound so it should behave as a stereo
(2D) sound.
I didn't find any possibility to accomplish this so I tried this blunt
trick:
("file" is a wrapper for a wave file)
if (eFormat == AL_FORMAT_MONO8)
{
char* c = new char[file.GetDataSize()*2];
memcpy(c, file.GetData(), file.GetDataSize()); // left chan
memcpy(c+file.GetDataSize(), file.GetData(), file.GetDataSize()); //
right chan
alBufferData(m_uiBuffer, AL_FORMAT_STEREO8, c, file.GetDataSize()*2,
file.GetFrequency()/2);
delete[] c;
}
Indeed - it works but this is obviously to easy because the problem is -
while playing there are bad noises.
But where do they come from?
Has anyone any hint for me (I'm still new to OpenAL ;) )?
In DirectSound I have to create a 3D sound buffer to declare the sound as a
3D sound - if I do not - even mono sounds are treated as 2D sounds.
Thanks
- Andrew
(and no, I don't have the possiblity to replace the mono sounds to stereo
sounds because it's for an already shipped project)
_______________________________________________
Openal mailing list
Openal at opensource.creative.com
http://opensource.creative.com/mailman/listinfo/openal
ForwardSourceID:NT0004B4BA
More information about the Openal
mailing list