![]() |
Sylloge
A C# helper library
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Runtime.InteropServices; 00005 using System.Text; 00006 using System.IO; 00007 00008 namespace Sylloge 00009 { 00010 public static partial class WinAPI 00011 { 00012 public static class WinMM 00013 { 00014 #region WinMM 00015 00016 #region Enums 00017 00018 public enum WaveFormats 00019 { 00020 Pcm = 1, 00021 Float = 3 00022 } 00023 00024 #endregion 00025 00026 #region Structs 00027 00028 [StructLayout(LayoutKind.Sequential)] 00029 public struct WaveHdr 00030 { 00031 public IntPtr lpData; // pointer to locked data buffer 00032 public int dwBufferLength; // length of data buffer 00033 public int dwBytesRecorded; // used for input only 00034 public IntPtr dwUser; // for client's use 00035 public int dwFlags; // assorted flags (see defines) 00036 public int dwLoops; // loop control counter 00037 public IntPtr lpNext; // PWaveHdr, reserved for driver 00038 public int reserved; // reserved for driver 00039 } 00040 00041 [StructLayout(LayoutKind.Sequential)] 00042 public class WaveFormat 00043 { 00044 public short wFormatTag; 00045 public short nChannels; 00046 public int nSamplesPerSec; 00047 public int nAvgBytesPerSec; 00048 public short nBlockAlign; 00049 public short wBitsPerSample; 00050 public short cbSize; 00051 00052 public WaveFormat(int rate, int bits, int channels) 00053 { 00054 wFormatTag = (short)WaveFormats.Pcm; 00055 nChannels = (short)channels; 00056 nSamplesPerSec = rate; 00057 wBitsPerSample = (short)bits; 00058 cbSize = 0; 00059 00060 nBlockAlign = (short)(channels * (bits / 8)); 00061 nAvgBytesPerSec = nSamplesPerSec * nBlockAlign; 00062 } 00063 } 00064 00065 #endregion 00066 00067 public const int MMSYSERR_NOERROR = 0; // no error 00068 00069 public const int MM_WOM_OPEN = 0x3BB; 00070 public const int MM_WOM_CLOSE = 0x3BC; 00071 public const int MM_WOM_DONE = 0x3BD; 00072 00073 public const int CALLBACK_FUNCTION = 0x00030000; // dwCallback is a FARPROC 00074 00075 public const int TIME_MS = 0x0001; // time in milliseconds 00076 public const int TIME_SAMPLES = 0x0002; // number of wave samples 00077 public const int TIME_BYTES = 0x0004; // current byte offset 00078 00079 // use the userdata as a reference 00080 // WaveOutProc http://msdn.microsoft.com/en-us/library/dd743869%28VS.85%29.aspx 00081 // WaveInProc http://msdn.microsoft.com/en-us/library/dd743849%28VS.85%29.aspx 00082 public delegate void WaveDelegate(IntPtr hdrvr, int uMsg, int dwUser, ref WaveHdr wavhdr, int dwParam2); 00083 00084 [DllImport("winmm.dll")] 00085 public static extern int waveOutGetNumDevs(); 00086 [DllImport("winmm.dll")] 00087 public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags); 00088 [DllImport("winmm.dll")] 00089 public static extern int waveOutGetVolume(IntPtr hWaveOut, out uint dwVolume); 00090 [DllImport("winmm.dll")] 00091 public static extern int waveOutSetVolume(IntPtr hWaveOut, uint dwVolume); 00092 [DllImport("winmm.dll")] 00093 public static extern int waveOutReset(IntPtr hWaveOut); 00094 [DllImport("winmm.dll")] 00095 public static extern int waveOutClose(IntPtr hWaveOut); 00096 [DllImport("winmm.dll")] 00097 public static extern int waveOutPause(IntPtr hWaveOut); 00098 [DllImport("winmm.dll")] 00099 public static extern int waveOutRestart(IntPtr hWaveOut); 00100 [DllImport("winmm.dll")] 00101 public static extern int waveOutGetPosition(IntPtr hWaveOut, out int lpInfo, int uSize); 00102 [DllImport("winmm.dll")] 00103 public static extern int waveOutPrepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize); 00104 [DllImport("winmm.dll")] 00105 public static extern int waveOutUnprepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize); 00106 [DllImport("winmm.dll")] 00107 public static extern int waveOutWrite(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize); 00108 00109 #endregion 00110 } 00111 } 00112 }