-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSound.cpp
More file actions
73 lines (65 loc) · 2.94 KB
/
Sound.cpp
File metadata and controls
73 lines (65 loc) · 2.94 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Sound.h"
// intializing the sound -- copied from lab04
void Sound::initializeOpenAL( int argc, char *argv[] ) {
ALsizei size, freq;
ALenum format;
ALvoid *data;
ALboolean loop;
alutInit(&argc,argv);
device=alcOpenDevice(NULL);
context=alcCreateContext(device,NULL);
alcMakeContextCurrent(context);
alGenBuffers(NUM_BUFFERS,buffers);
alGenSources(NUM_SOURCES,sources);
// WAV #1 -- NEED TO CHANGE ON PROGRAM BASIS
#ifdef __APPLE__
alutLoadWAVFile((ALbyte*)"SoundFiles/bird_chirping2.wav",&format,&data,&size,&freq);
#else
alutLoadWAVFile((ALbyte*)"SoundFiles/bird_chirping2.wav",&format,&data,&size,&freq,&loop);
#endif
alBufferData(buffers[0],format,data,size,freq);
alutUnloadWAV(format,data,size,freq);
alSourcei(sources[0],AL_BUFFER,buffers[0]);
alSourcei(sources[0],AL_LOOPING,AL_TRUE);
//positionSource(sources[0],0,0,0);
// WAV #2 -- NEED TO CHANGE ON PROGRAM BASIS
#ifdef __APPLE__
alutLoadWAVFile((ALbyte*)"SoundFiles/CartmanPoker_Face.wav",&format,&data,&size,&freq);
#else
alutLoadWAVFile((ALbyte*)"SoundFiles/CartmanPoker_Face.wav",&format,&data,&size,&freq,&loop);
#endif
alBufferData(buffers[1],format,data,size,freq);
alutUnloadWAV(format,data,size,freq);
alSourcei(sources[1],AL_BUFFER,buffers[1]);
alSourcei(sources[1],AL_LOOPING,AL_FALSE);
//positionSource(sources[1],0,0,0);
PrintOpenALInfo(); // print our OpenAL versioning information
}
// print the openAl information -- copied from lab04
void Sound::PrintOpenALInfo() {
fprintf( stdout, "[INFO]: /--------------------------------------------------------\\\n");
fprintf( stdout, "[INFO]: | OpenAL Information |\n");
fprintf( stdout, "[INFO]: |--------------------------------------------------------|\n");
fprintf( stdout, "[INFO]: | OpenAL Version: %35s |\n", alGetString(AL_VERSION) );
fprintf( stdout, "[INFO]: | OpenAL Renderer: %35s |\n", alGetString(AL_RENDERER) );
fprintf( stdout, "[INFO]: | OpenAL Vendor: %35s |\n", alGetString(AL_VENDOR) );
fprintf( stdout, "[INFO]: \\--------------------------------------------------------/\n\n");
}
// clean up the openAl things
void Sound::cleanupOpenAL() {
alutExit();
alDeleteBuffers(NUM_BUFFERS,buffers);
alDeleteSources(NUM_SOURCES,sources);
}
// position listener -- copied from lab04
void Sound::positionListener(float posX,float posY,float posZ,float dirX,float dirY,float dirZ,float upX,float upY,float upZ){
float listenerPosition[3]={posX,posY,posZ};
float listenerOrientation[6]={dirX,dirY,dirZ,upX,upY,upZ};
alListenerfv(AL_POSITION,listenerPosition);
alListenerfv(AL_ORIENTATION,listenerOrientation);
}
// position the source -- copied from lab04
void Sound::positionSource(ALuint src,float posX,float posY,float posZ){
float srcPosition[3]={posX,posY,posZ};
alSourcefv(src,AL_POSITION,srcPosition);
}