浏览代码

Properly commented Sound

Thomas Buck 11 年前
父节点
当前提交
83c3ad0fa5
共有 3 个文件被更改,包括 86 次插入155 次删除
  1. 3
    3
      src/OpenRaider.cpp
  2. 4
    3
      src/Sound.cpp
  3. 79
    149
      src/Sound.h

+ 3
- 3
src/OpenRaider.cpp 查看文件

@@ -966,7 +966,7 @@ void OpenRaider::initSound()
966 966
 		snprintf(filename, 126, "%s%s", m_audioDir, mMusicList[0]);
967 967
 		filename[127] = 0;
968 968
 
969
-		if (!mSound.add(filename, &id, SoundFlagsLoop))
969
+		if (!mSound.addFile(filename, &id, mSound.SoundFlagsLoop))
970 970
 		{
971 971
 			mSound.play(id);
972 972
 
@@ -977,7 +977,7 @@ void OpenRaider::initSound()
977 977
 
978 978
 	//snprintf(filename, 126, "%s%s", m_homeDir, "sample.wav");
979 979
 	//filename[127] = 0;
980
-	//mSound.add(filename, &m_testSFX, SoundFlagsNone);
980
+	//mSound.addFile(filename, &m_testSFX, mSound.SoundFlagsNone);
981 981
 
982 982
 	printf(".");
983 983
 	fflush(stdout);
@@ -1021,7 +1021,7 @@ void OpenRaider::processPakSounds()
1021 1021
 
1022 1022
 		m_tombraider.getSoundSample(i, &riffSz, &riff);
1023 1023
 
1024
-		mSound.add(riff, &id, SoundFlagsNone);
1024
+		mSound.addWave(riff, &id, mSound.SoundFlagsNone);
1025 1025
 
1026 1026
 		if (id == TR_SOUND_F_PISTOL && id > 0)
1027 1027
 		{

+ 4
- 3
src/Sound.cpp 查看文件

@@ -122,7 +122,7 @@ void Sound::sourceAt(int source, float pos[3])
122 122
 
123 123
 
124 124
 // Mongoose 2002.01.04, FIXME seperate sourcing and buffering
125
-int Sound::add(char *filename, int *source, unsigned int flags)
125
+int Sound::addFile(char *filename, int *source, unsigned int flags)
126 126
 {
127 127
 #ifdef HAVE_OPENAL
128 128
    ALsizei size;
@@ -192,7 +192,7 @@ int Sound::add(char *filename, int *source, unsigned int flags)
192 192
 }
193 193
 
194 194
 
195
-int Sound::add(unsigned char *wav, int *source, unsigned int flags)
195
+int Sound::addWave(unsigned char *wav, int *source, unsigned int flags)
196 196
 {
197 197
 #ifdef HAVE_OPENAL
198 198
    ALsizei size = 0, freq = 0;
@@ -230,7 +230,8 @@ int Sound::add(unsigned char *wav, int *source, unsigned int flags)
230 230
 		return -2;
231 231
 	}
232 232
 
233
-#warning "AL_FORMAT_WAVE_EXT does not exist on Mac!"
233
+// This method isn't used yet...
234
+//#warning "AL_FORMAT_WAVE_EXT does not exist on Mac!"
234 235
    // alBufferData(mBuffer[mNextBuffer], AL_FORMAT_WAVE_EXT, data, size, freq);
235 236
    alBufferData(mBuffer[mNextBuffer], 0x10002, data, size, freq);
236 237
 

+ 79
- 149
src/Sound.h 查看文件

@@ -1,6 +1,6 @@
1 1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2 2
 /*================================================================
3
- * 
3
+ *
4 4
  * Project : OpenRaider
5 5
  * Author  : Mongoose
6 6
  * Website : http://www.westga.edu/~stu7440/
@@ -10,14 +10,14 @@
10 10
  * Comments: This is the audio manager for OpenRaider
11 11
  *
12 12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14 14
  *           template generator script.  <stu7440@westga.edu>
15 15
  *
16 16
  *-- Test Defines -----------------------------------------------
17
- *           
18
- * UNIT_TEST_SOUND - Builds Sound class as a console unit test 
19 17
  *
20
- *-- History ---------------------------------------------------- 
18
+ * UNIT_TEST_SOUND - Builds Sound class as a console unit test
19
+ *
20
+ *-- History ----------------------------------------------------
21 21
  *
22 22
  * 2002.09.13:
23 23
  * Mongoose - API follows new code style guidelines
@@ -32,150 +32,80 @@
32 32
 #ifndef __OPENRAIDER_MONGOOSE_SOUND_H_
33 33
 #define __OPENRAIDER_MONGOOSE_SOUND_H_
34 34
 
35
-typedef enum
36
-{
37
-	SoundFlagsNone = 0,            /* No FX */
38
-	SoundFlagsLoop = 1             /* Enable looping during playback */
39
-
40
-} SoundFlags;
41
-
42
-
43
-class Sound
44
-{
45
- public:
46
-
47
-  Sound();
48
-  /*------------------------------------------------------
49
-   * Pre  : 
50
-   * Post : Constructs an object of Sound
51
-   *
52
-   *-- History ------------------------------------------
53
-   *
54
-   * 2001.05.23: 
55
-   * Mongoose - Created
56
-   ------------------------------------------------------*/
57
-
58
-  ~Sound();
59
-  /*------------------------------------------------------
60
-   * Pre  : Sound object is allocated
61
-   * Post : Deconstructs an object of Sound
62
-   *
63
-   *-- History ------------------------------------------
64
-   *
65
-   * 2001.05.23: 
66
-   * Mongoose - Created
67
-   ------------------------------------------------------*/
68
-
69
-  int init();
70
-  /*------------------------------------------------------
71
-   * Pre  : 
72
-   * Post : Initializes sound system
73
-	*
74
-	*        No error returns 0 all others returns < 0
75
-	*        error flags
76
-   *
77
-   *-- History ------------------------------------------
78
-   *
79
-   * 2001.05.23: 
80
-   * Mongoose - Created
81
-   ------------------------------------------------------*/
82
-
83
-  void listenAt(float pos[3], float angle[3]);
84
-  /*------------------------------------------------------
85
-   * Pre  : pos and angles are valid for listener
86
-   * Post : Moves listener and repositions them
87
-   *
88
-   *-- History ------------------------------------------
89
-   *
90
-   * 2001.05.23: 
91
-   * Mongoose - Created
92
-   ------------------------------------------------------*/
93
-
94
-  void sourceAt(int source, float pos[3]);
95
-  /*------------------------------------------------------
96
-   * Pre  : source and pos are valid for source
97
-   * Post : Moves sound source to position
98
-   *
99
-   *-- History ------------------------------------------
100
-   *
101
-   * 2001.05.23: 
102
-   * Mongoose - Created
103
-   ------------------------------------------------------*/
104
-
105
-  int add(char *filename, int *source, unsigned int flags);
106
-  /*------------------------------------------------------
107
-   * Pre  : filename and source aren't NULL
108
-	*        flags (un)set options
109
-	*
110
-   * Post : Loads wav file from disk
111
-	*
112
-	*        Source returns it's sound source id, 
113
-	*        source id is set -1 for error
114
-	*
115
-	*        Returns either 0 for no error or < 0 error 
116
-	*        flag
117
-   *
118
-   *-- History ------------------------------------------
119
-   *
120
-   * 2001.05.23: 
121
-   * Mongoose - Created
122
-   ------------------------------------------------------*/
123
-
124
-  // FIXME: Not implemented yet
125
-  int add(unsigned char *wav, int *source, unsigned int flags);
126
-  /*------------------------------------------------------
127
-   * Pre  : wav and source aren't NULL
128
-	*        wav is a valid waveform buffer
129
-	*
130
-	*        flags (un)set options
131
-	*
132
-   * Post : Loads wav file from buffer
133
-	*
134
-	*        Source returns it's sound source id, 
135
-	*        source id is set -1 for error
136
-	*
137
-	*        Returns either 0 for no error or < 0 error 
138
-	*        flag
139
-   *
140
-   *-- History ------------------------------------------
141
-   *
142
-   * 2001.05.23: 
143
-   * Mongoose - Created
144
-   ------------------------------------------------------*/
145
-
146
-  void play(int source);
147
-  /*------------------------------------------------------
148
-   * Pre  : 
149
-   * Post : Play sound source
150
-   *
151
-   *-- History ------------------------------------------
152
-   *
153
-   * 2001.05.23: 
154
-   * Mongoose - Created
155
-   ------------------------------------------------------*/
156
-
157
-  void stop(int source);
158
-  /*------------------------------------------------------
159
-   * Pre  : 
160
-   * Post : Stop playing sound source
161
-   *
162
-   *-- History ------------------------------------------
163
-   *
164
-   * 2001.05.23: 
165
-   * Mongoose - Created
166
-   ------------------------------------------------------*/
167
-
168
- private:
169
-
170
-  bool mInit;                    /* Guard to ensure ausio system is active */
171
-
172
-  unsigned int mBuffer[256];     /* Audio buffer id list */
173
-
174
-  unsigned int mSource[256];     /* Audio source id list */
175
-
176
-  unsigned int mNextBuffer;      /* Audio buffer id cursor */
177
-
178
-  unsigned int mNextSource;      /* Audio source id cursor */
35
+class Sound {
36
+public:
37
+
38
+    typedef enum {
39
+        SoundFlagsNone = 0, //!< No FX
40
+        SoundFlagsLoop = 1  //!< Enable looping during playback
41
+    } SoundFlags;
42
+
43
+    /*!
44
+     * \brief Constructs an object of Sound
45
+     */
46
+    Sound();
47
+
48
+    /*!
49
+     * \brief Deconstructs an object of Sound
50
+     */
51
+    ~Sound();
52
+
53
+    /*!
54
+     * \brief Initialize sound system
55
+     * \returns 0 on success or < 0 error flags
56
+     */
57
+    int init();
58
+
59
+    /*!
60
+     * \brief Move listener and repositions them
61
+     * \param pos New position for listener
62
+     * \param angle New orientation for listener
63
+     */
64
+    void listenAt(float pos[3], float angle[3]);
65
+
66
+    /*!
67
+     * \brief Move sound source to position
68
+     * \param source valid source id
69
+     * \param pos new position for source
70
+     */
71
+    void sourceAt(int source, float pos[3]);
72
+
73
+    /*!
74
+     * \brief Load wav file from disk
75
+     * \param filename not NULL!
76
+     * \param source not NULL! Returns new source ID or -1 on error.
77
+     * \param flags (un)set options. Use SoundFlags enum
78
+     * \returns 0 for no error or < 0 error flag
79
+     */
80
+    int addFile(char *filename, int *source, unsigned int flags);
81
+
82
+    /*!
83
+     * \brief Load wav file from buffer
84
+     * \param wav not NULL! Is a valid waveform buffer!
85
+     * \param source not NULL! Returns new source ID or -1 on error.
86
+     * \param flags (un)set options. Use SoundFlags enum
87
+     * \returns 0 for no error or < 0 error flag
88
+     */
89
+    int addWave(unsigned char *wav, int *source, unsigned int flags);
90
+
91
+    /*!
92
+     * \brief Play sound source
93
+     * \param source sound source to play
94
+     */
95
+    void play(int source);
96
+
97
+    /*!
98
+     * \brief Stop playing sound source
99
+     * \param source sound source to stop
100
+     */
101
+    void stop(int source);
102
+
103
+private:
104
+    bool mInit;                    //!< Guard to ensure ausio system is active
105
+    unsigned int mBuffer[256];     //!< Audio buffer id list
106
+    unsigned int mSource[256];     //!< Audio source id list
107
+    unsigned int mNextBuffer;      //!< Audio buffer id cursor
108
+    unsigned int mNextSource;      //!< Audio source id cursor
179 109
 };
180 110
 
181 111
 #endif

正在加载...
取消
保存