Example #1
0
        public void ProcessFrame(ProcessAudioFrameContext context)
        {
            unsafe
            {
                AudioFrame inputFrame = context.InputFrame;

                using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.ReadWrite))
                    using (IMemoryBufferReference inputReference = inputBuffer.CreateReference())
                    {
                        ((IMemoryBufferByteAccess)inputReference).GetBuffer(out byte *inputDataInBytes, out uint inputCapacity);

                        float *inputDataInFloat  = (float *)inputDataInBytes;
                        int    dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                        // Process audio data
                        for (int n = 0; n < dataInFloatLength; n++)
                        {
                            int ch = n % channels;

                            // cascaded filter to perform eq
                            for (int band = 0; band < bandCount; band++)
                            {
                                inputDataInFloat[n] = filters[ch, band].Transform(inputDataInFloat[n]);
                            }
                        }
                    }
            }
        }
        public unsafe void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame  = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                   outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                       outputReference = outputBuffer.CreateReference())
                {
                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out var inputDataInBytes, out _);
                    ((IMemoryBufferByteAccess)outputReference).GetBuffer(out var outputDataInBytes, out _);

                    float *inputDataInFloat  = (float *)inputDataInBytes;
                    float *outputDataInFloat = (float *)outputDataInBytes;

                    // Process audio data
                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                    for (int i = 0; i < dataInFloatLength; i++)
                    {
                        // var inputData = inputDataInFloat[i] * (1.0f - Mix);
                        var inputData = inputDataInFloat[i];
                        outputDataInFloat[i] = ProcessFilterSample(inputData);
                    }
                }
        }
Example #3
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame = context.InputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference())
                {
                    byte *inputDataInBytes;
                    uint  inputCapacity;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);

                    float *inputDataInFloat = (float *)inputDataInBytes;

                    float inputDataL;
                    float inputDataR;

                    // Process audio data
                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                    if (_chart == null)
                    {
                        _chart = new float[dataInFloatLength];
                        propertySet["chart"] = _chart;
                    }
                    for (int i = 0; i < dataInFloatLength; i += 2)
                    {
                        inputDataL    = inputDataInFloat[i];
                        inputDataR    = inputDataInFloat[i + 1];
                        _chart[i]     = inputDataL;
                        _chart[i + 1] = inputDataR;
                    }
                }
        }
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame = context.InputFrame;

            using (AudioBuffer inputBuffer = context.InputFrame.LockBuffer(AudioBufferAccessMode.Read))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference())
                {
                    byte * inputInBytes;
                    uint   inputCapacity;
                    float *inputInFloats;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputInBytes, out inputCapacity);

                    inputInFloats = (float *)inputInBytes;
                    int   inputLength = (int)inputBuffer.Length / sizeof(float);
                    float sum         = 0;

                    // Only process one channel for now (will average out unless the audio is severely unbalanced between left/right)
                    for (int i = 0; i < inputLength; i += 2)
                    {
                        sum += (inputInFloats[i] * inputInFloats[i]);
                    }
                    double rms = Math.Sqrt(sum / (inputLength / 2));
                    this.VolumeInDecibels = 20 * Math.Log10(rms);
                }
        }
Example #5
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame frame = context.InputFrame;

            using (AudioBuffer buffer = frame.LockBuffer(AudioBufferAccessMode.ReadWrite))
                using (IMemoryBufferReference reference = buffer.CreateReference())
                {
                    ((IMemoryBufferByteAccess)reference).GetBuffer(out byte *dataInBytes, out uint capacity);
                    float *dataInFloat       = (float *)dataInBytes;
                    int    dataInFloatLength = (int)buffer.Length / sizeof(float);

                    // read parameters once
                    float currentWet      = this.Mix;
                    float currentDry      = 1.0f - currentWet;
                    float currentFeedback = this.Feedback;

                    // Process audio data
                    float sample, echoSample, outSample;
                    for (int i = 0; i < dataInFloatLength; i++)
                    {
                        // read values
                        sample     = dataInFloat[i];
                        echoSample = _echoBuffer.Dequeue();

                        // compute output sample
                        outSample      = (currentDry * sample) + (currentWet * echoSample);
                        dataInFloat[i] = outSample;

                        // compute delay sample
                        echoSample = sample + (currentFeedback * echoSample);
                        _echoBuffer.Enqueue(echoSample);
                    }
                }
        }
