Skip to content

Instantly share code, notes, and snippets.

@desperius
Last active June 8, 2022 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desperius/5082114 to your computer and use it in GitHub Desktop.
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.
#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