Debian Codegraph @

sndlib/mixer.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <cstdlib>
20 #include <memory.h>
21
22 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
23 #include "ssl_lib.h"cxx . . $ `<file>/sndlib/ssl_lib.h`/
24 #include "mixer.h"cxx . . $ `<file>/sndlib/mixer.h`/
25 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
26
27 #define MIN_SOUND_MIX_VOLUMEcxx . . $ `sndlib/mixer.cpp:27:9`! 0.0f
28 #define MAX_WRITE_AHEADcxx . . $ `sndlib/mixer.cpp:28:9`! 0.04f // Seconds to write ahead of the play position (in seconds)
29 #define VOLUME_FIX_BITScxx . . $ `sndlib/mixer.cpp:29:9`! 1024
30
31 static inline void opti_8m_mixcxx . . $ opti_8m_mix(f587a911870491b1).(uint8_tcxx . . $ uint8_t# *cur_sample_8bit, const int num_write, int &samples_played,
32 int16_t *mixer_buffer16, const float l_volume, const float r_volume);
33 static inline void opti_8s_mixcxx . . $ opti_8s_mix(f587a911870491b1).(uint8_tcxx . . $ uint8_t# *cur_sample_8bit, const int num_write, int &samples_played,
34 int16_t *mixer_buffer16, const float l_volume, const float r_volume);
35 static inline void opti_16m_mixcxx . . $ opti_16m_mix(e74084f81eb47777).(int16_t *cur_sample_16bit, const int num_write, int &samples_played,
36 int16_t *mixer_buffer16, const float l_volume, const float r_volume);
37 static inline void opti_16s_mixcxx . . $ opti_16s_mix(e74084f81eb47777).(int16_t *cur_sample_16bit, const int num_write, int &samples_played,
38 int16_t *mixer_buffer16, const float l_volume, const float r_volume);
39
40 software_mixercxx . . $ software_mixer#::software_mixercxx . . $ software_mixer#software_mixer(49f6e7a06ebc5aa8).() {
41 m_initcxx . . $ software_mixer#m_init. = false;
42 m_buffercxx . . $ software_mixer#m_buffer. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
43 }
44
45 software_mixercxx . . $ software_mixer#::~cxx . . $ software_mixer#`~software_mixer`(ced63f7c635d850d).software_mixercxx . . $ software_mixer#() {
46 if (m_buffercxx . . $ software_mixer#m_buffer.) {
47 freecxx . . $ free(bd21765a0afc8e3c).(m_buffercxx . . $ software_mixer#m_buffer.);
48 }
49 }
50
51 bool software_mixercxx . . $ software_mixer#::Initializecxx . . $ software_mixer#Initialize(f98e0e26c84ad24b).(tMixerInitcxx . . $ tMixerInit# *mi) {
52 if (m_initcxx . . $ software_mixer#m_init.) {
53 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Mixer: Already Init\n");
54 Int3cxx . . $ `misc/pserror.h:247:9`!();
55 return false;
56 }
57
58 // Sam 6/29 - When using SDL, there's no primary buffer
59 // if(!mi->primary_buffer || !mi->ll_sound_ptr)
60 if (!mi->ll_sound_ptrcxx . . $ tMixerInit#ll_sound_ptr.) {
61 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Mixer: Bad Value passed on init\n");
62 Int3cxx . . $ `misc/pserror.h:247:9`!();
63 return false;
64 }
65
66 m_initcxx . . $ software_mixer#m_init. = true;
67
68 m_ll_sound_ptrcxx . . $ software_mixer#m_ll_sound_ptr. = mi->ll_sound_ptrcxx . . $ tMixerInit#ll_sound_ptr.;
69 m_primary_buffercxx . . $ software_mixer#m_primary_buffer. = mi->primary_buffercxx . . $ tMixerInit#primary_buffer.;
70
71 if (m_primary_buffercxx . . $ software_mixer#m_primary_buffer.) {
72 m_BufferSizecxx . . $ software_mixer#m_BufferSize. = m_primary_buffercxx . . $ software_mixer#m_primary_buffer.->GetNumBufferBytescxx . . $ sound_buffer#GetNumBufferBytes(b126dc7c1de90089).();
73 } else {
74 m_BufferSizecxx . . $ software_mixer#m_BufferSize. = 0;
75 }
76
77 m_max_sounds_availablecxx . . $ software_mixer#m_max_sounds_available. = mi->max_sounds_availablecxx . . $ tMixerInit#max_sounds_available.;
78 m_sound_cachecxx . . $ software_mixer#m_sound_cache. = mi->sound_cachecxx . . $ tMixerInit#sound_cache.;
79 m_primary_alignmentcxx . . $ software_mixer#m_primary_alignment. = mi->primary_alignmentcxx . . $ tMixerInit#primary_alignment.;
80
81 m_error_codecxx . . $ software_mixer#m_error_code. = mi->p_error_codecxx . . $ tMixerInit#p_error_code.;
82 m_fpSetErrorcxx . . $ software_mixer#m_fpSetError. = mi->fp_SetErrorcxx . . $ tMixerInit#fp_SetError.;
83 m_fpErrorTextcxx . . $ software_mixer#m_fpErrorText. = mi->fp_ErrorTextcxx . . $ tMixerInit#fp_ErrorText.;
84
85 if (m_BufferSizecxx . . $ software_mixer#m_BufferSize.) {
86 m_buffercxx . . $ software_mixer#m_buffer. = (uint8_tcxx . . $ uint8_t# *)malloccxx . . $ malloc(9f008b2a9698428b).(m_BufferSizecxx . . $ software_mixer#m_BufferSize.);
87 }
88
89 return true;
90 }
91
92 // A peroidic mixer that uses the primary buffer as a stream buffer
93 void software_mixercxx . . $ software_mixer#::DoFramecxx . . $ software_mixer#DoFrame(49f6e7a06ebc5aa8).(void) {
94 if (!m_initcxx . . $ software_mixer#m_init.)
95 return;
96
97 int amount = m_BufferSizecxx . . $ software_mixer#m_BufferSize.;
98
99 StreamMixercxx . . $ software_mixer#StreamMixer(a07d8cccb7673f5a).((char *)m_buffercxx . . $ software_mixer#m_buffer., amount);
100 m_primary_buffercxx . . $ software_mixer#m_primary_buffer.->Writecxx . . $ sound_buffer#Write(fc0f0e1646c32816).(m_buffercxx . . $ software_mixer#m_buffer., amount);
101 }
102
103 // The actual mixer code that sum's the sounds on each channel and does all the actual
104 // mixing and effects (writes data to the locked primary buffer)
105 void software_mixercxx . . $ software_mixer#::StreamMixercxx . . $ software_mixer#StreamMixer(a07d8cccb7673f5a).(char *ptr, int len) {
106 int i;
107 int16_t *mixer_buffer16 = (int16_t *)ptr;
108 int current_slot = 0;
109 bool f_loop;
110 bool f_mono;
111
112 const int buff_len = len / m_primary_alignmentcxx . . $ software_mixer#m_primary_alignment.;
113
114 // this code will assure that this function will not be called when sound system is in error mode.
115 if (*m_error_codecxx . . $ software_mixer#m_error_code. != SSL_OKcxx . . $ `sndlib/ssl_lib.h:410:9`!) {
116 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "MIX: Mixer in error code %d\n", *m_error_code);
117 return;
118 }
119
120 // ASSERT(len <= m_BufferSize);
121 ASSERTcxx . . $ `misc/pserror.h:246:9`!(ptr && len >= 0);
122
123 if ((len % m_primary_alignmentcxx . . $ software_mixer#m_primary_alignment.) != 0) {
124 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "MIX:Len is not aligned!\n");
125 (*m_fpSetErrorcxx . . $ software_mixer#m_fpSetError.)(SSL_ERROR_STREAMMIXERcxx . . $ `sndlib/ssl_lib.h:413:9`!);
126 (*m_fpErrorTextcxx . . $ software_mixer#m_fpErrorText.)("ASSERT((len % ll_sound_ptr->m_primary_alignment) == 0)\nLen:%d PrA:%d", len, m_primary_alignmentcxx . . $ software_mixer#m_primary_alignment.);
127 return;
128 }
129
130 memset((char *)ptr, 0, len);
131
132 // Mix the sound slots
133 while (current_slot < (*m_max_sounds_availablecxx . . $ software_mixer#m_max_sounds_available.)) {
134 sound_buffer_infocxx . . $ sound_buffer_info# *cur_buf = &m_sound_cachecxx . . $ software_mixer#m_sound_cache.[current_slot];
135 int num_samples = buff_len;
136 mixer_buffer16 = (int16_t *)ptr;
137 f_mono = true;
138
139 // Find slots with sounds in them
140 if ((cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. != SSF_UNUSEDcxx . . $ `sndlib/ssl_lib.h:416:9`!) && !(cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. & SSF_PAUSEDcxx . . $ `sndlib/ssl_lib.h:419:9`!)) {
141 float l_volume = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->left_volumecxx . . $ play_information#left_volume.;
142 float r_volume = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->right_volumecxx . . $ play_information#right_volume.;
143 int skip_interval = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->sample_skip_intervalcxx . . $ play_information#sample_skip_interval.;
144 int samples_played = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_samples_playedcxx . . $ play_information#m_samples_played.;
145 int16_t *sample_16bit;
146 uint8_tcxx . . $ uint8_t# *sample_8bit;
147 int np_sample_length = 0;
148 int sample_length;
149 int loop_start;
150 int loop_end;
151
152 if (cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. & SSF_PLAY_STREAMINGcxx . . $ `sndlib/ssl_lib.h:420:9`!) {
153 switch (cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_formatcxx . . $ play_information#m_stream_format.) {
154 case SIF_STREAMING_16_Mcxx . . $ `sndlib/ssl_lib.h:385:9`!:
155 sample_16bit = (int16_t *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
156 sample_8bit = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
157 np_sample_length = sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size. / 2;
158 break;
159 case SIF_STREAMING_8_Mcxx . . $ `sndlib/ssl_lib.h:384:9`!:
160 sample_16bit = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
161 sample_8bit = (uint8_tcxx . . $ uint8_t# *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
162 np_sample_length = sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size.;
163 break;
164 case SIF_STREAMING_16_Scxx . . $ `sndlib/ssl_lib.h:387:9`!:
165 sample_16bit = (int16_t *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
166 sample_8bit = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
167 np_sample_length = sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size. / 4;
168 f_mono = false;
169 break;
170 case SIF_STREAMING_8_Scxx . . $ `sndlib/ssl_lib.h:386:9`!:
171 sample_16bit = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
172 sample_8bit = (uint8_tcxx . . $ uint8_t# *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
173 np_sample_length = sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size. / 2;
174 f_mono = false;
175 break;
176 default:
177 Int3cxx . . $ `misc/pserror.h:247:9`!();
178 break;
179 }
180 loop_start = 0;
181 loop_end = np_sample_length - 1;
182 } else {
183 int sound_index = cur_buf->m_sound_indexcxx . . $ sound_buffer_info#m_sound_index.;
184 int sample_index = Soundscxx . . $ Sounds.[sound_index].sample_indexcxx . . $ sound_info#sample_index.;
185 sound_file_infocxx . . $ sound_file_info# *snd_file = &SoundFilescxx . . $ SoundFiles.[sample_index];
186 sample_16bit = snd_file->sample_16bitcxx . . $ sound_file_info#sample_16bit.;
187 sample_8bit = snd_file->sample_8bitcxx . . $ sound_file_info#sample_8bit.;
188 np_sample_length = snd_file->np_sample_lengthcxx . . $ sound_file_info#np_sample_length.;
189 sample_length = snd_file->sample_lengthcxx . . $ sound_file_info#sample_length.;
190 loop_start = Soundscxx . . $ Sounds.[sound_index].loop_startcxx . . $ sound_info#loop_start.;
191 loop_end = Soundscxx . . $ Sounds.[sound_index].loop_endcxx . . $ sound_info#loop_end.;
192 if (!sample_16bit && !sample_8bit) {
193 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "sound file %s didn't have data for samples.\n", snd_file->name);
194 }
195 }
196
197 // cleanly continue if this happens, and inform a logfile, if it does. error handling
198 // ASSERT(sample_16bit || sample_8bit);
199 if (!sample_16bit && !sample_8bit) {
200 sound_file_infocxx . . $ sound_file_info# *snd_file = &SoundFilescxx . . $ SoundFiles.[Soundscxx . . $ Sounds.[cur_buf->m_sound_indexcxx . . $ sound_buffer_info#m_sound_index.].sample_indexcxx . . $ sound_info#sample_index.];
201 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "MIX: No data for %s\n", snd_file->name);
202 (*m_fpSetErrorcxx . . $ software_mixer#m_fpSetError.)(SSL_ERROR_SAMPLE_NODATAcxx . . $ `sndlib/ssl_lib.h:412:9`!);
203 (*m_fpErrorTextcxx . . $ software_mixer#m_fpErrorText.)("ASSERT(sample_16bit || sample_8bit)\nNo data found for sound file: %s", snd_file->namecxx . . $ sound_file_info#name.);
204 cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. = SSF_UNUSEDcxx . . $ `sndlib/ssl_lib.h:416:9`!;
205 goto error_bail;
206 }
207
208 ASSERTcxx . . $ `misc/pserror.h:246:9`!(np_sample_length <= sample_length);
209 ASSERTcxx . . $ `misc/pserror.h:246:9`!(samples_played >= 0 || samples_played <= sample_length);
210
211 int num_write;
212
213 error_trap:
214
215 // We have not looped -- yet
216 f_loop = false;
217
218 // Verify the volume levels are o.k.
219 ASSERTcxx . . $ `misc/pserror.h:246:9`!(l_volume >= 0.0 && l_volume <= 1.0);
220 ASSERTcxx . . $ `misc/pserror.h:246:9`!(r_volume >= 0.0 && r_volume <= 1.0);
221
222 looping: // Will go to this label to do the next iteration of a looping sample
223
224 if (cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. &
225 (SSF_PLAY_LOOPINGcxx . . $ `sndlib/ssl_lib.h:418:9`! | SSF_PLAY_STREAMINGcxx . . $ `sndlib/ssl_lib.h:420:9`!)) // Looping sample's process is broken up into linear pieces
226 {
227 if (f_loop) {
228 ASSERTcxx . . $ `misc/pserror.h:246:9`!(num_write >= 0);
229
230 num_samples -= num_write;
231 ASSERTcxx . . $ `misc/pserror.h:246:9`!(num_samples > 0);
232
233 mixer_buffer16 += num_write << 1; // update to the new start position
234 // (2x because of left and right channels)
235 samples_played = loop_start;
236 }
237
238 if (cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. & SSF_PLAY_LOOPINGcxx . . $ `sndlib/ssl_lib.h:418:9`!) // Looping sample's process is broken up into linear pieces
239 {
240 ASSERTcxx . . $ `misc/pserror.h:246:9`!(loop_end < sample_length);
241 if (loop_end < samples_played) {
242 if (loop_end != loop_start) {
243 while (loop_end < samples_played) {
244 samples_played -= loop_end - loop_start;
245 }
246
247 ASSERTcxx . . $ `misc/pserror.h:246:9`!(samples_played >= 0);
248 } else {
249 cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. &= ~SSF_PLAY_LOOPINGcxx . . $ `sndlib/ssl_lib.h:418:9`!;
250 cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. |= SSF_PLAY_NORMALcxx . . $ `sndlib/ssl_lib.h:417:9`!;
251 }
252
253 goto error_trap;
254 }
255 }
256 // The number of samples to write to the primary buffer
257 num_write = ((num_samples) < (loop_end - samples_played + 1)) ? (num_samples) : (loop_end - samples_played + 1);
258 ASSERTcxx . . $ `misc/pserror.h:246:9`!(num_write >= 0 && num_write <= num_samples);
259
260 if (num_write < num_samples)
261 f_loop = true;
262 else
263 f_loop = false;
264
265 if (num_write <= 0) {
266 num_write = 0;
267 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "d");
268 goto stream_done;
269 }
270 } else {
271 // The number of samples to write to the primary buffer
272 num_write =
273 ((num_samples) < (np_sample_length - samples_played)) ? (num_samples) : (np_sample_length - samples_played);
274 if (!(num_write > 0 && num_write <= num_samples)) {
275 num_write = 0;
276 goto done;
277 }
278
279 // Optimization for silent sounds
280 if (l_volume <= MIN_SOUND_MIX_VOLUMEcxx . . $ `sndlib/mixer.cpp:27:9`! && r_volume <= MIN_SOUND_MIX_VOLUMEcxx . . $ `sndlib/mixer.cpp:27:9`!) {
281 cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_samples_playedcxx . . $ play_information#m_samples_played. += num_write;
282 goto done;
283 }
284 }
285
286 if ((num_write < 0) || (num_write > num_samples)) // this was an assert
287 {
288 num_write = 0;
289 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "D");
290 goto done;
291 }
292
293 // Mix at 16 bits per sample
294 if (skip_interval == 0) {
295 int16_t *cur_sample_16bit = sample_16bit;
296 uint8_tcxx . . $ uint8_t# *cur_sample_8bit = sample_8bit;
297
298 if (f_mono) {
299 if (sample_8bit) {
300 cur_sample_8bit += samples_played;
301 opti_8m_mixcxx . . $ opti_8m_mix(f587a911870491b1).(cur_sample_8bit, num_write, samples_played, mixer_buffer16, l_volume, r_volume);
302 } else {
303 cur_sample_16bit += samples_played;
304 opti_16m_mixcxx . . $ opti_16m_mix(e74084f81eb47777).(cur_sample_16bit, num_write, samples_played, mixer_buffer16, l_volume, r_volume);
305 }
306 } else {
307 if (sample_8bit) {
308 cur_sample_8bit += (samples_played << 1);
309 opti_8s_mixcxx . . $ opti_8s_mix(f587a911870491b1).(cur_sample_8bit, num_write, samples_played, mixer_buffer16, l_volume, r_volume);
310 } else {
311 cur_sample_16bit += (samples_played << 1);
312 opti_16s_mixcxx . . $ opti_16s_mix(e74084f81eb47777).(cur_sample_16bit, num_write, samples_played, mixer_buffer16, l_volume, r_volume);
313 }
314 }
315 } else
316 // Account for lower-sampling rate
317 {
318 if (skip_interval == 1) {
319 for (i = 0; i < (num_write << 1); i += 2) {
320 int sample;
321
322 if (sample_16bit) {
323 if (samples_played & 0x0001) {
324 sample = ((int)sample_16bit[samples_played ^ 0x0001] + (int)sample_16bit[samples_played + 1]) >> 1;
325 } else
326 sample = sample_16bit[samples_played];
327 } else {
328 if (samples_played & 0x0001) {
329 // Notes: (<<7) is from a (<<8) - (>>1)
330 // Notes: (-256) is from (-128) + (-128)
331 sample = ((int)sample_8bit[samples_played ^ 0x0001] + (int)sample_8bit[samples_played + 1] - 256) << 7;
332 } else
333 sample = (((int)sample_8bit[samples_played]) - (int)128) << 8;
334 }
335
336 samples_played++;
337
338 ASSERTcxx . . $ `misc/pserror.h:246:9`!(i >= 0 && (i + 1 < num_samples * 2));
339
340 int l_sample = mixer_buffer16[i] + (sample * l_volume);
341 int r_sample = mixer_buffer16[i + 1] + (sample * r_volume);
342
343 if (l_sample < -32767)
344 l_sample = -32767;
345 if (l_sample > 32767)
346 l_sample = 32767;
347 if (r_sample < -32767)
348 r_sample = -32767;
349 if (r_sample > 32767)
350 r_sample = 32767;
351
352 mixer_buffer16[i] = (int16_t)l_sample;
353 mixer_buffer16[i + 1] = (int16_t)r_sample;
354 }
355 } else {
356 for (i = 0; i < (num_write << 1); i += 2) {
357 int sample;
358 const int mod_pos = samples_played % 4;
359
360 if (sample_16bit) {
361 switch (mod_pos) {
362 case 0:
363 sample = sample_16bit[samples_played];
364 break;
365 case 1:
366 sample = (sample_16bit[samples_played - 1] * 3 + sample_16bit[samples_played + 3]) >> 2;
367 break;
368 case 2:
369 sample = (sample_16bit[samples_played - 2] + sample_16bit[samples_played + 2]) >> 1;
370 break;
371 case 3:
372 sample = (sample_16bit[samples_played - 3] + sample_16bit[samples_played + 1] * 3) >> 2;
373 break;
374 }
375 } else {
376 switch (mod_pos) {
377 case 0:
378 sample = ((((int)sample_8bit[samples_played]) - 128) << 8);
379 break;
380 case 1:
381 sample = (((((int)sample_8bit[samples_played - 1]) - 128) << 8) * 3 +
382 ((((int)sample_8bit[samples_played + 3]) - 128) << 8)) >>
383 2;
384 break;
385 case 2:
386 sample = (((((int)sample_8bit[samples_played - 2]) - 128) << 8) +
387 ((((int)sample_8bit[samples_played + 2]) - 128) << 8)) >>
388 1;
389 break;
390 case 3:
391 sample = (((((int)sample_8bit[samples_played - 3]) - 128) << 8) +
392 ((((int)sample_8bit[samples_played + 1]) - 128) << 8) * 3) >>
393 2;
394 break;
395 }
396 }
397
398 samples_played++;
399
400 ASSERTcxx . . $ `misc/pserror.h:246:9`!(i >= 0 && (i + 1 < num_samples * 2));
401
402 int l_sample = mixer_buffer16[i] + (sample * l_volume);
403 int r_sample = mixer_buffer16[i + 1] + (sample * r_volume);
404
405 if (l_sample < -32767)
406 l_sample = -32767;
407 if (l_sample > 32767)
408 l_sample = 32767;
409 if (r_sample < -32767)
410 r_sample = -32767;
411 if (r_sample > 32767)
412 r_sample = 32767;
413
414 mixer_buffer16[i] = (int16_t)l_sample;
415 mixer_buffer16[i + 1] = (int16_t)r_sample;
416 }
417 }
418 }
419
420 stream_done:
421
422 cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_samples_playedcxx . . $ play_information#m_samples_played. = samples_played;
423
424 if (cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. & SSF_PLAY_STREAMINGcxx . . $ `sndlib/ssl_lib.h:420:9`!) {
425 if (f_loop) {
426 if (cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_cbackcxx . . $ play_information#m_stream_cback. && cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.) {
427 cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data. = (*cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_cbackcxx . . $ play_information#m_stream_cback.)(
428 cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->user_datacxx . . $ play_information#user_data., cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_handlecxx . . $ play_information#m_stream_handle., &cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size.);
429 // cur_buf->s->current_position = (char*)cur_buf->play_info->m_stream_data;
430 // mprintf(0, "%x %d\n", cur_buf->play_info->m_stream_data, cur_buf->play_info->m_stream_size));
431 ASSERTcxx . . $ `misc/pserror.h:246:9`!(!(cur_buf->play_info->m_stream_data && cur_buf->play_info->m_stream_size <= 0));
432 // mprintf(0, "Data %X, length %d\n", cur_buf->play_info->m_stream_data, cur_buf->play_info->m_stream_size);
433
434 if (cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.) {
435 switch (cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_formatcxx . . $ play_information#m_stream_format.) {
436 case SIF_STREAMING_16_Mcxx . . $ `sndlib/ssl_lib.h:385:9`!:
437 sample_16bit = (int16_t *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
438 loop_end = sample_length = np_sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size. / 2;
439 break;
440 case SIF_STREAMING_8_Mcxx . . $ `sndlib/ssl_lib.h:384:9`!:
441 sample_8bit = (uint8_tcxx . . $ uint8_t# *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
442 loop_end = sample_length = np_sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size.;
443 break;
444 case SIF_STREAMING_16_Scxx . . $ `sndlib/ssl_lib.h:387:9`!:
445 sample_16bit = (int16_t *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
446 loop_end = sample_length = np_sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size. / 4;
447 break;
448 case SIF_STREAMING_8_Scxx . . $ `sndlib/ssl_lib.h:386:9`!:
449 sample_8bit = (uint8_tcxx . . $ uint8_t# *)cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_datacxx . . $ play_information#m_stream_data.;
450 loop_end = sample_length = np_sample_length = cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_stream_sizecxx . . $ play_information#m_stream_size. / 2;
451 break;
452 default:
453 Int3cxx . . $ `misc/pserror.h:247:9`!();
454 break;
455 }
456 loop_end -= 1;
457 } else {
458 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "SE: Data is NULL\n");
459 cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. &= ~SSF_PLAY_STREAMINGcxx . . $ `sndlib/ssl_lib.h:420:9`!;
460 f_loop = false;
461 }
462 } else {
463 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "SE: Callback/data is NULL\n");
464 cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. &= ~SSF_PLAY_STREAMINGcxx . . $ `sndlib/ssl_lib.h:420:9`!;
465 f_loop = false;
466 }
467 }
468 }
469
470 if (f_loop)
471 goto looping;
472
473 done:
474
475 if (cur_buf->play_infocxx . . $ sound_buffer_info#play_info.->m_samples_playedcxx . . $ play_information#m_samples_played. >= (np_sample_length) &&
476 !(cur_buf->m_statuscxx . . $ sound_buffer_info#m_status. & (SSF_PLAY_LOOPINGcxx . . $ `sndlib/ssl_lib.h:418:9`! | SSF_PLAY_STREAMINGcxx . . $ `sndlib/ssl_lib.h:420:9`!))) {
477 m_ll_sound_ptrcxx . . $ software_mixer#m_ll_sound_ptr.->StopSoundcxx . . $ llsSystem#StopSound(9633529ce3c4ff50).(cur_buf->m_unique_idcxx . . $ sound_buffer_info#m_unique_id.);
478 }
479 }
480
481 error_bail:
482 current_slot++;
483 }
484 }
485
486 inline void opti_8m_mixcxx . . $ opti_8m_mix(f587a911870491b1).(uint8_tcxx . . $ uint8_t# *cur_sample_8bit, const int num_write, int &samples_played, int16_t *mixer_buffer16,
487 const float l_volume, const float r_volume) {
488 int i;
489 int16_t *mb = mixer_buffer16;
490
491 for (i = 0; i < (num_write << 1); i += 2) {
492 int16_t sample;
493 int l_sample;
494 int r_sample;
495
496 sample = (((int16_t)(*cur_sample_8bit)) - (int16_t)128) << 8;
497 cur_sample_8bit++;
498
499 l_sample = *mb + (sample * l_volume);
500 r_sample = *(mb + 1) + (sample * r_volume);
501
502 samples_played++;
503
504 if (l_sample < -32767)
505 l_sample = -32767;
506 if (l_sample > 32767)
507 l_sample = 32767;
508 if (r_sample < -32767)
509 r_sample = -32767;
510 if (r_sample > 32767)
511 r_sample = 32767;
512
513 *mb = (int16_t)l_sample;
514 mb++;
515 *mb = (int16_t)r_sample;
516 mb++;
517 }
518 }
519
520 inline void opti_8s_mixcxx . . $ opti_8s_mix(f587a911870491b1).(uint8_tcxx . . $ uint8_t# *cur_sample_8bit, const int num_write, int &samples_played, int16_t *mixer_buffer16,
521 const float l_volume, const float r_volume) {
522 int i;
523 int16_t *mb = mixer_buffer16;
524
525 for (i = 0; i < (num_write << 1); i += 2) {
526 int16_t lsample;
527 int16_t rsample;
528 int l_sample;
529 int r_sample;
530
531 lsample = (((int16_t)(*cur_sample_8bit)) - (int16_t)128) << 8;
532 cur_sample_8bit++;
533 rsample = (((int16_t)(*cur_sample_8bit)) - (int16_t)128) << 8;
534 cur_sample_8bit++;
535
536 l_sample = *mb + (lsample * l_volume);
537 r_sample = *(mb + 1) + (rsample * r_volume);
538
539 samples_played++;
540
541 if (l_sample < -32767)
542 l_sample = -32767;
543 if (l_sample > 32767)
544 l_sample = 32767;
545 if (r_sample < -32767)
546 r_sample = -32767;
547 if (r_sample > 32767)
548 r_sample = 32767;
549
550 *mb = (int16_t)l_sample;
551 mb++;
552 *mb = (int16_t)r_sample;
553 mb++;
554 }
555 }
556
557 inline void opti_16m_mixcxx . . $ opti_16m_mix(e74084f81eb47777).(int16_t *cur_sample_16bit, const int num_write, int &samples_played, int16_t *mixer_buffer16,
558 const float l_volume, const float r_volume) {
559 int i;
560 int16_t *mb = mixer_buffer16;
561
562 for (i = 0; i < (num_write << 1); i += 2) {
563 int16_t sample;
564 int l_sample;
565 int r_sample;
566
567 sample = *cur_sample_16bit;
568 cur_sample_16bit++;
569
570 l_sample = *mb + (sample * l_volume);
571 r_sample = *(mb + 1) + (sample * r_volume);
572
573 samples_played++;
574
575 if (l_sample < -32767)
576 l_sample = -32767;
577 if (l_sample > 32767)
578 l_sample = 32767;
579 if (r_sample < -32767)
580 r_sample = -32767;
581 if (r_sample > 32767)
582 r_sample = 32767;
583
584 *mb = (int16_t)l_sample;
585 mb++;
586 *mb = (int16_t)r_sample;
587 mb++;
588 }
589 }
590
591 inline void opti_16s_mixcxx . . $ opti_16s_mix(e74084f81eb47777).(int16_t *cur_sample_16bit, const int num_write, int &samples_played, int16_t *mixer_buffer16,
592 const float l_volume, const float r_volume) {
593 int i;
594 int16_t *mb = mixer_buffer16;
595
596 for (i = 0; i < (num_write << 1); i += 2) {
597 int16_t lsample;
598 int16_t rsample;
599 int l_sample;
600 int r_sample;
601
602 lsample = *cur_sample_16bit;
603 cur_sample_16bit++;
604 rsample = *cur_sample_16bit;
605 cur_sample_16bit++;
606
607 l_sample = *mb + (lsample * l_volume);
608 r_sample = *(mb + 1) + (rsample * r_volume);
609
610 samples_played++;
611
612 if (l_sample < -32767)
613 l_sample = -32767;
614 if (l_sample > 32767)
615 l_sample = 32767;
616 if (r_sample < -32767)
617 r_sample = -32767;
618 if (r_sample > 32767)
619 r_sample = 32767;
620
621 *mb = (int16_t)l_sample;
622 mb++;
623 *mb = (int16_t)r_sample;
624 *mb++;
625 }
626 }