1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <iostream>
#include <alut.h>
int main ()
{
// Initialize OpenAL
ALCcontext * pContext = NULL; // Create a context
ALCdevice * pDevice = NULL; // Create a device
pDevice = alcOpenDevice (NULL); // Open the device
pContext = alcCreateContext (pDevice, NULL); // Initialize the context
alcMakeContextCurrent (pContext); // Make pContext the current context
ALuint uiBuffer; // My buffer
ALuint uiSource; // My source
alGenBuffers (1, &uiBuffer); // Generate the buffer
uiBuffer = alutCreateBufferFromFile ("morceau.wav"); // Loading the sound into the buffer
alGenSources (1, &uiSource); // Generate the source to play the buffer with
alSourcei (uiSource, AL_BUFFER, uiBuffer); // Attach source to buffer
alSourcePlay (uiSource);
alutSleep (5);
// Destroy everything
alDeleteSources (1, &uiSource);
alDeleteBuffers (1, &uiBuffer);
alcMakeContextCurrent (NULL);
alcDestroyContext (pContext);
alcCloseDevice (pDevice);
return EXIT_SUCCESS;
} |
Partager