22#include < iostream>
33#include < string>
44#include < thread>
5+ #include < AL/alut.h>
56bool AudioHelper::isEvonInit = false ;
67float AudioHelper::audioVolume = 0 .08f ;
7- ALCdevice* AudioHelper::device = nullptr ;
8- ALCcontext* AudioHelper::context = nullptr ;
8+ // ALCdevice* AudioHelper::device = nullptr;
9+ // ALCcontext* AudioHelper::context = nullptr;
910
1011std::map<std::string, XCWavFile> AudioHelper::wavSourceGroup;
1112std::map<ALuint, ALuint> AudioHelper::effectPlayingList;
1213
1314void AudioHelper::EvonInit ()
1415{
1516 if (!isEvonInit) {
16- device = alcOpenDevice (NULL );
17- if (device==nullptr ) {
18- std::cout << " [ERROR]Failed to init openal device.\n " ;
19- }
20- else {
21- ALCcontext* context = alcCreateContext (device, NULL );
22- if (context == nullptr ) {
23- std::cout << " [ERROR]Failed to create openal context.\n " ;
24- }
25- else {
26- alcMakeContextCurrent (context);
27- std::cout << " [INFO]Now OpenAL environment init.\n " ;
28- isEvonInit = true ;
29- }
30- }
31- alGetError (); // clear all error
17+ // device = alcOpenDevice(NULL);
18+ // if (device==nullptr) {
19+ // std::cout << "[ERROR]Failed to init openal device.\n";
20+ // }
21+ // else {
22+ // ALCcontext* context = alcCreateContext(device, NULL);
23+ // if (context == nullptr) {
24+ // std::cout << "[ERROR]Failed to create openal context.\n";
25+ // }
26+ // else {
27+ // alcMakeContextCurrent(context);
28+ // std::cout << "[INFO]Now OpenAL environment init.\n";
29+ // isEvonInit = true;
30+ // }
31+ // }
32+ // alGetError(); //clear all error
33+ alutInit (NULL , NULL );
3234 }
3335
3436}
@@ -46,12 +48,13 @@ void AudioHelper::UnloadEvon()
4648 alDeleteSources (1 , &work->second );
4749 }
4850
49- alcMakeContextCurrent (NULL );
50- alcDestroyContext (context);
51- alcCloseDevice (device);
51+ // alcMakeContextCurrent(NULL);
52+ // alcDestroyContext(context);
53+ // alcCloseDevice(device);
5254
53- context = nullptr ;
54- device = nullptr ;
55+ // context = nullptr;
56+ // device = nullptr;
57+ alutExit ();
5558
5659 std::cout << " [INFO]Now OpenAL environment unloaded.\n " ;
5760 isEvonInit = false ;
@@ -77,6 +80,18 @@ XCWavFile AudioHelper::loadWavFromFile(const std::string& filename)
7780 return wavFile;
7881}
7982
83+ ALuint AudioHelper::loadWavByAlut (const std::string & filename)
84+ {
85+ ALuint buffer = alutCreateBufferFromFile (filename.c_str ());
86+ if (!alIsBuffer (buffer)) {
87+ std::cout << " [ERROR]Failed to load audio file " << filename << ' \n ' ;
88+ }
89+ else {
90+ std::cout << " [INFO] Load audio from file " << filename << std::endl;
91+ }
92+ return buffer;
93+ }
94+
8095void AudioHelper::setVolume (float volume)
8196{
8297 audioVolume = volume;
0 commit comments