Improve flash screen (#7123)
[opentx.git] / sound / recorder / WaveNative.cs
blob1b35a4d15fff8cf0545eefa517bd6021335ff578
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
4 // PURPOSE.
5 //
6 // Email: ianier@hotmail.com
7 //
8 // Copyright (C) 1999-2003 Ianier Munoz. All Rights Reserved.
10 using System;
11 using System.Runtime.InteropServices;
13 namespace WaveLib
15 public enum WaveFormats
17 Pcm = 1,
18 Float = 3
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;
30 public short cbSize;
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;
38 cbSize = 0;
40 nBlockAlign = (short)(channels * (bits / 8));
41 nAvgBytesPerSec = nSamplesPerSec * nBlockAlign;
45 internal class WaveNative
47 // consts
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
64 // callbacks
65 public delegate void WaveDelegate(IntPtr hdrvr, int uMsg, int dwUser, ref WaveHdr wavhdr, int dwParam2);
67 // structs
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";
83 // WaveOut calls
84 [DllImport(mmdll)]
85 public static extern int waveOutGetNumDevs();
86 [DllImport(mmdll)]
87 public static extern int waveOutPrepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
88 [DllImport(mmdll)]
89 public static extern int waveOutUnprepareHeader(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
90 [DllImport(mmdll)]
91 public static extern int waveOutWrite(IntPtr hWaveOut, ref WaveHdr lpWaveOutHdr, int uSize);
92 [DllImport(mmdll)]
93 public static extern int waveOutOpen(out IntPtr hWaveOut, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
94 [DllImport(mmdll)]
95 public static extern int waveOutReset(IntPtr hWaveOut);
96 [DllImport(mmdll)]
97 public static extern int waveOutClose(IntPtr hWaveOut);
98 [DllImport(mmdll)]
99 public static extern int waveOutPause(IntPtr hWaveOut);
100 [DllImport(mmdll)]
101 public static extern int waveOutRestart(IntPtr hWaveOut);
102 [DllImport(mmdll)]
103 public static extern int waveOutGetPosition(IntPtr hWaveOut, out int lpInfo, int uSize);
104 [DllImport(mmdll)]
105 public static extern int waveOutSetVolume(IntPtr hWaveOut, int dwVolume);
106 [DllImport(mmdll)]
107 public static extern int waveOutGetVolume(IntPtr hWaveOut, out int dwVolume);
109 // WaveIn calls
110 [DllImport(mmdll)]
111 public static extern int waveInGetNumDevs();
112 [DllImport(mmdll)]
113 public static extern int waveInAddBuffer(IntPtr hwi, ref WaveHdr pwh, int cbwh);
114 [DllImport(mmdll)]
115 public static extern int waveInClose(IntPtr hwi);
116 [DllImport(mmdll)]
117 public static extern int waveInOpen(out IntPtr phwi, int uDeviceID, WaveFormat lpFormat, WaveDelegate dwCallback, int dwInstance, int dwFlags);
118 [DllImport(mmdll)]
119 public static extern int waveInPrepareHeader(IntPtr hWaveIn, ref WaveHdr lpWaveInHdr, int uSize);
120 [DllImport(mmdll)]
121 public static extern int waveInUnprepareHeader(IntPtr hWaveIn, ref WaveHdr lpWaveInHdr, int uSize);
122 [DllImport(mmdll)]
123 public static extern int waveInReset(IntPtr hwi);
124 [DllImport(mmdll)]
125 public static extern int waveInStart(IntPtr hwi);
126 [DllImport(mmdll)]
127 public static extern int waveInStop(IntPtr hwi);