0
我需要用OpenAL播放流聲音。這是我的代碼,但它不起作用。我需要做什麼?播放流聲音OpenAL
device = alcOpenDevice(NULL);
//
ofstream file;
file.open("TESTSPEAKER", std::ios_base::binary);
context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);
// alGetError();
char *alBuffer;
ALenum alFormatBuffer;
ALsizei alFreqBuffer;
long alBufferLen;
ALboolean alLoop;
unsigned int alSource;
unsigned int alSampleSet;
boost::array <char, 882> buf;
while (!ExitKey)
{
boost::system::error_code error;
size_t len = VoiceSocket->read_some(boost::asio::buffer(buf), error);
if (len==0)
{
continue;
}
file.write(buf.data(), 882);
alGenSources(1, &alSource);
alGenBuffers(1, &alSampleSet);
alBufferData(alSource, AL_FORMAT_MONO16, buf.data(), buf.size(), 44100);
alSourcei(alSource, AL_BUFFER, alSampleSet);
//
//alSourcei(alSource, AL_LOOPING, alSampleSet);
alSourcePlay(alSource);
//alSourcePlay(alSource);
}
VoiceSocket->close();
file.close();
如果我看到我的文件(「TESTSPEAKER」),我看我的聲音。所以我正確地傳遞了網絡。但是我怎麼能用openal來播放這個聲音呢?
我需要播放每10ms,882個字節的聲音(MONO16)。這個聲音在「buf」變量中。 – EXTRAM 2013-02-14 12:09:51