Example #6
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            //foreach (var item in context.InputFrame.ExtendedProperties.Keys)
            //{
            //    Debug.WriteLine(item);
            //}


            const int videoFrameRate = 60; // TODO: we should probably measure this

            //Debug.WriteLine(sw.ElapsedMilliseconds.ToString());
            AudioFrame inputFrame = context.InputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference())
                {
                    byte * inputInBytes;
                    uint   inputCapacity;
                    float *inputInFloats;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputInBytes, out inputCapacity);

                    inputInFloats = (float *)inputInBytes;
                    int inputLengthSamples = (int)inputBuffer.Length / sizeof(float);

                    int samplesPervBlank = (int)((float)currentEncodingProperties.SampleRate / (float)videoFrameRate);

                    int numVBlanksForCurrentAudioBuffer = (int)Math.Ceiling(((float)context.InputFrame.Duration.Value.Milliseconds / ((1.0f / (float)videoFrameRate) * 1000)));

                    var volumeSetLeft  = new double[numVBlanksForCurrentAudioBuffer];
                    var volumeSetRight = new double[numVBlanksForCurrentAudioBuffer];

                    //Left Channel
                    CalcAudioVolumedBPerVBlank(inputInFloats, inputLengthSamples, samplesPervBlank, volumeSetLeft, 0, (int)currentEncodingProperties.ChannelCount);

                    if (currentEncodingProperties.ChannelCount == 2)
                    {
                        //Right Channel
                        CalcAudioVolumedBPerVBlank(inputInFloats, inputLengthSamples, samplesPervBlank, volumeSetRight, 1, (int)currentEncodingProperties.ChannelCount);
                    }

                    lock (PassthroughEffect.GetBadLock())
                    {
                        for (var i = 0; i < numVBlanksForCurrentAudioBuffer; i++)
                        {
                            ((Queue <Tuple <double, double> >) this.propertySet["dataQueue"]).Enqueue(new Tuple <double, double>(volumeSetLeft[i], volumeSetRight[i]));
                        }
                        //((Queue<Double[]>)this.propertySet["AudioVolumeLeftQueue"]).Enqueue(volumeSetLeft);
                        //((Queue<Double[]>)this.propertySet["AudioVolumeRightQueue"]).Enqueue(volumeSetRight);
                        //this.propertySet["VolumeLeft"] = volumeSetLeft;
                        //this.propertySet["VolumeRight"] = volumeSetRight;
                    }
                }
        }
        // </SnippetMixProperty>

        // <SnippetProcessFrame>
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame  = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                   outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                       outputReference = outputBuffer.CreateReference())
                {
                    byte *inputDataInBytes;
                    byte *outputDataInBytes;
                    uint  inputCapacity;
                    uint  outputCapacity;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);
                    ((IMemoryBufferByteAccess)outputReference).GetBuffer(out outputDataInBytes, out outputCapacity);

                    float *inputDataInFloat  = (float *)inputDataInBytes;
                    float *outputDataInFloat = (float *)outputDataInBytes;

                    float inputData;
                    float echoData;

                    // Process audio data
                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                    for (int i = 0; i < dataInFloatLength; i++)
                    {
                        inputData            = inputDataInFloat[i] * (1.0f - this.Mix);
                        echoData             = echoBuffer[currentActiveSampleIndex] * this.Mix;
                        outputDataInFloat[i] = inputData + echoData;
                        echoBuffer[currentActiveSampleIndex] = inputDataInFloat[i];
                        currentActiveSampleIndex++;

                        if (currentActiveSampleIndex == echoBuffer.Length)
                        {
                            // Wrap around (after one second of samples)
                            currentActiveSampleIndex = 0;
                        }
                    }
                }
        }
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                                outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
            using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                                            outputReference = outputBuffer.CreateReference())
            {
                byte* inputDataInBytes;
                byte* outputDataInBytes;
                uint inputCapacity;
                uint outputCapacity;

                ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);
                ((IMemoryBufferByteAccess)outputReference).GetBuffer(out outputDataInBytes, out outputCapacity);

                float* inputDataInFloat = (float*)inputDataInBytes;
                float* outputDataInFloat = (float*)outputDataInBytes;

                float inputData;
                float echoData;

                // Process audio data
                int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                for (int i = 0; i < dataInFloatLength; i++)
                {
                    inputData = inputDataInFloat[i] * (1.0f - this.Mix);
                    echoData = echoBuffer[currentActiveSampleIndex] * this.Mix;
                    outputDataInFloat[i] = inputData + echoData;
                    echoBuffer[currentActiveSampleIndex] = inputDataInFloat[i];
                    currentActiveSampleIndex++;

                    if (currentActiveSampleIndex == echoBuffer.Length)
                    {
                        // Wrap around (after one second of samples)
                        currentActiveSampleIndex = 0;
                    }
                }
            }
        }
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame = context.InputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read))
            using (IMemoryBufferReference inputReference = inputBuffer.CreateReference())
            {
                byte* inputDataInBytes;
                uint inputCapacity;

                ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);

                float* inputDataInFloat = (float*)inputDataInBytes;

                // Process audio data
                int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                for (int i = 0; i < dataInFloatLength; i++)
                {
                    float inputData = inputDataInFloat[i];

                    lock (badLock)
                    {
                        if (propertySet.ContainsKey("InputDataRaw"))
                        {
                            propertySet["InputDataRaw"] = inputData;
                        }
                        else
                        {
                            propertySet.Add("InputDataRaw", inputData);
                        }
                    }

                    if (compositionPropertySet != null)
                    {
                        compositionPropertySet.InsertScalar("InputData", inputData * 500);
                    }
                }
            }
        }
