Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
sound.cpp
Go to the documentation of this file.
1/*
2 * ix / D:\Rnd\prj\ix\src\sound\sound.cpp
3 *
4 * Retail address range: 0x0046A4A0 - 0x0046B12F (14 functions)
5 * Object boundaries follow retail padding and alignment; diagnostic paths
6 * identify the source subsystem (see docs/ORDER.md).
7 *
8 * Implement in ADDRESS ORDER -- MSVC emits functions in source order, so the
9 * list below is the original source order of this file.
10 */
11#define IX_SOUND_CPP
12#include "ix.h"
13
14#define IX_SOUND_FILE "D:\\Rnd\\prj\\ix\\src\\sound\\sound.cpp"
15
16/* Function start: 0x46A4A0 */
18 unsigned char newBasePriority,
19 unsigned int initialVolume,
20 int newPitchOffset,
21 unsigned short newPan)
22{
24 voice = -1;
25 sample = newSample;
26 pitchOffset = newPitchOffset;
27 volume = 0xffff;
28 pan = newPan;
29 basePriority = newBasePriority;
30 previous = 0;
31 next = previous;
32 stopTime = (unsigned int)-1;
34 priority = ((int)volume << 8) / 0xffff +
35 (pitchOffset << 8) / 0xac44 + basePriority;
37 previous = 0;
38 if (g_1_pFreeSoundHead != 0)
40 g_1_pFreeSoundHead = this;
41}
42
43/* Function start: 0x46A597 */
45 unsigned char newBasePriority)
46{
47 ix_system_sound_init(newSample, newBasePriority, 0xffff, 0, 0);
48}
49
50/* Function start: 0x46A5C8 */
52{
53 ix_system_sound_init(newSample, 0x80, 0xffff, 0, 0);
54}
55
56/* Function start: 0x46A5FA */
67
68/* Function start: 0x46A667 */
69void IxSound::ix_system_sound_set_volume(unsigned short newVolume)
70{
72 volume = newVolume;
74}
75
76/* Function start: 0x46A698 */
77void IxSound::ix_system_sound_set_pan(unsigned short newPan)
78{
80 pan = newPan;
81}
82
83/* Function start: 0x46A6C4 */
85{
87 if (-(int)(sample->frequency - 1) <= newPitchOffset) {
88 pitchOffset = newPitchOffset < 0xac44 ? newPitchOffset : 0xac44;
89 } else {
90 pitchOffset = -(int)(sample->frequency - 1);
91 }
93}
94
95/* Function start: 0x46A72F */
96void IxSound::ix_system_sound_set_priority(unsigned char newBasePriority)
97{
98 basePriority = newBasePriority;
100}
101
102/* Function start: 0x46A758 */ /* source line 103 */
103extern "C" void __fastcall ix_sound_start(IxSound *sound)
104{
105 int voice;
106 IxSound *lowestPlaying;
107 int releasedVoice;
108
109 if ((sound->flags & IX_SOUND_PLAYING) != 0) {
110 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 103);
111 ix_log_printf("sound already started!");
112 return;
113 }
114
115 sound->flags |= IX_SOUND_PLAYING;
116 sound->startTime = ix_dsp_get_tick();
117 if ((sound->sample->flags & IX_SAMPLE_LOOPING) != 0) {
118 sound->flags |= IX_SOUND_LOOPING;
120 sound->stopTime = (unsigned int)-1;
121 } else {
122 sound->stopTime = sound->startTime +
123 (sound->sample->sampleCount * 15) /
124 (sound->sample->frequency + sound->pitchOffset);
125 }
126
129
130 if (sound == g_1_pFreeSoundHead)
131 g_1_pFreeSoundHead = sound->next;
132 if (sound->next != 0)
133 sound->next->previous = sound->previous;
134 if (sound->previous != 0)
135 sound->previous->next = sound->next;
136 sound->next = g_1_pActiveSoundList;
137 sound->previous = 0;
138 if (g_1_pActiveSoundList != 0)
140 g_1_pActiveSoundList = sound;
141 ix_system_assign_voice(sound, voice);
142 } else {
143 lowestPlaying = ix_system_find_lowest_playing(
145 if (lowestPlaying != 0) {
146 releasedVoice = ix_system_release_voice(lowestPlaying);
147
148 if (lowestPlaying == g_1_pActiveSoundList)
149 g_1_pActiveSoundList = lowestPlaying->next;
150 if (lowestPlaying->next != 0)
151 lowestPlaying->next->previous = lowestPlaying->previous;
152 if (lowestPlaying->previous != 0)
153 lowestPlaying->previous->next = lowestPlaying->next;
154 lowestPlaying->next = g_1_pWaitingSoundList;
155 lowestPlaying->previous = 0;
156 if (g_1_pWaitingSoundList != 0)
157 g_1_pWaitingSoundList->previous = lowestPlaying;
158 g_1_pWaitingSoundList = lowestPlaying;
159
160 if (sound == g_1_pFreeSoundHead)
161 g_1_pFreeSoundHead = sound->next;
162 if (sound->next != 0)
163 sound->next->previous = sound->previous;
164 if (sound->previous != 0)
165 sound->previous->next = sound->next;
166 sound->next = g_1_pActiveSoundList;
167 sound->previous = 0;
168 if (g_1_pActiveSoundList != 0)
170 g_1_pActiveSoundList = sound;
171 ix_system_assign_voice(sound, releasedVoice);
172 } else {
173 if (sound == g_1_pFreeSoundHead)
174 g_1_pFreeSoundHead = sound->next;
175 if (sound->next != 0)
176 sound->next->previous = sound->previous;
177 if (sound->previous != 0)
178 sound->previous->next = sound->next;
180 sound->previous = 0;
181 if (g_1_pWaitingSoundList != 0)
183 g_1_pWaitingSoundList = sound;
184 }
185 }
186}
187
188/* Function start: 0x46AA9E */ /* source lines 151, 152 */
189extern "C" void __fastcall ix_sound_release(IxSound *sound)
190{
191 if ((sound->flags & IX_SOUND_PLAYING) == 0) {
192 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 151);
193 ix_log_printf("can't release non playing sound!");
194 return;
195 }
196 if ((sound->flags & IX_SOUND_LOOPING) == 0) {
197 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 152);
198 ix_log_printf("can't release non looping sound!");
199 return;
200 }
201 if ((sound->flags & IX_SOUND_HAS_VOICE) != 0) {
204 } else {
205 ix_sound_stop(sound);
206 }
207 return;
208}
209
210/* Function start: 0x46AB4F */ /* source line(s) 165: can't stop sound that's not playing! */
211extern "C" void __fastcall ix_sound_stop(IxSound *sound)
212{
213 IxSound *replacement;
214 int voice;
215
216 if ((sound->flags & IX_SOUND_PLAYING) == 0) {
217 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 165);
218 ix_log_printf("can't stop sound that's not playing!");
219 return;
220 }
221
222 sound->flags &= ~IX_SOUND_PLAYING;
223 if ((sound->flags & IX_SOUND_HAS_VOICE) != 0) {
224 voice = ix_system_release_voice(sound);
225 replacement = ix_system_find_highest_waiting(
227
228 if (sound == g_1_pActiveSoundList)
229 g_1_pActiveSoundList = sound->next;
230 if (sound->next != 0)
231 sound->next->previous = sound->previous;
232 if (sound->previous != 0)
233 sound->previous->next = sound->next;
234 sound->next = g_1_pFreeSoundHead;
235 sound->previous = 0;
236 if (g_1_pFreeSoundHead != 0)
238 g_1_pFreeSoundHead = sound;
239
240 if (replacement != 0) {
241 ix_system_assign_voice(replacement, voice);
242 if (replacement == g_1_pWaitingSoundList)
243 g_1_pWaitingSoundList = replacement->next;
244 if (replacement->next != 0)
245 replacement->next->previous = replacement->previous;
246 if (replacement->previous != 0)
247 replacement->previous->next = replacement->next;
248 replacement->next = g_1_pActiveSoundList;
249 replacement->previous = 0;
250 if (g_1_pActiveSoundList != 0)
251 g_1_pActiveSoundList->previous = replacement;
252 g_1_pActiveSoundList = replacement;
253 }
254 } else {
255 if (sound == g_1_pWaitingSoundList)
257 if (sound->next != 0)
258 sound->next->previous = sound->previous;
259 if (sound->previous != 0)
260 sound->previous->next = sound->next;
261 sound->next = g_1_pFreeSoundHead;
262 sound->previous = 0;
263 if (g_1_pFreeSoundHead != 0)
265 g_1_pFreeSoundHead = sound;
266 }
267
268 if ((sound->flags & IX_SOUND_DELETE_ON_STOP) != 0)
270}
271
272/* Function start: 0x46AD9A */
274{
275 unsigned int revisedPriority;
276 IxSound *waiting;
277 int releasedVoice;
278 IxSound *playingSound;
279 int reassignedVoice;
280
281 revisedPriority = (volume << 8) / 0xffff +
282 (pitchOffset << 8) / 0xac44 + basePriority;
283 if ((flags & IX_SOUND_HAS_VOICE) != 0) {
284 if (priority > revisedPriority) {
286 g_1_pWaitingSoundList, revisedPriority);
287 if (waiting != 0) {
288 releasedVoice = ix_system_release_voice(this);
289
290 if (this == g_1_pActiveSoundList)
292 if (next != 0)
294 if (previous != 0)
295 previous->next = next;
297 previous = 0;
298 if (g_1_pWaitingSoundList != 0)
301
302 if (waiting == g_1_pWaitingSoundList)
303 g_1_pWaitingSoundList = waiting->next;
304 if (waiting->next != 0)
305 waiting->next->previous = waiting->previous;
306 if (waiting->previous != 0)
307 waiting->previous->next = waiting->next;
308 waiting->next = g_1_pActiveSoundList;
309 waiting->previous = 0;
310 if (g_1_pActiveSoundList != 0)
312 g_1_pActiveSoundList = waiting;
313 ix_system_assign_voice(waiting, releasedVoice);
314 }
315 }
316 } else if ((flags & IX_SOUND_PLAYING) != 0 && priority < revisedPriority) {
317 playingSound = ix_system_find_lowest_playing(
318 g_1_pActiveSoundList, revisedPriority);
319 if (playingSound != 0) {
320 reassignedVoice = ix_system_release_voice(playingSound);
321
322 if (playingSound == g_1_pActiveSoundList)
323 g_1_pActiveSoundList = playingSound->next;
324 if (playingSound->next != 0)
325 playingSound->next->previous = playingSound->previous;
326 if (playingSound->previous != 0)
327 playingSound->previous->next = playingSound->next;
328 playingSound->next = g_1_pWaitingSoundList;
329 playingSound->previous = 0;
330 if (g_1_pWaitingSoundList != 0)
331 g_1_pWaitingSoundList->previous = playingSound;
332 g_1_pWaitingSoundList = playingSound;
333
334 if (this == g_1_pWaitingSoundList)
336 if (next != 0)
338 if (previous != 0)
339 previous->next = next;
341 previous = 0;
342 if (g_1_pActiveSoundList != 0)
345 ix_system_assign_voice(this, reassignedVoice);
346 }
347 }
348 priority = revisedPriority;
349}
350
351/* Function start: 0x46B0C5 */
353{
354 if (enabled != 0)
356 else
358}
359
360/* Function start: 0x46B0F8 */
361extern "C" int __fastcall ix_sound_is_playing(IxSound *sound)
362{
363 return (sound->flags & IX_SOUND_PLAYING) != 0;
364}
unsigned int ix_dsp_get_tick(void)
Definition dsp.cpp:139
void ix_dspv_clear_flag4(int voice)
Definition dspv.cpp:55
void __fastcall ix_sound_stop(IxSound *sound)
Definition sound.cpp:211
int __fastcall ix_sound_is_playing(IxSound *sound)
Definition sound.cpp:361
void __fastcall ix_sound_start(IxSound *sound)
Definition sound.cpp:103
void ix_system_delete_sound(IxSound *sound)
Definition system.cpp:184
void __fastcall ix_sound_release(IxSound *sound)
Definition sound.cpp:189
Audio classes, DirectSound interfaces and shared ix state.
int ix_system_find_free_voice(void)
Definition system.cpp:319
IxSound * g_1_pWaitingSoundList
Definition system.cpp:20
int g_nSystemVoiceCount
Definition system.cpp:18
@ IX_SAMPLE_LOOPING
Definition ix.h:95
IxSound * g_1_pFreeSoundHead
Definition system.cpp:15
void ix_log_printf(const char *fmt,...)
Definition stream.cpp:164
IxSound * ix_system_find_lowest_playing(IxSound *sound, unsigned int maximumPriority)
Definition system.cpp:303
int ix_system_release_voice(IxSound *sound)
Definition system.cpp:225
IxSound * ix_system_find_highest_waiting(IxSound *sound, unsigned int minimumPriority)
Definition system.cpp:287
@ IX_SOUND_LOOPING
Definition ix.h:102
@ IX_SOUND_HAS_VOICE
Definition ix.h:104
@ IX_SOUND_VOLUME_DIRTY
Definition ix.h:105
@ IX_SOUND_RELEASE_PENDING
Definition ix.h:108
@ IX_SOUND_PAN_DIRTY
Definition ix.h:107
@ IX_SOUND_ALLOCATED
Definition ix.h:100
@ IX_SOUND_FREQUENCY_DIRTY
Definition ix.h:106
@ IX_SOUND_DELETE_ON_STOP
Definition ix.h:103
@ IX_SOUND_PLAYING
Definition ix.h:101
int g_nActiveVoices
Definition system.cpp:17
void ix_system_assign_voice(IxSound *sound, int voice)
Definition system.cpp:237
IxSound * g_1_pActiveSoundList
Definition system.cpp:19
#define IX_SOUND_FILE
Definition sound.cpp:14
unsigned int flags
Definition game.h:128
unsigned int frequency
Definition ix.h:78
unsigned int sampleCount
Definition ix.h:72
void ix_sound_unlink_from_free_list(void)
Definition sound.cpp:57
void ix_sound_reprioritise(void)
Definition sound.cpp:273
IxSound * next
Definition ix.h:123
unsigned short volume
Definition ix.h:119
void ix_system_sound_construct(IxSample *newSample, unsigned char newBasePriority)
Definition sound.cpp:44
IxSound * previous
Definition ix.h:122
unsigned short pan
Definition ix.h:120
void ix_system_sound_set_frequency(int newPitchOffset)
Definition sound.cpp:84
unsigned int flags
Definition game.h:138
int voice
Definition ix.h:114
void ix_system_sound_set_pan(unsigned short pan)
Definition sound.cpp:77
IxSample * sample
Definition game.h:139
unsigned int stopTime
Definition ix.h:116
void ix_system_sound_set_volume(unsigned short volume)
Definition sound.cpp:69
unsigned int priority
Definition ix.h:117
void ix_system_sound_set_priority(unsigned char newBasePriority)
Definition sound.cpp:96
int pitchOffset
Definition ix.h:118
unsigned int startTime
Definition ix.h:115
void ix_system_sound_construct_centred(IxSample *newSample)
Definition sound.cpp:51
void ix_system_sound_init(IxSample *newSample, unsigned char newBasePriority, unsigned int initialVolume, int newPitchOffset, unsigned short newPan)
Definition sound.cpp:17
void ix_sound_set_delete_on_stop(int enabled)
Definition sound.cpp:352
unsigned char basePriority
Definition ix.h:121