當前位置: 首頁>>代碼示例>>C#>>正文


C# Wave.BufferedWaveProvider類代碼示例

本文整理匯總了C#中NAudio.Wave.BufferedWaveProvider的典型用法代碼示例。如果您正苦於以下問題:C# BufferedWaveProvider類的具體用法?C# BufferedWaveProvider怎麽用?C# BufferedWaveProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BufferedWaveProvider類屬於NAudio.Wave命名空間,在下文中一共展示了BufferedWaveProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Speaker

        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Constructor
        //------------------------------------------------------------------------------------------------------------------------
        public Speaker()
        {
            waveout = new WaveOut();
            bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 2));
            waveout.PlaybackStopped += Waveout_PlaybackStopped;
            volumeProvider = new VolumeWaveProvider16(bufferedWaveProvider);
            waveout.Init(volumeProvider);
        }
開發者ID:yodiwo,項目名稱:plegma,代碼行數:13,代碼來源:Speaker.cs

示例2: StartEncoding

        void StartEncoding()
        {
            _startTime = DateTime.Now;
            _bytesSent = 0;
            _segmentFrames = 960;
            _encoder = new OpusEncoder(48000, 1, OpusNet.OpusApplication.Voip);
            _encoder.Bitrate = 8192;
            _decoder = new OpusDecoder(48000, 1);
            _bytesPerSegment = _encoder.FrameByteCount(_segmentFrames);

            _waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback());
            _waveIn.BufferMilliseconds = 50;
            _waveIn.DeviceNumber = comboBox1.SelectedIndex;
            _waveIn.DataAvailable += _waveIn_DataAvailable;
            _waveIn.WaveFormat = new WaveFormat(48000, 16, 1);

            _playBuffer = new BufferedWaveProvider(new WaveFormat(48000, 16, 1));

            _waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
            _waveOut.DeviceNumber = comboBox2.SelectedIndex;
            _waveOut.Init(_playBuffer);

            _waveOut.Play();
            _waveIn.StartRecording();

            if (_timer == null)
            {
                _timer = new Timer();
                _timer.Interval = 1000;
                _timer.Tick += _timer_Tick;
            }
            _timer.Start();
        }
開發者ID:VirusFree,項目名稱:Opus.NET,代碼行數:33,代碼來源:Form1.cs

示例3: Input

 /// <summary>
 /// Create an input
 /// </summary>
 /// <param name="ID">The ID of the input to be created</param>
 public Input(string ID)
 {
     // Set the device ID
     deviceID = ID;
     // Get Device from specified ID
     MMDeviceEnumerator devices = new MMDeviceEnumerator();
     device = devices.GetDevice(ID);
     // Set wave in to WASAPI capture of the specified device
     waveIn = new WasapiCapture(device);
     // Set the number of bytes used by each sample
     sampleByteSize = waveIn.WaveFormat.BitsPerSample / 8;
     // Add event handler to retrieve samples from the device
     waveIn.DataAvailable += waveIn_DataAvailable;
     // Create buffered wave provider
     bufferedWaveProvider = new BufferedWaveProvider(waveIn.WaveFormat);
     bufferedWaveProvider.DiscardOnBufferOverflow = true;
     // Create sample channel
     sampleChannel = new SampleChannel(bufferedWaveProvider);
     // Create sample provider
     sampleChannel.PreVolumeMeter += sampleProvider_StreamVolume;
     // Start recording
     try
     {
         waveIn.StartRecording();
     }
     catch
     {
         throw new ArgumentException("This input device is not supported.");
     }
 }
開發者ID:orryverducci,項目名稱:ShockCast,代碼行數:34,代碼來源:Input.cs

示例4: WaveFormat

        private WaveFormat _waveFormat = new WaveFormat(8000, 16, 1); // The format that both the input and output audio streams will use, i.e. PCMU.

        #endregion Fields

        #region Constructors

        public AudioChannel()
        {
            // Set up the device that will play the audio from the RTP received from the remote end of the call.
            m_waveOut = new WaveOut();
            m_waveProvider = new BufferedWaveProvider(_waveFormat);
            m_waveOut.Init(m_waveProvider);
            m_waveOut.Play();

            // Set up the input device that will provide audio samples that can be encoded, packaged into RTP and sent to
            // the remote end of the call.
            m_waveInEvent = new WaveInEvent();
            m_waveInEvent.BufferMilliseconds = 20;
            m_waveInEvent.NumberOfBuffers = 1;
            m_waveInEvent.DeviceNumber = 0;
            m_waveInEvent.DataAvailable += RTPChannelSampleAvailable;
            m_waveInEvent.WaveFormat = _waveFormat;

            // Create a UDP socket to use for sending and receiving RTP packets.
            int port = FreePort.FindNextAvailableUDPPort(DEFAULT_START_RTP_PORT);
            _rtpEndPoint = new IPEndPoint(_defaultLocalAddress, port);
            m_rtpChannel = new RTPChannel(_rtpEndPoint);
            m_rtpChannel.OnFrameReady += RTPChannelSampleReceived;

            _audioLogger.Debug("RTP channel endpoint " + _rtpEndPoint.ToString());
        }
