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


C# Microphone.GetSampleSizeInBytes方法代碼示例

本文整理匯總了C#中Microsoft.Xna.Framework.Audio.Microphone.GetSampleSizeInBytes方法的典型用法代碼示例。如果您正苦於以下問題:C# Microphone.GetSampleSizeInBytes方法的具體用法?C# Microphone.GetSampleSizeInBytes怎麽用?C# Microphone.GetSampleSizeInBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Xna.Framework.Audio.Microphone的用法示例。


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

示例1: Recorder

        public Recorder()
        {
            //Microphone config
            _microphone = Microphone.Default;
            _microphone.BufferDuration = TimeSpan.FromMilliseconds(100);
            _duration = _microphone.BufferDuration;
            numBytes = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration);
            TimeSpan sample = TimeSpan.FromSeconds(1.0 / _microphone.SampleRate);
            int numBytesPerSample = _microphone.GetSampleSizeInBytes(sample);
            _buffer = new byte[numBytes];
            _microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady);

            stream = new MemoryStream();

            totalNumBytes = 0;
        }
開發者ID:jasonkuster,項目名稱:MetroLooper,代碼行數:16,代碼來源:Recorder.cs

示例2: WitMic

        /// <summary>
        /// Initializes new instance of WitMic
        /// </summary>
        /// <param name="witPipedStream">Stream to write audio to</param>
        /// <param name="detectSpeechStop">Voice activity detection feature</param>
        public WitMic(WitPipedStream witPipedStream, bool detectSpeechStop)
        {
            this.witPipedStream = witPipedStream;
            this.detectSpeechStop = detectSpeechStop;

            microphone = Microphone.Default;

            if (microphone == null)
            {
                WitLog.Log("Did you enabled ID_CAP_MICROPHONE in WMAppManifest.xml?");

                return;
            }

            witDetectTalking = new WitVadWrapper(8.0, 16000, 60);

            microphone.BufferDuration = TimeSpan.FromMilliseconds(100);

            speech = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

            microphone.BufferReady += microphone_BufferReady;

            updateTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(1)
            };
            updateTimer.Tick += (s, e) =>
            {
                FrameworkDispatcher.Update();
            };
        }
開發者ID:carriercomm,項目名稱:wit-windowsphone-sdk,代碼行數:36,代碼來源:WitMic.cs

示例3: RecPage

 byte[] msBuffer; //讀取數據的緩衝區
 public RecPage()
 {
     InitializeComponent();
     // Microphone.Default靜態屬性獲得默認麥克風的引用
     myMicrophone = Microphone.Default;
    // myMicrophone.BufferDuration = TimeSpan.FromMilliseconds(1000);
     msBuffer = new byte[myMicrophone.GetSampleSizeInBytes(myMicrophone.BufferDuration)];
     //FrameworkDispatcher.Update();
 }
開發者ID:Jasminekiki,項目名稱:WinProg,代碼行數:10,代碼來源:RecPage.xaml.cs

示例4: AudioRecorder

        /// <summary>
        /// Creates new instance of the AudioRecorder class.
        /// </summary>
        public AudioRecorder()
        {
            this.microphone = Microphone.Default;
            this.microphone.BufferDuration = TimeSpan.FromMilliseconds(500);

            this.buffer = new byte[microphone.GetSampleSizeInBytes(this.microphone.BufferDuration)];

            this.microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady);

            this.InitializeXnaGameLoop();

            // microphone requires special XNA initialization to work
            InitializeComponent();
        }
開發者ID:sgrebnov,項目名稱:phonegap-wp7,代碼行數:17,代碼來源:AudioRecorder.xaml.cs

示例5: Game1

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            // Extend battery life under lock.
            InactiveSleepTime = TimeSpan.FromSeconds(1);

            mic = Microphone.Default;
            mic.BufferDuration = TimeSpan.FromSeconds(1);
            audioBuffer = new byte[mic.GetSampleSizeInBytes(mic.BufferDuration)];
            mic.BufferReady += BufferIsReady;
        }
開發者ID:Vintharas,項目名稱:WP7projects,代碼行數:16,代碼來源:Game1.cs

