Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
dspv.cpp
Go to the documentation of this file.
1/*
2 * ix / D:\rnd\prj\ix\win95\dsp\dspv.cpp
3 *
4 * Original address range: 0x004467C5 - 0x004471FF (15 functions)
5 * Range is exact: recovered from this module's own assert __FILE__ anchors in
6 * the shipped debug build (see docs/ORDER.md).
7 *
8 * Built /Od like the rest of ix: full EBP frame, EBX/ESI/EDI saved whether used
9 * or not, one shared epilogue. Do not optimise this file.
10 *
11 * Implement in ADDRESS ORDER -- MSVC emits functions in source order, so the
12 * list below is the original source order of this file.
13 */
14#include "ix.h"
15#include <stdlib.h>
16#include <string.h>
17#include <time.h>
18
19IxVoice g_2_voices[34]; /* 0x005c52f0 */
20CRITICAL_SECTION g_7_csMixer; /* 0x005c5730 */
21int g_nVoiceCapacity; /* 0x005c5748 */
22
23/* The buffer, position and volume setters further down. With the voice
24 * table's initializer, their named parameters give this unit retail's
25 * symbol-key numbering. */
26void ix_dspv_set_buffer(int voice, unsigned char *buffer, int length);
27void ix_dspv_set_position(int voice, int offset);
28void ix_dspv_set_volume(int voice, short volume);
29
30/* Function start: 0x48A235 */ /* source line 23 */
31void ix_dspv_set_active(int voice)
32{
33 if (voice < 0 || voice >= g_nVoiceCapacity) {
34 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 23);
35 ix_log_printf("%d Invalid voice index!", voice);
36 exit(-1);
37 }
39}
40
41/* Function start: 0x48A299 */ /* source line 29 */
42void ix_dspv_clear_active(int voice)
43{
44 if (voice < 0 || voice >= g_nVoiceCapacity) {
45 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 29);
46 ix_log_printf("%d Invalid voice index!", voice);
47 exit(-1);
48 }
50}
51
52unsigned int ix_dspv_get_flags(int voice);
53
54/* Function start: 0x48A2FE */ /* source line 35 */
55void ix_dspv_clear_flag4(int voice)
56{
57 if (voice < 0 || voice >= g_nVoiceCapacity) {
58 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 35);
59 ix_log_printf("%d Invalid voice index!", voice);
60 exit(-1);
61 }
63}
64
65/* Function start: 0x48A362 */ /* source line 41 */
66unsigned int ix_dspv_get_flags(int voice)
67{
68 if (voice < 0 || voice >= g_nVoiceCapacity) {
69 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 41);
70 ix_log_printf("%d Invalid voice index!", voice);
71 exit(-1);
72 }
73 return g_2_voices[voice].flags;
74}
75
76/* Function start: 0x48A3C6 */
77/* No bounds check in the original -- callers are internal. */
78void ix_dspv_set_flag4(int voice, int on)
79{
80 if (on != 0)
82 else
84}
85
86/* Function start: 0x48A3FF */ /* source line 55 */
87void ix_dspv_set_buffer(int voice, unsigned char *p, int len)
88{
89 if (voice < 0 || voice >= g_nVoiceCapacity) {
90 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 55);
91 ix_log_printf("%d Invalid voice index!", voice);
92 exit(-1);
93 }
94 IxVoice *v = &g_2_voices[voice];
95
96 EnterCriticalSection(&g_7_csMixer);
97 v->cursor = p;
98 v->start = p;
99 v->end = p + len;
100 LeaveCriticalSection(&g_7_csMixer);
101}
102
103/* Function start: 0x48A49B */ /* source line 69 */
105{
106 if (voice < 0 || voice >= g_nVoiceCapacity) {
107 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 69);
108 ix_log_printf("%d Invalid voice index!", voice);
109 exit(-1);
110 }
111 IxVoice *v = &g_2_voices[voice];
112
113 return v->cursor - v->start;
114}
115
116void ix_dspv_recalc_mix(int voice);
117
118/* Function start: 0x48A510 */ /* source line 77 */
119void ix_dspv_set_position(int voice, int off)
120{
121 if (voice < 0 || voice >= g_nVoiceCapacity) {
122 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 77);
123 ix_log_printf("%d Invalid voice index!", voice);
124 exit(-1);
125 }
126 IxVoice *v = &g_2_voices[voice];
127
128 v->cursor = v->start + off;
129}
130
131void ix_dspv_set_pan(int voice, unsigned short angle);
132void ix_dspv_set_frequency(int voice, unsigned int hz);
133
134/* Function start: 0x48A588 */ /* source line 85 */
135void ix_dspv_set_volume(int voice, short vol)
136{
137 if (voice < 0 || voice >= g_nVoiceCapacity) {
138 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 85);
139 ix_log_printf("%d Invalid voice index!", voice);
140 exit(-1);
141 }
142 g_2_voices[voice].volume = vol;
143 ix_dspv_recalc_mix(voice);
144}
145
146/* Function start: 0x48A5FC */ /* source line 93 */
147void ix_dspv_set_pan(int voice, unsigned short angle)
148{
149 IxVoice *state;
150 short step;
151 short delta;
152 short position;
153
154 if (voice < 0 || g_nVoiceCapacity <= voice) {
155 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 93);
156 ix_log_printf("%d Invalid voice index!", voice);
157 exit(-1);
158 }
159 state = &g_2_voices[voice];
160 step = (short)((unsigned short)angle >> 9);
161 delta = step - state->panAngle;
162 if (delta > 0x40)
163 delta = delta - 0x80;
164 if (delta < -0x40)
165 delta = delta + 0x80;
166 position = state->panPos + delta;
167 if (position < 0)
168 position = position + 0x100;
169 if (position >= 0x100)
170 position = position - 0x100;
171 state->panAngle = step;
172 state->panPos = position;
173 ix_dspv_recalc_mix(voice);
174}
175
176/* Function start: 0x48A721 */ /* source line 131 */
177void ix_dspv_set_frequency(int voice, unsigned int hz)
178{
179 if (voice < 0 || g_nVoiceCapacity <= voice) {
180 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 131);
181 ix_log_printf("%d Invalid voice index!", voice);
182 exit(-1);
183 }
184 g_2_voices[voice].rate =
185 (short)(((int)(hz & 0xffff) << 8) / IX_MIXER_BASE_RATE);
186}
187
188/* Function start: 0x48A79C */ /* source lines 137, 138 */
189void ix_dspv_set_bits_per_sample(int voice, int bps)
190{
191 if (voice < 0 || voice >= g_nVoiceCapacity) {
192 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 137);
193 ix_log_printf("%d Invalid voice index!", voice);
194 exit(-1);
195 }
196 if (bps != 8 && bps != 16) {
197 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 138);
198 ix_log_printf("%d is an unsupported bps!", bps);
199 exit(-1);
200 }
201 if (bps == 16)
203 else
205}
206
207/* Function start: 0x48A865 */ /* source lines 148, 149 */
208void ix_dspv_set_channels(int voice, int channels)
209{
210 if (voice < 0 || voice >= g_nVoiceCapacity) {
211 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 148);
212 ix_log_printf("%d Invalid voice index!", voice);
213 exit(-1);
214 }
215 if (channels != 1 && channels != 2) {
216 ix_log_printf("Fatal [%s - %d]:\n", IX_DSPV_FILE, 149);
217 ix_log_printf("%d is an unsupported number of channels!", channels);
218 exit(-1);
219 }
220 if (channels == 2)
222 else
224}
225
226/* Function start: 0x48A92F */
227void ix_dspv_recalc_mix(int voice)
228{
229 IxVoice *state;
230 short position;
231 int level;
232
233 state = &g_2_voices[voice];
234 position = state->panPos;
235 level = ((unsigned int)state->volume
236 * (unsigned int)g_nMasterVolume) / 0xffff;
237 EnterCriticalSection(&g_7_csMixer);
238 state->leftGain =
239 (short)((int)g_3_anPanTable[position * 2] * level >> 0x10);
240 state->rightGain =
241 (short)((int)g_3_anPanTable[position * 2 + 1] * level >> 0x10);
242 state->leftGainHi = (unsigned char)(state->leftGain >> 8);
243 state->rightGainHi = (unsigned char)(state->rightGain >> 8);
244 LeaveCriticalSection(&g_7_csMixer);
245}
246
247/* The allocated-voice counter that dsp.cpp maintains; retail keeps it in
248 * this unit's .bss. */
249int g_nVoicesReserved; /* 0x005c574c */
int g_nVoicesReserved
Definition dspv.cpp:249
unsigned short g_nMasterVolume
Definition dsp.cpp:35
short g_3_anPanTable[512]
Definition dsp.cpp:29
void ix_dspv_set_channels(int voice, int channels)
Definition dspv.cpp:208
int g_nVoiceCapacity
Definition dspv.cpp:21
unsigned int ix_dspv_get_flags(int voice)
Definition dspv.cpp:66
void ix_dspv_set_active(int voice)
Definition dspv.cpp:31
void ix_dspv_set_flag4(int voice, int on)
Definition dspv.cpp:78
void ix_dspv_set_bits_per_sample(int voice, int bps)
Definition dspv.cpp:189
IxVoice g_2_voices[34]
Definition dspv.cpp:19
void ix_dspv_set_buffer(int voice, unsigned char *buffer, int length)
Definition dspv.cpp:87
void ix_dspv_set_pan(int voice, unsigned short angle)
Definition dspv.cpp:147
int ix_dspv_get_position(int voice)
Definition dspv.cpp:104
void ix_dspv_set_position(int voice, int offset)
Definition dspv.cpp:119
void ix_dspv_clear_flag4(int voice)
Definition dspv.cpp:55
void ix_dspv_set_frequency(int voice, unsigned int hz)
Definition dspv.cpp:177
CRITICAL_SECTION g_7_csMixer
Definition dspv.cpp:20
void ix_dspv_clear_active(int voice)
Definition dspv.cpp:42
void ix_dspv_set_volume(int voice, short volume)
Definition dspv.cpp:135
void ix_dspv_recalc_mix(int voice)
Definition dspv.cpp:227
Audio classes, DirectSound interfaces and shared ix state.
void ix_log_printf(const char *fmt,...)
Definition stream.cpp:164
#define IX_MIXER_BASE_RATE
Definition ix.h:160
#define IX_DSPV_FILE
Definition ix.h:169
@ IX_VOICE_STEREO
Definition ix.h:45
@ IX_VOICE_FLAG4
Definition ix.h:43
@ IX_VOICE_16BIT
Definition ix.h:44
@ IX_VOICE_ACTIVE
Definition ix.h:42
Definition ix.h:48
unsigned char * start
Definition ix.h:51
short rate
Definition ix.h:54
short panPos
Definition ix.h:61
unsigned char * cursor
Definition ix.h:50
short leftGain
Definition ix.h:58
unsigned char * end
Definition ix.h:52
unsigned char rightGainHi
Definition ix.h:57
short panAngle
Definition ix.h:60
short rightGain
Definition ix.h:59
unsigned int flags
Definition ix.h:49
unsigned char leftGainHi
Definition ix.h:56
unsigned short volume
Definition ix.h:55