1 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
2 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
3 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
6 // Email: ianier@hotmail.com
8 // Copyright (C) 1999-2003 Ianier Munoz. All Rights Reserved.
11 using System
.Runtime
.InteropServices
;
15 public enum WaveFormats
21 [StructLayout(LayoutKind
.Sequential
)]
22 public class WaveFormat
24 public short wFormatTag
;
25 public short nChannels
;
26 public int nSamplesPerSec
;
27 public int nAvgBytesPerSec
;
28 public short nBlockAlign
;
29 public short wBitsPerSample
;
32 public WaveFormat(int rate
, int bits
, int channels
)
34 wFormatTag
= (short)WaveFormats
.Pcm
;
35 nChannels
= (short)channels
;
36 nSamplesPerSec
= rate
;
37 wBitsPerSample
= (short)bits
;
40 nBlockAlign
= (short)(channels
* (bits
/ 8));
41 nAvgBytesPerSec
= nSamplesPerSec
* nBlockAlign
;
45 internal class WaveNative
48 public const int MMSYSERR_NOERROR
= 0; // no error
50 public const int MM_WOM_OPEN
= 0x3BB;
51 public const int MM_WOM_CLOSE
= 0x3BC;
52 public const int MM_WOM_DONE
= 0x3BD;
54 public const int MM_WIM_OPEN
= 0x3BE;
55 public const int MM_WIM_CLOSE
= 0x3BF;
56 public const int MM_WIM_DATA
= 0x3C0;
58 public const int CALLBACK_FUNCTION
= 0x00030000; // dwCallback is a FARPROC
60 public const int TIME_MS
= 0x0001; // time in milliseconds
61 public const int TIME_SAMPLES
= 0x0002; // number of wave samples
62 public const int TIME_BYTES
= 0x0004; // current byte offset
65 public delegate void WaveDelegate(IntPtr hdrvr
, int uMsg
, int dwUser
, ref WaveHdr wavhdr
, int dwParam2
);
69 [StructLayout(LayoutKind
.Sequential
)] public struct WaveHdr
71 public IntPtr lpData
; // pointer to locked data buffer
72 public int dwBufferLength
; // length of data buffer
73 public int dwBytesRecorded
; // used for input only
74 public IntPtr dwUser
; // for client's use
75 public int dwFlags
; // assorted flags (see defines)
76 public int dwLoops
; // loop control counter
77 public IntPtr lpNext
; // PWaveHdr, reserved for driver
78 public int reserved
; // reserved for driver
81 private const string mmdll
= "winmm.dll";
85 public static extern int waveOutGetNumDevs();
87 public static extern int waveOutPrepareHeader(IntPtr hWaveOut
, ref WaveHdr lpWaveOutHdr
, int uSize
);
89 public static extern int waveOutUnprepareHeader(IntPtr hWaveOut
, ref WaveHdr lpWaveOutHdr
, int uSize
);
91 public static extern int waveOutWrite(IntPtr hWaveOut
, ref WaveHdr lpWaveOutHdr
, int uSize
);
93 public static extern int waveOutOpen(out IntPtr hWaveOut
, int uDeviceID
, WaveFormat lpFormat
, WaveDelegate dwCallback
, int dwInstance
, int dwFlags
);
95 public static extern int waveOutReset(IntPtr hWaveOut
);
97 public static extern int waveOutClose(IntPtr hWaveOut
);
99 public static extern int waveOutPause(IntPtr hWaveOut
);
101 public static extern int waveOutRestart(IntPtr hWaveOut
);
103 public static extern int waveOutGetPosition(IntPtr hWaveOut
, out int lpInfo
, int uSize
);
105 public static extern int waveOutSetVolume(IntPtr hWaveOut
, int dwVolume
);
107 public static extern int waveOutGetVolume(IntPtr hWaveOut
, out int dwVolume
);
111 public static extern int waveInGetNumDevs();
113 public static extern int waveInAddBuffer(IntPtr hwi
, ref WaveHdr pwh
, int cbwh
);
115 public static extern int waveInClose(IntPtr hwi
);
117 public static extern int waveInOpen(out IntPtr phwi
, int uDeviceID
, WaveFormat lpFormat
, WaveDelegate dwCallback
, int dwInstance
, int dwFlags
);
119 public static extern int waveInPrepareHeader(IntPtr hWaveIn
, ref WaveHdr lpWaveInHdr
, int uSize
);
121 public static extern int waveInUnprepareHeader(IntPtr hWaveIn
, ref WaveHdr lpWaveInHdr
, int uSize
);
123 public static extern int waveInReset(IntPtr hwi
);
125 public static extern int waveInStart(IntPtr hwi
);
127 public static extern int waveInStop(IntPtr hwi
);