示例6: StartCapture

 public void StartCapture()
 {
     try
     {
         if (_microphone == null)
         {
             _microphone = Microphone.Default;
             _microphone.BufferDuration = TimeSpan.FromMilliseconds(100);
             var sampleSize = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration);
             _baBuffer = new byte[sampleSize];
             _microphone.BufferReady += MicrophoneBufferReady;
             _microphone.Start();
         }
     }
     catch (Exception)
     {
     }
 }
開發者ID:Bootz,項目名稱:VoIP_Project_Archives_Testing,代碼行數:18,代碼來源:AudioDeviceResource.cs

示例7: MicRecorder

        public MicRecorder()
        {
            worker.WorkerReportsProgress = true;
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);

            _microphone = Microphone.Default;

            /*
             * The duration of the capture buffer must be between 100ms and 1000ms. Additionally, the capture buffer must be 10ms aligned (BufferDuration % 10 == 0).
             * Silverlight applications must ensure that FrameworkDispatcher.Update is called regularly in order for "fire and forget" sounds to work correctly.
             * BufferDuration throws an InvalidOperationException if FrameworkDispatcher.Update has not been called at least once before making this call.
             * For more information, see Enable XNA Framework Events in Windows Phone Applications.
             */
            _microphone.BufferDuration = TimeSpan.FromMilliseconds(100);
            _duration = _microphone.BufferDuration;
            _bufferSize = _microphone.GetSampleSizeInBytes(_microphone.BufferDuration);

            _microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady);
        }
開發者ID:vetoketju,項目名稱:WP-Noteradar,代碼行數:19,代碼來源:MicRecorder.cs

示例8: MicrophoneButton

        private MicrophoneButton(Microphone microphone)
        {
            FrameworkDispatcher.Update();
                        
            var minSupportedBufferDurationMs = 100;
            var duration = TimeSpan.FromMilliseconds(minSupportedBufferDurationMs);

            Microphone = microphone;
            Microphone.BufferDuration = duration;

            Buffer = new byte[Microphone.GetSampleSizeInBytes(duration)];
            Buffer2D = new Color[TexWidth * byte.MaxValue];

            Texture2D = Texture2D ?? Program.Renderer.LeaseFor<Gray, byte>(TexWidth, byte.MaxValue);
            Texture2D.SetData(Buffer2D);

            Microphone.BufferReady += OnBufferReady;

            Microphone.Start();            
        }
開發者ID:JaapSuter,項目名稱:Pentacorn,代碼行數:20,代碼來源:MicrophoneButton.cs

示例9: Clapper

        public Clapper()
        {
            // for pumping XNA framework events
            t = new Timer()
            {
                Interval = 50,
            };

            t.Tick += new EventHandler(t_Tick);

            UpperThreshold = 3000;
            LowerThreshold = 800;
            state = ClapperState.WaitLow;

            eventWatch = new Stopwatch();

            window = new Queue<short>();

            m = Microphone.Default;
            buffer = new byte[m.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(100))];

            m.BufferReady += new EventHandler<EventArgs>(m_BufferReady);
        }
開發者ID:kallanreed,項目名稱:clapper,代碼行數:23,代碼來源:Clapper.cs

示例10: StartRecording

        /// <summary>
        /// Starts recording, data is stored in memory
        /// </summary>
        private void StartRecording()
        {
            this.microphone = Microphone.Default;
            this.microphone.BufferDuration = TimeSpan.FromMilliseconds(500);

            this.btnTake.IsEnabled = false;
            this.btnStartStop.Content = RecordingStopCaption;

            this.buffer = new byte[microphone.GetSampleSizeInBytes(this.microphone.BufferDuration)];
            this.microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady);

            this.memoryStream = new MemoryStream();
            this.WriteWavHeader(this.memoryStream, this.microphone.SampleRate);

            this.duration = new TimeSpan(0);

            this.microphone.Start();
        }
開發者ID:rudolfo,項目名稱:phonegap,代碼行數:21,代碼來源:AudioRecorder.xaml.cs

