8 #define SOUND_BUTTON_CLICK 1
9 #define SOUND_BUTTON_HOVER 2
15 bool LoadAudioData(char *musicSource
, char *buttonSource
);
16 void PlayMusic(int id
);
17 void PlaySound(int id
);
19 ALuint Buffers
[NUM_BUFFERS
]; // Buffers hold sound data.
20 ALuint Sources
[NUM_SOURCES
]; // Sources are points of emitting sound.
21 ALfloat SourcesPos
[NUM_SOURCES
][3]; // Position of the source sounds.
22 ALfloat SourcesVel
[NUM_SOURCES
][3]; // Velocity of the source sounds.
23 ALfloat ListenerPos
[3] ;// Position of the listener.
24 ALfloat ListenerVel
[3] ;// Velocity of the listener.
25 ALfloat ListenerOri
[6] ;// Orientation of the listener. (first 3 elements are "at", second 3 are "up")
30 // Position of the listener.
31 ListenerPos
[0]=0.0; //{ 0.0, 0.0, 0.0 }
35 // Velocity of the listener.
36 ListenerVel
[0]=0.0; //{ 0.0, 0.0, 0.0 }
40 // Orientation of the listener. (first 3 elements are "at", second 3 are "up")
41 ListenerOri
[0]=0.0;// { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }
50 alDeleteBuffers(NUM_BUFFERS
, Buffers
);
51 alDeleteSources(NUM_SOURCES
, Sources
);
55 bool CAudio:: LoadAudioData(char *musicSource
, char *buttonSource
)
57 // Initialize OpenAL and clear the error bit.
61 if(alGetError() != AL_NO_ERROR
)
64 // Variables to load into.
71 // Load wav data into buffers.
72 alGenBuffers(NUM_BUFFERS
, Buffers
);
74 if(alGetError() != AL_NO_ERROR
)
78 alutLoadWAVFile(musicSource
, &format
, &data
, &size
, &freq
, &loop
);
79 alBufferData(Buffers
[MUSIC
], format
, data
, size
, freq
);
80 alutUnloadWAV(format
, data
, size
, freq
);
82 // Load button audio file
83 alutLoadWAVFile(buttonSource
, &format
, &data
, &size
, &freq
, &loop
);
84 alBufferData(Buffers
[BUTTON
], format
, data
, size
, freq
);
85 alutUnloadWAV(format
, data
, size
, freq
);
87 // Bind buffers into audio sources.
89 alGenSources(NUM_SOURCES
, Sources
);
91 if(alGetError() != AL_NO_ERROR
)
94 alSourcei (Sources
[MUSIC
], AL_BUFFER
, Buffers
[MUSIC
] );
95 alSourcef (Sources
[MUSIC
], AL_PITCH
, 1.0f
);
96 alSourcef (Sources
[MUSIC
], AL_GAIN
, 1.0f
);
97 alSourcefv(Sources
[MUSIC
], AL_POSITION
, SourcesPos
[MUSIC
]);
98 alSourcefv(Sources
[MUSIC
], AL_VELOCITY
, SourcesVel
[MUSIC
]);
99 alSourcei (Sources
[MUSIC
], AL_LOOPING
, AL_TRUE
);
101 alSourcei (Sources
[BUTTON
], AL_BUFFER
, Buffers
[BUTTON
] );
102 alSourcef (Sources
[BUTTON
], AL_PITCH
, 1.0f
);
103 alSourcef (Sources
[BUTTON
], AL_GAIN
, 1.0f
);
104 alSourcefv(Sources
[BUTTON
], AL_POSITION
, SourcesPos
[BUTTON
]);
105 alSourcefv(Sources
[BUTTON
], AL_VELOCITY
, SourcesVel
[BUTTON
]);
106 alSourcei (Sources
[BUTTON
], AL_LOOPING
, AL_FALSE
);
108 // Do another error check and return.
109 if(alGetError() != AL_NO_ERROR
)
112 alListenerfv(AL_POSITION
, ListenerPos
);
113 alListenerfv(AL_VELOCITY
, ListenerVel
);
114 alListenerfv(AL_ORIENTATION
, ListenerOri
);
119 void CAudio::PlayMusic(void)
121 alSourcePlay(Sources
[MUSIC
]);
124 void CAudio::PlayButton(void)
126 alSourcePlay(Sources
[BUTTON
]);