X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=snd_mix.c;h=10da40047ec05355f7ccf85eff87d7b1a115344f;hp=cf992904c96c672a997849601df81760ae7c00c4;hb=786fd991962a03bacba0d8ba8fc3dd7f7dfdc0ef;hpb=3f9f3e395065f16028f1ce7748f703c1afc0da6f diff --git a/snd_mix.c b/snd_mix.c index cf992904..10da4004 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -28,7 +28,7 @@ static portable_sampleframe_t paintbuffer_unswapped[PAINTBUFFER_SIZE]; extern speakerlayout_t snd_speakerlayout; // for querying the listeners -extern void SCR_CaptureVideo_SoundFrame(const portable_sampleframe_t *paintbuffer, size_t length); +#ifdef CONFIG_VIDEO_CAPTURE static void S_CaptureAVISound(const portable_sampleframe_t *paintbuffer, size_t length) { size_t i; @@ -47,10 +47,11 @@ static void S_CaptureAVISound(const portable_sampleframe_t *paintbuffer, size_t SCR_CaptureVideo_SoundFrame(paintbuffer_unswapped, length); } +#endif extern cvar_t snd_softclip; -static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbframes, int width, int channels) +static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbframes, int width, int nchannels) { int i; @@ -69,7 +70,7 @@ static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbfra maxvol = max(1.0f, maxvol * (1.0f - nbframes / (0.4f * snd_renderbuffer->format.speed))); #define SOFTCLIP(x) if(fabs(x)>maxvol) maxvol=fabs(x); (x) /= maxvol; - if (channels == 8) // 7.1 surround + if (nchannels == 8) // 7.1 surround { for (i = 0;i < nbframes;i++, p++) { @@ -83,7 +84,7 @@ static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbfra SOFTCLIP(p->sample[7]); } } - else if (channels == 6) // 5.1 surround + else if (nchannels == 6) // 5.1 surround { for (i = 0; i < nbframes; i++, p++) { @@ -95,7 +96,7 @@ static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbfra SOFTCLIP(p->sample[5]); } } - else if (channels == 4) // 4.0 surround + else if (nchannels == 4) // 4.0 surround { for (i = 0; i < nbframes; i++, p++) { @@ -105,7 +106,7 @@ static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbfra SOFTCLIP(p->sample[3]); } } - else if (channels == 2) // 2.0 stereo + else if (nchannels == 2) // 2.0 stereo { for (i = 0; i < nbframes; i++, p++) { @@ -113,7 +114,7 @@ static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbfra SOFTCLIP(p->sample[1]); } } - else if (channels == 1) // 1.0 mono + else if (nchannels == 1) // 1.0 mono { for (i = 0; i < nbframes; i++, p++) { @@ -124,7 +125,7 @@ static void S_SoftClipPaintBuffer(portable_sampleframe_t *painted_ptr, int nbfra } } -static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_ptr, int nbframes, int width, int channels) +static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_ptr, int nbframes, int width, int nchannels) { int i, val; @@ -133,7 +134,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p if (width == 2) // 16bit { short *snd_out = (short*)rb_ptr; - if (channels == 8) // 7.1 surround + if (nchannels == 8) // 7.1 surround { for (i = 0;i < nbframes;i++, painted_ptr++) { @@ -147,7 +148,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[7] * 32768.0f);*snd_out++ = bound(-32768, val, 32767); } } - else if (channels == 6) // 5.1 surround + else if (nchannels == 6) // 5.1 surround { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -159,7 +160,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[5] * 32768.0f);*snd_out++ = bound(-32768, val, 32767); } } - else if (channels == 4) // 4.0 surround + else if (nchannels == 4) // 4.0 surround { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -169,7 +170,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[3] * 32768.0f);*snd_out++ = bound(-32768, val, 32767); } } - else if (channels == 2) // 2.0 stereo + else if (nchannels == 2) // 2.0 stereo { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -177,7 +178,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[1] * 32768.0f);*snd_out++ = bound(-32768, val, 32767); } } - else if (channels == 1) // 1.0 mono + else if (nchannels == 1) // 1.0 mono { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -187,12 +188,12 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p // noise is really really annoying if (cls.timedemo) - memset(rb_ptr, 0, nbframes * channels * width); + memset(rb_ptr, 0, nbframes * nchannels * width); } else // 8bit { unsigned char *snd_out = (unsigned char*)rb_ptr; - if (channels == 8) // 7.1 surround + if (nchannels == 8) // 7.1 surround { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -206,7 +207,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[7] * 128.0f) + 128; *snd_out++ = bound(0, val, 255); } } - else if (channels == 6) // 5.1 surround + else if (nchannels == 6) // 5.1 surround { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -218,7 +219,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[5] * 128.0f) + 128; *snd_out++ = bound(0, val, 255); } } - else if (channels == 4) // 4.0 surround + else if (nchannels == 4) // 4.0 surround { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -228,7 +229,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[3] * 128.0f) + 128; *snd_out++ = bound(0, val, 255); } } - else if (channels == 2) // 2.0 stereo + else if (nchannels == 2) // 2.0 stereo { for (i = 0; i < nbframes; i++, painted_ptr++) { @@ -236,7 +237,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p val = (int)(painted_ptr->sample[1] * 128.0f) + 128; *snd_out++ = bound(0, val, 255); } } - else if (channels == 1) // 1.0 mono + else if (nchannels == 1) // 1.0 mono { for (i = 0;i < nbframes;i++, painted_ptr++) { @@ -246,7 +247,7 @@ static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_p // noise is really really annoying if (cls.timedemo) - memset(rb_ptr, 128, nbframes * channels); + memset(rb_ptr, 128, nbframes * nchannels); } } @@ -302,7 +303,7 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) // paint in the channels. // channels with zero volumes still advance in time but don't paint. - ch = channels; + ch = channels; // cppcheck complains here but it is wrong, channels is a channel_t[MAX_CHANNELS] and not an int for (channelindex = 0;channelindex < (int)total_channels;channelindex++, ch++) { sfx = ch->sfx; @@ -361,7 +362,6 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) // do the actual paint now (may skip work if silent) paint = paintbuffer; - wantframes = totalmixframes; istartframe = 0; for (wantframes = totalmixframes;wantframes > 0;posd += count * speedd, wantframes -= count) { @@ -522,8 +522,10 @@ void S_MixToBuffer(void *stream, unsigned int bufferframes) S_SoftClipPaintBuffer(paintbuffer, totalmixframes, snd_renderbuffer->format.width, snd_renderbuffer->format.channels); +#ifdef CONFIG_VIDEO_CAPTURE if (!snd_usethreadedmixing) S_CaptureAVISound(paintbuffer, totalmixframes); +#endif S_ConvertPaintBuffer(paintbuffer, outbytes, totalmixframes, snd_renderbuffer->format.width, snd_renderbuffer->format.channels);