示例11: startRecording

        /// <summary>
        /// Starts recording, data is stored in memory
        /// </summary>
        /// <param name="filePath"></param>
        public void startRecording(string filePath)
        {
            if (this.player != null)
            {
                InvokeCallback(MediaError, MediaErrorPlayModeSet, false);
            }
            else if (this.recorder == null)
            {
                try
                {
                    this.audioFile = filePath;
                    this.InitializeXnaGameLoop();
                    this.recorder = Microphone.Default;
                    this.recorder.BufferDuration = TimeSpan.FromMilliseconds(500);
                    this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)];
                    this.recorder.BufferReady += new EventHandler<EventArgs>(recorderBufferReady);
                    MemoryStream stream  = new MemoryStream();
                    this.memoryStream = stream;
                    int numBits = 16;
                    int numBytes = numBits / 8;

                    // inline version from AudioFormatsHelper
                    stream.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"), 0, 4);
                    stream.Write(BitConverter.GetBytes(0), 0, 4);
                    stream.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"), 0, 4);
                    stream.Write(System.Text.Encoding.UTF8.GetBytes("fmt "), 0, 4);
                    stream.Write(BitConverter.GetBytes(16), 0, 4);
                    stream.Write(BitConverter.GetBytes((short)1), 0, 2);
                    stream.Write(BitConverter.GetBytes((short)1), 0, 2);
                    stream.Write(BitConverter.GetBytes(this.recorder.SampleRate), 0, 4);
                    stream.Write(BitConverter.GetBytes(this.recorder.SampleRate * numBytes), 0, 4);
                    stream.Write(BitConverter.GetBytes((short)(numBytes)), 0, 2);
                    stream.Write(BitConverter.GetBytes((short)(numBits)), 0, 2);
                    stream.Write(System.Text.Encoding.UTF8.GetBytes("data"), 0, 4);
                    stream.Write(BitConverter.GetBytes(0), 0, 4);

                    this.recorder.Start();
                    FrameworkDispatcher.Update();
                    this.SetState(PlayerState_Running);
                }
                catch (Exception)
                {
                    InvokeCallback(MediaError, MediaErrorStartingRecording, false);
                    //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorStartingRecording),false);
                }
            }
            else
            {
                InvokeCallback(MediaError, MediaErrorAlreadyRecording, false);
                //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorAlreadyRecording),false);
            }
        }
開發者ID:CN-Onboarding,項目名稱:Cerner-Onboarding,代碼行數:56,代碼來源:AudioPlayer.cs

示例12: startRecording

 /// <summary>
 /// Starts recording, data is stored in memory
 /// </summary>
 /// <param name="filePath"></param>
 public void startRecording(string filePath)
 {
     if (this.player != null)
     {
         InvokeCallback(MediaError, MediaErrorPlayModeSet, false);
     }
     else if (this.recorder == null)
     {
         try
         {
             this.audioFile = filePath;
             this.InitializeXnaGameLoop();
             this.recorder = Microphone.Default;
             this.recorder.BufferDuration = TimeSpan.FromMilliseconds(500);
             this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)];
             this.recorder.BufferReady += new EventHandler<EventArgs>(recorderBufferReady);
             this.memoryStream = new MemoryStream();
             this.memoryStream.InitializeWavStream(this.recorder.SampleRate);
             this.recorder.Start();
             FrameworkDispatcher.Update();
             this.SetState(PlayerState_Running);
         }
         catch (Exception)
         {
             InvokeCallback(MediaError, MediaErrorStartingRecording, false);
             //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorStartingRecording),false);
         }
     }
     else
     {
         InvokeCallback(MediaError, MediaErrorAlreadyRecording, false);
         //this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorAlreadyRecording),false);
     }
 }
開發者ID:peter76111,項目名稱:myGeoApp,代碼行數:38,代碼來源:AudioPlayer.cs

