Ver código fonte

Sound subsystem now working!

Thomas Buck 11 anos atrás
pai
commit
daf344aa66
3 arquivos alterados com 24 adições e 14 exclusões
  1. 1
    1
      src/OpenRaider.cpp
  2. 21
    10
      src/Sound.cpp
  3. 2
    3
      src/Sound.h

+ 1
- 1
src/OpenRaider.cpp Ver arquivo

1011
 
1011
 
1012
 		m_tombraider.getSoundSample(i, &riffSz, &riff);
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
 		if (id == TR_SOUND_F_PISTOL && id > 0)
1016
 		if (id == TR_SOUND_F_PISTOL && id > 0)
1017
 		{
1017
 		{

+ 21
- 10
src/Sound.cpp Ver arquivo

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
 int Sound::addFile(char *filename, int *source, unsigned int flags)
114
 int Sound::addFile(char *filename, int *source, unsigned int flags)
115
 {
115
 {
116
 #ifdef HAVE_OPENAL
116
 #ifdef HAVE_OPENAL
180
 #endif
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
 #ifdef HAVE_OPENAL
185
 #ifdef HAVE_OPENAL
189
-   ALsizei size = 0, freq = 0;
186
+   ALsizei size;
187
+   ALfloat freq;
188
+   ALenum format;
190
    ALvoid *data;
189
    ALvoid *data;
191
 #endif
190
 #endif
192
 
191
 
221
 		return -2;
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
    alSourcei(mSource[mNextSource], AL_BUFFER, mBuffer[mNextBuffer]);
239
    alSourcei(mSource[mNextSource], AL_BUFFER, mBuffer[mNextBuffer]);
229
 
240
 
323
 			fclose(f);
334
 			fclose(f);
324
 
335
 
325
 			printf("Loading buffer of %s\n", argv[1]);
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
 			printf("Load returned %i\n", ret);
338
 			printf("Load returned %i\n", ret);
328
 			printf("Playing buffer of %u::%s\n", id, argv[1]);
339
 			printf("Playing buffer of %u::%s\n", id, argv[1]);
329
 			snd.play(id);
340
 			snd.play(id);

+ 2
- 3
src/Sound.h Ver arquivo

64
     /*!
64
     /*!
65
      * \brief Load wav file from buffer
65
      * \brief Load wav file from buffer
66
      * \param wav not NULL! Is a valid waveform buffer!
66
      * \param wav not NULL! Is a valid waveform buffer!
67
+     * \param length length of wav buffer
67
      * \param source not NULL! Returns new source ID or -1 on error.
68
      * \param source not NULL! Returns new source ID or -1 on error.
68
      * \param flags (un)set options. Use SoundFlags enum
69
      * \param flags (un)set options. Use SoundFlags enum
69
      * \returns 0 for no error or < 0 error flag
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
      * \brief Play sound source
75
      * \brief Play sound source

Carregando…
Cancelar
Salvar