|
我从服务器获得PCm格式的数据包,然后用下面的方法播放,但是播放是会有很多的杂音,并且,播放会就会卡死,求高人指点,谢谢了
下面是主要函数
#define QUEUECOUNT 10
void initOpenAL()
{
mDevice=alcOpenDevice(NULL);
if (mDevice) {
mContext=alcCreateContext(mDevice, NULL);
alcMakeContextCurrent(mContext);
}
alGenSources(1, &outSourceID);
alSpeedOfSound(1.0);
alSourcef(outSourceID, AL_PITCH, 1.0f);
alSourcef(outSourceID, AL_GAIN, 1.0f);
alSourcei(outSourceID, AL_LOOPING, AL_FALSE);
alSourcei(outSourceID, AL_BUFFERS_QUEUED, QUEUECOUNT);
}
void openAudioFromQueue(unsigned char* data ,(UInt32)dataSize)
{
updataQueueBuffer();
ALuint bufferID = 0;
alGenBuffers(1, &bufferID);
alBufferData(bufferID, AL_FORMAT_STEREO16, data, dataSize, 44100);
alSourceQueueBuffers(outSourceID, 1, &bufferID);
alSourcePlay(outSourceID);
}
void updataQueueBuffer()
{
int processed;
alGetSourcei(outSourceID, AL_BUFFERS_PROCESSED, &processed);
while(processed--)
{
ALuint buff;
alSourceUnqueueBuffers(outSourceID, 1, &buff);
check();
alSourceQueueBuffers(outSourceID, 1, &buff);
check();
}
} |
|