-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio.cpp
54 lines (43 loc) · 1.04 KB
/
audio.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include <cstdio>
#include <string>
using namespace std;
ALuint buffer, source;
ALCdevice* device;
ALCcontext* context;
void initSound()
{
alutInit(0, NULL);
device = alcOpenDevice(NULL);
context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);
alGenSources(1, &source);
alListener3f(AL_POSITION, 0, 0, 0);
alListener3f(AL_VELOCITY, 0, 0, 0);
string file = "sounds/taken.wav";
buffer = alutCreateBufferFromFile(file.c_str());
alSourcef(source, AL_PITCH, 1);
alSourcef(source, AL_GAIN, 1);
alSource3f(source, AL_POSITION, 0, 0, 0);
alSource3f(source, AL_VELOCITY, 0, 0, 0);
alSourcei(source, AL_LOOPING, AL_FALSE);
//attach a source to a buffer
alSourcei(source, AL_BUFFER, buffer);
}
void playSound()
{
//play sound
alSourcePlay(source);
//getc(stdin);
}
void stopSound()
{
//close source
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
alcDestroyContext(context);
alcCloseDevice(device);
alutExit();
}