예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputFormat">format of audio supplied to `Send`</param>
        /// <param name="inputFrameSize">Size of frames which will should be provided from `GetFrameBuffer`</param>
        /// <param name="intermediateFrameSize">Size of frames which should be passed into `PreprocessAudioFrame`</param>
        /// <param name="intermediateSampleRate">Sample rate which should be passed into `PreprocessAudioFrame`</param>
        /// <param name="outputFrameSize">Size of frames which will be provided sent to `SendSamplesToSubscribers`</param>
        /// <param name="outputSampleRate"></param>
        protected BasePreprocessingPipeline(WaveFormat inputFormat, int inputFrameSize, int intermediateFrameSize, int intermediateSampleRate, int outputFrameSize, int outputSampleRate)
        {
            if (inputFrameSize < 0)
            {
                throw new ArgumentOutOfRangeException("inputFrameSize", "Input frame size cannot be less than zero");
            }

            _inputFrameSize  = inputFrameSize;
            _outputFrameSize = outputFrameSize;
            _outputFormat    = new WaveFormat(1, outputSampleRate);

            //Create input system (source of empty buffers, queue of waiting input data)
            _inputBufferSource = new ConcurrentPool <float[]>(24, () => new float[inputFrameSize]);
            _inputQueue        = new TransferBuffer <float[]>(12);
            _emptyInputFrame   = new float[inputFrameSize];

            //Create resampler to resample input to intermediate rate
            _resamplerInput    = new BufferedSampleProvider(inputFormat, InputFrameSize * 4);
            _resampler         = new Resampler(_resamplerInput, 48000);
            _resampledOutput   = new SampleToFrameProvider(_resampler, (uint)OutputFrameSize);
            _intermediateFrame = new float[intermediateFrameSize];

            _threadEvent = new AutoResetEvent(false);
            _thread      = new DThread(ThreadEntry);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputFormat">format of audio supplied to `Send`</param>
        /// <param name="intermediateFrameSize">Size of frames which should be passed into `PreprocessAudioFrame`</param>
        /// <param name="intermediateSampleRate">Sample rate which should be passed into `PreprocessAudioFrame`</param>
        /// <param name="outputFrameSize">Size of frames which will be provided sent to `SendSamplesToSubscribers`</param>
        /// <param name="outputSampleRate"></param>
        protected BasePreprocessingPipeline([NotNull] WaveFormat inputFormat, int intermediateFrameSize, int intermediateSampleRate, int outputFrameSize, int outputSampleRate)
        {
            if (inputFormat == null)
            {
                throw new ArgumentNullException("inputFormat");
            }
            if (intermediateFrameSize < 0)
            {
                throw new ArgumentOutOfRangeException("intermediateFrameSize", "Intermediate frame size cannot be less than zero");
            }
            if (intermediateSampleRate < 0)
            {
                throw new ArgumentOutOfRangeException("intermediateSampleRate", "Intermediate sample rate cannot be less than zero");
            }
            if (outputFrameSize < 0)
            {
                throw new ArgumentOutOfRangeException("outputFrameSize", "Output frame size cannot be less than zero");
            }
            if (outputSampleRate < 0)
            {
                throw new ArgumentOutOfRangeException("outputSampleRate", "Output sample rate cannot be less than zero");
            }

            _outputFrameSize = outputFrameSize;
            _outputFormat    = new WaveFormat(outputSampleRate, 1);

            //Create resampler to resample input to intermediate rate
            _resamplerInput    = new BufferedSampleProvider(inputFormat, intermediateFrameSize * 16);
            _resampler         = new Resampler(_resamplerInput, 48000);
            _resampledOutput   = new SampleToFrameProvider(_resampler, (uint)OutputFrameSize);
            _intermediateFrame = new float[intermediateFrameSize];

            //Create a thread to drive the audio processing
            _threadEvent = new AutoResetEvent(false);
            _thread      = new DThread(ThreadEntry);

            // We don't want to overestimate the latency. It's hard to come up with a reasonable number for this because if the input frames are >= the...
            // ...intermediate frames there will actually be no buffering delay in the preprocessor (it'll pick up a complete frame and process it right away).
            _estimatedPreprocessorLatencyMs = 0;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputFormat">format of audio supplied to `Send`</param>
        /// <param name="inputFrameSize">Size of frames which will should be provided from `GetFrameBuffer`</param>
        /// <param name="intermediateFrameSize">Size of frames which should be passed into `PreprocessAudioFrame`</param>
        /// <param name="intermediateSampleRate">Sample rate which should be passed into `PreprocessAudioFrame`</param>
        /// <param name="outputFrameSize">Size of frames which will be provided sent to `SendSamplesToSubscribers`</param>
        /// <param name="outputSampleRate"></param>
        protected BasePreprocessingPipeline([NotNull] WaveFormat inputFormat, int inputFrameSize, int intermediateFrameSize, int intermediateSampleRate, int outputFrameSize, int outputSampleRate)
        {
            if (inputFormat == null)
            {
                throw new ArgumentNullException("inputFormat");
            }
            if (inputFrameSize < 0)
            {
                throw new ArgumentOutOfRangeException("inputFrameSize", "Input frame size cannot be less than zero");
            }
            if (intermediateFrameSize < 0)
            {
                throw new ArgumentOutOfRangeException("intermediateFrameSize", "Intermediate frame size cannot be less than zero");
            }
            if (intermediateSampleRate < 0)
            {
                throw new ArgumentOutOfRangeException("intermediateSampleRate", "Intermediate sample rate cannot be less than zero");
            }
            if (outputFrameSize < 0)
            {
                throw new ArgumentOutOfRangeException("outputFrameSize", "Output frame size cannot be less than zero");
            }
            if (outputSampleRate < 0)
            {
                throw new ArgumentOutOfRangeException("outputSampleRate", "Output sample rate cannot be less than zero");
            }

            _inputFrameSize  = inputFrameSize;
            _outputFrameSize = outputFrameSize;
            _outputFormat    = new WaveFormat(1, outputSampleRate);

            //Create resampler to resample input to intermediate rate
            _resamplerInput    = new BufferedSampleProvider(inputFormat, InputFrameSize * 16);
            _resampler         = new Resampler(_resamplerInput, 48000);
            _resampledOutput   = new SampleToFrameProvider(_resampler, (uint)OutputFrameSize);
            _intermediateFrame = new float[intermediateFrameSize];

            _threadEvent = new AutoResetEvent(false);
            _thread      = new DThread(ThreadEntry);
        }