開發者ID:sipsorcery,項目名稱:sipsorcery,代碼行數:31,代碼來源:AudioChannel.cs

示例5: Start

        public void Start()
        {
            if (WaveIn.DeviceCount < 1)
                throw new Exception("Insufficient input device(s)!");

            if (WaveOut.DeviceCount < 1)
                throw new Exception("Insufficient output device(s)!");

            frame_size = toxav.CodecSettings.audio_sample_rate * toxav.CodecSettings.audio_frame_duration / 1000;

            toxav.PrepareTransmission(CallIndex, false);

            WaveFormat format = new WaveFormat((int)toxav.CodecSettings.audio_sample_rate, (int)toxav.CodecSettings.audio_channels);
            wave_provider = new BufferedWaveProvider(format);
            wave_provider.DiscardOnBufferOverflow = true;

            wave_out = new WaveOut();
            //wave_out.DeviceNumber = config["device_output"];
            wave_out.Init(wave_provider);

            wave_source = new WaveIn();
            //wave_source.DeviceNumber = config["device_input"];
            wave_source.WaveFormat = format;
            wave_source.DataAvailable += wave_source_DataAvailable;
            wave_source.RecordingStopped += wave_source_RecordingStopped;
            wave_source.BufferMilliseconds = (int)toxav.CodecSettings.audio_frame_duration;
            wave_source.StartRecording();

            wave_out.Play();
        }
開發者ID:kstaruch,項目名稱:Toxy,代碼行數:30,代碼來源:ToxCall.cs

示例6: AudioPlayer

 public AudioPlayer(DiscordVoiceConfig __config)
 {
     config = __config;
     callbackInfo = WaveCallbackInfo.FunctionCallback();
     outputDevice = new WaveOut(callbackInfo);
     bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(48000, 16, config.Channels));
 }
開發者ID:thedanieldude1,項目名稱:DanielCode,代碼行數:7,代碼來源:Program.cs

示例7: PlayAudioFromConnection

        private void PlayAudioFromConnection(TcpClient client)
        {
            var inputStream = new BufferedStream(client.GetStream());

            var bufferedWaveProvider = new BufferedWaveProvider(waveFormat);
            var savingWaveProvider = new SavingWaveProvider(bufferedWaveProvider, "temp.wav");

            var player = new WaveOut();
            player.Init(savingWaveProvider);
            player.Play();

            while (client.Connected)
            {
                if (terminate)
                {
                    client.Close();
                    break;
                }

                var available = client.Available;
                if (available > 0)
                {
                    var buffer = new byte[available];
                    var bytes = inputStream.Read(buffer, 0, buffer.Length);
                    bufferedWaveProvider.AddSamples(buffer, 0, bytes);
                    Console.WriteLine("{0} \t {1} bytes", client.Client.RemoteEndPoint, bytes);
                }
            }

            player.Stop();
            savingWaveProvider.Dispose();
        }
開發者ID:duszekmestre,項目名稱:MoN.Messenger,代碼行數:32,代碼來源:AudioRecorder.cs

示例8: DirectSoundPlayer

		public DirectSoundPlayer(INetworkChatCodec c)
			: base(c)
		{
			waveProvider = new BufferedWaveProvider(codec.RecordFormat);
			wavePlayer = new DirectSoundOut();
			wavePlayer.Init(waveProvider);
		}
開發者ID:wangws556,項目名稱:duoduo-chat,代碼行數:7,代碼來源:Players.cs

示例9: Initialise

        public void Initialise(WaveFormat format, WaveOut driver)
        {
            if (driver == null)
            {
                throw new ArgumentNullException("driver", "Must specify a WaveIn device instance");
            }

            if (format == null)
            {
                throw new ArgumentNullException("format", "Must specify an audio format");
            }

            var caps = WaveOut.GetCapabilities(driver.DeviceNumber);

            device = new WaveOutDeviceData
            {
                Driver = driver,
                Name = caps.ProductName,
                Channels = caps.Channels,
                Buffers = new float[caps.Channels][]
            };

            Format = WaveFormat.CreateIeeeFloatWaveFormat(format.SampleRate, caps.Channels);
            OutputBuffer = new BufferedWaveProvider(Format);
            OutputBuffer.DiscardOnBufferOverflow = true;

            driver.Init(OutputBuffer);

            mapOutputs();
        }
