Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
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 */
17
void
IxSound::ix_system_sound_init
(
IxSample
*newSample,
18
unsigned
char
newBasePriority,
19
unsigned
int
initialVolume,
20
int
newPitchOffset,
21
unsigned
short
newPan)
22
{
23
flags
=
IX_SOUND_ALLOCATED
;
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;
33
startTime
=
stopTime
;
34
priority
= ((int)
volume
<< 8) / 0xffff +
35
(
pitchOffset
<< 8) / 0xac44 +
basePriority
;
36
next
=
g_1_pFreeSoundHead
;
37
previous
= 0;
38
if
(
g_1_pFreeSoundHead
!= 0)
39
g_1_pFreeSoundHead
->
previous
=
this
;
40
g_1_pFreeSoundHead
=
this
;
41
}
42
43
/* Function start: 0x46A597 */
44
void
IxSound::ix_system_sound_construct
(
IxSample
*newSample,
45
unsigned
char
newBasePriority)
46
{
47
ix_system_sound_init
(newSample, newBasePriority, 0xffff, 0, 0);
48
}
49
50
/* Function start: 0x46A5C8 */
51
void
IxSound::ix_system_sound_construct_centred
(
IxSample
*newSample)
52
{
53
ix_system_sound_init
(newSample, 0x80, 0xffff, 0, 0);
54
}
55
56
/* Function start: 0x46A5FA */
57
void
IxSound::ix_sound_unlink_from_free_list
(
void
)
58
{
59
if
(
this
==
g_1_pFreeSoundHead
)
60
g_1_pFreeSoundHead
=
next
;
61
if
(
next
!= 0)
62
next
->
previous
=
previous
;
63
if
(
previous
!= 0)
64
previous
->
next
=
next
;
65
flags
&=
~IX_SOUND_ALLOCATED
;
66
}
67
68
/* Function start: 0x46A667 */
69
void
IxSound::ix_system_sound_set_volume
(
unsigned
short
newVolume)
70
{
71
flags
|=
IX_SOUND_VOLUME_DIRTY
;
72
volume
= newVolume;
73
ix_sound_reprioritise
();
74
}
75
76
/* Function start: 0x46A698 */
77
void
IxSound::ix_system_sound_set_pan
(
unsigned
short
newPan)
78
{
79
flags
|=
IX_SOUND_PAN_DIRTY
;
80
pan
= newPan;
81
}
82
83
/* Function start: 0x46A6C4 */
84
void
IxSound::ix_system_sound_set_frequency
(
int
newPitchOffset)
85
{
86
flags
|=
IX_SOUND_FREQUENCY_DIRTY
;
87
if
(-(
int
)(
sample
->
frequency
- 1) <= newPitchOffset) {
88
pitchOffset
= newPitchOffset < 0xac44 ? newPitchOffset : 0xac44;
89
}
else
{
90
pitchOffset
= -(int)(
sample
->
frequency
- 1);
91
}
92
ix_sound_reprioritise
();
93
}
94
95
/* Function start: 0x46A72F */
96
void
IxSound::ix_system_sound_set_priority
(
unsigned
char
newBasePriority)
97
{
98
basePriority
= newBasePriority;
99
ix_sound_reprioritise
();
100
}
101
102
/* Function start: 0x46A758 */
/* source line 103 */
103
extern
"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
;
119
sound->
flags
&=
~IX_SOUND_RELEASE_PENDING
;
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
127
if
(
g_nActiveVoices
<
g_nSystemVoiceCount
) {
128
voice =
ix_system_find_free_voice
();
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)
139
g_1_pActiveSoundList
->
previous
= sound;
140
g_1_pActiveSoundList
= sound;
141
ix_system_assign_voice
(sound, voice);
142
}
else
{
143
lowestPlaying =
ix_system_find_lowest_playing
(
144
g_1_pActiveSoundList
, sound->
priority
);
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)
169
g_1_pActiveSoundList
->
previous
= sound;
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
;
179
sound->
next
=
g_1_pWaitingSoundList
;
180
sound->
previous
= 0;
181
if
(
g_1_pWaitingSoundList
!= 0)
182
g_1_pWaitingSoundList
->
previous
= sound;
183
g_1_pWaitingSoundList
= sound;
184
}
185
}
186
}
187
188
/* Function start: 0x46AA9E */
/* source lines 151, 152 */
189
extern
"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) {
202
ix_dspv_clear_flag4
(sound->
voice
);
203
sound->
flags
|=
IX_SOUND_RELEASE_PENDING
;
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! */
211
extern
"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
(
226
g_1_pWaitingSoundList
, 0);
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)
237
g_1_pFreeSoundHead
->
previous
= sound;
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
)
256
g_1_pWaitingSoundList
= sound->
next
;
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)
264
g_1_pFreeSoundHead
->
previous
= sound;
265
g_1_pFreeSoundHead
= sound;
266
}
267
268
if
((sound->
flags
&
IX_SOUND_DELETE_ON_STOP
) != 0)
269
ix_system_delete_sound
(sound);
270
}
271
272
/* Function start: 0x46AD9A */
273
void
IxSound::ix_sound_reprioritise
(
void
)
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) {
285
waiting =
ix_system_find_highest_waiting
(
286
g_1_pWaitingSoundList
, revisedPriority);
287
if
(waiting != 0) {
288
releasedVoice =
ix_system_release_voice
(
this
);
289
290
if
(
this
==
g_1_pActiveSoundList
)
291
g_1_pActiveSoundList
=
next
;
292
if
(
next
!= 0)
293
next
->
previous
=
previous
;
294
if
(
previous
!= 0)
295
previous
->
next
=
next
;
296
next
=
g_1_pWaitingSoundList
;
297
previous
= 0;
298
if
(
g_1_pWaitingSoundList
!= 0)
299
g_1_pWaitingSoundList
->
previous
=
this
;
300
g_1_pWaitingSoundList
=
this
;
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)
311
g_1_pActiveSoundList
->
previous
= waiting;
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
)
335
g_1_pWaitingSoundList
=
next
;
336
if
(
next
!= 0)
337
next
->
previous
=
previous
;
338
if
(
previous
!= 0)
339
previous
->
next
=
next
;
340
next
=
g_1_pActiveSoundList
;
341
previous
= 0;
342
if
(
g_1_pActiveSoundList
!= 0)
343
g_1_pActiveSoundList
->
previous
=
this
;
344
g_1_pActiveSoundList
=
this
;
345
ix_system_assign_voice
(
this
, reassignedVoice);
346
}
347
}
348
priority
= revisedPriority;
349
}
350
351
/* Function start: 0x46B0C5 */
352
void
IxSound::ix_sound_set_delete_on_stop
(
int
enabled)
353
{
354
if
(enabled != 0)
355
flags
|=
IX_SOUND_DELETE_ON_STOP
;
356
else
357
flags
&=
~IX_SOUND_DELETE_ON_STOP
;
358
}
359
360
/* Function start: 0x46B0F8 */
361
extern
"C"
int
__fastcall
ix_sound_is_playing
(
IxSound
*sound)
362
{
363
return
(sound->
flags
&
IX_SOUND_PLAYING
) != 0;
364
}
ix_dsp_get_tick
unsigned int ix_dsp_get_tick(void)
Definition
dsp.cpp:139
ix_dspv_clear_flag4
void ix_dspv_clear_flag4(int voice)
Definition
dspv.cpp:55
ix_sound_stop
void __fastcall ix_sound_stop(IxSound *sound)
Definition
sound.cpp:211
ix_sound_is_playing
int __fastcall ix_sound_is_playing(IxSound *sound)
Definition
sound.cpp:361
ix_sound_start
void __fastcall ix_sound_start(IxSound *sound)
Definition
sound.cpp:103
ix_system_delete_sound
void ix_system_delete_sound(IxSound *sound)
Definition
system.cpp:184
ix_sound_release
void __fastcall ix_sound_release(IxSound *sound)
Definition
sound.cpp:189
ix.h
Audio classes, DirectSound interfaces and shared ix state.
ix_system_find_free_voice
int ix_system_find_free_voice(void)
Definition
system.cpp:319
g_1_pWaitingSoundList
IxSound * g_1_pWaitingSoundList
Definition
system.cpp:20
g_nSystemVoiceCount
int g_nSystemVoiceCount
Definition
system.cpp:18
IX_SAMPLE_LOOPING
@ IX_SAMPLE_LOOPING
Definition
ix.h:95
g_1_pFreeSoundHead
IxSound * g_1_pFreeSoundHead
Definition
system.cpp:15
ix_log_printf
void ix_log_printf(const char *fmt,...)
Definition
stream.cpp:164
ix_system_find_lowest_playing
IxSound * ix_system_find_lowest_playing(IxSound *sound, unsigned int maximumPriority)
Definition
system.cpp:303
ix_system_release_voice
int ix_system_release_voice(IxSound *sound)
Definition
system.cpp:225
ix_system_find_highest_waiting
IxSound * ix_system_find_highest_waiting(IxSound *sound, unsigned int minimumPriority)
Definition
system.cpp:287
IX_SOUND_LOOPING
@ IX_SOUND_LOOPING
Definition
ix.h:102
IX_SOUND_HAS_VOICE
@ IX_SOUND_HAS_VOICE
Definition
ix.h:104
IX_SOUND_VOLUME_DIRTY
@ IX_SOUND_VOLUME_DIRTY
Definition
ix.h:105
IX_SOUND_RELEASE_PENDING
@ IX_SOUND_RELEASE_PENDING
Definition
ix.h:108
IX_SOUND_PAN_DIRTY
@ IX_SOUND_PAN_DIRTY
Definition
ix.h:107
IX_SOUND_ALLOCATED
@ IX_SOUND_ALLOCATED
Definition
ix.h:100
IX_SOUND_FREQUENCY_DIRTY
@ IX_SOUND_FREQUENCY_DIRTY
Definition
ix.h:106
IX_SOUND_DELETE_ON_STOP
@ IX_SOUND_DELETE_ON_STOP
Definition
ix.h:103
IX_SOUND_PLAYING
@ IX_SOUND_PLAYING
Definition
ix.h:101
g_nActiveVoices
int g_nActiveVoices
Definition
system.cpp:17
ix_system_assign_voice
void ix_system_assign_voice(IxSound *sound, int voice)
Definition
system.cpp:237
g_1_pActiveSoundList
IxSound * g_1_pActiveSoundList
Definition
system.cpp:19
IX_SOUND_FILE
#define IX_SOUND_FILE
Definition
sound.cpp:14
IxSample
Definition
game.h:127
IxSample::flags
unsigned int flags
Definition
game.h:128
IxSample::frequency
unsigned int frequency
Definition
ix.h:78
IxSample::sampleCount
unsigned int sampleCount
Definition
ix.h:72
IxSound
Definition
game.h:137
IxSound::ix_sound_unlink_from_free_list
void ix_sound_unlink_from_free_list(void)
Definition
sound.cpp:57
IxSound::ix_sound_reprioritise
void ix_sound_reprioritise(void)
Definition
sound.cpp:273
IxSound::next
IxSound * next
Definition
ix.h:123
IxSound::volume
unsigned short volume
Definition
ix.h:119
IxSound::ix_system_sound_construct
void ix_system_sound_construct(IxSample *newSample, unsigned char newBasePriority)
Definition
sound.cpp:44
IxSound::previous
IxSound * previous
Definition
ix.h:122
IxSound::pan
unsigned short pan
Definition
ix.h:120
IxSound::ix_system_sound_set_frequency
void ix_system_sound_set_frequency(int newPitchOffset)
Definition
sound.cpp:84
IxSound::flags
unsigned int flags
Definition
game.h:138
IxSound::voice
int voice
Definition
ix.h:114
IxSound::ix_system_sound_set_pan
void ix_system_sound_set_pan(unsigned short pan)
Definition
sound.cpp:77
IxSound::sample
IxSample * sample
Definition
game.h:139
IxSound::stopTime
unsigned int stopTime
Definition
ix.h:116
IxSound::ix_system_sound_set_volume
void ix_system_sound_set_volume(unsigned short volume)
Definition
sound.cpp:69
IxSound::priority
unsigned int priority
Definition
ix.h:117
IxSound::ix_system_sound_set_priority
void ix_system_sound_set_priority(unsigned char newBasePriority)
Definition
sound.cpp:96
IxSound::pitchOffset
int pitchOffset
Definition
ix.h:118
IxSound::startTime
unsigned int startTime
Definition
ix.h:115
IxSound::ix_system_sound_construct_centred
void ix_system_sound_construct_centred(IxSample *newSample)
Definition
sound.cpp:51
IxSound::ix_system_sound_init
void ix_system_sound_init(IxSample *newSample, unsigned char newBasePriority, unsigned int initialVolume, int newPitchOffset, unsigned short newPan)
Definition
sound.cpp:17
IxSound::ix_sound_set_delete_on_stop
void ix_sound_set_delete_on_stop(int enabled)
Definition
sound.cpp:352
IxSound::basePriority
unsigned char basePriority
Definition
ix.h:121
src
ix
sound.cpp
Generated by
1.18.0