Beispiel #1
0
        private bool ProcessInternal <T>(IAudioDescription input, IntPtr samples, short channels, int length, IMediaSample output) where T : struct
        {
            UpdateGpuResources(length);

            var sampleCount = length / channels;

            try
            {
                var devInputSamples = GetDevInputSamples <T>(length);
                var devInputResult  = GetDevNormSamples(channels, sampleCount);
                var devOutputResult = GetDevOutputSamples <T>(length);
                Gpu.CopyToDevice(samples, 0, devInputSamples, 0, length);
                Gpu.Launch(AudioProc.THREAD_COUNT, 1, string.Format("GetSamples{0}", typeof(T).Name),
                           devInputSamples, devInputResult);
                Process(input, devInputResult, channels, sampleCount);
                output.GetPointer(out samples);
                Gpu.Launch(AudioProc.THREAD_COUNT, 1, string.Format("PutSamples{0}", typeof(T).Name),
                           devInputResult, devOutputResult);
                Gpu.CopyFromDevice(devOutputResult, 0, samples, 0, length);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                return(false);
            }
            return(true);
        }
            protected override void Process(IAudioDescription input, float[,] samples, short channels, int sampleCount)
            {
                const int threadCount = 512;

                // Note: samples resides on OpenCL device memory
                Gpu.Launch(threadCount, 1).Amplify(samples, 2.0f);
            }
 protected override void Process(IAudioDescription input, float[,] samples, short channels, int sampleCount)
 {
     for (int i = 0; i < sampleCount; i++)
     {
         samples[CHANNEL_TO_SILENT, i] = 0;
     }
 }
        protected override void Process(IAudioDescription input, float[,] samples, short channels, int sampleCount)
        {
            if (channels != 2)
            {
                return;
            }

            Apply(samples, input.Format.nSamplesPerSec);
        }
Beispiel #5
0
            private void UpdateEnvelopeDetectors(IAudioDescription Input)
            {
                if (m_Attack != null && m_Release != null)
                {
                    return;
                }

                var sampleRate = Input.Format.nSamplesPerSec;

                m_Attack  = new EnvelopeDetector(AttackMs, sampleRate);
                m_Release = new EnvelopeDetector(ReleaseMs, sampleRate);
            }
            private void GargleSamples(IAudioDescription input, float[,] samples, bool triangle)
            {
                int period = input.Format.nSamplesPerSec / GARGLE_RATE;

                var channels = samples.GetLength(0);
                var length   = samples.GetLength(1);

                for (int i = 0; i < length; i++)
                {
                    // m_Phase is the number of samples from the start of the period.
                    // We keep this running from one call to the next,
                    // but if the period changes so as to make this more
                    // than Period then we reset to 0 with a bang.  This may cause
                    // an audible click or pop (but, hey! it's only a sample!)
                    //
                    m_Phase++;

                    if (m_Phase > period)
                    {
                        m_Phase = 0;
                    }

                    var m = m_Phase; // m is what we modulate with
                    for (int c = 0; c < channels; c++)
                    {
                        if (triangle)
                        {
                            // Triangle
                            if (m > period / 2)
                            {
                                m = period - m;               // handle downslope
                            }
                        }
                        else
                        {
                            // Square wave
                            if (m <= period / 2)
                            {
                                m = period / 2;
                            }
                            else
                            {
                                m = 0;
                            }
                        }
                        var v = samples[c, i];
                        // Note: No clipping required - the framework clips it to [-1.0f..1.0f] for us
                        samples[c, i] = (v * m * 2) / period;
                    }
                }
            }
Beispiel #7
0
        private bool ProcessCpuInternal <T>(IAudioDescription input, IntPtr samples, short channels, int length, IMediaSample output) where T : struct
        {
            UpdateGpuResources(length);

            var inputSamples = GetInputSamplesCpu <T>(samples, channels, length);

            if (inputSamples == null)
            {
                return(false);
            }

            var sampleCount = length / channels;

            Process(input, inputSamples, channels, sampleCount);

            output.GetPointer(out samples);
            return(PutOutputSamplesCpu <T>(inputSamples, samples));
        }
Beispiel #8
0
 public IAudioOutput Allocate(IAudioDescription input)
 {
     return(new PinAudioOutput(input));
 }
Beispiel #9
0
 public PinAudioOutput(IAudioDescription format)
 {
     m_Format = format;
 }
Beispiel #10
0
 protected abstract void Process(IAudioDescription input, float[,] samples, short channels, int sampleCount);
Beispiel #11
0
 private bool Process(IAudioDescription input, AudioSampleFormat sampleFormat, IntPtr samples, short channels, int length, IMediaSample output)
 {
     UpdateSampleFormat(sampleFormat);
     return(m_ProcessFunc(input, samples, channels, length, output));
 }
Beispiel #12
0
 protected override void Process(IAudioDescription input, float[,] samples, short channels, int sampleCount)
 {
     UpdateEnvelopeDetectors(input);
     Compress(samples, sampleCount, ThresholddB, Ratio, MakeupGaindB);
 }
 protected override void Process(IAudioDescription input, float[,] samples, short channels, int sampleCount)
 {
     // Note: This runs on CPU only (in .NET) but it can just as easily be ported to run on OpenCL
     GargleSamples(input, samples, SHAPE == 0);
 }