コード例 #1
0
 public WdlResamplingSampleProvider(ISampleProvider source, WdlResampler resampler, int newSampleRate)
 {
     channels       = source.WaveFormat.Channels;
     outFormat      = WaveFormat.CreateIeeeFloatWaveFormat(newSampleRate, channels);
     this.source    = source;
     this.resampler = resampler;
 }
コード例 #2
0
 public WdlResamplingSampleProvider(ISampleProvider source, int newSampleRate)
 {
     this.channels  = source.WaveFormat.Channels;
     this.outFormat = WaveFormat.CreateIeeeFloatWaveFormat(newSampleRate, this.channels);
     this.source    = source;
     this.resampler = new WdlResampler();
     this.resampler.SetMode(true, 2, false, 64, 32);
     this.resampler.SetFilterParms(0.693f, 0.707f);
     this.resampler.SetFeedMode(false);
     this.resampler.SetRates((double)source.WaveFormat.SampleRate, (double)newSampleRate);
 }
コード例 #3
0
        /// <summary>
        /// Constructs a new resampler
        /// </summary>
        /// <param name="source">Source to resample</param>
        /// <param name="newSampleRate">Desired output sample rate</param>
        public WdlResamplingSampleProvider(ISampleProvider source, int newSampleRate)
        {
            channels    = source.WaveFormat.Channels;
            outFormat   = WaveFormat.CreateIeeeFloatWaveFormat(newSampleRate, channels);
            this.source = source;

            resampler = new WdlResampler();
            resampler.SetMode(true, 2, false);
            resampler.SetFilterParms();
            resampler.SetFeedMode(false); // output driven
            resampler.SetRates(source.WaveFormat.SampleRate, newSampleRate);
        }
コード例 #4
0
ファイル: Resampler.cs プロジェクト: ChatVR/ChatVR-Mirror
        public Resampler(ISampleSource source, IRateProvider rate)
        {
            _source = source;
            _rate   = rate;

            AudioSettings.OnAudioConfigurationChanged += OnAudioConfigurationChanged;
            OnAudioConfigurationChanged(false);

            _resampler = new WdlResampler();
            _resampler.SetMode(true, 2, false);
            _resampler.SetFilterParms();
            _resampler.SetFeedMode(false);
        }
コード例 #5
0
        public TransmitForm(MMDevice speaker,
                            MMDevice microphone,
                            bool muteAudio,
                            int bitrate,
                            UdpClient client,
                            IPEndPoint endpoint,
                            byte[] sessionID,
                            KeyPair localKey,
                            byte[] remotePublicKey)
        {
            this.speaker    = speaker;
            this.microphone = microphone;
            this.muteAudio  = muteAudio;
            wasAudioMuted   = speaker.AudioEndpointVolume.Mute;
            speaker.AudioEndpointVolume.Mute = muteAudio ? true : this.wasAudioMuted;
            this.client          = client;
            this.endpoint        = endpoint;
            this.sessionID       = sessionID;
            this.localKeyPair    = localKey;
            this.remotePublicKey = remotePublicKey;
            InitializeComponent();

            stream    = new MemoryStream();
            outFormat = new WaveFormat(48000, 2);

            capture    = new WasapiLoopbackCapture(speaker);
            waveStream = new RawSourceWaveStream(stream, capture.WaveFormat);
            resampler  = new WdlResampler();
            resampler.SetMode(true, 0, false);
            resampler.SetFeedMode(true);
            resampler.SetRates(capture.WaveFormat.SampleRate, outFormat.SampleRate);



            output       = new WasapiOut(microphone, AudioClientShareMode.Shared, true, 0);
            waveProvider = new BufferedWaveProvider(new WaveFormat(48000, 2));
            waveProvider.BufferLength            = 100000;
            waveProvider.DiscardOnBufferOverflow = true;
            output.Init(waveProvider);
            output.Play();
            encoder = new OpusEncoder(48000, 2, Concentus.Enums.OpusApplication.OPUS_APPLICATION_AUDIO)
            {
                Bitrate = bitrate * 1000
            };
            decoder = new OpusDecoder(48000, 2);
            capture.DataAvailable += DataAvailable;
            capture.StartRecording();

            receiverThread = new Thread(new ThreadStart(ReceiverLoop));
            receiverThread.Start();
        }
コード例 #6
0
        public Resampler([NotNull] ISampleProvider source, int newSampleRate)
        {
            _source = source;
            _format = new WaveFormat(source.WaveFormat.Channels, newSampleRate);

            if (source.WaveFormat.SampleRate != newSampleRate)
            {
                _resampler = new WdlResampler();
                _resampler.SetMode(true, 2, false);
                _resampler.SetFilterParms();
                _resampler.SetFeedMode(false); // output driven
                _resampler.SetRates(source.WaveFormat.SampleRate, newSampleRate);
            }
        }
コード例 #7
0
ファイル: Resampler.cs プロジェクト: AhmedMoustafa1/voip
        public bool Read(ArraySegment <float> samples)
        {
            var inFormat  = _source.WaveFormat;
            var outFormat = _outputFormat;

            if (outFormat.SampleRate == inFormat.SampleRate)
            {
                return(_source.Read(samples));
            }

            if (_resampler == null || outFormat.SampleRate != (int)_resampler.OutputSampleRate)
            {
                Log.Debug("Initializing resampler to resample {0}Hz source to {1}Hz output", inFormat.SampleRate, outFormat.SampleRate);

                _resampler = new WdlResampler();
                _resampler.SetMode(true, 2, false);
                _resampler.SetFilterParms();
                _resampler.SetFeedMode(false); // output driven
                _resampler.SetRates(inFormat.SampleRate, outFormat.SampleRate);
            }

            var channels = inFormat.Channels;

            // prepare buffers
            float[] inBuffer;
            int     inBufferOffset;
            var     samplesPerChannelRequested = samples.Count / channels;
            var     samplesPerChannelRequired  = _resampler.ResamplePrepare(samplesPerChannelRequested, channels, out inBuffer, out inBufferOffset);
            var     sourceBuffer = new ArraySegment <float>(inBuffer, inBufferOffset, samplesPerChannelRequired * channels);

            // read source
            var complete = _source.Read(sourceBuffer);

            // resample
            Log.Trace("Resampling {0}Hz -> {1}Hz", inFormat.SampleRate, outFormat.SampleRate);
            _resampler.ResampleOut(samples.Array, samples.Offset, samplesPerChannelRequired, samplesPerChannelRequested, channels);

            return(complete);
        }