Last active
June 8, 2022 13:30
-
-
Save desperius/5082114 to your computer and use it in GitHub Desktop.
Trivial example of loading and playback of audio file in WAV format using OpenAL library and ALUT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <alut.h> | |
const unsigned NUM_BUFFERS = 1; | |
const unsigned NUM_SOURCES = 1; | |
int main(int argc, char* argv[]) | |
{ | |
/* Sound buffer variable */ | |
ALuint buffer = 0; | |
/* Sound source varialbe */ | |
ALuint source = 0; | |
/* Initialize ALUT */ | |
alutInit(&argc, argv); | |
/* Generate sound buffer */ | |
alGenBuffers(NUM_BUFFERS, &buffer); | |
/* Load WAV file */ | |
buffer = alutCreateBufferFromFile("sound.wav"); | |
/* Generate sound source (sound position in 3D space) */ | |
alGenSources(NUM_SOURCES, &source); | |
/* Associate source with sound buffer */ | |
alSourcei(source, AL_BUFFER, buffer); | |
/* Play the sound */ | |
alSourcePlay(source); | |
/* Wait for playing sound */ | |
alutSleep(1); | |
/* Exit from ALUT */ | |
alutExit(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment