0

I need to play stream sound with OpenAL. This is my code, but it's not working. What i need to do?

    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();

if I see my file ("TESTSPEAKER"), i watch my sound. So I'm passing on the network it correctly. But how i can play this sound with openal?

Alexander Mashin
  • 693
  • 3
  • 14
  • 34

1 Answers1

0

If you are streaming, then you should use

alSourceQueueBuffers(alSource, 1, &alSampleSet);

instead of setting it as static buffer, like

alSourcei(alSource, AL_BUFFER, alSampleSet);

and issue the command alSourcePlay(alSource); only once, when the first buffer was queued.