Example #10
0
        public void ProcessFrame(ProcessAudioFrameContext context)
        {
            unsafe
            {
                AudioFrame inputFrame  = context.InputFrame;
                AudioFrame outputFrame = context.OutputFrame;

                using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                       outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                    using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                           outputReference = outputBuffer.CreateReference())
                    {
                        ((IMemoryBufferByteAccess)inputReference).GetBuffer(out byte *inputDataInBytes, out uint inputCapacity);
                        ((IMemoryBufferByteAccess)outputReference).GetBuffer(out byte *outputDataInBytes, out uint outputCapacity);

                        float *inputDataInFloat  = (float *)inputDataInBytes;
                        float *outputDataInFloat = (float *)outputDataInBytes;

                        // Process audio data
                        int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);
                    }
            }
        }
Example #11
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame  = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                   outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                       outputReference = outputBuffer.CreateReference())
                {
                    byte *inputDataInBytes;
                    byte *outputDataInBytes;
                    uint  inputCapacity;
                    uint  outputCapacity;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);
                    ((IMemoryBufferByteAccess)outputReference).GetBuffer(out outputDataInBytes, out outputCapacity);

                    float *inputDataInFloat  = (float *)inputDataInBytes;
                    float *outputDataInFloat = (float *)outputDataInBytes;

                    float inputDataL;
                    float inputDataR;

                    // Process audio data
                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                    for (int i = 0; i < dataInFloatLength; i += 2)
                    {
                        inputDataL = inputDataInFloat[i] * ((Balance < 0) ? 1 : (1.0f - this.Balance));
                        inputDataR = inputDataInFloat[i + 1] * ((Balance > 0) ? 1 : (1.0f + this.Balance));

                        outputDataInFloat[i]     = inputDataL;
                        outputDataInFloat[i + 1] = inputDataR;
                    }
                }
        }
