資源簡介
c#開發的 實時監控麥克風輸入音量 轉換為百分比顯示

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Collections.Specialized;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading;
using?System.Windows.Forms;
using?Microsoft.DirectX;
using?Microsoft.DirectX.DirectSound;
namespace?demo
{
????public?partial?class?Form1?:?Form
????{
????????private?const?int?SAMPLES?=?8;
????????private?static?CaptureDevicesCollection?audioDevices;
????????private?int?deviceIndex?=?-1;
????????private?Microsoft.DirectX.DirectSound.CaptureBuffer?buffer;
????????private?string?deviceName?=?“沒有檢測到音頻輸入設備“;
????????private?static?StringCollection?deviceNames;
????????private?System.Threading.Thread?liveVolumeThread;
????????private?int?sampleDelay?=?100;
????????private?int?frameDelay?=?10;
????????private?static?int[]?SAMPLE_FORMAT_ARRAY?=?{?SAMPLES?2?1?};
????????public?Form1()
????????{
????????????InitializeComponent();
????????????Initmiclist();
????????????progressBar.Maximum?=?Int16.MaxValue?+?1;
????????????System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls?=?false;
????????}
????????///?
????????///?加載麥克風列表
????????///?
????????private?void?Initmiclist()
????????{
????????????audioDevices?=?new?CaptureDevicesCollection();
????????????deviceNames?=?new?StringCollection();
????????????for?(int?i?=?0;?i?????????????{
????????????????deviceNames.Add(audioDevices[i].Description);
????????????}
????????????for?(int?i?=?0;?i?????????????{
????????????????comboBox1.Items.Add(deviceNames[i].ToString());
????????????????comboBox1.SelectedIndex?=?0;
????????????}
????????????if?(deviceNames.Count?0)
????????????{
????????????????comboBox1.Items.Clear();
????????????????comboBox1.Items.Add(deviceName);
????????????}
????????}
????????public?void?Stop()
????????{
????????????if?(liveVolumeThread?!=?null)
????????????{
????????????????liveVolumeThread.Abort();
????????????????liveVolumeThread.Join();
????????????????liveVolumeThread?=?null;
????????????}
????????????if?(buffer?!=?null)
????????????{
????????????????if?(buffer.Capturing)
????????????????{
????????????????????buffer.Stop();
????????????????}
????????????????buffer.Dispose();
????????????????buffer?=?null;
????????????}
????????}
????????public?void?Start()
????????{
????????????Stop();
????????????if?(deviceIndex?!=?-1)
????????????{
????????????????//?capture?對象?捕獲麥克風設備
????????????????Capture?cap?=?new?Capture(audioDevices[deviceIndex].DriverGuid);
????????????????//?創建對?緩沖區信息?的描述
????????????????CaptureBufferDescription?desc?=?new?CaptureBufferDescription();
????????????????WaveFormat?wf?=?new?WaveFormat();
????????????????wf.BitsPerSample?=?16;
????????????????wf.SamplesPerSecond?=?44100;
????????????????wf.Channels?=?2;
????????????????//?數據的最小的原子單元
????????????????wf.BlockAlign?=?(shor
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????12288??2013-12-12?17:29??demo\demo\bin\Debug\demo.exe
?????文件??????28160??2013-12-12?17:29??demo\demo\bin\Debug\demo.pdb
?????文件??????21472??2013-12-12?17:29??demo\demo\bin\Debug\demo.vshost.exe
?????文件????????490??2010-03-17?22:39??demo\demo\bin\Debug\demo.vshost.exe.manifest
?????文件???????4236??2013-12-12?14:37??demo\demo\demo.csproj
?????文件???????6307??2013-12-12?17:53??demo\demo\Form1.cs
?????文件???????3754??2013-12-12?15:53??demo\demo\Form1.Designer.cs
?????文件???????5817??2013-12-12?15:53??demo\demo\Form1.resx
?????文件????????826??2013-12-12?17:29??demo\demo\obj\Debug\demo.csproj.FileListAbsolute.txt
?????文件????????847??2013-12-12?15:53??demo\demo\obj\Debug\demo.csproj.GenerateResource.Cache
?????文件??????25462??2013-12-12?17:20??demo\demo\obj\Debug\demo.csprojResolveAssemblyReference.cache
?????文件??????12288??2013-12-12?17:29??demo\demo\obj\Debug\demo.exe
?????文件????????180??2013-12-12?15:53??demo\demo\obj\Debug\demo.Form1.resources
?????文件??????28160??2013-12-12?17:29??demo\demo\obj\Debug\demo.pdb
?????文件????????180??2013-12-12?14:37??demo\demo\obj\Debug\demo.Properties.Resources.resources
?????文件????????789??2013-12-12?15:08??demo\demo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7062??2013-12-12?17:09??demo\demo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????485??2013-12-12?14:18??demo\demo\Program.cs
?????文件???????1346??2013-12-12?14:18??demo\demo\Properties\AssemblyInfo.cs
?????文件???????2860??2013-12-12?14:18??demo\demo\Properties\Resources.Designer.cs
?????文件???????5612??2013-12-12?14:18??demo\demo\Properties\Resources.resx
?????文件???????1091??2013-12-12?14:18??demo\demo\Properties\Settings.Designer.cs
?????文件????????249??2013-12-12?14:18??demo\demo\Properties\Settings.settings
?????文件????????902??2013-12-12?14:18??demo\demo.sln
????..A..H.?????30208??2013-12-12?17:53??demo\demo.v11.suo
?????目錄??????????0??2013-12-12?14:18??demo\demo\obj\Debug\TempPE
?????目錄??????????0??2013-12-12?14:24??demo\demo\bin\Debug
?????目錄??????????0??2013-12-12?17:29??demo\demo\obj\Debug
?????目錄??????????0??2013-12-12?14:18??demo\demo\bin
?????目錄??????????0??2013-12-12?14:18??demo\demo\obj
............此處省略6個文件信息
評論
共有 條評論