開發者ID:gareththegeek,項目名稱:ndaw,代碼行數:30,代碼來源:WaveOutputMapper.cs

示例10: Connect

        private void Connect(IPEndPoint endPoint, int inputDeviceNumber, INetworkChatCodec codec)
        {
            waveIn = new WaveIn();
            waveIn.BufferMilliseconds = 50;
            waveIn.DeviceNumber = inputDeviceNumber;
            waveIn.WaveFormat = codec.RecordFormat;
            waveIn.DataAvailable += waveIn_DataAvailable;
            waveIn.StartRecording();

            udpSender = new UdpClient();
            udpListener = new UdpClient();

            // To allow us to talk to ourselves for test purposes:
            // http://stackoverflow.com/questions/687868/sending-and-receiving-udp-packets-between-two-programs-on-the-same-computer
            udpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            udpListener.Client.Bind(endPoint);

            udpSender.Connect(endPoint);

            waveOut = new WaveOut();
            waveProvider = new BufferedWaveProvider(codec.RecordFormat);
            waveOut.Init(waveProvider);
            waveOut.Play();

            connected = true;
            var state = new ListenerThreadState { Codec = codec, EndPoint = endPoint };
            ThreadPool.QueueUserWorkItem(ListenerThread, state);
        }
開發者ID:LibertyLocked,項目名稱:NAudio,代碼行數:28,代碼來源:NetworkChatPanel.cs

示例11: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            byte[] apk, ask, bpk, bsk;
            NaClClient.CreateKeys(out apk, out ask);
            NaClClient.CreateKeys(out bpk, out bsk);

            var hasher = System.Security.Cryptography.SHA256.Create();

            _clientA = NaClClient.Create(apk, ask, bpk);
            _clientB = NaClClient.Create(bpk, bsk, apk);

            _sw = new Stopwatch();
            _sw.Start();

            _wave = new WaveIn(this.Handle);
            _wave.WaveFormat = new WaveFormat(12000, 8, 1);
            _wave.BufferMilliseconds = 100;
            _wave.DataAvailable += _wave_DataAvailable;
            _wave.StartRecording();

            _playback = new BufferedWaveProvider(_wave.WaveFormat);

            _waveOut = new WaveOut();
            _waveOut.DesiredLatency = 100;
            _waveOut.Init(_playback);
            _waveOut.Play();
        }
開發者ID:odinhaus,項目名稱:Saltable,代碼行數:27,代碼來源:Form1.cs

示例12: AudioRecorder

 public AudioRecorder(int microphone)
 {
     waveIn = new WaveIn();
     waveIn.DeviceNumber = microphone;
     waveIn.WaveFormat = new WaveFormat(44100, 1);
     bufferedWaveProvider = new BufferedWaveProvider(waveIn.WaveFormat);
     writer = new WaveFileWriter(Settings.Default.tempSoundLocation, waveIn.WaveFormat);
 }
開發者ID:undecimus,項目名稱:komunikator,代碼行數:8,代碼來源:AudioRecorder.cs

示例13: HaltableBufferedWaveProvider

 public HaltableBufferedWaveProvider(WaveFormat waveFormat)
 {
     _bufferedWaveProvider = new BufferedWaveProvider(waveFormat)
                             {
                                 DiscardOnBufferOverflow = true,
                                 BufferDuration = new TimeSpan(0, 10, 0)
                             };
 }
開發者ID:jonfinerty,項目名稱:Spotbox,代碼行數:8,代碼來源:HaltableBufferedWaveProvider.cs

示例14: EmptyBufferCanReturnZeroFromRead

 public void EmptyBufferCanReturnZeroFromRead()
 {
     var bwp = new BufferedWaveProvider(new WaveFormat());
     bwp.ReadFully = false;
     var buffer = new byte[44100];
     var read = bwp.Read(buffer, 0, buffer.Length);
     Assert.AreEqual(0, read);
 }
開發者ID:ActivePHOENiX,項目名稱:NAudio,代碼行數:8,代碼來源:BufferedWaveProviderTests.cs

示例15: FullReadsByDefault

 public void FullReadsByDefault()
 {
     var bwp = new BufferedWaveProvider(new WaveFormat());
     var buffer = new byte[44100];
     bwp.AddSamples(buffer, 0, 2000);
     var read = bwp.Read(buffer, 0, buffer.Length);
     Assert.AreEqual(buffer.Length, read);
     Assert.AreEqual(0, bwp.BufferedBytes);
 }
開發者ID:ActivePHOENiX,項目名稱:NAudio,代碼行數:9,代碼來源:BufferedWaveProviderTests.cs


注:本文中的NAudio.Wave.BufferedWaveProvider類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。