Example #12
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame  = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                   outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                       outputReference = outputBuffer.CreateReference())
                {
                    byte *inputDataInBytes;
                    byte *outputDataInBytes;
                    uint  inputCapacity;
                    uint  outputCapacity;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);
                    ((IMemoryBufferByteAccess)outputReference).GetBuffer(out outputDataInBytes, out outputCapacity);

                    float *inputDataInFloat  = (float *)inputDataInBytes;
                    float *outputDataInFloat = (float *)outputDataInBytes;

                    float inputDataL;
                    float inputDataR;
                    float valueWithNoise;

                    // Process audio data
                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);
                    for (int i = 0; i < dataInFloatLength; i += 2)
                    {
                        inputDataL               = inputDataInFloat[i];
                        inputDataR               = inputDataInFloat[i + 1];
                        valueWithNoise           = Truncate(inputDataL + ((float)_rand.NextDouble() * NoiseAmplitude - NoiseAmplitude / 2));
                        outputDataInFloat[i]     = valueWithNoise;
                        outputDataInFloat[i + 1] = valueWithNoise;
                    }
                }
        }
Example #13
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame  = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                   outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                       outputReference = outputBuffer.CreateReference())
                {
                    byte *inputDataInBytes;
                    byte *outputDataInBytes;
                    uint  inputCapacity;
                    uint  outputCapacity;

                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);
                    ((IMemoryBufferByteAccess)outputReference).GetBuffer(out outputDataInBytes, out outputCapacity);

                    float *inputDataInFloat  = (float *)inputDataInBytes;
                    float *outputDataInFloat = (float *)outputDataInBytes;



                    // Process audio data
                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                    outputData = new double[dataInFloatLength];

                    for (int i = 0; i < dataInFloatLength; i++)
                    {
                        outputData[i]        = inputDataInFloat[i];
                        outputDataInFloat[i] = inputDataInFloat[i];
                    }

                    Data = outputData;
                }
        }
Example #14
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            var q            = Q;
            var maxFrequency = MaxFrequency;

            if (maxFrequency != autowahEffect.MaxFrequency)
            {
                autowahEffect.MaxFrequency = maxFrequency;
            }
            if (q != autowahEffect.Q)
            {
                autowahEffect.Q = q;
            }

            AudioFrame inputFrame  = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                   outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
                using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                       outputReference = outputBuffer.CreateReference())
                {
                    ((IMemoryBufferByteAccess)inputReference).GetBuffer(out byte *inputDataInBytes, out uint inputCapacity);
                    ((IMemoryBufferByteAccess)outputReference).GetBuffer(out byte *outputDataInBytes, out uint outputCapacity);

                    float *inputDataInFloat  = (float *)inputDataInBytes;
                    float *outputDataInFloat = (float *)outputDataInBytes;

                    int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                    for (int i = 0; i < dataInFloatLength; i++)
                    {
                        outputDataInFloat[i] = autowahEffect.Process(inputDataInFloat[i]);
                    }
                }
        }
Example #15
0
        public unsafe void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame = context.InputFrame;
            AudioFrame outputFrame = context.OutputFrame;

            using (AudioBuffer inputBuffer = inputFrame.LockBuffer(AudioBufferAccessMode.Read),
                                outputBuffer = outputFrame.LockBuffer(AudioBufferAccessMode.Write))
            using (IMemoryBufferReference inputReference = inputBuffer.CreateReference(),
                                            outputReference = outputBuffer.CreateReference())
            {
                byte* inputDataInBytes;
                byte* outputDataInBytes;
                uint inputCapacity;
                uint outputCapacity;

                ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputDataInBytes, out inputCapacity);
                ((IMemoryBufferByteAccess)outputReference).GetBuffer(out outputDataInBytes, out outputCapacity);

                float* inputDataInFloat = (float*)inputDataInBytes;
                float* outputDataInFloat = (float*)outputDataInBytes;

                // Process audio data
                int dataInFloatLength = (int)inputBuffer.Length / sizeof(float);

                outputData = new double[dataInFloatLength];

                for (int i = 0; i < dataInFloatLength; i++)
                {
                    outputData[i] = inputDataInFloat[i];
                    outputDataInFloat[i] = inputDataInFloat[i];
                }

                Data = outputData;
            }
        }
Example #16
0
        unsafe public void ProcessFrame(ProcessAudioFrameContext context)
        {
            AudioFrame inputFrame = context.InputFrame;

            renderer?.Render(inputFrame);
        }