ClampedAdd() публичный статический Метод

public static ClampedAdd ( short &a, int b ) : void
a short
b int
Результат void
Пример #1
0
        public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
        {
            var obufPos = 0;
            var inPos   = 0;
            var oend    = count;

            while (obufPos < oend)
            {
                // read enough input samples so that opos < 0
                while (FRAC_ONE_LOW <= opos)
                {
                    // Check if we have to refill the buffer
                    if (inLen == 0)
                    {
                        inPos = 0;
                        inLen = input.ReadBuffer(inBuf, RateHelper.IntermediateBufferSize);
                        if (inLen <= 0)
                        {
                            return(obufPos / 2);
                        }
                    }
                    inLen -= (stereo ? 2 : 1);
                    ilast0 = icur0;
                    icur0  = inBuf[inPos++];
                    if (stereo)
                    {
                        ilast1 = icur1;
                        icur1  = inBuf[inPos++];
                    }
                    opos -= FRAC_ONE_LOW;
                }

                // Loop as long as the outpos trails behind, and as long as there is
                // still space in the output buffer.
                while (opos < FRAC_ONE_LOW && obufPos < oend)
                {
                    // interpolate
                    int out0, out1;
                    out0 = (short)(ilast0 + (((icur0 - ilast0) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW));
                    out1 = stereo ? (short)(ilast1 + (((icur1 - ilast1) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW)) : out0;

                    // output left channel
                    RateHelper.ClampedAdd(ref obuf[obufPos + (reverseStereo ? 1 : 0)], (out0 * volLeft) / Mixer.MaxMixerVolume);

                    // output right channel
                    RateHelper.ClampedAdd(ref obuf[obufPos + (reverseStereo ? 0 : 1)], (out1 * volRight) / Mixer.MaxMixerVolume);

                    obufPos += 2;

                    // Increment output position
                    opos += oposInc;
                }
            }
            return(obufPos / 2);
        }
Пример #2
0
        public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
        {
            int   pos = 0;
            int   oend = count * 2;
            short out0, out1;

            while (pos < oend)
            {
                // read enough input samples so that opos >= 0
                do
                {
                    // Check if we have to refill the buffer
                    if (inLen == 0)
                    {
                        inPtr = 0;
                        inLen = input.ReadBuffer(inBuf, RateHelper.IntermediateBufferSize);
                        if (inLen <= 0)
                        {
                            return(pos / 2);
                        }
                    }
                    inLen -= (stereo ? 2 : 1);
                    opos--;
                    if (opos >= 0)
                    {
                        inPtr += (stereo ? 2 : 1);
                    }
                } while (opos >= 0);

                out0 = inBuf[inPtr++];
                out1 = (stereo ? inBuf[inPtr++] : out0);

                // Increment output position
                opos += oposInc;

                // output left channel
                RateHelper.ClampedAdd(ref obuf[reverseStereo ? 1 : 0], (out0 * (int)volLeft) / Mixer.MaxMixerVolume);

                // output right channel
                RateHelper.ClampedAdd(ref obuf[(reverseStereo ? 1 : 0) ^ 1], (out1 * (int)volRight) / Mixer.MaxMixerVolume);

                pos += 2;
            }
            return(pos / 2);
        }
Пример #3
0
        public int Flow(IAudioStream input, short[] obuf, int count, int volLeft, int volRight)
        {
            Debug.Assert(input.IsStereo == stereo);

            var osamp = count / 2;

            if (stereo)
            {
                osamp *= 2;
            }

            // Reallocate temp buffer, if necessary
            if (osamp > _bufferSize)
            {
                _buffer     = new short[osamp];
                _bufferSize = osamp;
            }

            // Read up to 'osamp' samples into our temporary buffer
            var len = input.ReadBuffer(_buffer, _bufferSize);

            int   iPos = 0;
            var   oPos = 0;
            var   inc  = stereo ? 2 : 1;
            short out0;
            short out1;

            // Mix the data into the output buffer
            for (; iPos < len; iPos += inc)
            {
                out0 = _buffer[iPos];
                out1 = stereo ? _buffer[iPos + 1] : out0;

                // output left channel
                RateHelper.ClampedAdd(ref obuf[oPos + (reverseStereo ? 1 : 0)], (out0 * volLeft) / Mixer.MaxMixerVolume);

                // output right channel
                RateHelper.ClampedAdd(ref obuf[oPos + (reverseStereo ? 0 : 1)], (out1 * volRight) / Mixer.MaxMixerVolume);

                oPos += 2;
            }
            return(oPos / 2);
        }