Exemple #1
0
        // functions
        unsafe void GenerateSlowChannel(ref FracTime playPos, int sampleCount44k, float *finalBuffer)
        {
            int i, zeroedPos, count = 0;

            var sw = (SoundWorldLocal)soundSystemLocal.PlayingSoundWorld;

            var in_ = stackalloc float[Simd.MIXBUFFER_SAMPLES + 3]; var src = in_ + 2;
            var out_ = stackalloc float[Simd.MIXBUFFER_SAMPLES + 3]; var spline = out_ + 2;

            var slowmoSpeed   = sw != null ? sw.slowmoSpeed : 1f;
            var neededSamples = (int)(sampleCount44k * slowmoSpeed + 4);

            // get the channel's samples
            chan.GatherChannelSamples(playPos.time * 2, neededSamples, src);
            for (i = 0; i < neededSamples >> 1; i++)
            {
                spline[i] = src[i * 2];
            }

            // interpolate channel
            zeroedPos    = playPos.time;
            playPos.time = 0;

            for (i = 0; i < sampleCount44k >> 1; i++, count += 2)
            {
                var val = spline[playPos.time];
                src[i] = val;
                playPos.Increment(slowmoSpeed);
            }

            // lowpass filter
            var in_p = in_ + 2; var out_p = out_ + 2;
            var numSamples = sampleCount44k >> 1;

            lowpass.GetContinuitySamples(out in_p[-1], out in_p[-2], out out_p[-1], out out_p[-2]);
            lowpass.SetParms(slowmoSpeed * 15000, 1.2f);

            for (i = 0, count = 0; i < numSamples; i++, count += 2)
            {
                lowpass.ProcessSample(in_p + i, out_p + i);
                finalBuffer[count] = finalBuffer[count + 1] = out_[i];
            }

            lowpass.SetContinuitySamples(in_p[numSamples - 2], in_p[numSamples - 3], out_p[numSamples - 2], out_p[numSamples - 3]);

            playPos.time += zeroedPos;
        }
Exemple #2
0
        public unsafe void GatherChannelSamples(int sampleOffset44k, int sampleCount44k, float *dest)
        {
            PLAYBACK state = 0;

            // setup chan
            active          = true;
            newSampleOffset = sampleOffset44k >> 1;

            // set state
            if (newSampleOffset < curSampleOffset)
            {
                state = PLAYBACK.RESET;
            }
            else if (newSampleOffset > curSampleOffset)
            {
                state = PLAYBACK.ADVANCING;
            }

            if (state == PLAYBACK.RESET)
            {
                curPosition.Set(newSampleOffset);
            }

            // set current vars
            curSampleOffset = newSampleOffset;
            newPosition     = curPosition;

            // do the slow processing
            GenerateSlowChannel(ref newPosition, sampleCount44k, dest);

            // finish off
            if (state == PLAYBACK.ADVANCING)
            {
                curPosition = newPosition;
            }
        }