示例13: InitializeMicrophone

        void InitializeMicrophone()
        {
            try
            {
                bool retry = true;
                while (retry)
                {
                    try
                    {
                        _microphone = Microphone.Default;

                        _graphicsManager = new GraphicsDeviceManager(this);
                        _graphicsManager.PreferredBackBufferHeight = 1;
                        _graphicsManager.PreferredBackBufferWidth = 1;

                        Form gameWindowForm = (Form)Form.FromHandle(this.Window.Handle);
                        gameWindowForm.Hide();
                        gameWindowForm.ShowInTaskbar = false;
                        gameWindowForm.ControlBox = false;
                        gameWindowForm.ShowIcon = false;
                        gameWindowForm.Opacity = 0;
                        gameWindowForm.Left = 1;
                        gameWindowForm.Top = 1;

                        FrameworkDispatcher.Update();

                        // todo: make the microphone capture timespan configurable
                        float timespan = float.Parse(ConfigurationManager.AppSettings["audioTimerInterval"]);

                        _microphone.BufferDuration = TimeSpan.FromMilliseconds(timespan);
                        _buffer = new byte[_microphone.GetSampleSizeInBytes(_microphone.BufferDuration)];
                        _microphone.BufferReady += OnBufferReady;
                        _isRunning = true;
                        _stream = new MemoryStream();
                        retry = false;
                    }
                    catch (Exception ex)
                    {
                        Tools.Instance.Logger.LogError(ex.ToString());
                        retry = true;
                        if (_microphone != null)
                        {
                            _microphone.Stop();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tools.Instance.Logger.LogError(ex.ToString());
            }
        }
開發者ID:Riccon,項目名稱:remote-desktop,代碼行數:52,代碼來源:AudioStream.cs

示例14: StartRecording

        /// <summary>
        /// Starts recording, data is stored in memory
        /// </summary>
        private void StartRecording()
        {
            this.microphone = Microphone.Default;
            this.microphone.BufferDuration = TimeSpan.FromMilliseconds(500);

            this.btnTake.IsEnabled = false;
            this.btnStartStop.Content = RecordingStopCaption;

            this.buffer = new byte[microphone.GetSampleSizeInBytes(this.microphone.BufferDuration)];
            this.microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady);

            MemoryStream stream = new MemoryStream();
            this.memoryStream = stream;
            int numBits = 16;
            int numBytes = numBits / 8;

            // inline version from AudioFormatsHelper
            stream.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"), 0, 4);
            stream.Write(BitConverter.GetBytes(0), 0, 4);
            stream.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"), 0, 4);
            stream.Write(System.Text.Encoding.UTF8.GetBytes("fmt "), 0, 4);
            stream.Write(BitConverter.GetBytes(16), 0, 4);
            stream.Write(BitConverter.GetBytes((short)1), 0, 2);
            stream.Write(BitConverter.GetBytes((short)1), 0, 2);
            stream.Write(BitConverter.GetBytes(this.microphone.SampleRate), 0, 4);
            stream.Write(BitConverter.GetBytes(this.microphone.SampleRate * numBytes), 0, 4);
            stream.Write(BitConverter.GetBytes((short)(numBytes)), 0, 2);
            stream.Write(BitConverter.GetBytes((short)(numBits)), 0, 2);
            stream.Write(System.Text.Encoding.UTF8.GetBytes("data"), 0, 4);
            stream.Write(BitConverter.GetBytes(0), 0, 4);

            this.duration = new TimeSpan(0);

            this.microphone.Start();
        }
開發者ID:giansar,項目名稱:ScreenPatterns,代碼行數:38,代碼來源:AudioRecorder.xaml.cs

示例15: StartRecording

        private void StartRecording()
        {
            currentRecordingStream = new MemoryStream(1048576);

              if (currentMicrophone == null)
              {
            currentMicrophone = Microphone.Default;
            currentMicrophone.BufferDuration = TimeSpan.FromMilliseconds(300);
            currentMicrophone.BufferReady += currentMicrophone_BufferReady;
            audioBuffer = new byte[currentMicrophone.GetSampleSizeInBytes(
                            currentMicrophone.BufferDuration)];
            sampleRate = currentMicrophone.SampleRate;
              }

              stopRequested = false;
              currentMicrophone.Start();

              startTime = DateTime.UtcNow;
              Thread counter = new System.Threading.Thread(CountTime);
              counter.Start();
        }
開發者ID:kernelhunter92,項目名稱:CatrobatForWindows,代碼行數:21,代碼來源:Recorder.xaml.cs


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