135 float *snd_out = (
float*)rb_ptr;
138 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
140 *snd_out++ = painted_ptr->
sample[0];
141 *snd_out++ = painted_ptr->
sample[1];
142 *snd_out++ = painted_ptr->
sample[2];
143 *snd_out++ = painted_ptr->
sample[3];
144 *snd_out++ = painted_ptr->
sample[4];
145 *snd_out++ = painted_ptr->
sample[5];
146 *snd_out++ = painted_ptr->
sample[6];
147 *snd_out++ = painted_ptr->
sample[7];
150 else if (nchannels == 6)
152 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
154 *snd_out++ = painted_ptr->
sample[0];
155 *snd_out++ = painted_ptr->
sample[1];
156 *snd_out++ = painted_ptr->
sample[2];
157 *snd_out++ = painted_ptr->
sample[3];
158 *snd_out++ = painted_ptr->
sample[4];
159 *snd_out++ = painted_ptr->
sample[5];
162 else if (nchannels == 4)
164 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
166 *snd_out++ = painted_ptr->
sample[0];
167 *snd_out++ = painted_ptr->
sample[1];
168 *snd_out++ = painted_ptr->
sample[2];
169 *snd_out++ = painted_ptr->
sample[3];
172 else if (nchannels == 2)
174 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
176 *snd_out++ = painted_ptr->
sample[0];
177 *snd_out++ = painted_ptr->
sample[1];
180 else if (nchannels == 1)
182 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
184 *snd_out++ = painted_ptr->
sample[0];
190 short *snd_out = (
short*)rb_ptr;
193 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
195 val = (
int)(painted_ptr->
sample[0] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
196 val = (
int)(painted_ptr->
sample[1] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
197 val = (
int)(painted_ptr->
sample[2] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
198 val = (
int)(painted_ptr->
sample[3] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
199 val = (
int)(painted_ptr->
sample[4] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
200 val = (
int)(painted_ptr->
sample[5] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
201 val = (
int)(painted_ptr->
sample[6] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
202 val = (
int)(painted_ptr->
sample[7] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
205 else if (nchannels == 6)
207 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
209 val = (
int)(painted_ptr->
sample[0] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
210 val = (
int)(painted_ptr->
sample[1] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
211 val = (
int)(painted_ptr->
sample[2] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
212 val = (
int)(painted_ptr->
sample[3] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
213 val = (
int)(painted_ptr->
sample[4] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
214 val = (
int)(painted_ptr->
sample[5] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
217 else if (nchannels == 4)
219 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
221 val = (
int)(painted_ptr->
sample[0] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
222 val = (
int)(painted_ptr->
sample[1] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
223 val = (
int)(painted_ptr->
sample[2] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
224 val = (
int)(painted_ptr->
sample[3] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
227 else if (nchannels == 2)
229 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
231 val = (
int)(painted_ptr->
sample[0] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
232 val = (
int)(painted_ptr->
sample[1] * 32768.0f);*snd_out++ =
bound(-32768, val, 32767);
235 else if (nchannels == 1)
237 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
239 val = (
int)((painted_ptr->
sample[0] + painted_ptr->
sample[1]) * 16384.0f);*snd_out++ =
bound(-32768, val, 32767);
245 unsigned char *snd_out = (
unsigned char*)rb_ptr;
248 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
250 val = (
int)(painted_ptr->
sample[0] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
251 val = (
int)(painted_ptr->
sample[1] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
252 val = (
int)(painted_ptr->
sample[2] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
253 val = (
int)(painted_ptr->
sample[3] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
254 val = (
int)(painted_ptr->
sample[4] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
255 val = (
int)(painted_ptr->
sample[5] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
256 val = (
int)(painted_ptr->
sample[6] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
257 val = (
int)(painted_ptr->
sample[7] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
260 else if (nchannels == 6)
262 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
264 val = (
int)(painted_ptr->
sample[0] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
265 val = (
int)(painted_ptr->
sample[1] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
266 val = (
int)(painted_ptr->
sample[2] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
267 val = (
int)(painted_ptr->
sample[3] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
268 val = (
int)(painted_ptr->
sample[4] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
269 val = (
int)(painted_ptr->
sample[5] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
272 else if (nchannels == 4)
274 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
276 val = (
int)(painted_ptr->
sample[0] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
277 val = (
int)(painted_ptr->
sample[1] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
278 val = (
int)(painted_ptr->
sample[2] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
279 val = (
int)(painted_ptr->
sample[3] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
282 else if (nchannels == 2)
284 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
286 val = (
int)(painted_ptr->
sample[0] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
287 val = (
int)(painted_ptr->
sample[1] * 128.0f) + 128; *snd_out++ =
bound(0, val, 255);
290 else if (nchannels == 1)
292 for (
i = 0;
i < nbframes;
i++, painted_ptr++)
294 val = (
int)((painted_ptr->
sample[0] + painted_ptr->
sample[1]) * 64.0f) + 128; *snd_out++ =
bound(0, val, 255);
374 unsigned char *outbytes = (
unsigned char *) stream;
389#define S_FETCHBUFFERSIZE 4096
391 const float *fetchsampleframe;
422 if (!sfx->total_length)
441 silent = maxvol < (1.0f / (256.0f));
445 silent = maxvol < (1.0f / (65536.0f));
449 silent = maxvol < 1.0e-13f;
465 totallength = sfx->total_length;
467 looping = loopstart < totallength;
472 for (wantframes = totalmixframes;wantframes > 0;posd +=
count * speedd, wantframes -=
count)
490 ilengthframes =
count > 1 ? (iendframe - istartframe + 2) : 2;
501 memset(fetchsampleframes, 0, ilengthframes*sfx->format.channels*
sizeof(fetchsampleframes[0]));
507 fetch =
min(ilengthframes - fetched, totallength - istartframe);
511 sfx->fetcher->getsamplesfloat(ch, sfx, istartframe, fetch, fetchsampleframes + fetched*sfx->format.channels);
512 istartframe += fetch;
515 if (istartframe == totallength && looping && fetched < ilengthframes)
518 posd += loopstart - totallength;
519 istartframe = loopstart;
528 fetchsampleframe = fetchsampleframes;
530 indexfracstep = (
int)
floor(speedd * 65536.0);
533 if (sfx->format.channels == 2)
536#if SND_LISTENERS != 8
537#error the following code only supports up to 8 channels, update it
544 lerp[1] = indexfrac * (1.0f / 65536.0f);
545 lerp[0] = 1.0f - lerp[1];
546 sample[0] = fetchsampleframe[0] * lerp[0] + fetchsampleframe[2] * lerp[1];
547 sample[1] = fetchsampleframe[1] * lerp[0] + fetchsampleframe[3] * lerp[1];
548 sample[2] = (sample[0] + sample[1]) * 0.5f;
549 paint->
sample[0] += sample[0] * vol[0];
550 paint->
sample[1] += sample[1] * vol[1];
551 paint->
sample[2] += sample[0] * vol[2];
552 paint->
sample[3] += sample[1] * vol[3];
553 paint->
sample[4] += sample[2] * vol[4];
554 paint->
sample[5] += sample[2] * vol[5];
555 paint->
sample[6] += sample[0] * vol[6];
556 paint->
sample[7] += sample[1] * vol[7];
557 indexfrac += indexfracstep;
558 fetchsampleframe += 2 * (indexfrac >> 16);
567 lerp[1] = indexfrac * (1.0f / 65536.0f);
568 lerp[0] = 1.0f - lerp[1];
569 sample[0] = fetchsampleframe[0] * lerp[0] + fetchsampleframe[2] * lerp[1];
570 sample[1] = fetchsampleframe[1] * lerp[0] + fetchsampleframe[3] * lerp[1];
571 paint->
sample[0] += sample[0] * vol[0];
572 paint->
sample[1] += sample[1] * vol[1];
573 indexfrac += indexfracstep;
574 fetchsampleframe += 2 * (indexfrac >> 16);
579 else if (sfx->format.channels == 1)
582#if SND_LISTENERS != 8
583#error the following code only supports up to 8 channels, update it
590 lerp[1] = indexfrac * (1.0f / 65536.0f);
591 lerp[0] = 1.0f - lerp[1];
592 sample[0] = fetchsampleframe[0] * lerp[0] + fetchsampleframe[1] * lerp[1];
593 paint->
sample[0] += sample[0] * vol[0];
594 paint->
sample[1] += sample[0] * vol[1];
595 paint->
sample[2] += sample[0] * vol[2];
596 paint->
sample[3] += sample[0] * vol[3];
597 paint->
sample[4] += sample[0] * vol[4];
598 paint->
sample[5] += sample[0] * vol[5];
599 paint->
sample[6] += sample[0] * vol[6];
600 paint->
sample[7] += sample[0] * vol[7];
601 indexfrac += indexfracstep;
602 fetchsampleframe += (indexfrac >> 16);
611 lerp[1] = indexfrac * (1.0f / 65536.0f);
612 lerp[0] = 1.0f - lerp[1];
613 sample[0] = fetchsampleframe[0] * lerp[0] + fetchsampleframe[1] * lerp[1];
614 paint->
sample[0] += sample[0] * vol[0];
615 paint->
sample[1] += sample[0] * vol[1];
616 indexfrac += indexfracstep;
617 fetchsampleframe += (indexfrac >> 16);
625 if (!looping && istartframe == totallength)
634#ifdef CONFIG_VIDEO_CAPTURE
643 bufferframes -= totalmixframes;
unsigned int total_channels
void S_StopChannel(unsigned int channel_ind, qbool lockmutex, qbool freesfx)
channel_t channels[MAX_CHANNELS]
snd_ringbuffer_t * snd_renderbuffer
qbool snd_usethreadedmixing
if true, the main thread does not mix sound, soundtime does not advance, and neither does snd_renderb...
qbool S_LoadSound(struct sfx_s *sfx, qbool complain)