Sfoglia il codice sorgente

Sound working with cmake

Thomas Buck 10 anni fa
parent
commit
842a2d2007
1 ha cambiato i file con 14 aggiunte e 4 eliminazioni
  1. 14
    4
      src/Sound.cpp

+ 14
- 4
src/Sound.cpp Vedi File

@@ -60,7 +60,14 @@ int Sound::init()
60 60
     close(fd);
61 61
 #endif
62 62
 
63
-    alutInit(NULL, 0);
63
+    ALCdevice *Device = alcOpenDevice("OSS");
64
+    ALCcontext *Context = alcCreateContext(Device, NULL);
65
+    alcMakeContextCurrent(Context);
66
+
67
+    if (alutInitWithoutContext(NULL, NULL) == AL_FALSE) {
68
+        printf("Sound::Init> Could not initialize alut (%s)\n", alutGetErrorString(alutGetError()));
69
+        return -2;
70
+    }
64 71
 
65 72
     mInit = true;
66 73
     printf("Created OpenAL Context\n");
@@ -129,7 +136,7 @@ int Sound::addFile(const char *filename, int *source, unsigned int flags)
129 136
     // is deprecated!
130 137
     data = alutLoadMemoryFromFile(filename, &format, &size, &freq);
131 138
 
132
-    if (alGetError() != AL_NO_ERROR)
139
+    if (alutGetError() != ALUT_ERROR_NO_ERROR)
133 140
     {
134 141
         fprintf(stderr, "Could not load %s\n", filename);
135 142
         return -3;
@@ -158,6 +165,7 @@ int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigne
158 165
     ALfloat freq;
159 166
     ALenum format;
160 167
     ALvoid *data;
168
+    int error = 0;
161 169
 
162 170
     if (!mInit || !wav || !source)
163 171
     {
@@ -197,8 +205,8 @@ int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigne
197 205
 
198 206
     data = alutLoadMemoryFromFileImage(wav, length, &format, &size, &freq);
199 207
 
200
-    if ((alGetError() != AL_NO_ERROR) || (data == NULL)) {
201
-        fprintf(stderr, "Could not load wav buffer\n");
208
+    if (((error = alutGetError()) != ALUT_ERROR_NO_ERROR) || (data == NULL)) {
209
+        fprintf(stderr, "Could not load wav buffer (%s)\n", alutGetErrorString(error));
202 210
         return -3;
203 211
     }
204 212
 
@@ -217,6 +225,8 @@ int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigne
217 225
 
218 226
     *source = mNextBuffer;
219 227
 
228
+    //! \fixme Should free alut buffer?
229
+
220 230
     return 0;
221 231
 }
222 232
 

Loading…
Annulla
Salva