Parcourir la source

Sound subsystem now working!

Thomas Buck il y a 11 ans
Parent
révision
daf344aa66
3 fichiers modifiés avec 24 ajouts et 14 suppressions
  1. 1
    1
      src/OpenRaider.cpp
  2. 21
    10
      src/Sound.cpp
  3. 2
    3
      src/Sound.h

+ 1
- 1
src/OpenRaider.cpp Voir le fichier

@@ -1011,7 +1011,7 @@ void OpenRaider::processPakSounds()
1011 1011
 
1012 1012
 		m_tombraider.getSoundSample(i, &riffSz, &riff);
1013 1013
 
1014
-		mSound.addWave(riff, &id, mSound.SoundFlagsNone);
1014
+		mSound.addWave(riff, riffSz, &id, mSound.SoundFlagsNone);
1015 1015
 
1016 1016
 		if (id == TR_SOUND_F_PISTOL && id > 0)
1017 1017
 		{

+ 21
- 10
src/Sound.cpp Voir le fichier

@@ -110,7 +110,7 @@ void Sound::sourceAt(int source, float pos[3])
110 110
 }
111 111
 
112 112
 
113
-// Mongoose 2002.01.04, FIXME seperate sourcing and buffering
113
+//! \fixme Seperate sourcing and buffering, Mongoose 2002.01.04
114 114
 int Sound::addFile(char *filename, int *source, unsigned int flags)
115 115
 {
116 116
 #ifdef HAVE_OPENAL
@@ -180,13 +180,12 @@ int Sound::addFile(char *filename, int *source, unsigned int flags)
180 180
 #endif
181 181
 }
182 182
 
183
-/*!
184
- * \todo Reimplement, not using deprecated FORMAT specifier
185
- */
186
-int Sound::addWave(unsigned char *wav, int *source, unsigned int flags)
183
+int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags)
187 184
 {
188 185
 #ifdef HAVE_OPENAL
189
-   ALsizei size = 0, freq = 0;
186
+   ALsizei size;
187
+   ALfloat freq;
188
+   ALenum format;
190 189
    ALvoid *data;
191 190
 #endif
192 191
 
@@ -221,9 +220,21 @@ int Sound::addWave(unsigned char *wav, int *source, unsigned int flags)
221 220
 		return -2;
222 221
 	}
223 222
 
224
-#warning "AL_FORMAT_WAVE_EXT does not exist on Mac!"
225
-   // alBufferData(mBuffer[mNextBuffer], AL_FORMAT_WAVE_EXT, data, size, freq);
226
-   alBufferData(mBuffer[mNextBuffer], 0x10002, data, size, freq);
223
+    //AL_FORMAT_WAVE_EXT does not exist on Mac!"
224
+    // alBufferData(mBuffer[mNextBuffer], AL_FORMAT_WAVE_EXT, data, size, freq);
225
+    // Idea: Fill Buffer with
226
+    // alutLoadMemoryFromFileImage
227
+    //     (const ALvoid *data, ALsizei length, ALenum *format, ALsizei *size, ALfloat *frequency)
228
+
229
+    data = alutLoadMemoryFromFileImage(wav, length, &format, &size, &freq);
230
+
231
+    if ((alGetError() != AL_NO_ERROR) || (data == NULL)) {
232
+	   fprintf(stderr, "Could not load wav buffer\n");
233
+	   return -3;
234
+    }
235
+
236
+
237
+   alBufferData(mBuffer[mNextBuffer], format, data, size, freq);
227 238
 
228 239
    alSourcei(mSource[mNextSource], AL_BUFFER, mBuffer[mNextBuffer]);
229 240
 
@@ -323,7 +334,7 @@ int main(int argc, char* argv[])
323 334
 			fclose(f);
324 335
 
325 336
 			printf("Loading buffer of %s\n", argv[1]);
326
-			ret = snd.addWave(buf, &id, snd.SoundFlagsNone);
337
+			ret = snd.addWave(buf, l, &id, snd.SoundFlagsNone);
327 338
 			printf("Load returned %i\n", ret);
328 339
 			printf("Playing buffer of %u::%s\n", id, argv[1]);
329 340
 			snd.play(id);

+ 2
- 3
src/Sound.h Voir le fichier

@@ -64,13 +64,12 @@ public:
64 64
     /*!
65 65
      * \brief Load wav file from buffer
66 66
      * \param wav not NULL! Is a valid waveform buffer!
67
+     * \param length length of wav buffer
67 68
      * \param source not NULL! Returns new source ID or -1 on error.
68 69
      * \param flags (un)set options. Use SoundFlags enum
69 70
      * \returns 0 for no error or < 0 error flag
70
-     *
71
-     * \todo not yet implemented!
72 71
      */
73
-    int addWave(unsigned char *wav, int *source, unsigned int flags);
72
+    int addWave(unsigned char *wav, unsigned int length, int *source, unsigned int flags);
74 73
 
75 74
     /*!
76 75
      * \brief Play sound source

Chargement…
Annuler
Enregistrer