[Openal] playing a raw buffer
gmail
angelo70 at gmail.com
Wed Apr 22 11:50:53 PDT 2009
Hi all,
i have a PCM stream recorded to file, as 16bit mono, 8Khz. The data
buffer don't have any header/info, it contains just pure PCM samples.
I am trying to play the data:
ALint size = get_file_size(*raw);
char *buf = new char[size];
if (buf)
{
int left = size;
while (left>0)
{
raw->read (buf, left);
left -= raw->gcount();
}
_t << "read size " << size << "\n";
raw->close ();
alGenBuffers (1, &buffer);
alBufferData (buffer, AL_FORMAT_MONO16, buf, size, 8000);
alGenSources (1, &source);
ALint state;
// attach buffer and play
alSourcei (source, AL_BUFFER, buffer);
alSourcePlay (source);
do
{
wait (200);
alGetSourcei (source, AL_SOURCE_STATE, &state);
}
while ((state == AL_PLAYING) && play);
alSourceStop(source);
alDeleteSources (1, &source);
delete (buf)
}
My program anyway have still another source.
The problem is that, strange things happen: sometimes the raw file
buffer is played fine, sometimes, if i play it after have used the other
source, it start to be played from half of its' size. Some time it is
not played at all.
I am quite sure i am using a bad approach,
any help is really appreciated.
greetings,
Angelo
More information about the Openal
mailing list