2013-02-14 4 views
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")이 보이면 소리를 봅니다. 그래서 나는 그것을 정확하게 전달할 것입니다. 하지만 내가 어떻게이 소리를 공개적으로 연주 할 수 있을까? 당신이 스트리밍하는 경우

+0

10ms, 882 바이트의 사운드 (MONO16)를 재생해야합니다. 이 소리는 "buf"변수에 있습니다. – EXTRAM

답변

0

, 당신은

alSourcei(alSource, AL_BUFFER, alSampleSet); 

처럼, 대신 정적 버퍼를 설정하는

alSourceQueueBuffers(alSource, 1, &alSampleSet); 

를 사용해야 만 한 번, 첫 번째 버퍼가 대기 할 때 명령 alSourcePlay(alSource);을 실행 .