Код: Выделить всё
//g++ vc.cpp -o vc -l openal
#include
#include
#include
#include
using namespace std;
const int nos = 204800;
const int freq = 44100;
const float pi = 3.14159265359;
int main(){
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") ==AL_TRUE)
printf("enum supported\n");
//to do: get the list of devices printed and choose one
ALCdevice* Device = alcOpenDevice(NULL);
ALCcontext* Context = alcCreateContext(Device,NULL);
alcMakeContextCurrent(Context);
alGetError();
ALuint buffer;
alGenBuffers((ALuint)1, &buffer);
unsigned char testdata[nos];
for(int n = 0; n < nos; n++){
testdata[n] = 128+(char)(126*sin(2*pi*freq/10.0*n));
}
alBufferData(buffer, AL_FORMAT_MONO8, &testdata[0], nos, freq);
ALuint source;
alGenSources((ALuint)1, &source);
alSourcei(source, AL_BUFFER, buffer);
printf("test\n");
alSourcePlay(source);
ALint source_state;
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
while (source_state == AL_PLAYING) {
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
}
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
Device = alcGetContextsDevice(Context);
alcMakeContextCurrent(NULL);
alcDestroyContext(Context);
alcCloseDevice(Device);
printf("done\n");
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... ing-played