using
System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Text;
namespace WaveLib
... {
public enum WaveFormats
...{
Pcm = 1,
Float = 3
}
[StructLayout(LayoutKind.Sequential)]
public class WaveFormat
...{
public short wFormatTag;
public short nChannels;
public int nSamplesPerSec;
public int nAvgBytesPerSec;
public short nBlockAlign;
public short wBitsPerSample;
public short cbSize;
public WaveFormat()
...{
wFormatTag = (short)WaveFormats.Pcm;
nChannels = 1;
nSamplesPerSec = 8000;
nAvgBytesPerSec = 16000;
nBlockAlign = 2;
wBitsPerSample = 16;
cbSize = 0;
}
}
internal class WaveNative
...{
// consts
public const int MMSYSERR_NOERROR = 0; // no error
public const int MM_WOM_OPEN = 0x3BB;
public const int MM_WOM_CLOSE = 0x3BC;
public const int MM_WOM_DONE = 0x3BD;
public const int MM_WIM_OPEN = 0x3BE;
public const int MM_WIM_CLOSE = 0x3BF;
public const int MM_WIM_DATA = 0x3C0;
public const int CALLBACK_FUNCTION = 0x00030000; // dwCallback is a FARPROC
public const int TIME_MS = 0x0001; // time in milliseconds
public const int TIME_SAMPLES = 0x0002; // number of wave samples
public const int TIME_BYTES = 0x0004; // current byte offset
public const uint MIXER_GETLINEINFOF_DESTINATION = 0;
public const uint MIXER_GETLINEINFOF_SOURCE = 1;
public const uint MIXER_GETLINECONTROLSF_ALL = 0;
public const uint MIXER_OBJECTF_HMIXER = 2147483648;
public const uint MIXER_GETCONTROLDETAILSF_VALUE=0;
public const uint MIXERCONTROL_CONTROLTYPE_MUX=1879113729;
public const uint MIXERLINE_COMPONENTTYPE_DST_WAVEIN=1;
public const uint MIXERLINE_COMPONENTTYPE_SRC_DIGITAL=4097;
public const uint MIXERLINE_COMPONENTTYPE_SRC_LINE=4098;
public const uint MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = 4099;
public const uint MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER = 4100;
public const uint MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = 4101;
public const uint MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = 4102;
public const uint MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = 4103;
public const uint MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = 4104;
public const uint MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = 4105;
public const uint MIXERLINE_COMPONENTTYPE_SRC_ANALOG = 4106;
// callbacks
public delegate void WaveDelegate(IntPtr hdrvr, int uMsg, int dwUser, ref WaveHdr wavhdr, int dwParam2);
// structs
[StructLayout(LayoutKind.Sequential)] public struct WaveHdr
...{
public IntPtr lpData; // pointer to locked data buffer
public int dwBufferLength; // length of data buffer
public int dwBytesRecorded; // used for input only
public IntPtr dwUser; // for client's use
public int dwFlags; // assorted flags (see defines)
public int dwLoops; // loop control counter
public IntPtr lpNext; // PWaveHdr, reserved for driver
public int reserved; // reserved for driver
}
[StructLayout(LayoutKind.Sequential)] public struct rect
...{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERCAPS
...{
public short wMid;
public short WPid;
public int vDriverVersion;
public byte[] szPname;
public int fdwSuppport;
public int cDestinations;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERLINE
...{
public int cbStruct;//结构大小
public uint dwDestination;//目标单元编号
public int dwSource;//线路编号
public int dwLineID;//Mixer设备
public int fdwLine;
public int dwUser;//实例数据
public uint dwComponentType;//线路类型
public int cChannels;//独立声道数
public int cConnections;//关联的音频线路总数
public int cControls; //相关控制总数
public byte[] szShortName;//dwlineID对应的设备名
public byte[] szName;
public int dwType;
public int dwDeviceID;//标识符
public short wMid;//厂家标识
public short wPid;//产品版本
public int vDriverVersion;//驱动版本
public byte[] szPname;//设备名
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERLINECONTROLS
...{
public int cbStruct;
public int dwLineID;
public int dwControl;
public int cControls;
public int cbmxctrl;
public byte[] pamxctrl;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERCONTROL
...{
public int cbStruct;
public int dwControlID;
public int dwControlType;
public int fdwControl;
public int cMultipleItems;
public byte[] szShortName;
public byte[] szName;
public byte[] Bounds;
public byte[] Metrics;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERCONTROLDETAILS
...{
public int cbStruct;
public uint dwControlID;
public int cChannels;
public uint union;
public int cbDetails;
public int[] paDetails;
}
private const string mmdll = "winmm.dll";
// WaveOut calls
/**//*[DllImport(mmdll)]
public static extern int waveOutGetNumDevs();
[DllImport(mmdll)]
public static extern int waveOutPrepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveOutUnprepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveOutWrite(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
[DllImport(mmdll)]
public static extern int waveOutReset(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutClose(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutPause(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutRestart(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutGetPosition(IntPtr hWaveOut, out int lpInfo, int uSize);
[DllImport(mmdll)]
public static extern int waveOutSetVolume(IntPtr hWaveOut, int dwVolume);
[DllImport(mmdll)]
public static extern int waveOutGetVolume(IntPtr hWaveOut, out int dwVolume);*/
// WaveIn calls
[DllImport(mmdll)]
public static extern int waveInGetNumDevs();
[DllImport(mmdll)]
public static extern int waveInAddBuffer(IntPtr hwi, ref WaveHdr pwh, int cbwh);
[DllImport(mmdll)]
public static extern int waveInClose(IntPtr hwi);
[DllImport(mmdll)]
public static extern int waveInOpen(out IntPtr phwi, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
[DllImport(mmdll)]
public static extern int waveInPrepareHeader(IntPtr hWaveIn, ref WaveHdr lpWaveInHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveInUnprepareHeader(IntPtr hWaveIn, ref WaveHdr lpWaveInHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveInReset(IntPtr hwi);
[DllImport(mmdll)]
public static extern int waveInStart(IntPtr hwi);
[DllImport(mmdll)]
public static extern int waveInStop(IntPtr hwi);
//设置音源dll
[DllImport(mmdll)]
public static extern int mixerGetNumDevs();
[DllImport(mmdll)]
public static extern int mixerOpen(out int phmx,int uMxID,int dwCallback,int dwInstance,int fdwOpen);
[DllImport(mmdll)]
public static extern int mixerClose(int hmx);
[DllImport(mmdll)]
public static extern int mixerGetDevCaps(int uMxID,ref MIXERCAPS pmxcaps,int cbmxcaps);
[DllImport(mmdll)]
public static extern int mixerGetLineControls(int hmxobj,out MIXERLINECONTROLS pmxlc,uint fdwControls);
[DllImport(mmdll)]
public static extern int mixerGetLineInfo(int hmxobj, out MIXERLINE pmxl, uint fdwInf);
[DllImport(mmdll)]
public static extern int mixerGetControlDetails(int hmxobj, out MIXERCONTROLDETAILS pmxlc, int fdwDetails);
[DllImport(mmdll)]
public static extern int mixerSetControlDetails(int hmxobj, out MIXERCONTROLDETAILS pmxcd, uint fdwDetails);
// GDI
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth,
int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
[DllImport("gdi32.dll")]
public static extern bool FillRgn(IntPtr hdc, IntPtr hrgn, IntPtr hbr);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateSolidBrush(int crColor);
[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth,
int nHeight);
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("user32.dll")]
public static extern int FillRect(IntPtr hDC,out Rectangle lprc, IntPtr hbr);
[DllImport("gdi32.dll")]
public static extern bool LineTo(IntPtr hdc, int nXEnd, int nYEnd);
[DllImport("gdi32.dll")]
public static extern IntPtr CreatePen(int nPenStyle, int nWidth, int crColor);
[DllImport("gdi32.dll", EntryPoint="SelectObject")]
public static extern int SelectObject(
IntPtr hDC,
IntPtr font);
[DllImport("gdi32.dll")]
public static extern bool MoveToEx(IntPtr hdc, int X, int Y, int lpPoint);
[DllImport("gdi32.dll")]
public static extern bool SetPixelV(IntPtr hdc, int X, int Y, int crColor);
}
}
using System.Runtime.InteropServices;
using System.Drawing;
using System.Text;
namespace WaveLib
... {
public enum WaveFormats
...{
Pcm = 1,
Float = 3
}
[StructLayout(LayoutKind.Sequential)]
public class WaveFormat
...{
public short wFormatTag;
public short nChannels;
public int nSamplesPerSec;
public int nAvgBytesPerSec;
public short nBlockAlign;
public short wBitsPerSample;
public short cbSize;
public WaveFormat()
...{
wFormatTag = (short)WaveFormats.Pcm;
nChannels = 1;
nSamplesPerSec = 8000;
nAvgBytesPerSec = 16000;
nBlockAlign = 2;
wBitsPerSample = 16;
cbSize = 0;
}
}
internal class WaveNative
...{
// consts
public const int MMSYSERR_NOERROR = 0; // no error
public const int MM_WOM_OPEN = 0x3BB;
public const int MM_WOM_CLOSE = 0x3BC;
public const int MM_WOM_DONE = 0x3BD;
public const int MM_WIM_OPEN = 0x3BE;
public const int MM_WIM_CLOSE = 0x3BF;
public const int MM_WIM_DATA = 0x3C0;
public const int CALLBACK_FUNCTION = 0x00030000; // dwCallback is a FARPROC
public const int TIME_MS = 0x0001; // time in milliseconds
public const int TIME_SAMPLES = 0x0002; // number of wave samples
public const int TIME_BYTES = 0x0004; // current byte offset
public const uint MIXER_GETLINEINFOF_DESTINATION = 0;
public const uint MIXER_GETLINEINFOF_SOURCE = 1;
public const uint MIXER_GETLINECONTROLSF_ALL = 0;
public const uint MIXER_OBJECTF_HMIXER = 2147483648;
public const uint MIXER_GETCONTROLDETAILSF_VALUE=0;
public const uint MIXERCONTROL_CONTROLTYPE_MUX=1879113729;
public const uint MIXERLINE_COMPONENTTYPE_DST_WAVEIN=1;
public const uint MIXERLINE_COMPONENTTYPE_SRC_DIGITAL=4097;
public const uint MIXERLINE_COMPONENTTYPE_SRC_LINE=4098;
public const uint MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = 4099;
public const uint MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER = 4100;
public const uint MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC = 4101;
public const uint MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE = 4102;
public const uint MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER = 4103;
public const uint MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT = 4104;
public const uint MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY = 4105;
public const uint MIXERLINE_COMPONENTTYPE_SRC_ANALOG = 4106;
// callbacks
public delegate void WaveDelegate(IntPtr hdrvr, int uMsg, int dwUser, ref WaveHdr wavhdr, int dwParam2);
// structs
[StructLayout(LayoutKind.Sequential)] public struct WaveHdr
...{
public IntPtr lpData; // pointer to locked data buffer
public int dwBufferLength; // length of data buffer
public int dwBytesRecorded; // used for input only
public IntPtr dwUser; // for client's use
public int dwFlags; // assorted flags (see defines)
public int dwLoops; // loop control counter
public IntPtr lpNext; // PWaveHdr, reserved for driver
public int reserved; // reserved for driver
}
[StructLayout(LayoutKind.Sequential)] public struct rect
...{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERCAPS
...{
public short wMid;
public short WPid;
public int vDriverVersion;
public byte[] szPname;
public int fdwSuppport;
public int cDestinations;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERLINE
...{
public int cbStruct;//结构大小
public uint dwDestination;//目标单元编号
public int dwSource;//线路编号
public int dwLineID;//Mixer设备
public int fdwLine;
public int dwUser;//实例数据
public uint dwComponentType;//线路类型
public int cChannels;//独立声道数
public int cConnections;//关联的音频线路总数
public int cControls; //相关控制总数
public byte[] szShortName;//dwlineID对应的设备名
public byte[] szName;
public int dwType;
public int dwDeviceID;//标识符
public short wMid;//厂家标识
public short wPid;//产品版本
public int vDriverVersion;//驱动版本
public byte[] szPname;//设备名
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERLINECONTROLS
...{
public int cbStruct;
public int dwLineID;
public int dwControl;
public int cControls;
public int cbmxctrl;
public byte[] pamxctrl;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERCONTROL
...{
public int cbStruct;
public int dwControlID;
public int dwControlType;
public int fdwControl;
public int cMultipleItems;
public byte[] szShortName;
public byte[] szName;
public byte[] Bounds;
public byte[] Metrics;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIXERCONTROLDETAILS
...{
public int cbStruct;
public uint dwControlID;
public int cChannels;
public uint union;
public int cbDetails;
public int[] paDetails;
}
private const string mmdll = "winmm.dll";
// WaveOut calls
/**//*[DllImport(mmdll)]
public static extern int waveOutGetNumDevs();
[DllImport(mmdll)]
public static extern int waveOutPrepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveOutUnprepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveOutWrite(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
[DllImport(mmdll)]
public static extern int waveOutReset(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutClose(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutPause(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutRestart(IntPtr hWaveOut);
[DllImport(mmdll)]
public static extern int waveOutGetPosition(IntPtr hWaveOut, out int lpInfo, int uSize);
[DllImport(mmdll)]
public static extern int waveOutSetVolume(IntPtr hWaveOut, int dwVolume);
[DllImport(mmdll)]
public static extern int waveOutGetVolume(IntPtr hWaveOut, out int dwVolume);*/
// WaveIn calls
[DllImport(mmdll)]
public static extern int waveInGetNumDevs();
[DllImport(mmdll)]
public static extern int waveInAddBuffer(IntPtr hwi, ref WaveHdr pwh, int cbwh);
[DllImport(mmdll)]
public static extern int waveInClose(IntPtr hwi);
[DllImport(mmdll)]
public static extern int waveInOpen(out IntPtr phwi, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
[DllImport(mmdll)]
public static extern int waveInPrepareHeader(IntPtr hWaveIn, ref WaveHdr lpWaveInHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveInUnprepareHeader(IntPtr hWaveIn, ref WaveHdr lpWaveInHdr, int uSize);
[DllImport(mmdll)]
public static extern int waveInReset(IntPtr hwi);
[DllImport(mmdll)]
public static extern int waveInStart(IntPtr hwi);
[DllImport(mmdll)]
public static extern int waveInStop(IntPtr hwi);
//设置音源dll
[DllImport(mmdll)]
public static extern int mixerGetNumDevs();
[DllImport(mmdll)]
public static extern int mixerOpen(out int phmx,int uMxID,int dwCallback,int dwInstance,int fdwOpen);
[DllImport(mmdll)]
public static extern int mixerClose(int hmx);
[DllImport(mmdll)]
public static extern int mixerGetDevCaps(int uMxID,ref MIXERCAPS pmxcaps,int cbmxcaps);
[DllImport(mmdll)]
public static extern int mixerGetLineControls(int hmxobj,out MIXERLINECONTROLS pmxlc,uint fdwControls);
[DllImport(mmdll)]
public static extern int mixerGetLineInfo(int hmxobj, out MIXERLINE pmxl, uint fdwInf);
[DllImport(mmdll)]
public static extern int mixerGetControlDetails(int hmxobj, out MIXERCONTROLDETAILS pmxlc, int fdwDetails);
[DllImport(mmdll)]
public static extern int mixerSetControlDetails(int hmxobj, out MIXERCONTROLDETAILS pmxcd, uint fdwDetails);
// GDI
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth,
int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
[DllImport("gdi32.dll")]
public static extern bool FillRgn(IntPtr hdc, IntPtr hrgn, IntPtr hbr);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateSolidBrush(int crColor);
[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth,
int nHeight);
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll", SetLastError=true)]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("user32.dll")]
public static extern int FillRect(IntPtr hDC,out Rectangle lprc, IntPtr hbr);
[DllImport("gdi32.dll")]
public static extern bool LineTo(IntPtr hdc, int nXEnd, int nYEnd);
[DllImport("gdi32.dll")]
public static extern IntPtr CreatePen(int nPenStyle, int nWidth, int crColor);
[DllImport("gdi32.dll", EntryPoint="SelectObject")]
public static extern int SelectObject(
IntPtr hDC,
IntPtr font);
[DllImport("gdi32.dll")]
public static extern bool MoveToEx(IntPtr hdc, int X, int Y, int lpPoint);
[DllImport("gdi32.dll")]
public static extern bool SetPixelV(IntPtr hdc, int X, int Y, int crColor);
}
}