Beispiel #1
0
        public RubberBandWaveStream(IWaveProvider source)
        {
            if (source.WaveFormat.BitsPerSample != 16)
            {
                throw new FormatException("Can't process bit depth of " + source.WaveFormat.BitsPerSample);
            }

            _source = source;

            _sourceSamples    = Enumerable.Range(1, source.WaveFormat.Channels).Select(channel => new float[16384]).ToArray();
            _sourceBuffer     = new byte[_sourceSamples.Sum(channel => channel.Length) * 2];
            _stretchedSamples = Enumerable.Range(1, source.WaveFormat.Channels).Select(channel => new float[16384]).ToArray();

            _stretcher = new RubberBandStretcher(_source.WaveFormat.SampleRate, _source.WaveFormat.Channels, RubberBandStretcher.Options.ProcessRealTime);

            _tempo = 1.0;
        }
Beispiel #2
0
        private void _updateAudioContext()
        {
            _dataWasSent = false;
            _stretcher?.Dispose();
            var speedRatio = (_renderer.RefreshRate / _config.TargetFps);

            Console.Write(speedRatio);
            _stretcher = new RubberBandStretcher(
                _config.SampleRate,
                2,
                RubberBandStretcher.Options.ProcessRealTime,
                1 / speedRatio,
                speedRatio
                );

            _latencyCounter = _stretcher.GetLatency();

            if (_resamplerState != IntPtr.Zero)
            {
                SampleRate.src_delete(_resamplerState);
            }

            if (_config.SampleRate != (int)_currentSystemAvInfo.Timing.SampleRate)
            {
                _resampleNeeded     = true;
                _audioResampleRatio = (_config.SampleRate / _currentSystemAvInfo.Timing.SampleRate);
                _resamplerState     = SampleRate.src_new(SampleRate.Quality.SRC_SINC_BEST_QUALITY, 2, out var error);

                if (error > 0)
                {
                    Logger.Error("Error initializing resampler: '{0}'", SampleRate.src_strerror(error));
                }

                Logger.Debug("Audio Resample Ratio: {0}", _audioResampleRatio);
            }
            else
            {
                _resampleNeeded = false;
                Logger.Debug("Resampling not needed");
            }
        }