Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
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
19
IxVoice
g_2_voices
[34];
/* 0x005c52f0 */
20
CRITICAL_SECTION
g_7_csMixer
;
/* 0x005c5730 */
21
int
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. */
26
void
ix_dspv_set_buffer
(
int
voice,
unsigned
char
*buffer,
int
length);
27
void
ix_dspv_set_position
(
int
voice,
int
offset);
28
void
ix_dspv_set_volume
(
int
voice,
short
volume);
29
30
/* Function start: 0x48A235 */
/* source line 23 */
31
void
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
}
38
g_2_voices
[voice].
flags
|=
IX_VOICE_ACTIVE
;
39
}
40
41
/* Function start: 0x48A299 */
/* source line 29 */
42
void
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
}
49
g_2_voices
[voice].
flags
&=
~IX_VOICE_ACTIVE
;
50
}
51
52
unsigned
int
ix_dspv_get_flags
(
int
voice);
53
54
/* Function start: 0x48A2FE */
/* source line 35 */
55
void
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
}
62
g_2_voices
[voice].
flags
&=
~IX_VOICE_FLAG4
;
63
}
64
65
/* Function start: 0x48A362 */
/* source line 41 */
66
unsigned
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. */
78
void
ix_dspv_set_flag4
(
int
voice,
int
on)
79
{
80
if
(on != 0)
81
g_2_voices
[voice].
flags
|=
IX_VOICE_FLAG4
;
82
else
83
g_2_voices
[voice].
flags
&=
~IX_VOICE_FLAG4
;
84
}
85
86
/* Function start: 0x48A3FF */
/* source line 55 */
87
void
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 */
104
int
ix_dspv_get_position
(
int
voice)
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
116
void
ix_dspv_recalc_mix
(
int
voice);
117
118
/* Function start: 0x48A510 */
/* source line 77 */
119
void
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
131
void
ix_dspv_set_pan
(
int
voice,
unsigned
short
angle);
132
void
ix_dspv_set_frequency
(
int
voice,
unsigned
int
hz);
133
134
/* Function start: 0x48A588 */
/* source line 85 */
135
void
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 */
147
void
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 */
177
void
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 */
189
void
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)
202
g_2_voices
[voice].
flags
|=
IX_VOICE_16BIT
;
203
else
204
g_2_voices
[voice].
flags
&=
~IX_VOICE_16BIT
;
205
}
206
207
/* Function start: 0x48A865 */
/* source lines 148, 149 */
208
void
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)
221
g_2_voices
[voice].
flags
|=
IX_VOICE_STEREO
;
222
else
223
g_2_voices
[voice].
flags
&=
~IX_VOICE_STEREO
;
224
}
225
226
/* Function start: 0x48A92F */
227
void
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. */
249
int
g_nVoicesReserved
;
/* 0x005c574c */
g_nVoicesReserved
int g_nVoicesReserved
Definition
dspv.cpp:249
g_nMasterVolume
unsigned short g_nMasterVolume
Definition
dsp.cpp:35
g_3_anPanTable
short g_3_anPanTable[512]
Definition
dsp.cpp:29
ix_dspv_set_channels
void ix_dspv_set_channels(int voice, int channels)
Definition
dspv.cpp:208
g_nVoiceCapacity
int g_nVoiceCapacity
Definition
dspv.cpp:21
ix_dspv_get_flags
unsigned int ix_dspv_get_flags(int voice)
Definition
dspv.cpp:66
ix_dspv_set_active
void ix_dspv_set_active(int voice)
Definition
dspv.cpp:31
ix_dspv_set_flag4
void ix_dspv_set_flag4(int voice, int on)
Definition
dspv.cpp:78
ix_dspv_set_bits_per_sample
void ix_dspv_set_bits_per_sample(int voice, int bps)
Definition
dspv.cpp:189
g_2_voices
IxVoice g_2_voices[34]
Definition
dspv.cpp:19
ix_dspv_set_buffer
void ix_dspv_set_buffer(int voice, unsigned char *buffer, int length)
Definition
dspv.cpp:87
ix_dspv_set_pan
void ix_dspv_set_pan(int voice, unsigned short angle)
Definition
dspv.cpp:147
ix_dspv_get_position
int ix_dspv_get_position(int voice)
Definition
dspv.cpp:104
ix_dspv_set_position
void ix_dspv_set_position(int voice, int offset)
Definition
dspv.cpp:119
ix_dspv_clear_flag4
void ix_dspv_clear_flag4(int voice)
Definition
dspv.cpp:55
ix_dspv_set_frequency
void ix_dspv_set_frequency(int voice, unsigned int hz)
Definition
dspv.cpp:177
g_7_csMixer
CRITICAL_SECTION g_7_csMixer
Definition
dspv.cpp:20
ix_dspv_clear_active
void ix_dspv_clear_active(int voice)
Definition
dspv.cpp:42
ix_dspv_set_volume
void ix_dspv_set_volume(int voice, short volume)
Definition
dspv.cpp:135
ix_dspv_recalc_mix
void ix_dspv_recalc_mix(int voice)
Definition
dspv.cpp:227
ix.h
Audio classes, DirectSound interfaces and shared ix state.
ix_log_printf
void ix_log_printf(const char *fmt,...)
Definition
stream.cpp:164
IX_MIXER_BASE_RATE
#define IX_MIXER_BASE_RATE
Definition
ix.h:160
IX_DSPV_FILE
#define IX_DSPV_FILE
Definition
ix.h:169
IX_VOICE_STEREO
@ IX_VOICE_STEREO
Definition
ix.h:45
IX_VOICE_FLAG4
@ IX_VOICE_FLAG4
Definition
ix.h:43
IX_VOICE_16BIT
@ IX_VOICE_16BIT
Definition
ix.h:44
IX_VOICE_ACTIVE
@ IX_VOICE_ACTIVE
Definition
ix.h:42
IxVoice
Definition
ix.h:48
IxVoice::start
unsigned char * start
Definition
ix.h:51
IxVoice::rate
short rate
Definition
ix.h:54
IxVoice::panPos
short panPos
Definition
ix.h:61
IxVoice::cursor
unsigned char * cursor
Definition
ix.h:50
IxVoice::leftGain
short leftGain
Definition
ix.h:58
IxVoice::end
unsigned char * end
Definition
ix.h:52
IxVoice::rightGainHi
unsigned char rightGainHi
Definition
ix.h:57
IxVoice::panAngle
short panAngle
Definition
ix.h:60
IxVoice::rightGain
short rightGain
Definition
ix.h:59
IxVoice::flags
unsigned int flags
Definition
ix.h:49
IxVoice::leftGainHi
unsigned char leftGainHi
Definition
ix.h:56
IxVoice::volume
unsigned short volume
Definition
ix.h:55
src
ix
dspv.cpp
Generated by
1.18.0