using
System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
namespace cswavrec
... {
/**//// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
...{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button StopButton;
private System.Windows.Forms.Button StartButton;
private Button button1;
private PictureBox pictureBox1;
private TextBox textBox1;
private System.Windows.Forms.OpenFileDialog OpenDlg;
public MainForm()
...{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
...{
this.StartButton = new System.Windows.Forms.Button();
this.StopButton = new System.Windows.Forms.Button();
this.OpenDlg = new System.Windows.Forms.OpenFileDialog();
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.textBox1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// StartButton
//
this.StartButton.Location = new System.Drawing.Point(10, 13);
this.StartButton.Name = "StartButton";
this.StartButton.Size = new System.Drawing.Size(86, 26);
this.StartButton.TabIndex = 0;
this.StartButton.Text = "Start";
this.StartButton.Click += new System.EventHandler(this.StartButton_Click);
//
// StopButton
//
this.StopButton.Enabled = false;
this.StopButton.Location = new System.Drawing.Point(106, 13);
this.StopButton.Name = "StopButton";
this.StopButton.Size = new System.Drawing.Size(86, 26);
this.StopButton.TabIndex = 1;
this.StopButton.Text = "Stop";
this.StopButton.Click += new System.EventHandler(this.StopButton_Click);
//
// OpenDlg
//
this.OpenDlg.DefaultExt = "wav";
this.OpenDlg.Filter = "WAV files|*.wav";
//
// button1
//
this.button1.Location = new System.Drawing.Point(457, 30);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.pictureBox1.Location = new System.Drawing.Point(34, 57);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(256, 127);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(412, 81);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(130, 178);
this.textBox1.TabIndex = 4;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(574, 311);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.StopButton);
this.Controls.Add(this.StartButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
this.Text = "Full-duplex audio sample";
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.Load += new System.EventHandler(this.MainForm_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new MainForm());
}
private WaveLib.WaveInRecorder m_Recorder;
//private WaveLib.FifoStream m_Fifo = new WaveLib.FifoStream();
private byte[] m_RecBuffer;
/**//*private void Filler(IntPtr data, int size)
{
if (m_PlayBuffer == null || m_PlayBuffer.Length < size)
m_PlayBuffer = new byte[size];
if (m_Fifo.Length >= size)
m_Fifo.Read(m_PlayBuffer, 0, size);
else
for (int i = 0; i < m_PlayBuffer.Length; i++)
m_PlayBuffer[i] = 0;
System.Runtime.InteropServices.Marshal.Copy(m_PlayBuffer, 0, data, size);
}*/
private void DataArrived(IntPtr data, int size)
...{
int 音频数据 = 0;
if (m_RecBuffer == null || m_RecBuffer.Length < size)
m_RecBuffer = new byte[size];
WaveLib.WaveNative.FillRect(hd内存画板1句柄, out 填充范围, hd刷子句柄);
WaveLib.WaveNative.MoveToEx(hd内存画板1句柄, 0, 64 + m_RecBuffer[1] / 256, 0);
for (int i = 1; i <256; i++)
...{
音频数据 = (BitConverter.ToInt16(m_RecBuffer, i * 4 - 3) + BitConverter.ToInt16(m_RecBuffer, i * 4 - 1)) / 2;
音频数据 = 音频数据 / size;
WaveLib.WaveNative.LineTo(hd内存画板1句柄, i, 64+音频数据);
}
WaveLib.WaveNative.BitBlt(hd画板1句柄, 0, 0, 256, 127, hd内存画板1句柄, 0, 0, 0xcc0020);
Marshal.Copy(data, m_RecBuffer, 0, size);
}
private void Stop()
...{
if (m_Recorder != null)
try
...{
m_Recorder.Dispose();
}
finally
...{
m_Recorder = null;
}
}
private void Start()
...{
Stop();
try
...{
WaveLib.WaveFormat fmt = new WaveLib.WaveFormat();
m_Recorder = new WaveLib.WaveInRecorder(-1, fmt,1024, 2, new WaveLib.BufferDoneEventHandler(DataArrived));
}
catch
...{
Stop();
throw;
}
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
...{
Stop();
}
private void StartButton_Click(object sender, System.EventArgs e)
...{
StartButton.Enabled = false;
StopButton.Enabled = true;
Start();
}
private void StopButton_Click(object sender, System.EventArgs e)
...{
StartButton.Enabled = true;
StopButton.Enabled = false;
Stop();
}
private void button1_Click(object sender, EventArgs e)
...{
/**//* MIXERLINE_COMPONENTTYPE_SRC_DIGITAL 数码
MIXERLINE_COMPONENTTYPE_SRC_LINE Line In
MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE 麦克风
MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER 电子合成器(MIDI)
MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC CD
MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE 电话(调制解调器)
MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER PC
MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT 波形
MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY AUX
MIXERLINE_COMPONENTTYPE_SRC_ANALOG 辅助*/
SetInLine设录制线路(WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
}
public bool SetInLine设录制线路(uint line)
...{
int fmixerhandle=new int ();
fmixerhandle = 0;
int mixerID;
WaveLib.WaveNative.MIXERCAPS MIXERCAPS=new WaveLib.WaveNative.MIXERCAPS ();
WaveLib.WaveNative.MIXERLINE MIXERLINE1=new WaveLib.WaveNative.MIXERLINE ();
WaveLib.WaveNative.MIXERLINE MIXERLINE2=new WaveLib.WaveNative.MIXERLINE ();
WaveLib.WaveNative.MIXERLINECONTROLS MIXERLINECONTROLS=new WaveLib.WaveNative.MIXERLINECONTROLS ();
WaveLib.WaveNative.MIXERCONTROLDETAILS MIXERCONTROLDETAILS=new WaveLib.WaveNative.MIXERCONTROLDETAILS ();
byte[] tmp;
MIXERCAPS.szPname = new byte[32];
MIXERLINE1.szShortName = new byte[16];
MIXERLINE1.szName = new byte[64];
MIXERLINE1.szPname = new byte[32];
MIXERLINE2.szShortName = new byte[16];
MIXERLINE2.szName = new byte[64];
MIXERLINE2.szPname = new byte[32];
MIXERLINECONTROLS.pamxctrl = new byte[1];
// int LineSelet线路索引;
// int ControlSelet控制索引;
int Controlindex控制位置;
Controlindex控制位置 = 0;
if (WaveLib.WaveNative.mixerGetNumDevs() == 0)
...{
return false;
}
mixerID = 0;
if (WaveLib.WaveNative.mixerOpen(out fmixerhandle, mixerID, 0, 0, 0) != 0)
...{
return false;
}
if (WaveLib.WaveNative.mixerGetDevCaps(mixerID, ref MIXERCAPS, 48) != 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
MIXERLINE1.cbStruct=168;
MIXERLINE1.dwDestination=WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
if(WaveLib .WaveNative.mixerGetLineInfo(fmixerhandle,out MIXERLINE1,WaveLib.WaveNative.MIXER_GETLINEINFOF_DESTINATION)!=0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
if (MIXERLINE1.cControls <= 0 || MIXERLINE1.cConnections <= 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
MIXERLINE2.cbStruct = 168;
MIXERLINE2.dwDestination = WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
for (int i = 0; i < MIXERLINE1.cConnections - 1; i++)
...{
MIXERLINE2.dwSource = i;
if (WaveLib.WaveNative.mixerGetLineInfo(fmixerhandle, out MIXERLINE2, WaveLib.WaveNative.MIXER_GETLINEINFOF_SOURCE) != 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
if (MIXERLINE2.dwComponentType == line)
...{
Controlindex控制位置 = MIXERLINE1.cConnections - i;
break;
}
}
if (Controlindex控制位置 == 0)
...{
if (line == WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT)
...{
Controlindex控制位置 = MIXERLINE1.cConnections;
}
else
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
}
MIXERLINECONTROLS.cbStruct = 24;
MIXERLINECONTROLS.dwLineID = MIXERLINE1.dwLineID;
MIXERLINECONTROLS.cControls = MIXERLINE1.cControls;
MIXERLINECONTROLS.cbmxctrl = 148;
MIXERLINECONTROLS.pamxctrl = new byte[148 * MIXERLINE1.cControls];
if (WaveLib.WaveNative.mixerGetLineControls(fmixerhandle, out MIXERLINECONTROLS, WaveLib.WaveNative.MIXER_GETLINECONTROLSF_ALL) != 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
tmp = MIXERLINECONTROLS.pamxctrl;
for (int j = 0; j < MIXERLINECONTROLS.cControls; j++)
...{
if (BitConverter.ToUInt32(tmp, GetStuctNum(j, "dwControlType")) == WaveLib.WaveNative.MIXERCONTROL_CONTROLTYPE_MUX)
...{
MIXERCONTROLDETAILS.cbStruct = 24;
MIXERCONTROLDETAILS.dwControlID = BitConverter.ToUInt32(tmp, GetStuctNum(j, "dwControlID"));
MIXERCONTROLDETAILS.cChannels = 1;
MIXERCONTROLDETAILS.union = BitConverter.ToUInt32(tmp, GetStuctNum(j, "cMultipleItems"));
MIXERCONTROLDETAILS.cbDetails = 4;
MIXERCONTROLDETAILS.paDetails = new int[MIXERLINE1.cConnections];
MIXERCONTROLDETAILS.paDetails[j] = 1;
if (WaveLib.WaveNative.mixerSetControlDetails(fmixerhandle, out MIXERCONTROLDETAILS, WaveLib.WaveNative.MIXER_OBJECTF_HMIXER + WaveLib.WaveNative.MIXER_GETCONTROLDETAILSF_VALUE) == 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return true;
}
else
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
}
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
return true;
}
public int GetStuctNum(int selectindex, string StructName)
...{
if (StructName == "cbStruct") return 148 * (selectindex - 1) + 1;
if (StructName == "dwControlID") return 148 * (selectindex - 1) + 5;
if (StructName == "dwControlType") return 148 * (selectindex - 1) + 9;
if (StructName == "fdwControl") return 148 * (selectindex - 1) + 13;
if (StructName == "cMultipleItems") return 148 * (selectindex - 1) + 17;
if (StructName == "szShortName") return 148 * (selectindex - 1) + 21;
if (StructName == "szName") return 148 * (selectindex - 1) + 37;
if (StructName == "Bounds") return 148 * (selectindex - 1) + 101;
if (StructName == "Metrics") return 148 * (selectindex - 1) + 125;
return -1;
}
public IntPtr hd画板1句柄;
public IntPtr hd内存画板;
public IntPtr hd内存画板1句柄;
public IntPtr hd位图句柄1;
public IntPtr hd画笔句柄;
public IntPtr hd刷子句柄;
public Rectangle 填充范围;
private void MainForm_Load(object sender, EventArgs e)
...{
hd画板1句柄 = WaveLib.WaveNative.GetDC(pictureBox1.Handle);
hd内存画板1句柄 = WaveLib.WaveNative.CreateCompatibleDC(hd画板1句柄);
hd位图句柄1 = WaveLib.WaveNative.CreateCompatibleBitmap(hd画板1句柄, pictureBox1.Width, pictureBox1.Height);
WaveLib.WaveNative.SelectObject(hd内存画板1句柄, hd位图句柄1);
hd画笔句柄 = WaveLib.WaveNative.CreatePen(0, 1, 65280);
WaveLib.WaveNative.SelectObject(hd内存画板1句柄, hd画笔句柄);
hd刷子句柄=WaveLib .WaveNative.CreateSolidBrush(0);
/**//*填充范围.left=0;
填充范围.top=0;
填充范围.right=pictureBox1.Width;
填充范围.bottom = pictureBox1.Height;*/
填充范围.X = 0;
填充范围.Y = 0;
填充范围.Width = pictureBox1.Width;
填充范围.Height = pictureBox1.Height;
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
namespace cswavrec
... {
/**//// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
...{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button StopButton;
private System.Windows.Forms.Button StartButton;
private Button button1;
private PictureBox pictureBox1;
private TextBox textBox1;
private System.Windows.Forms.OpenFileDialog OpenDlg;
public MainForm()
...{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
...{
this.StartButton = new System.Windows.Forms.Button();
this.StopButton = new System.Windows.Forms.Button();
this.OpenDlg = new System.Windows.Forms.OpenFileDialog();
this.button1 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.textBox1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// StartButton
//
this.StartButton.Location = new System.Drawing.Point(10, 13);
this.StartButton.Name = "StartButton";
this.StartButton.Size = new System.Drawing.Size(86, 26);
this.StartButton.TabIndex = 0;
this.StartButton.Text = "Start";
this.StartButton.Click += new System.EventHandler(this.StartButton_Click);
//
// StopButton
//
this.StopButton.Enabled = false;
this.StopButton.Location = new System.Drawing.Point(106, 13);
this.StopButton.Name = "StopButton";
this.StopButton.Size = new System.Drawing.Size(86, 26);
this.StopButton.TabIndex = 1;
this.StopButton.Text = "Stop";
this.StopButton.Click += new System.EventHandler(this.StopButton_Click);
//
// OpenDlg
//
this.OpenDlg.DefaultExt = "wav";
this.OpenDlg.Filter = "WAV files|*.wav";
//
// button1
//
this.button1.Location = new System.Drawing.Point(457, 30);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.pictureBox1.Location = new System.Drawing.Point(34, 57);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(256, 127);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(412, 81);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(130, 178);
this.textBox1.TabIndex = 4;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(574, 311);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.StopButton);
this.Controls.Add(this.StartButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
this.Text = "Full-duplex audio sample";
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.Load += new System.EventHandler(this.MainForm_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new MainForm());
}
private WaveLib.WaveInRecorder m_Recorder;
//private WaveLib.FifoStream m_Fifo = new WaveLib.FifoStream();
private byte[] m_RecBuffer;
/**//*private void Filler(IntPtr data, int size)
{
if (m_PlayBuffer == null || m_PlayBuffer.Length < size)
m_PlayBuffer = new byte[size];
if (m_Fifo.Length >= size)
m_Fifo.Read(m_PlayBuffer, 0, size);
else
for (int i = 0; i < m_PlayBuffer.Length; i++)
m_PlayBuffer[i] = 0;
System.Runtime.InteropServices.Marshal.Copy(m_PlayBuffer, 0, data, size);
}*/
private void DataArrived(IntPtr data, int size)
...{
int 音频数据 = 0;
if (m_RecBuffer == null || m_RecBuffer.Length < size)
m_RecBuffer = new byte[size];
WaveLib.WaveNative.FillRect(hd内存画板1句柄, out 填充范围, hd刷子句柄);
WaveLib.WaveNative.MoveToEx(hd内存画板1句柄, 0, 64 + m_RecBuffer[1] / 256, 0);
for (int i = 1; i <256; i++)
...{
音频数据 = (BitConverter.ToInt16(m_RecBuffer, i * 4 - 3) + BitConverter.ToInt16(m_RecBuffer, i * 4 - 1)) / 2;
音频数据 = 音频数据 / size;
WaveLib.WaveNative.LineTo(hd内存画板1句柄, i, 64+音频数据);
}
WaveLib.WaveNative.BitBlt(hd画板1句柄, 0, 0, 256, 127, hd内存画板1句柄, 0, 0, 0xcc0020);
Marshal.Copy(data, m_RecBuffer, 0, size);
}
private void Stop()
...{
if (m_Recorder != null)
try
...{
m_Recorder.Dispose();
}
finally
...{
m_Recorder = null;
}
}
private void Start()
...{
Stop();
try
...{
WaveLib.WaveFormat fmt = new WaveLib.WaveFormat();
m_Recorder = new WaveLib.WaveInRecorder(-1, fmt,1024, 2, new WaveLib.BufferDoneEventHandler(DataArrived));
}
catch
...{
Stop();
throw;
}
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
...{
Stop();
}
private void StartButton_Click(object sender, System.EventArgs e)
...{
StartButton.Enabled = false;
StopButton.Enabled = true;
Start();
}
private void StopButton_Click(object sender, System.EventArgs e)
...{
StartButton.Enabled = true;
StopButton.Enabled = false;
Stop();
}
private void button1_Click(object sender, EventArgs e)
...{
/**//* MIXERLINE_COMPONENTTYPE_SRC_DIGITAL 数码
MIXERLINE_COMPONENTTYPE_SRC_LINE Line In
MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE 麦克风
MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER 电子合成器(MIDI)
MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC CD
MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE 电话(调制解调器)
MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER PC
MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT 波形
MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY AUX
MIXERLINE_COMPONENTTYPE_SRC_ANALOG 辅助*/
SetInLine设录制线路(WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
}
public bool SetInLine设录制线路(uint line)
...{
int fmixerhandle=new int ();
fmixerhandle = 0;
int mixerID;
WaveLib.WaveNative.MIXERCAPS MIXERCAPS=new WaveLib.WaveNative.MIXERCAPS ();
WaveLib.WaveNative.MIXERLINE MIXERLINE1=new WaveLib.WaveNative.MIXERLINE ();
WaveLib.WaveNative.MIXERLINE MIXERLINE2=new WaveLib.WaveNative.MIXERLINE ();
WaveLib.WaveNative.MIXERLINECONTROLS MIXERLINECONTROLS=new WaveLib.WaveNative.MIXERLINECONTROLS ();
WaveLib.WaveNative.MIXERCONTROLDETAILS MIXERCONTROLDETAILS=new WaveLib.WaveNative.MIXERCONTROLDETAILS ();
byte[] tmp;
MIXERCAPS.szPname = new byte[32];
MIXERLINE1.szShortName = new byte[16];
MIXERLINE1.szName = new byte[64];
MIXERLINE1.szPname = new byte[32];
MIXERLINE2.szShortName = new byte[16];
MIXERLINE2.szName = new byte[64];
MIXERLINE2.szPname = new byte[32];
MIXERLINECONTROLS.pamxctrl = new byte[1];
// int LineSelet线路索引;
// int ControlSelet控制索引;
int Controlindex控制位置;
Controlindex控制位置 = 0;
if (WaveLib.WaveNative.mixerGetNumDevs() == 0)
...{
return false;
}
mixerID = 0;
if (WaveLib.WaveNative.mixerOpen(out fmixerhandle, mixerID, 0, 0, 0) != 0)
...{
return false;
}
if (WaveLib.WaveNative.mixerGetDevCaps(mixerID, ref MIXERCAPS, 48) != 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
MIXERLINE1.cbStruct=168;
MIXERLINE1.dwDestination=WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
if(WaveLib .WaveNative.mixerGetLineInfo(fmixerhandle,out MIXERLINE1,WaveLib.WaveNative.MIXER_GETLINEINFOF_DESTINATION)!=0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
if (MIXERLINE1.cControls <= 0 || MIXERLINE1.cConnections <= 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
MIXERLINE2.cbStruct = 168;
MIXERLINE2.dwDestination = WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
for (int i = 0; i < MIXERLINE1.cConnections - 1; i++)
...{
MIXERLINE2.dwSource = i;
if (WaveLib.WaveNative.mixerGetLineInfo(fmixerhandle, out MIXERLINE2, WaveLib.WaveNative.MIXER_GETLINEINFOF_SOURCE) != 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
if (MIXERLINE2.dwComponentType == line)
...{
Controlindex控制位置 = MIXERLINE1.cConnections - i;
break;
}
}
if (Controlindex控制位置 == 0)
...{
if (line == WaveLib.WaveNative.MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT)
...{
Controlindex控制位置 = MIXERLINE1.cConnections;
}
else
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
}
MIXERLINECONTROLS.cbStruct = 24;
MIXERLINECONTROLS.dwLineID = MIXERLINE1.dwLineID;
MIXERLINECONTROLS.cControls = MIXERLINE1.cControls;
MIXERLINECONTROLS.cbmxctrl = 148;
MIXERLINECONTROLS.pamxctrl = new byte[148 * MIXERLINE1.cControls];
if (WaveLib.WaveNative.mixerGetLineControls(fmixerhandle, out MIXERLINECONTROLS, WaveLib.WaveNative.MIXER_GETLINECONTROLSF_ALL) != 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
tmp = MIXERLINECONTROLS.pamxctrl;
for (int j = 0; j < MIXERLINECONTROLS.cControls; j++)
...{
if (BitConverter.ToUInt32(tmp, GetStuctNum(j, "dwControlType")) == WaveLib.WaveNative.MIXERCONTROL_CONTROLTYPE_MUX)
...{
MIXERCONTROLDETAILS.cbStruct = 24;
MIXERCONTROLDETAILS.dwControlID = BitConverter.ToUInt32(tmp, GetStuctNum(j, "dwControlID"));
MIXERCONTROLDETAILS.cChannels = 1;
MIXERCONTROLDETAILS.union = BitConverter.ToUInt32(tmp, GetStuctNum(j, "cMultipleItems"));
MIXERCONTROLDETAILS.cbDetails = 4;
MIXERCONTROLDETAILS.paDetails = new int[MIXERLINE1.cConnections];
MIXERCONTROLDETAILS.paDetails[j] = 1;
if (WaveLib.WaveNative.mixerSetControlDetails(fmixerhandle, out MIXERCONTROLDETAILS, WaveLib.WaveNative.MIXER_OBJECTF_HMIXER + WaveLib.WaveNative.MIXER_GETCONTROLDETAILSF_VALUE) == 0)
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return true;
}
else
...{
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
}
WaveLib.WaveNative.mixerClose(fmixerhandle);
return false;
}
return true;
}
public int GetStuctNum(int selectindex, string StructName)
...{
if (StructName == "cbStruct") return 148 * (selectindex - 1) + 1;
if (StructName == "dwControlID") return 148 * (selectindex - 1) + 5;
if (StructName == "dwControlType") return 148 * (selectindex - 1) + 9;
if (StructName == "fdwControl") return 148 * (selectindex - 1) + 13;
if (StructName == "cMultipleItems") return 148 * (selectindex - 1) + 17;
if (StructName == "szShortName") return 148 * (selectindex - 1) + 21;
if (StructName == "szName") return 148 * (selectindex - 1) + 37;
if (StructName == "Bounds") return 148 * (selectindex - 1) + 101;
if (StructName == "Metrics") return 148 * (selectindex - 1) + 125;
return -1;
}
public IntPtr hd画板1句柄;
public IntPtr hd内存画板;
public IntPtr hd内存画板1句柄;
public IntPtr hd位图句柄1;
public IntPtr hd画笔句柄;
public IntPtr hd刷子句柄;
public Rectangle 填充范围;
private void MainForm_Load(object sender, EventArgs e)
...{
hd画板1句柄 = WaveLib.WaveNative.GetDC(pictureBox1.Handle);
hd内存画板1句柄 = WaveLib.WaveNative.CreateCompatibleDC(hd画板1句柄);
hd位图句柄1 = WaveLib.WaveNative.CreateCompatibleBitmap(hd画板1句柄, pictureBox1.Width, pictureBox1.Height);
WaveLib.WaveNative.SelectObject(hd内存画板1句柄, hd位图句柄1);
hd画笔句柄 = WaveLib.WaveNative.CreatePen(0, 1, 65280);
WaveLib.WaveNative.SelectObject(hd内存画板1句柄, hd画笔句柄);
hd刷子句柄=WaveLib .WaveNative.CreateSolidBrush(0);
/**//*填充范围.left=0;
填充范围.top=0;
填充范围.right=pictureBox1.Width;
填充范围.bottom = pictureBox1.Height;*/
填充范围.X = 0;
填充范围.Y = 0;
填充范围.Width = pictureBox1.Width;
填充范围.Height = pictureBox1.Height;
}
}
}