Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
sound.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup ixlib
4 * @brief Sound objects: initialization, volume, pan, frequency and priority.
5 *
6 * Originally `D:\Rnd\prj\ix\src\sound\sound.cpp`, address range
7 * 447a20-4486af. The assert paths identify the source; linker INT3 fill marks
8 * the object boundaries.
9 */
10#include "ix.h"
11#include <assert.h>
12
13#define IX_SOUND_FILE "D:\\Rnd\\prj\\ix\\src\\sound\\sound.cpp"
14
15/* Function start: 0x00447A20 */
17 unsigned char newBasePriority,
18 unsigned int initialVolume,
19 int newPitchOffset,
20 unsigned short newPan)
21{
23 voice = -1;
24 sample = newSample;
25 pitchOffset = newPitchOffset;
26 volume = 0xffff;
27 pan = newPan;
28 basePriority = newBasePriority;
29 previous = 0;
30 next = previous;
31 stopTime = (unsigned int)-1;
33 priority = ((int)volume << 8) / 0xffff +
34 (pitchOffset << 8) / 0xac44 + basePriority;
36 previous = 0;
37 if (pIdleSoundList != 0)
39 pIdleSoundList = this;
40}
41
42/* Function start: 0x00447B17 */
44 unsigned char newBasePriority)
45{
46 ix_system_sound_init(newSample, newBasePriority, 0xffff, 0, 0);
47}
48
49/* Function start: 0x00447B48 */
51{
52 ix_system_sound_init(newSample, 0x80, 0xffff, 0, 0);
53}
54
55/* Function start: 0x00447B7A */
57{
58 if (sound == pIdleSoundList)
59 pIdleSoundList = sound->next;
60 if (sound->next != 0)
61 sound->next->previous = sound->previous;
62 if (sound->previous != 0)
63 sound->previous->next = sound->next;
64 sound->flags &= ~IX_SOUND_ALLOCATED;
65}
66
67/* Function start: 0x00447BE7 */
68void IxSound::ix_system_sound_set_volume(unsigned short newVolume)
69{
71 volume = newVolume;
73}
74
75/* Function start: 0x00447C18 */
76void IxSound::ix_system_sound_set_pan(unsigned short newPan)
77{
79 pan = newPan;
80}
81
82/* Function start: 0x00447C44 */
84{
86 if (-(int)(sample->frequency - 1) <= newPitchOffset) {
87 pitchOffset = newPitchOffset < 0xac44 ? newPitchOffset : 0xac44;
88 } else {
89 pitchOffset = -(int)(sample->frequency - 1);
90 }
92}
93
94/* Function start: 0x00447CAF */
95void IxSound::ix_system_sound_set_priority(unsigned char newBasePriority)
96{
97 basePriority = newBasePriority;
99}
100
101/* Function start: 0x00447CD8 */ /* source line 103 */
102extern "C" void __fastcall ix_sound_start(IxSound *sound)
103{
104 int voice;
105 IxSound *lowestPlaying;
106 int releasedVoice;
107
108 if ((sound->flags & IX_SOUND_PLAYING) != 0) {
109 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 103);
110 ix_log_printf("sound already started!");
111 return;
112 }
113
114 sound->flags |= IX_SOUND_PLAYING;
115 sound->startTime = ix_dsp_get_tick();
116 if ((sound->sample->flags & IX_SAMPLE_LOOPING) != 0) {
117 sound->flags |= IX_SOUND_LOOPING;
119 sound->stopTime = (unsigned int)-1;
120 } else {
121 sound->stopTime = sound->startTime +
122 (sound->sample->sampleCount * 15) /
123 (sound->sample->frequency + sound->pitchOffset);
124 }
125
128
129 if (sound == pIdleSoundList)
130 pIdleSoundList = sound->next;
131 if (sound->next != 0)
132 sound->next->previous = sound->previous;
133 if (sound->previous != 0)
134 sound->previous->next = sound->next;
135 sound->next = pPlayingSoundList;
136 sound->previous = 0;
137 if (pPlayingSoundList != 0)
139 pPlayingSoundList = sound;
140 ix_system_assign_voice(sound, voice);
141 } else {
142 lowestPlaying = ix_system_find_lowest_playing(
144 if (lowestPlaying != 0) {
145 releasedVoice = ix_system_release_voice(lowestPlaying);
146
147 if (lowestPlaying == pPlayingSoundList)
148 pPlayingSoundList = lowestPlaying->next;
149 if (lowestPlaying->next != 0)
150 lowestPlaying->next->previous = lowestPlaying->previous;
151 if (lowestPlaying->previous != 0)
152 lowestPlaying->previous->next = lowestPlaying->next;
153 lowestPlaying->next = pQueuedSoundList;
154 lowestPlaying->previous = 0;
155 if (pQueuedSoundList != 0)
156 pQueuedSoundList->previous = lowestPlaying;
157 pQueuedSoundList = lowestPlaying;
158
159 if (sound == pIdleSoundList)
160 pIdleSoundList = sound->next;
161 if (sound->next != 0)
162 sound->next->previous = sound->previous;
163 if (sound->previous != 0)
164 sound->previous->next = sound->next;
165 sound->next = pPlayingSoundList;
166 sound->previous = 0;
167 if (pPlayingSoundList != 0)
169 pPlayingSoundList = sound;
170 ix_system_assign_voice(sound, releasedVoice);
171 } else {
172 if (sound == pIdleSoundList)
173 pIdleSoundList = sound->next;
174 if (sound->next != 0)
175 sound->next->previous = sound->previous;
176 if (sound->previous != 0)
177 sound->previous->next = sound->next;
178 sound->next = pQueuedSoundList;
179 sound->previous = 0;
180 if (pQueuedSoundList != 0)
181 pQueuedSoundList->previous = sound;
182 pQueuedSoundList = sound;
183 }
184 }
185}
186
187/* Function start: 0x0044801E */ /* source lines 151, 152 */
188extern "C" void __fastcall ix_sound_release(IxSound *sound)
189{
190 if ((sound->flags & IX_SOUND_PLAYING) == 0) {
191 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 151);
192 ix_log_printf("can't release non playing sound!");
193 return;
194 }
195 if ((sound->flags & IX_SOUND_LOOPING) == 0) {
196 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 152);
197 ix_log_printf("can't release non looping sound!");
198 return;
199 }
200 if ((sound->flags & IX_SOUND_HAS_VOICE) != 0) {
203 } else {
204 ix_sound_stop(sound);
205 }
206}
207
208/* Function start: 0x004480CF */ /* source line(s) 165: can't stop sound that's not playing! */
209extern "C" void __fastcall ix_sound_stop(IxSound *sound)
210{
211 IxSound *replacement;
212 int voice;
213
214 if ((sound->flags & IX_SOUND_PLAYING) == 0) {
215 ix_log_printf("Warning [%s - %d]:\n", IX_SOUND_FILE, 165);
216 ix_log_printf("can't stop sound that's not playing!");
217 return;
218 }
219
220 sound->flags &= ~IX_SOUND_PLAYING;
221 if ((sound->flags & IX_SOUND_HAS_VOICE) != 0) {
222 voice = ix_system_release_voice(sound);
223 replacement = ix_system_find_highest_waiting(
225
226 if (sound == pPlayingSoundList)
227 pPlayingSoundList = sound->next;
228 if (sound->next != 0)
229 sound->next->previous = sound->previous;
230 if (sound->previous != 0)
231 sound->previous->next = sound->next;
232 sound->next = pIdleSoundList;
233 sound->previous = 0;
234 if (pIdleSoundList != 0)
235 pIdleSoundList->previous = sound;
236 pIdleSoundList = sound;
237
238 if (replacement != 0) {
239 ix_system_assign_voice(replacement, voice);
240 if (replacement == pQueuedSoundList)
241 pQueuedSoundList = replacement->next;
242 if (replacement->next != 0)
243 replacement->next->previous = replacement->previous;
244 if (replacement->previous != 0)
245 replacement->previous->next = replacement->next;
246 replacement->next = pPlayingSoundList;
247 replacement->previous = 0;
248 if (pPlayingSoundList != 0)
249 pPlayingSoundList->previous = replacement;
250 pPlayingSoundList = replacement;
251 }
252 } else {
253 if (sound == pQueuedSoundList)
254 pQueuedSoundList = sound->next;
255 if (sound->next != 0)
256 sound->next->previous = sound->previous;
257 if (sound->previous != 0)
258 sound->previous->next = sound->next;
259 sound->next = pIdleSoundList;
260 sound->previous = 0;
261 if (pIdleSoundList != 0)
262 pIdleSoundList->previous = sound;
263 pIdleSoundList = sound;
264 }
265
266 if ((sound->flags & IX_SOUND_DELETE_ON_STOP) != 0)
268}
269
270/* Function start: 0x0044831A */
272{
273 unsigned int newPriority;
274
275 newPriority = (volume << 8) / 0xffff +
276 (pitchOffset << 8) / 0xac44 + basePriority;
277 if ((flags & IX_SOUND_HAS_VOICE) != 0) {
278 if (priority > newPriority) {
280 pQueuedSoundList, newPriority);
281 if (waitingSound != 0) {
282 int releasedVoice = ix_system_release_voice(this);
283
284 if (this == pPlayingSoundList)
286 if (next != 0)
288 if (previous != 0)
289 previous->next = next;
291 previous = 0;
292 if (pQueuedSoundList != 0)
294 pQueuedSoundList = this;
295
296 if (waitingSound == pQueuedSoundList)
297 pQueuedSoundList = waitingSound->next;
298 if (waitingSound->next != 0)
299 waitingSound->next->previous = waitingSound->previous;
300 if (waitingSound->previous != 0)
301 waitingSound->previous->next = waitingSound->next;
302 waitingSound->next = pPlayingSoundList;
303 waitingSound->previous = 0;
304 if (pPlayingSoundList != 0)
305 pPlayingSoundList->previous = waitingSound;
306 pPlayingSoundList = waitingSound;
307 ix_system_assign_voice(waitingSound, releasedVoice);
308 }
309 }
310 } else if ((flags & IX_SOUND_PLAYING) != 0 && priority < newPriority) {
312 pPlayingSoundList, newPriority);
313 if (playingSound != 0) {
314 int reassignedVoice = ix_system_release_voice(playingSound);
315
316 if (playingSound == pPlayingSoundList)
317 pPlayingSoundList = playingSound->next;
318 if (playingSound->next != 0)
319 playingSound->next->previous = playingSound->previous;
320 if (playingSound->previous != 0)
321 playingSound->previous->next = playingSound->next;
322 playingSound->next = pQueuedSoundList;
323 playingSound->previous = 0;
324 if (pQueuedSoundList != 0)
325 pQueuedSoundList->previous = playingSound;
326 pQueuedSoundList = playingSound;
327
328 if (this == pQueuedSoundList)
330 if (next != 0)
332 if (previous != 0)
333 previous->next = next;
335 previous = 0;
336 if (pPlayingSoundList != 0)
338 pPlayingSoundList = this;
339 ix_system_assign_voice(this, reassignedVoice);
340 }
341 }
342 priority = newPriority;
343}
344
345/* Function start: 0x00448645 */
347{
348 if (enabled != 0)
350 else
352}
353
354/* Function start: 0x00448678 */
355extern "C" int __fastcall ix_sound_is_playing(IxSound *sound)
356{
357 return (sound->flags & IX_SOUND_PLAYING) != 0;
358}
unsigned int ix_dsp_get_tick(void)
Definition dsp.cpp:134
void ix_dspv_clear_flag4(int voice)
Definition dspv.cpp:47
The library's classes and shared declarations.
int ix_system_find_free_voice(void)
Definition system.cpp:316
IxSound * pIdleSoundList
Definition system.cpp:15
IxSound * pPlayingSoundList
Definition system.cpp:19
@ IX_SAMPLE_LOOPING
Definition ix.h:134
void ix_log_printf(const char *fmt,...)
Definition ixlog.cpp:32
IxSound * ix_system_find_lowest_playing(IxSound *sound, unsigned int maximumPriority)
Definition system.cpp:300
int ix_system_release_voice(IxSound *sound)
Definition system.cpp:222
IxSound * ix_system_find_highest_waiting(IxSound *sound, unsigned int minimumPriority)
Definition system.cpp:284
@ IX_SOUND_LOOPING
Definition ix.h:141
@ IX_SOUND_HAS_VOICE
Definition ix.h:143
@ IX_SOUND_VOLUME_DIRTY
Definition ix.h:144
@ IX_SOUND_RELEASE_PENDING
Definition ix.h:147
@ IX_SOUND_PAN_DIRTY
Definition ix.h:146
@ IX_SOUND_ALLOCATED
Definition ix.h:139
@ IX_SOUND_FREQUENCY_DIRTY
Definition ix.h:145
@ IX_SOUND_DELETE_ON_STOP
Definition ix.h:142
@ IX_SOUND_PLAYING
Definition ix.h:140
IxSound * pQueuedSoundList
Definition system.cpp:20
void ix_system_assign_voice(IxSound *sound, int voice)
Definition system.cpp:234
int nSystemVoices
Definition system.cpp:18
int nActiveVoices
Definition system.cpp:17
void __fastcall ix_sound_unlink_from_free_list(IxSound *sound)
Definition sound.cpp:56
#define IX_SOUND_FILE
Definition sound.cpp:13
unsigned int flags
Definition wc1base.h:55
unsigned int frequency
Definition ix.h:117
unsigned int sampleCount
Definition ix.h:111
void ix_sound_reprioritise(void)
Definition sound.cpp:271
IxSound * next
Definition ix.h:162
unsigned short volume
Definition ix.h:158
void ix_system_sound_construct(IxSample *newSample, unsigned char newBasePriority)
Definition sound.cpp:43
void ix_system_sound_set_volume(unsigned short newVolume)
Definition sound.cpp:68
IxSound * previous
Definition ix.h:161
unsigned short pan
Definition ix.h:159
void ix_system_sound_set_frequency(int newPitchOffset)
Definition sound.cpp:83
unsigned int flags
Definition wc1base.h:62
int voice
Definition ix.h:153
void ix_system_sound_set_pan(unsigned short newPan)
Definition sound.cpp:76
IxSample * sample
Definition wc1base.h:63
unsigned int stopTime
Definition ix.h:155
unsigned int priority
Definition ix.h:156
void ix_system_sound_set_priority(unsigned char newBasePriority)
Definition sound.cpp:95
int pitchOffset
Definition ix.h:157
unsigned int startTime
Definition ix.h:154
void ix_system_sound_construct_centred(IxSample *newSample)
Definition sound.cpp:50
void ix_system_sound_init(IxSample *newSample, unsigned char newBasePriority, unsigned int initialVolume, int newPitchOffset, unsigned short newPan)
Definition sound.cpp:16
void ix_sound_set_delete_on_stop(int enabled)
Definition sound.cpp:346
unsigned char basePriority
Definition ix.h:160
void __fastcall ix_sound_stop(IxSound *sound)
Definition sound.cpp:209
int __fastcall ix_sound_is_playing(IxSound *sound)
Definition sound.cpp:355
void __fastcall ix_sound_start(IxSound *sound)
Definition sound.cpp:102
void ix_system_delete_sound(IxSound *sound)
Definition system.cpp:184
void __fastcall ix_sound_release(IxSound *sound)
Definition sound.cpp:188