#pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Vanara.PInvoke
{
/// Items from the WinMm.dll
public static partial class WinMm
{
/// Flags for opening the device.
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInOpen")]
[Flags]
public enum WAVE_OPEN : uint
{
/// The function queries the device to determine whether it supports the given format, but it does not open the device.
WAVE_FORMAT_QUERY = 0x0001,
///
WAVE_ALLOWSYNC = 0x0002,
/// The uDeviceID parameter specifies a waveform-audio device to be mapped to by the wave mapper.
WAVE_MAPPED = 0x0004,
/// If this flag is specified, the ACM driver does not perform conversions on the audio data.
WAVE_FORMAT_DIRECT = 0x0008,
///
WAVE_FORMAT_DIRECT_QUERY = WAVE_FORMAT_QUERY | WAVE_FORMAT_DIRECT,
///
/// If this flag is specified and the uDeviceID parameter is WAVE_MAPPER, the function opens the default communication device.
/// This flag applies only when uDeviceID equals WAVE_MAPPER.
///
WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE = 0x0010,
/// No callback mechanism. This is the default setting.
CALLBACK_NULL = 0x00000000,
/// The dwCallback parameter is a window handle.
CALLBACK_WINDOW = 0x00010000,
/// The dwCallback parameter is a task handle.
CALLBACK_TASK = 0x00020000,
/// The dwCallback parameter is a callback procedure address. See .
CALLBACK_FUNCTION = 0x00030000,
/// The dwCallback parameter is a thread identifier.
CALLBACK_THREAD = CALLBACK_TASK,
/// The dwCallback parameter is an event handle.
CALLBACK_EVENT = 0x00050000,
}
/// Optional functionality supported by the device.
[PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.waveoutcaps_tag")]
[Flags]
public enum WAVECAPS : uint
{
/// Supports pitch control.
WAVECAPS_PITCH = 0x0001,
/// Supports playback rate control.
WAVECAPS_PLAYBACKRATE = 0x0002,
/// Supports volume control.
WAVECAPS_VOLUME = 0x0004,
/// Supports separate left and right volume control.
WAVECAPS_LRVOLUME = 0x0008,
/// The driver is synchronous and will block while playing a buffer.
WAVECAPS_SYNC = 0x0010,
/// Returns sample-accurate position information.
WAVECAPS_SAMPLEACCURATE = 0x0020,
}
/// Flags for WAVEHDR.
[PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.wavehdr_tag")]
[Flags]
public enum WHDR
{
/// Set by the device driver to indicate that it is finished with the buffer and is returning it to the application.
WHDR_DONE = 0x00000001,
///
/// Set by Windows to indicate that the buffer has been prepared with the waveInPrepareHeader or waveOutPrepareHeader function.
///
WHDR_PREPARED = 0x00000002,
/// This buffer is the first buffer in a loop. This flag is used only with output buffers.
WHDR_BEGINLOOP = 0x00000004,
/// This buffer is the last buffer in a loop. This flag is used only with output buffers.
WHDR_ENDLOOP = 0x00000008,
/// Set by Windows to indicate that the buffer is queued for playback.
WHDR_INQUEUE = 0x00000010,
}
///
/// The waveInAddBuffer function sends an input buffer to the given waveform-audio input device. When the buffer is filled,
/// the application is notified.
///
/// Handle to the waveform-audio input device.
/// Pointer to a WAVEHDR structure that identifies the buffer.
/// Size, in bytes, of the WAVEHDR structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_UNPREPARED
/// The buffer pointed to by the pwh parameter hasn't been prepared.
///
///
///
///
/// When the buffer is filled, the WHDR_DONE bit is set in the dwFlags member of the WAVEHDR structure.
/// The buffer must be prepared with the waveInPrepareHeader function before it is passed to this function.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinaddbuffer MMRESULT waveInAddBuffer( HWAVEIN hwi,
// LPWAVEHDR pwh, UINT cbwh );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInAddBuffer")]
public static extern MMRESULT waveInAddBuffer([In] HWAVEIN hwi, ref WAVEHDR pwh, uint cbwh);
/// The waveInClose function closes the given waveform-audio input device.
///
/// Handle to the waveform-audio input device. If the function succeeds, the handle is no longer valid after this call.
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_STILLPLAYING
/// There are still buffers in the queue.
///
///
///
///
/// If there are input buffers that have been sent with the waveInAddBuffer function and that haven't been returned to the
/// application, the close operation will fail. Call the waveInReset function to mark all pending buffers as done.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinclose MMRESULT waveInClose( HWAVEIN hwi );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInClose")]
public static extern MMRESULT waveInClose(HWAVEIN hwi);
/// The waveInGetDevCaps function retrieves the capabilities of a given waveform-audio input device.
///
/// Identifier of the waveform-audio output device. It can be either a device identifier or a handle of an open waveform-audio input device.
///
/// Pointer to a WAVEINCAPS structure to be filled with information about the capabilities of the device.
/// Size, in bytes, of the WAVEINCAPS structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_BADDEVICEID
/// Specified device identifier is out of range.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
/// Use this function to determine the number of waveform-audio input devices present in the system. If the value specified by the
/// uDeviceID parameter is a device identifier, it can vary from zero to one less than the number of devices present. The
/// WAVE_MAPPER constant can also be used as a device identifier. Only cbwic bytes (or less) of information is copied to the
/// location pointed to by pwic. If cbwic is zero, nothing is copied and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveingetdevcaps MMRESULT waveInGetDevCaps( UINT uDeviceID,
// LPWAVEINCAPS pwic, UINT cbwic );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInGetDevCaps")]
public static extern MMRESULT waveInGetDevCaps(uint uDeviceID, out WAVEINCAPS pwic, uint cbwic);
///
/// The waveInGetErrorText function retrieves a textual description of the error identified by the given error number.
///
/// Error number.
/// Pointer to the buffer to be filled with the textual error description.
/// Size, in characters, of the buffer pointed to by pszText.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_BADERRNUM
/// Specified error number is out of range.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
/// If the textual error description is longer than the specified buffer, the description is truncated. The returned error string is
/// always null-terminated. If cchText is zero, nothing is copied and the function returns zero. All error descriptions are less
/// than MAXERRORLENGTH characters long.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveingeterrortext MMRESULT waveInGetErrorText( MMRESULT
// mmrError, LPSTR pszText, UINT cchText );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInGetErrorText")]
public static extern MMRESULT waveInGetErrorText(MMRESULT mmrError, [MarshalAs(UnmanagedType.LPStr)] StringBuilder pszText, uint cchText);
///
/// The waveInGetID function gets the device identifier for the given waveform-audio input device.
///
/// This function is supported for backward compatibility. New applications can cast a handle of the device rather than retrieving
/// the device identifier.
///
///
/// Handle to the waveform-audio input device.
/// Pointer to a variable to be filled with the device identifier.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// The hwi parameter specifies an invalid handle.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveingetid MMRESULT waveInGetID( HWAVEIN hwi, LPUINT
// puDeviceID );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInGetID")]
public static extern MMRESULT waveInGetID(HWAVEIN hwi, out uint puDeviceID);
/// The waveInGetNumDevs function returns the number of waveform-audio input devices present in the system.
/// Returns the number of devices. A return value of zero means that no devices are present or that an error occurred.
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveingetnumdevs UINT waveInGetNumDevs();
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInGetNumDevs")]
public static extern uint waveInGetNumDevs();
///
/// [ waveInGetPosition is no longer supported for use as of Windows Vista. Instead, use IAudioClock::GetPosition.]
/// The waveInGetPosition function retrieves the current input position of the given waveform-audio input device.
///
/// Handle to the waveform-audio input device.
/// Pointer to an MMTIME structure.
/// Size, in bytes, of the MMTIME structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
///
/// Before calling this function, set the wType member of the MMTIME structure to indicate the time format you want. After
/// calling this function, check wType to determine whether the desired time format is supported. If the format is not
/// supported, the member will specify an alternative format.
///
/// The position is set to zero when the device is opened or reset.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveingetposition MMRESULT waveInGetPosition( HWAVEIN hwi,
// LPMMTIME pmmt, UINT cbmmt );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInGetPosition")]
public static extern MMRESULT waveInGetPosition(HWAVEIN hwi, ref MMTIME pmmt, uint cbmmt);
/// The waveInMessage function sends messages to the waveform-audio input device drivers.
///
/// Identifier of the waveform device that receives the message. You must cast the device ID to the HWAVEIN handle type. If
/// you supply a handle instead of a device ID, the function fails and returns the MMSYSERR_NOSUPPORT error code.
///
/// Message to send.
/// Message parameter.
/// Message parameter.
/// Returns the value returned from the driver.
///
/// The
/// DRV_QUERYDEVICEINTERFACE
/// message queries for the device-interface name of a waveIn, waveOut, midiIn, midiOut, or mixer device.
///
/// For
/// DRV_QUERYDEVICEINTERFACE
/// , dwParam1 is a pointer to a caller-allocated buffer into which the function writes a null-terminated Unicode string containing
/// the device-interface name. If the device has no device interface, the string length is zero.
///
/// For
/// DRV_QUERYDEVICEINTERFACE
/// , dwParam2 specifies the buffer size in bytes. This is an input parameter to the function. The caller should specify a size that
/// is greater than or equal to the buffer size retrieved by the DRV_QUERYDEVICEINTERFACESIZE message.
///
///
/// The DRV_QUERYDEVICEINTERFACE message is supported in Windows Me, and Windows 2000 and later. This message is valid only for the
/// waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The system intercepts this
/// message and returns the appropriate value without sending the message to the device driver. For general information about
/// system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
/// The following two message constants are used together for the purpose of obtaining device interface names:
///
/// -
/// DRV_QUERYDEVICEINTERFACESIZE
///
/// -
/// DRV_QUERYDEVICEINTERFACE
///
///
///
/// The first message obtains the size in bytes of the buffer needed to hold the string containing the device interface name. The
/// second message retrieves the name string in a buffer of the required size.
///
/// For more information, see Obtaining a Device Interface Name.
/// The
/// DRV_QUERYDEVICEINTERFACESIZE
/// message queries for the size of the buffer required to hold the device-interface name.
///
/// For
/// DRV_QUERYDEVICEINTERFACESIZE
/// , dwParam1 is a pointer to buffer size. This parameter points to a ULONG variable into which the function writes the required
/// buffer size in bytes. The size includes storage space for the name string's terminating null. The size is zero if the device ID
/// identifies a device that has no device interface.
///
/// For
/// DRV_QUERYDEVICEINTERFACESIZE
/// , dwParam2 is unused. Set this parameter to zero.
///
///
/// This message is valid only for the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage
/// functions. The system intercepts this message and returns the appropriate value without sending the message to the device
/// driver. For general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// The buffer size retrieved by this message is expressed as a byte count. It specifies the size of the buffer needed to hold the
/// null-terminated Unicode string that contains the device-interface name. The caller allocates a buffer of the specified size and
/// uses the DRV_QUERYDEVICEINTERFACE message to retrieve the device-interface name string.
///
/// For more information, see Obtaining a Device Interface Name.
/// The
/// DRV_QUERYDEVNODE
/// message queries for the devnode number assigned to the device by the Plug and Play manager.
///
/// For
/// DRV_QUERYDEVNODE
/// , dwParam1 is a pointer to a caller-allocated DWORD variable into which the function writes the devnode number. If no devnode is
/// assigned to the device, the function sets this variable to zero.
///
/// For
/// DRV_QUERYDEVNODE
/// , dwParam2 is unused. Set this parameter to zero.
///
///
/// In Windows 2000 and later, the message always returns MMSYSERR_NOTSUPPORTED. This message is valid only for the
/// waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The system intercepts this
/// message and returns the appropriate value without sending the message to the device driver. For general information about
/// system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
/// The
/// DRV_QUERYMAPPABLE
/// message queries for whether the specified device can be used by a mapper.
///
/// For
/// DRV_QUERYMAPPABLE
/// , dwParam1 is unused. Set this parameter to zero.
///
/// For
/// DRV_QUERYMAPPABLE
/// , dwParam2 is unused. Set this parameter to zero.
///
///
/// This message is valid only for the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, mixerMessage and
/// auxOutMessage functions. The system intercepts this message and returns the appropriate value without sending the message to the
/// device driver. For general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// When an application program opens a mapper instead of a specific audio device, the system inserts a mapper between the
/// application and the available devices. The mapper selects an appropriate device by mapping the application's requirements to one
/// of the available devices. For more information about mappers, see the Microsoft Windows SDK documentation.
///
/// The
/// DRVM_MAPPER_CONSOLEVOICECOM_GET
/// message retrieves the device ID of the preferred voice-communications device.
///
/// For
/// DRVM_MAPPER_CONSOLEVOICECOM_GET
/// , dwParam1 is a pointer to device ID. This parameter points to a DWORD variable into which the function writes the device ID of
/// the current preferred voice-communications device. The function writes the value (-1) if no device is available that qualifies
/// as a preferred voice-communications device.
///
/// For
/// DRVM_MAPPER_CONSOLEVOICECOM_GET
/// , dwParam2 is a pointer to status flags. This parameter points to a DWORD variable into which the function writes the
/// device-status flags. Only one flag bit is currently defined: DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY.
///
///
/// This message is valid only for the waveInMessage and waveOutMessage functions. When a caller calls these two functions
/// with the DRVM_MAPPER_CONSOLEVOICECOM_GET message, the caller must specify the device ID as WAVE_MAPPER, and then cast this value
/// to the appropriate handle type. For the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, or
/// mixerMessage functions, the caller must cast the device ID to a handle of type HWAVEIN, HWAVEOUT, HMIDIIN, HMIDIOUT, or HMIXER,
/// respectively. Note that if the caller supplies a valid handle instead of a device ID for this parameter, the function fails and
/// returns error code MMSYSERR_NOSUPPORT.
///
///
/// The system intercepts this message and returns the appropriate value without sending the message to the device driver. For
/// general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// This message provides a way to determine which device is preferred specifically for voice communications, in contrast to the
/// DRVM_MAPPER_PREFERRED_GET message, which determines which device is preferred for all other audio functions.
///
///
/// For example, the preferred waveOut device for voice communications might be the earpiece in a headset, but the preferred
/// waveOut device for all other audio functions might be a set of stereo speakers.
///
///
/// When the DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY flag bit is set in the DWORD location pointed to by dwParam2, the
/// waveIn and waveOut APIs use only the current preferred voice-communications device and do not search for other
/// available devices if the preferred device is unavailable. The flag that is output by either the waveInMessage or
/// waveOutMessage call applies to the preferred voice-communications device for both the waveIn and waveOut
/// APIs, regardless of whether the call is made to waveInMessage or waveOutMessage. For more information, see
/// Preferred Voice-Communications Device ID.
///
/// The
/// DRVM_MAPPER_PREFERRED_GET
/// message retrieves the device ID of the preferred audio device.
///
/// For
/// DRVM_MAPPER_PREFERRED_GET
/// , dwParam1 is a pointer to device ID. This parameter points to a DWORD variable into which the function writes the device ID of
/// the current preferred device. The function writes the value (-1) if no device is available that qualifies as a preferred device.
///
/// For
/// DRVM_MAPPER_PREFERRED_GET
/// , dwParam2 is a pointer to status flags. This parameter points to a DWORD variable into which the function writes the
/// device-status flags. Only one flag bit is currently defined (for waveInMessage and waveOutMessage calls only): DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY.
///
///
/// This message is valid only for the waveInMessage, waveOutMessage and midiOutMessage functions. When the caller calls
/// these functions with the DRVM_MAPPER_PREFERRED_GET message, the caller must first specify the device ID as WAVE_MAPPER (for
/// waveInMessage or waveOutMessage) or MIDI_MAPPER (for midiOutMessage), and then cast this value to the
/// appropriate handle type. For the waveInMessage, waveOutMessage, or midiOutMessage functions, the caller
/// must cast the device ID to a handle type HWAVEIN, HWAVEOUT or HMIDIOUT, respectively. Note that if the caller supplies a valid
/// handle instead of a device ID for this parameter, the function fails and returns error code MMSYSERR_NOSUPPORT.
///
///
/// The system intercepts this message and returns the appropriate value without sending the message to the device driver. For
/// general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// This message provides a way to determine which device is preferred for audio functions in general, in contrast to the
/// DRVM_MAPPER_CONSOLEVOICECOM_GET message, which determines which device is preferred specifically for voice communications.
///
///
/// When the DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY flag bit is set in the DWORD location pointed to by dwParam2, the
/// waveIn and waveOut APIs use only the current preferred device and do not search for other available devices if the
/// preferred device is unavailable. Note that the midiOutMessage function does not output this flag--the midiOut API
/// always uses only the preferred device. The flag that is output by either the waveInMessage or waveOutMessage call
/// applies to the preferred device for both the waveIn and waveOut APIs, regardless of whether the call is made to
/// waveInMessage or waveOutMessage.
///
///
/// The xxxMessage functions accept this value in place of a valid device handle in order to allow an application to determine the
/// default device ID without first having to open a device. For more information, see Accessing the Preferred Device ID.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinmessage MMRESULT waveInMessage( HWAVEIN hwi, UINT uMsg,
// DWORD_PTR dw1, DWORD_PTR dw2 );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInMessage")]
public static extern MMRESULT waveInMessage(HWAVEIN hwi, uint uMsg, IntPtr dw1, IntPtr dw2);
/// The waveInOpen function opens the given waveform-audio input device for recording.
///
/// Pointer to a buffer that receives a handle identifying the open waveform-audio input device. Use this handle to identify the
/// device when calling other waveform-audio input functions. This parameter can be NULL if WAVE_FORMAT_QUERY is
/// specified for fdwOpen.
///
///
///
/// Identifier of the waveform-audio input device to open. It can be either a device identifier or a handle of an open
/// waveform-audio input device. You can use the following flag instead of a device identifier.
///
///
///
/// Value
/// Meaning
///
/// -
/// WAVE_MAPPER
/// The function selects a waveform-audio input device capable of recording in the specified format.
///
///
///
///
/// Pointer to a WAVEFORMATEX structure that identifies the desired format for recording waveform-audio data. You can free this
/// structure immediately after waveInOpen returns.
///
///
/// Pointer to a fixed callback function, an event handle, a handle to a window, or the identifier of a thread to be called during
/// waveform-audio recording to process messages related to the progress of recording. If no callback function is required, this
/// value can be zero. For more information on the callback function, see waveInProc.
///
///
/// User-instance data passed to the callback mechanism. This parameter is not used with the window callback mechanism.
///
///
/// Flags for opening the device. The following values are defined.
///
///
/// Value
/// Meaning
///
/// -
/// CALLBACK_EVENT
/// The dwCallback parameter is an event handle.
///
/// -
/// CALLBACK_FUNCTION
/// The dwCallback parameter is a callback procedure address.
///
/// -
/// CALLBACK_NULL
/// No callback mechanism. This is the default setting.
///
/// -
/// CALLBACK_THREAD
/// The dwCallback parameter is a thread identifier.
///
/// -
/// CALLBACK_WINDOW
/// The dwCallback parameter is a window handle.
///
/// -
/// WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE
///
/// If this flag is specified and the uDeviceID parameter is WAVE_MAPPER, the function opens the default communication device. This
/// flag applies only when uDeviceID equals WAVE_MAPPER.
///
///
/// -
/// WAVE_FORMAT_DIRECT
/// If this flag is specified, the ACM driver does not perform conversions on the audio data.
///
/// -
/// WAVE_FORMAT_QUERY
/// The function queries the device to determine whether it supports the given format, but it does not open the device.
///
/// -
/// WAVE_MAPPED
/// The uDeviceID parameter specifies a waveform-audio device to be mapped to by the wave mapper.
///
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_ALLOCATED
/// Specified resource is already allocated.
///
/// -
/// MMSYSERR_BADDEVICEID
/// Specified device identifier is out of range.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_BADFORMAT
/// Attempted to open with an unsupported waveform-audio format.
///
///
///
///
///
/// Use the waveInGetNumDevs function to determine the number of waveform-audio input devices present on the system. The device
/// identifier specified by uDeviceID varies from zero to one less than the number of devices present. The WAVE_MAPPER constant can
/// also be used as a device identifier.
///
///
/// If you choose to have a window or thread receive callback information, the following messages are sent to the window procedure
/// or thread to indicate the progress of waveform-audio input: MM_WIM_OPEN, MM_WIM_CLOSE, and MM_WIM_DATA.
///
///
/// If you choose to have a function receive callback information, the following messages are sent to the function to indicate the
/// progress of waveform-audio input: WIM_OPEN, WIM_CLOSE, and WIM_DATA.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinopen MMRESULT waveInOpen( LPHWAVEIN phwi, UINT
// uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInOpen")]
public static extern MMRESULT waveInOpen(out SafeHWAVEIN phwi, uint uDeviceID, in WAVEFORMATEX pwfx, [In, Optional] IntPtr dwCallback, [In, Optional] IntPtr dwInstance, WAVE_OPEN fdwOpen);
/// The waveInPrepareHeader function prepares a buffer for waveform-audio input.
/// Handle to the waveform-audio input device.
/// Pointer to a WAVEHDR structure that identifies the buffer to be prepared.
/// Size, in bytes, of the WAVEHDR structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
/// The lpData, dwBufferLength, and dwFlags members of the WAVEHDR structure must be set before calling
/// this function ( dwFlags must be zero).
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinprepareheader MMRESULT waveInPrepareHeader( HWAVEIN
// hwi, LPWAVEHDR pwh, UINT cbwh );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInPrepareHeader")]
public static extern MMRESULT waveInPrepareHeader(HWAVEIN hwi, ref WAVEHDR pwh, uint cbwh);
///
/// The waveInReset function stops input on the given waveform-audio input device and resets the current position to zero.
/// All pending buffers are marked as done and returned to the application.
///
/// Handle to the waveform-audio input device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinreset MMRESULT waveInReset( HWAVEIN hwi );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInReset")]
public static extern MMRESULT waveInReset(HWAVEIN hwi);
/// The waveInStart function starts input on the given waveform-audio input device.
/// Handle to the waveform-audio input device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
///
/// Buffers are returned to the application when full or when the waveInReset function is called (the dwBytesRecorded
/// member in the header will contain the length of data). If there are no buffers in the queue, the data is thrown away without
/// notifying the application, and input continues.
///
/// Calling this function when input is already started has no effect, and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinstart MMRESULT waveInStart( HWAVEIN hwi );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInStart")]
public static extern MMRESULT waveInStart(HWAVEIN hwi);
/// The waveInStop function stops waveform-audio input.
/// Handle to the waveform-audio input device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
///
/// If there are any buffers in the queue, the current buffer will be marked as done (the dwBytesRecorded member in the
/// header will contain the length of data), but any empty buffers in the queue will remain there.
///
/// Calling this function when input is not started has no effect, and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinstop MMRESULT waveInStop( HWAVEIN hwi );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInStop")]
public static extern MMRESULT waveInStop(HWAVEIN hwi);
///
/// The waveInUnprepareHeader function cleans up the preparation performed by the waveInPrepareHeader function. This function
/// must be called after the device driver fills a buffer and returns it to the application. You must call this function before
/// freeing the buffer.
///
/// Handle to the waveform-audio input device.
/// Pointer to a WAVEHDR structure identifying the buffer to be cleaned up.
/// Size, in bytes, of the WAVEHDR structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_STILLPLAYING
/// The buffer pointed to by the pwh parameter is still in the queue.
///
///
///
///
/// This function complements the waveInPrepareHeader function.
///
/// You must call this function before freeing the buffer. After passing a buffer to the device driver with the
/// waveInAddBuffer function, you must wait until the driver is finished with the buffer before calling
/// waveInUnprepareHeader. Unpreparing a buffer that has not been prepared has no effect, and the function returns zero.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveinunprepareheader MMRESULT waveInUnprepareHeader( HWAVEIN
// hwi, LPWAVEHDR pwh, UINT cbwh );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveInUnprepareHeader")]
public static extern MMRESULT waveInUnprepareHeader(HWAVEIN hwi, ref WAVEHDR pwh, uint cbwh);
///
/// The waveOutBreakLoop function breaks a loop on the given waveform-audio output device and allows playback to continue
/// with the next block in the driver list.
///
/// Handle to the waveform-audio output device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
/// The blocks making up the loop are played to the end before the loop is terminated.
/// Calling this function when nothing is playing or looping has no effect, and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutbreakloop MMRESULT waveOutBreakLoop( HWAVEOUT hwo );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutBreakLoop")]
public static extern MMRESULT waveOutBreakLoop(HWAVEOUT hwo);
/// The waveOutClose function closes the given waveform-audio output device.
///
/// Handle to the waveform-audio output device. If the function succeeds, the handle is no longer valid after this call.
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_STILLPLAYING
/// There are still buffers in the queue.
///
///
///
///
/// The close operation fails if the device is still playing a waveform-audio buffer that was previously sent by calling
/// waveOutWrite. Before calling waveOutClose, the application must wait for all buffers to finish playing or call the
/// waveOutReset function to terminate playback.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutclose MMRESULT waveOutClose( HWAVEOUT hwo );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutClose")]
public static extern MMRESULT waveOutClose(HWAVEOUT hwo);
/// The waveOutGetDevCaps function retrieves the capabilities of a given waveform-audio output device.
///
/// Identifier of the waveform-audio output device. It can be either a device identifier or a handle of an open waveform-audio
/// output device.
///
/// Pointer to a WAVEOUTCAPS structure to be filled with information about the capabilities of the device.
/// Size, in bytes, of the WAVEOUTCAPS structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_BADDEVICEID
/// Specified device identifier is out of range.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
/// Use the waveOutGetNumDevs function to determine the number of waveform-audio output devices present in the system. If the
/// value specified by the uDeviceID parameter is a device identifier, it can vary from zero to one less than the number of devices
/// present. The WAVE_MAPPER constant can also be used as a device identifier. Only cbwoc bytes (or less) of information is copied
/// to the location pointed to by pwoc. If cbwoc is zero, nothing is copied and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetdevcaps MMRESULT waveOutGetDevCaps( UINT uDeviceID,
// LPWAVEOUTCAPS pwoc, UINT cbwoc );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetDevCaps")]
public static extern MMRESULT waveOutGetDevCaps(uint uDeviceID, out WAVEOUTCAPS pwoc, uint cbwoc);
///
/// The waveOutGetErrorText function retrieves a textual description of the error identified by the given error number.
///
/// Error number.
/// Pointer to a buffer to be filled with the textual error description.
/// Size, in characters, of the buffer pointed to by pszText.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_BADERRNUM
/// Specified error number is out of range.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
/// If the textual error description is longer than the specified buffer, the description is truncated. The returned error string is
/// always null-terminated. If cchText is zero, nothing is copied and the function returns zero. All error descriptions are less
/// than MAXERRORLENGTH characters long.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgeterrortext MMRESULT waveOutGetErrorText( MMRESULT
// mmrError, LPSTR pszText, UINT cchText );
[DllImport(Lib_Winmm, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetErrorText")]
public static extern MMRESULT waveOutGetErrorText(MMRESULT mmrError, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder pszText, uint cchText);
///
/// The waveOutGetID function retrieves the device identifier for the given waveform-audio output device.
///
/// This function is supported for backward compatibility. New applications can cast a handle of the device rather than retrieving
/// the device identifier.
///
///
/// Handle to the waveform-audio output device.
/// Pointer to a variable to be filled with the device identifier.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// The hwo parameter specifies an invalid handle.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetid MMRESULT waveOutGetID( HWAVEOUT hwo, LPUINT
// puDeviceID );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetID")]
public static extern MMRESULT waveOutGetID(HWAVEOUT hwo, out uint puDeviceID);
/// The waveOutGetNumDevs function retrieves the number of waveform-audio output devices present in the system.
/// Returns the number of devices. A return value of zero means that no devices are present or that an error occurred.
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetnumdevs UINT waveOutGetNumDevs();
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetNumDevs")]
public static extern uint waveOutGetNumDevs();
///
/// The waveOutGetPitch function retrieves the current pitch setting for the specified waveform-audio output device.
///
/// Handle to the waveform-audio output device.
///
///
/// Pointer to a variable to be filled with the current pitch multiplier setting. The pitch multiplier indicates the current change
/// in pitch from the original authored setting. The pitch multiplier must be a positive value.
///
///
/// The pitch multiplier is specified as a fixed-point value. The high-order word of the variable contains the signed integer part
/// of the number, and the low-order word contains the fractional part. A value of 0x8000 in the low-order word represents one-half,
/// and 0x4000 represents one-quarter. For example, the value 0x00010000 specifies a multiplier of 1.0 (no pitch change), and a
/// value of 0x000F8000 specifies a multiplier of 15.5.
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Function isn't supported.
///
///
///
///
/// Changing the pitch does not change the playback rate, sample rate, or playback time. Not all devices support pitch changes. To
/// determine whether the device supports pitch control, use the WAVECAPS_PITCH flag to test the dwSupport member of the
/// WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function).
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetpitch MMRESULT waveOutGetPitch( HWAVEOUT hwo,
// LPDWORD pdwPitch );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetPitch")]
public static extern MMRESULT waveOutGetPitch(HWAVEOUT hwo, out uint pdwPitch);
///
/// The waveOutGetPlaybackRate function retrieves the current playback rate for the specified waveform-audio output device.
///
/// Handle to the waveform-audio output device.
///
///
/// Pointer to a variable to be filled with the current playback rate. The playback rate setting is a multiplier indicating the
/// current change in playback rate from the original authored setting. The playback rate multiplier must be a positive value.
///
///
/// The rate is specified as a fixed-point value. The high-order word of the variable contains the signed integer part of the
/// number, and the low-order word contains the fractional part. A value of 0x8000 in the low-order word represents one-half, and
/// 0x4000 represents one-quarter. For example, the value 0x00010000 specifies a multiplier of 1.0 (no playback rate change), and a
/// value of 0x000F8000 specifies a multiplier of 15.5.
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Function isn't supported.
///
///
///
///
/// Changing the playback rate does not change the sample rate but does change the playback time. Not all devices support playback
/// rate changes. To determine whether a device supports playback rate changes, use the WAVECAPS_PLAYBACKRATE flag to test the
/// dwSupport member of the WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function).
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetplaybackrate MMRESULT waveOutGetPlaybackRate(
// HWAVEOUT hwo, LPDWORD pdwRate );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetPlaybackRate")]
public static extern MMRESULT waveOutGetPlaybackRate(HWAVEOUT hwo, out uint pdwRate);
///
/// The waveOutGetPosition function retrieves the current playback position of the given waveform-audio output device.
///
/// Handle to the waveform-audio output device.
/// Pointer to an MMTIME structure.
/// Size, in bytes, of the MMTIME structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
///
/// Before calling this function, set the wType member of the MMTIME structure to indicate the time format you want.
/// After calling this function, check wType to determine whether the time format is supported. If the format is not
/// supported, wType will specify an alternative format.
///
/// The position is set to zero when the device is opened or reset.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetposition MMRESULT waveOutGetPosition( HWAVEOUT hwo,
// LPMMTIME pmmt, UINT cbmmt );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetPosition")]
public static extern MMRESULT waveOutGetPosition(HWAVEOUT hwo, ref MMTIME pmmt, uint cbmmt);
/// The waveOutGetVolume function retrieves the current volume level of the specified waveform-audio output device.
/// Handle to an open waveform-audio output device. This parameter can also be a device identifier.
///
///
/// Pointer to a variable to be filled with the current volume setting. The low-order word of this location contains the
/// left-channel volume setting, and the high-order word contains the right-channel setting. A value of 0xFFFF represents full
/// volume, and a value of 0x0000 is silence.
///
///
/// If a device does not support both left and right volume control, the low-order word of the specified location contains the mono
/// volume level.
///
///
/// The full 16-bit setting(s) set with the waveOutSetVolume function is returned, regardless of whether the device supports the
/// full 16 bits of volume-level control.
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Function isn't supported.
///
///
///
///
///
/// If a device identifier is used, then the result of the waveOutGetVolume call and the information returned in pdwVolume
/// applies to all instances of the device. If a device handle is used, then the result and information returned applies only to the
/// instance of the device referenced by the device handle.
///
///
/// Not all devices support volume changes. To determine whether the device supports volume control, use the WAVECAPS_VOLUME flag to
/// test the dwSupport member of the WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function).
///
///
/// To determine whether the device supports left- and right-channel volume control, use the WAVECAPS_LRVOLUME flag to test the
/// dwSupport member of the WAVEOUTCAPS structure (filled by waveOutGetDevCaps).
///
///
/// Volume settings are interpreted logarithmically. This means the perceived increase in volume is the same when increasing the
/// volume level from 0x5000 to 0x6000 as it is from 0x4000 to 0x5000.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutgetvolume MMRESULT waveOutGetVolume( HWAVEOUT hwo,
// LPDWORD pdwVolume );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutGetVolume")]
public static extern MMRESULT waveOutGetVolume(HWAVEOUT hwo, out uint pdwVolume);
/// The waveOutMessage function sends messages to the waveform-audio output device drivers.
///
/// Identifier of the waveform device that receives the message. You must cast the device ID to the HWAVEOUT handle type. If
/// you supply a handle instead of a device ID, the function fails and returns the MMSYSERR_NOSUPPORT error code.
///
/// Message to send.
/// Message parameter.
/// Message parameter.
/// Returns the value returned from the driver.
///
/// The
/// DRV_QUERYDEVICEINTERFACE
/// message queries for the device-interface name of a waveIn, waveOut, midiIn, midiOut, or mixer device.
///
/// For
/// DRV_QUERYDEVICEINTERFACE
/// , dwParam1 is a pointer to a caller-allocated buffer into which the function writes a null-terminated Unicode string containing
/// the device-interface name. If the device has no device interface, the string length is zero.
///
/// For
/// DRV_QUERYDEVICEINTERFACE
/// , dwParam2 specifies the buffer size in bytes. This is an input parameter to the function. The caller should specify a size that
/// is greater than or equal to the buffer size retrieved by the DRV_QUERYDEVICEINTERFACESIZE message.
///
///
/// The DRV_QUERYDEVICEINTERFACE message is supported in Windows Me, and Windows 2000 and later. This message is valid only for the
/// waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The system intercepts this
/// message and returns the appropriate value without sending the message to the device driver. For general information about
/// system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
/// The following two message constants are used together for the purpose of obtaining device interface names:
///
/// -
/// DRV_QUERYDEVICEINTERFACESIZE
///
/// -
/// DRV_QUERYDEVICEINTERFACE
///
///
///
/// The first message obtains the size in bytes of the buffer needed to hold the string containing the device interface name. The
/// second message retrieves the name string in a buffer of the required size.
///
/// For more information, see Obtaining a Device Interface Name.
/// The
/// DRV_QUERYDEVICEINTERFACESIZE
/// message queries for the size of the buffer required to hold the device-interface name.
///
/// For
/// DRV_QUERYDEVICEINTERFACESIZE
/// , dwParam1 is a pointer to buffer size. This parameter points to a ULONG variable into which the function writes the required
/// buffer size in bytes. The size includes storage space for the name string's terminating null. The size is zero if the device ID
/// identifies a device that has no device interface.
///
/// For
/// DRV_QUERYDEVICEINTERFACESIZE
/// , dwParam2 is unused. Set this parameter to zero.
///
///
/// This message is valid only for the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage
/// functions. The system intercepts this message and returns the appropriate value without sending the message to the device
/// driver. For general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// The buffer size retrieved by this message is expressed as a byte count. It specifies the size of the buffer needed to hold the
/// null-terminated Unicode string that contains the device-interface name. The caller allocates a buffer of the specified size and
/// uses the DRV_QUERYDEVICEINTERFACE message to retrieve the device-interface name string.
///
/// For more information, see Obtaining a Device Interface Name.
/// The
/// DRV_QUERYDEVNODE
/// message queries for the devnode number assigned to the device by the Plug and Play manager.
///
/// For
/// DRV_QUERYDEVNODE
/// , dwParam1 is a pointer to a caller-allocated DWORD variable into which the function writes the devnode number. If no devnode is
/// assigned to the device, the function sets this variable to zero.
///
/// For
/// DRV_QUERYDEVNODE
/// , dwParam2 is unused. Set this parameter to zero.
///
///
/// In Windows 2000 and later, the message always returns MMSYSERR_NOTSUPPORTED. This message is valid only for the waveInMessage,
/// waveOutMessage, midiInMessage, midiOutMessage, and mixerMessage functions. The system intercepts this message and returns
/// the appropriate value without sending the message to the device driver. For general information about system-intercepted
/// xxxMessage functions, see System-Intercepted Device Messages.
///
/// The
/// DRV_QUERYMAPPABLE
/// message queries for whether the specified device can be used by a mapper.
///
/// For
/// DRV_QUERYMAPPABLE
/// , dwParam1 is unused. Set this parameter to zero.
///
/// For
/// DRV_QUERYMAPPABLE
/// , dwParam2 is unused. Set this parameter to zero.
///
///
/// This message is valid only for the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, mixerMessage and
/// auxOutMessage functions. The system intercepts this message and returns the appropriate value without sending the message to the
/// device driver. For general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// When an application program opens a mapper instead of a specific audio device, the system inserts a mapper between the
/// application and the available devices. The mapper selects an appropriate device by mapping the application's requirements to one
/// of the available devices. For more information about mappers, see the Microsoft Windows SDK documentation.
///
/// The
/// DRVM_MAPPER_CONSOLEVOICECOM_GET
/// message retrieves the device ID of the preferred voice-communications device.
///
/// For
/// DRVM_MAPPER_CONSOLEVOICECOM_GET
/// , dwParam1 is a pointer to device ID. This parameter points to a DWORD variable into which the function writes the device ID of
/// the current preferred voice-communications device. The function writes the value (-1) if no device is available that qualifies
/// as a preferred voice-communications device.
///
/// For
/// DRVM_MAPPER_CONSOLEVOICECOM_GET
/// , dwParam2 is a pointer to status flags. This parameter points to a DWORD variable into which the function writes the
/// device-status flags. Only one flag bit is currently defined: DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY.
///
///
/// This message is valid only for the waveInMessage and waveOutMessage functions. When a caller calls these two functions
/// with the DRVM_MAPPER_CONSOLEVOICECOM_GET message, the caller must specify the device ID as WAVE_MAPPER, and then cast this value
/// to the appropriate handle type. For the waveInMessage, waveOutMessage, midiInMessage, midiOutMessage, or
/// mixerMessage functions, the caller must cast the device ID to a handle of type HWAVEIN, HWAVEOUT, HMIDIIN, HMIDIOUT, or HMIXER,
/// respectively. Note that if the caller supplies a valid handle instead of a device ID for this parameter, the function fails and
/// returns error code MMSYSERR_NOSUPPORT.
///
///
/// The system intercepts this message and returns the appropriate value without sending the message to the device driver. For
/// general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// This message provides a way to determine which device is preferred specifically for voice communications, in contrast to the
/// DRVM_MAPPER_PREFERRED_GET message, which determines which device is preferred for all other audio functions.
///
///
/// For example, the preferred waveOut device for voice communications might be the earpiece in a headset, but the preferred
/// waveOut device for all other audio functions might be a set of stereo speakers.
///
///
/// When the DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY flag bit is set in the DWORD location pointed to by dwParam2, the
/// waveIn and waveOut APIs use only the current preferred voice-communications device and do not search for other
/// available devices if the preferred device is unavailable. The flag that is output by either the waveInMessage or
/// waveOutMessage call applies to the preferred voice-communications device for both the waveIn and waveOut
/// APIs, regardless of whether the call is made to waveInMessage or waveOutMessage. For more information, see
/// Preferred Voice-Communications Device ID.
///
/// The
/// DRVM_MAPPER_PREFERRED_GET
/// message retrieves the device ID of the preferred audio device.
///
/// For
/// DRVM_MAPPER_PREFERRED_GET
/// , dwParam1 is a pointer to device ID. This parameter points to a DWORD variable into which the function writes the device ID of
/// the current preferred device. The function writes the value (-1) if no device is available that qualifies as a preferred device.
///
/// For
/// DRVM_MAPPER_PREFERRED_GET
/// , dwParam2 is a pointer to status flags. This parameter points to a DWORD variable into which the function writes the
/// device-status flags. Only one flag bit is currently defined (for waveInMessage and waveOutMessage calls only): DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY.
///
///
/// This message is valid only for the waveInMessage, waveOutMessage and midiOutMessage functions. When the caller calls
/// these functions with the DRVM_MAPPER_PREFERRED_GET message, the caller must first specify the device ID as WAVE_MAPPER (for
/// waveInMessage or waveOutMessage) or MIDI_MAPPER (for midiOutMessage), and then cast this value to the
/// appropriate handle type. For the waveInMessage, waveOutMessage, or midiOutMessage functions, the caller
/// must cast the device ID to a handle type HWAVEIN, HWAVEOUT or HMIDIOUT, respectively. Note that if the caller supplies a valid
/// handle instead of a device ID for this parameter, the function fails and returns error code MMSYSERR_NOSUPPORT.
///
///
/// The system intercepts this message and returns the appropriate value without sending the message to the device driver. For
/// general information about system-intercepted xxxMessage functions, see System-Intercepted Device Messages.
///
///
/// This message provides a way to determine which device is preferred for audio functions in general, in contrast to the
/// DRVM_MAPPER_CONSOLEVOICECOM_GET message, which determines which device is preferred specifically for voice communications.
///
///
/// When the DRVM_MAPPER_PREFERRED_FLAGS_PREFERREDONLY flag bit is set in the DWORD location pointed to by dwParam2, the
/// waveIn and waveOut APIs use only the current preferred device and do not search for other available devices if the
/// preferred device is unavailable. Note that the midiOutMessage function does not output this flag--the midiOut API
/// always uses only the preferred device. The flag that is output by either the waveInMessage or waveOutMessage call
/// applies to the preferred device for both the waveIn and waveOut APIs, regardless of whether the call is made to
/// waveInMessage or waveOutMessage.
///
///
/// The xxxMessage functions accept this value in place of a valid device handle in order to allow an application to determine the
/// default device ID without first having to open a device. For more information, see Accessing the Preferred Device ID.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutmessage MMRESULT waveOutMessage( HWAVEOUT hwo, UINT
// uMsg, DWORD_PTR dw1, DWORD_PTR dw2 );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutMessage")]
public static extern MMRESULT waveOutMessage(HWAVEOUT hwo, uint uMsg, IntPtr dw1, IntPtr dw2);
/// The waveOutOpen function opens the given waveform-audio output device for playback.
///
/// Pointer to a buffer that receives a handle identifying the open waveform-audio output device. Use the handle to identify the
/// device when calling other waveform-audio output functions. This parameter might be NULL if the WAVE_FORMAT_QUERY
/// flag is specified for fdwOpen.
///
///
///
/// Identifier of the waveform-audio output device to open. It can be either a device identifier or a handle of an open
/// waveform-audio input device. You can also use the following flag instead of a device identifier:
///
///
///
/// Value
/// Meaning
///
/// -
/// WAVE_MAPPER
/// The function selects a waveform-audio output device capable of playing the given format.
///
///
///
///
/// Pointer to a WAVEFORMATEX structure that identifies the format of the waveform-audio data to be sent to the device. You can free
/// this structure immediately after passing it to waveOutOpen.
///
///
/// Specifies the callback mechanism. The value must be one of the following:
///
/// -
/// A pointer to a callback function. For the function signature, see waveOutProc.
///
/// -
/// A handle to a window.
///
/// -
/// A thread identifier.
///
/// -
/// A handle to an event.
///
/// -
/// The value NULL.
///
///
/// The
/// fdwOpen
/// parameter specifies how the
/// dwCallback
/// parameter is interpreted. For more information, see Remarks.
///
///
/// User-instance data passed to the callback mechanism. This parameter is not used with the window callback mechanism.
///
///
/// Flags for opening the device. The following values are defined.
///
///
/// Value
/// Meaning
///
/// -
/// CALLBACK_EVENT
/// The dwCallback parameter is an event handle.
///
/// -
/// CALLBACK_FUNCTION
/// The dwCallback parameter is a callback procedure address.
///
/// -
/// CALLBACK_NULL
/// No callback mechanism. This is the default setting.
///
/// -
/// CALLBACK_THREAD
/// The dwCallback parameter is a thread identifier.
///
/// -
/// CALLBACK_WINDOW
/// The dwCallback parameter is a window handle.
///
/// -
/// WAVE_ALLOWSYNC
///
/// If this flag is specified, a synchronous waveform-audio device can be opened. If this flag is not specified while opening a
/// synchronous driver, the device will fail to open.
///
///
/// -
/// WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE
///
/// If this flag is specified and the uDeviceID parameter is WAVE_MAPPER, the function opens the default communication device. This
/// flag applies only when uDeviceID equals WAVE_MAPPER.
///
///
/// -
/// WAVE_FORMAT_DIRECT
/// If this flag is specified, the ACM driver does not perform conversions on the audio data.
///
/// -
/// WAVE_FORMAT_QUERY
///
/// If this flag is specified, waveOutOpen queries the device to determine if it supports the given format, but the device is not
/// actually opened.
///
///
/// -
/// WAVE_MAPPED
/// If this flag is specified, the uDeviceID parameter specifies a waveform-audio device to be mapped to by the wave mapper.
///
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_ALLOCATED
/// Specified resource is already allocated.
///
/// -
/// MMSYSERR_BADDEVICEID
/// Specified device identifier is out of range.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_BADFORMAT
/// Attempted to open with an unsupported waveform-audio format.
///
/// -
/// WAVERR_SYNC
/// The device is synchronous but waveOutOpen was called without using the WAVE_ALLOWSYNC flag.
///
///
///
///
///
/// Use the waveOutGetNumDevs function to determine the number of waveform-audio output devices present in the system. If the value
/// specified by the uDeviceID parameter is a device identifier, it can vary from zero to one less than the number of devices
/// present. The WAVE_MAPPER constant can also be used as a device identifier.
///
///
/// The structure pointed to by pwfx can be extended to include type-specific information for certain data formats. For example, for
/// PCM data, an extra UINT is added to specify the number of bits per sample. Use the PCMWAVEFORMAT structure in this case.
/// For all other waveform-audio formats, use the WAVEFORMATEX structure to specify the length of the additional data.
///
///
/// If you choose to have a window or thread receive callback information, the following messages are sent to the window procedure
/// function to indicate the progress of waveform-audio output: MM_WOM_OPEN, MM_WOM_CLOSE, and MM_WOM_DONE.
///
/// Callback Mechanism
/// The dwCallback and fdwOpen parameters specify how the application is notified about the progress of waveform-audio output.
///
/// If fdwOpen contains the CALLBACK_FUNCTION flag, dwCallback is a pointer to a callback function. For the function
/// signature, see waveOutProc. The uMsg parameter of the callback indicates the progress of the audio output:
///
///
/// -
/// WOM_OPEN
///
/// -
/// WOM_CLOSE
///
/// -
/// WOM_DONE
///
///
///
/// If fdwOpen contains the CALLBACK_WINDOW flag, dwCallback is a handle to a window.The window receives the following
/// messages, indicating the progress:
///
///
/// -
/// MM_WOM_OPEN
///
/// -
/// MM_WOM_CLOSE
///
/// -
/// MM_WOM_DONE
///
///
///
/// If fdwOpen contains the CALLBACK_THREAD flag, dwCallback is a thread identifier. The thread receives the messages listed
/// previously for CALLBACK_WINDOW.
///
///
/// If fdwOpen contains the CALLBACK_EVENT flag, dwCallback is a handle to an event. The event is signaled whenever the state
/// of the waveform buffer changes. The application can use WaitForSingleObject or WaitForMultipleObjects to wait for the event.
/// When the event is signaled, you can get the current state of the waveform buffer by checking the dwFlags member of the
/// WAVEHDR structure. (See waveOutPrepareHeader.)
///
///
/// If fdwOpen contains the CALLBACK_NULL flag, dwCallback must be NULL. In that case, no callback mechanism is used.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutopen MMRESULT waveOutOpen( LPHWAVEOUT phwo, UINT
// uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutOpen")]
public static extern MMRESULT waveOutOpen(out SafeHWAVEOUT phwo, uint uDeviceID, in WAVEFORMATEX pwfx, [In, Optional] IntPtr dwCallback, [In, Optional] IntPtr dwInstance, [In, Optional] WAVE_OPEN fdwOpen);
///
/// The waveOutPause function pauses playback on the given waveform-audio output device. The current position is saved. Use
/// the waveOutRestart function to resume playback from the current position.
///
/// Handle to the waveform-audio output device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Specified device is synchronous and does not support pausing.
///
///
///
/// Calling this function when the output is already paused has no effect, and the function returns zero.
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutpause MMRESULT waveOutPause( HWAVEOUT hwo );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutPause")]
public static extern MMRESULT waveOutPause(HWAVEOUT hwo);
/// The waveOutPrepareHeader function prepares a waveform-audio data block for playback.
/// Handle to the waveform-audio output device.
/// Pointer to a WAVEHDR structure that identifies the data block to be prepared.
/// Size, in bytes, of the WAVEHDR structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
///
///
///
///
/// Set the lpData, dwBufferLength, and dwFlags members of the WAVEHDR structure before calling this function.
/// Set the dwFlags member to zero.
///
///
/// The dwFlags, dwBufferLength, and dwLoops members of the WAVEHDR structure can change between calls to this
/// function and the waveOutWrite function. If you change the size specified by dwBufferLength before the call to
/// waveOutWrite, the new value must be less than the prepared value.
///
/// If the method succeeds, the WHDR_PREPARED flag is set in the dwFlags member of the WAVEHDR structure.
/// Preparing a header that has already been prepared has no effect, and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutprepareheader MMRESULT waveOutPrepareHeader( HWAVEOUT
// hwo, LPWAVEHDR pwh, UINT cbwh );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutPrepareHeader")]
public static extern MMRESULT waveOutPrepareHeader(HWAVEOUT hwo, ref WAVEHDR pwh, uint cbwh);
///
/// The waveOutReset function stops playback on the given waveform-audio output device and resets the current position to
/// zero. All pending playback buffers are marked as done (WHDR_DONE) and returned to the application.
///
/// Handle to the waveform-audio output device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Specified device is synchronous and does not support pausing.
///
///
///
///
/// After this function returns, the application can send new playback buffers to the device by calling waveOutWrite, or close the
/// device by calling waveOutClose.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutreset MMRESULT waveOutReset( HWAVEOUT hwo );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutReset")]
public static extern MMRESULT waveOutReset(HWAVEOUT hwo);
/// The waveOutRestart function resumes playback on a paused waveform-audio output device.
/// Handle to the waveform-audio output device.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Specified device is synchronous and does not support pausing.
///
///
///
/// Calling this function when the output is not paused has no effect, and the function returns zero.
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutrestart MMRESULT waveOutRestart( HWAVEOUT hwo );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutRestart")]
public static extern MMRESULT waveOutRestart(HWAVEOUT hwo);
/// The waveOutSetPitch function sets the pitch for the specified waveform-audio output device.
/// Handle to the waveform-audio output device.
///
///
/// New pitch multiplier setting. This setting indicates the current change in pitch from the original authored setting. The pitch
/// multiplier must be a positive value.
///
///
/// The pitch multiplier is specified as a fixed-point value. The high-order word contains the signed integer part of the number,
/// and the low-order word contains the fractional part. A value of 0x8000 in the low-order word represents one-half, and 0x4000
/// represents one-quarter. For example, the value 0x00010000 specifies a multiplier of 1.0 (no pitch change), and a value of
/// 0x000F8000 specifies a multiplier of 15.5.
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Function isn't supported.
///
///
///
///
/// Changing the pitch does not change the playback rate or the sample rate, nor does it change the playback time. Not all devices
/// support pitch changes. To determine whether the device supports pitch control, use the WAVECAPS_PITCH flag to test the
/// dwSupport member of the WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function).
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutsetpitch MMRESULT waveOutSetPitch( HWAVEOUT hwo, DWORD
// dwPitch );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutSetPitch")]
public static extern MMRESULT waveOutSetPitch(HWAVEOUT hwo, uint dwPitch);
/// The waveOutSetPlaybackRate function sets the playback rate for the specified waveform-audio output device.
/// Handle to the waveform-audio output device.
///
///
/// New playback rate setting. This setting is a multiplier indicating the current change in playback rate from the original
/// authored setting. The playback rate multiplier must be a positive value.
///
///
/// The rate is specified as a fixed-point value. The high-order word contains the signed integer part of the number, and the
/// low-order word contains the fractional part. A value of 0x8000 in the low-order word represents one-half, and 0x4000 represents
/// one-quarter. For example, the value 0x00010000 specifies a multiplier of 1.0 (no playback rate change), and a value of
/// 0x000F8000 specifies a multiplier of 15.5.
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Function isn't supported.
///
///
///
///
/// Changing the playback rate does not change the sample rate but does change the playback time. Not all devices support playback
/// rate changes. To determine whether a device supports playback rate changes, use the WAVECAPS_PLAYBACKRATE flag to test the
/// dwSupport member of the WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function).
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutsetplaybackrate MMRESULT waveOutSetPlaybackRate(
// HWAVEOUT hwo, DWORD dwRate );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutSetPlaybackRate")]
public static extern MMRESULT waveOutSetPlaybackRate(HWAVEOUT hwo, uint dwRate);
/// The waveOutSetVolume function sets the volume level of the specified waveform-audio output device.
/// Handle to an open waveform-audio output device. This parameter can also be a device identifier.
///
///
/// New volume setting. The low-order word contains the left-channel volume setting, and the high-order word contains the
/// right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
///
///
/// If a device does not support both left and right volume control, the low-order word of dwVolume specifies the volume level, and
/// the high-order word is ignored.
///
///
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// MMSYSERR_NOTSUPPORTED
/// Function is not supported.
///
///
///
///
///
/// If a device identifier is used, then the result of the waveOutSetVolume call applies to all instances of the device. If a
/// device handle is used, then the result applies only to the instance of the device referenced by the device handle.
///
///
/// Not all devices support volume changes. To determine whether the device supports volume control, use the WAVECAPS_VOLUME flag to
/// test the dwSupport member of the WAVEOUTCAPS structure (filled by the waveOutGetDevCaps function). To determine whether
/// the device supports volume control on both the left and right channels, use the WAVECAPS_LRVOLUME flag.
///
///
/// Most devices do not support the full 16 bits of volume-level control and will not use the least-significant bits of the
/// requested volume setting. For example, if a device supports 4 bits of volume control, the values 0x4000, 0x4FFF, and 0x43BE will
/// all be truncated to 0x4000. The waveOutGetVolume function returns the full 16-bit setting set with waveOutSetVolume.
///
///
/// Volume settings are interpreted logarithmically. This means the perceived increase in volume is the same when increasing the
/// volume level from 0x5000 to 0x6000 as it is from 0x4000 to 0x5000.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutsetvolume MMRESULT waveOutSetVolume( HWAVEOUT hwo,
// DWORD dwVolume );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutSetVolume")]
public static extern MMRESULT waveOutSetVolume(HWAVEOUT hwo, uint dwVolume);
///
/// The waveOutUnprepareHeader function cleans up the preparation performed by the waveOutPrepareHeader function. This
/// function must be called after the device driver is finished with a data block. You must call this function before freeing the buffer.
///
/// Handle to the waveform-audio output device.
/// Pointer to a WAVEHDR structure identifying the data block to be cleaned up.
/// Size, in bytes, of the WAVEHDR structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_STILLPLAYING
/// The data block pointed to by the pwh parameter is still in the queue.
///
///
///
///
///
/// This function complements waveOutPrepareHeader. You must call this function before freeing the buffer. After passing a
/// buffer to the device driver with the waveOutWrite function, you must wait until the driver is finished with the buffer
/// before calling waveOutUnprepareHeader.
///
/// Unpreparing a buffer that has not been prepared has no effect, and the function returns zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutunprepareheader MMRESULT waveOutUnprepareHeader(
// HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutUnprepareHeader")]
public static extern MMRESULT waveOutUnprepareHeader(HWAVEOUT hwo, ref WAVEHDR pwh, uint cbwh);
/// The waveOutWrite function sends a data block to the given waveform-audio output device.
/// Handle to the waveform-audio output device.
/// Pointer to a WAVEHDR structure containing information about the data block.
/// Size, in bytes, of the WAVEHDR structure.
///
/// Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
///
///
/// Return code
/// Description
///
/// -
/// MMSYSERR_INVALHANDLE
/// Specified device handle is invalid.
///
/// -
/// MMSYSERR_NODRIVER
/// No device driver is present.
///
/// -
/// MMSYSERR_NOMEM
/// Unable to allocate or lock memory.
///
/// -
/// WAVERR_UNPREPARED
/// The data block pointed to by the pwh parameter hasn't been prepared.
///
///
///
///
/// When the buffer is finished, the WHDR_DONE bit is set in the dwFlags member of the WAVEHDR structure.
///
/// The buffer must be prepared with the waveOutPrepareHeader function before it is passed to waveOutWrite. Unless the
/// device is paused by calling the waveOutPause function, playback begins when the first data block is sent to the device.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/nf-mmeapi-waveoutwrite MMRESULT waveOutWrite( HWAVEOUT hwo, LPWAVEHDR
// pwh, UINT cbwh );
[DllImport(Lib_Winmm, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mmeapi.h", MSDNShortId = "NF:mmeapi.waveOutWrite")]
public static extern MMRESULT waveOutWrite(HWAVEOUT hwo, ref WAVEHDR pwh, uint cbwh);
/// Provides a handle to a waveform-audio input device.
[StructLayout(LayoutKind.Sequential)]
public struct HWAVEIN : IHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HWAVEIN(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HWAVEIN NULL => new(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HWAVEIN h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HWAVEIN(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HWAVEIN h1, HWAVEIN h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HWAVEIN h1, HWAVEIN h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HWAVEIN h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a waveform-audio output device.
[StructLayout(LayoutKind.Sequential)]
public struct HWAVEOUT : IHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HWAVEOUT(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HWAVEOUT NULL => new(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HWAVEOUT h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HWAVEOUT(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HWAVEOUT h1, HWAVEOUT h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HWAVEOUT h1, HWAVEOUT h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HWAVEOUT h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
///
///
/// The WAVEFORMATEX structure defines the format of waveform-audio data. Only format information common to all
/// waveform-audio data formats is included in this structure. For formats that require additional information, this structure is
/// included as the first member in another structure, along with the additional information.
///
///
/// Formats that support more than two channels or sample sizes of more than 16 bits can be described in a WAVEFORMATEXTENSIBLE
/// structure, which includes the WAVEFORMAT structure.
///
///
///
/// An example of a format that uses extra information is the Microsoft Adaptive Delta Pulse Code Modulation (MS-ADPCM) format. The
/// wFormatTag for MS-ADPCM is WAVE_FORMAT_ADPCM. The cbSize member will typically be set to 32. The extra information
/// stored for WAVE_FORMAT_ADPCM is coefficient pairs required for encoding and decoding the waveform-audio data.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-waveformatex typedef struct tWAVEFORMATEX { WORD wFormatTag;
// WORD nChannels; DWORD nSamplesPerSec; DWORD nAvgBytesPerSec; WORD nBlockAlign; WORD wBitsPerSample; WORD cbSize; } WAVEFORMATEX,
// *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
[PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.tWAVEFORMATEX")]
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct WAVEFORMATEX
{
///
/// Waveform-audio format type. Format tags are registered with Microsoft Corporation for many compression algorithms. A
/// complete list of format tags can be found in the Mmreg.h header file. For one- or two-channel PCM data, this value should be
/// WAVE_FORMAT_PCM. When this structure is included in a WAVEFORMATEXTENSIBLE structure, this value must be WAVE_FORMAT_EXTENSIBLE.
///
public WAVE_FORMAT wFormatTag;
/// Number of channels in the waveform-audio data. Monaural data uses one channel and stereo data uses two channels.
public ushort nChannels;
///
/// Sample rate, in samples per second (hertz). If wFormatTag is WAVE_FORMAT_PCM, then common values for
/// nSamplesPerSec are 8.0 kHz, 11.025 kHz, 22.05 kHz, and 44.1 kHz. For non-PCM formats, this member must be computed
/// according to the manufacturer's specification of the format tag.
///
public uint nSamplesPerSec;
///
/// Required average data-transfer rate, in bytes per second, for the format tag. If wFormatTag is WAVE_FORMAT_PCM,
/// nAvgBytesPerSec should be equal to the product of nSamplesPerSec and nBlockAlign. For non-PCM formats,
/// this member must be computed according to the manufacturer's specification of the format tag.
///
public uint nAvgBytesPerSec;
///
///
/// Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the wFormatTag format type. If
/// wFormatTag is WAVE_FORMAT_PCM or WAVE_FORMAT_EXTENSIBLE, nBlockAlign must be equal to the product of
/// nChannels and wBitsPerSample divided by 8 (bits per byte). For non-PCM formats, this member must be computed
/// according to the manufacturer's specification of the format tag.
///
///
/// Software must process a multiple of nBlockAlign bytes of data at a time. Data written to and read from a device must
/// always start at the beginning of a block. For example, it is illegal to start playback of PCM data in the middle of a sample
/// (that is, on a non-block-aligned boundary).
///
///
public ushort nBlockAlign;
///
/// Bits per sample for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, then wBitsPerSample
/// should be equal to 8 or 16. For non-PCM formats, this member must be set according to the manufacturer's specification of
/// the format tag. If wFormatTag is WAVE_FORMAT_EXTENSIBLE, this value can be any integer multiple of 8 and represents
/// the container size, not necessarily the sample size; for example, a 20-bit sample size is in a 24-bit container. Some
/// compression schemes cannot define a value for wBitsPerSample, so this member can be 0.
///
public ushort wBitsPerSample;
///
/// Size, in bytes, of extra format information appended to the end of the WAVEFORMATEX structure. This information can
/// be used by non-PCM formats to store extra attributes for the wFormatTag. If no extra information is required by the
/// wFormatTag, this member must be set to 0. For WAVE_FORMAT_PCM formats (and only WAVE_FORMAT_PCM formats), this member
/// is ignored. When this structure is included in a WAVEFORMATEXTENSIBLE structure, this value must be at least 22.
///
public ushort cbSize;
}
///
/// The WAVEFORMATEXTENSIBLE structure defines the format of waveform-audio data for formats having more than two channels or
/// higher sample resolutions than allowed by WAVEFORMATEX. It can also be used to define any format that can be defined by WAVEFORMATEX.
///
///
///
/// WAVEFORMATEXTENSIBLE can describe any format that can be described by WAVEFORMATEX, but provides additional support for
/// more than two channels, for greater precision in the number of bits per sample, and for new compression schemes.
///
///
/// WAVEFORMATEXTENSIBLE can safely be cast to WAVEFORMATEX, because it simply configures the extra bytes specified by WAVEFORMATEX.cbSize.
///
///
/// The dwChannelMask member specifies which channels are present in the multichannel stream. The least significant bit
/// corresponds with the front left speaker, the next least significant bit corresponds to the front right speaker, and so on. The
/// bits, in order of significance, are defined as follows.
///
///
///
/// Speaker position
/// Flag bit
///
/// -
/// SPEAKER_FRONT_LEFT
/// 0x1
///
/// -
/// SPEAKER_FRONT_RIGHT
/// 0x2
///
/// -
/// SPEAKER_FRONT_CENTER
/// 0x4
///
/// -
/// SPEAKER_LOW_FREQUENCY
/// 0x8
///
/// -
/// SPEAKER_BACK_LEFT
/// 0x10
///
/// -
/// SPEAKER_BACK_RIGHT
/// 0x20
///
/// -
/// SPEAKER_FRONT_LEFT_OF_CENTER
/// 0x40
///
/// -
/// SPEAKER_FRONT_RIGHT_OF_CENTER
/// 0x80
///
/// -
/// SPEAKER_BACK_CENTER
/// 0x100
///
/// -
/// SPEAKER_SIDE_LEFT
/// 0x200
///
/// -
/// SPEAKER_SIDE_RIGHT
/// 0x400
///
/// -
/// SPEAKER_TOP_CENTER
/// 0x800
///
/// -
/// SPEAKER_TOP_FRONT_LEFT
/// 0x1000
///
/// -
/// SPEAKER_TOP_FRONT_CENTER
/// 0x2000
///
/// -
/// SPEAKER_TOP_FRONT_RIGHT
/// 0x4000
///
/// -
/// SPEAKER_TOP_BACK_LEFT
/// 0x8000
///
/// -
/// SPEAKER_TOP_BACK_CENTER
/// 0x10000
///
/// -
/// SPEAKER_TOP_BACK_RIGHT
/// 0x20000
///
///
///
/// The channels specified in dwChannelMask must be present in the prescribed order (from least significant bit up). For
/// example, if only SPEAKER_FRONT_LEFT and SPEAKER_FRONT_RIGHT are specified, then the samples for the front left speaker must come
/// first in the interleaved stream. The number of bits set in dwChannelMask should be the same as the number of channels
/// specified in WAVEFORMATEX.nChannels.
///
///
/// For backward compatibility, any wave format that can be specified by a stand-alone WAVEFORMATEX structure can also be defined by
/// a WAVEFORMATEXTENSIBLE structure. Thus, every wave-format tag in mmreg.h has a corresponding SubFormat GUID. The
/// following table shows some typical wave-format tags and their corresponding SubFormat GUIDs. These GUIDs are defined in Ksmedia.h.
///
///
///
/// Wave-Format Tag
/// SubFormat GUID
///
/// -
/// WAVE_FORMAT_PCM
/// KSDATAFORMAT_SUBTYPE_PCM
///
/// -
/// WAVE_FORMAT_IEEE_FLOAT
/// KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
///
/// -
/// WAVE_FORMAT_DRM
/// KSDATAFORMAT_SUBTYPE_DRM
///
/// -
/// WAVE_FORMAT_ALAW
/// KSDATAFORMAT_SUBTYPE_ALAW
///
/// -
/// WAVE_FORMAT_MULAW
/// KSDATAFORMAT_SUBTYPE_MULAW
///
/// -
/// WAVE_FORMAT_ADPCM
/// KSDATAFORMAT_SUBTYPE_ADPCM
///
///
///
/// Because WAVEFORMATEXTENSIBLE is an extended version of WAVEFORMATEX, it can describe additional formats that cannot be
/// described by WAVEFORMATEX alone. Vendors are free to define their own SubFormat GUIDs to identify proprietary
/// formats for which no wave-format tags exist.
///
/// The following structures, for particular extended formats, are defined as WAVEFORMATEXTENSIBLE.
///
///
/// Definition
/// Value of SubFormat
///
/// -
/// WAVEFORMATIEEEFLOATEX
/// KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
///
/// -
/// WAVEFORMATPCMEX
/// KSDATAFORMAT_SUBTYPE_PCM
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmreg/ns-mmreg-waveformatextensible typedef struct { WAVEFORMATEX Format;
// union { WORD wValidBitsPerSample; WORD wSamplesPerBlock; WORD wReserved; } Samples; DWORD dwChannelMask; GUID SubFormat; }
// WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
[PInvokeData("mmreg.h", MSDNShortId = "NS:mmreg.__unnamed_struct_0")]
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct WAVEFORMATEXTENSIBLE
{
///
/// WAVEFORMATEX structure that specifies the basic format. The wFormatTag member must be WAVE_FORMAT_EXTENSIBLE. The
/// cbSize member must be at least 22.
///
public WAVEFORMATEX Format;
/// A union describing the sample format.
public SAMPLES Samples;
/// Bitmask specifying the assignment of channels in the stream to speaker positions.
public uint dwChannelMask;
///
/// Subformat of the data, such as KSDATAFORMAT_SUBTYPE_PCM. The subformat information is similar to that provided by the tag in
/// the WAVEFORMATEX structure's wFormatTag member.
///
public Guid SubFormat;
/// A union describing the sample format.
[StructLayout(LayoutKind.Explicit)]
public struct SAMPLES
{
///
/// Number of bits of precision in the signal. Usually equal to WAVEFORMATEX.wBitsPerSample. However,
/// wBitsPerSample is the container size and must be a multiple of 8, whereas wValidBitsPerSample can be any
/// value not exceeding the container size. For example, if the format uses 20-bit samples, wBitsPerSample must be at
/// least 24, but wValidBitsPerSample is 20.
///
[FieldOffset(0)]
public ushort wValidBitsPerSample;
///
/// Number of samples contained in one compressed block of audio data. This value is used in buffer estimation. This value
/// is used with compressed formats that have a fixed number of samples within each block. This value can be set to 0 if a
/// variable number of samples is contained in each block of compressed audio data. In this case, buffer estimation and
/// position information needs to be obtained in other ways.
///
[FieldOffset(0)]
public ushort wSamplesPerBlock;
/// Reserved for internal use by operating system. Set to 0.
[FieldOffset(0)]
public ushort wReserved;
}
}
/// The WAVEHDR structure defines the header used to identify a waveform-audio buffer.
///
///
/// Use the WHDR_BEGINLOOP and WHDR_ENDLOOP flags in the dwFlags member to specify the beginning and ending data blocks for
/// looping. To loop on a single block, specify both flags for the same block. Use the dwLoops member in the WAVEHDR
/// structure for the first block in the loop to specify the number of times to play the loop.
///
///
/// The lpData, dwBufferLength, and dwFlags members must be set before calling the waveInPrepareHeader or
/// waveOutPrepareHeader function. (For either function, the dwFlags member must be set to zero.)
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-wavehdr typedef struct wavehdr_tag { LPSTR lpData; DWORD
// dwBufferLength; DWORD dwBytesRecorded; DWORD_PTR dwUser; DWORD dwFlags; DWORD dwLoops; struct wavehdr_tag *lpNext; DWORD_PTR
// reserved; } WAVEHDR, *PWAVEHDR, *NPWAVEHDR, *LPWAVEHDR;
[PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.wavehdr_tag")]
[StructLayout(LayoutKind.Sequential)]
public struct WAVEHDR
{
/// Pointer to the waveform buffer.
public IntPtr lpData;
/// Length, in bytes, of the buffer.
public uint dwBufferLength;
/// When the header is used in input, specifies how much data is in the buffer.
public uint dwBytesRecorded;
/// User data.
public IntPtr dwUser;
///
/// A bitwise OR of zero of more flags. The following flags are defined:
///
///
/// Name
/// Description
///
/// -
/// WHDR_BEGINLOOP
/// This buffer is the first buffer in a loop. This flag is used only with output buffers.
///
/// -
/// WHDR_DONE
/// Set by the device driver to indicate that it is finished with the buffer and is returning it to the application.
///
/// -
/// WHDR_ENDLOOP
/// This buffer is the last buffer in a loop. This flag is used only with output buffers.
///
/// -
/// WHDR_INQUEUE
/// Set by Windows to indicate that the buffer is queued for playback.
///
/// -
/// WHDR_PREPARED
///
/// Set by Windows to indicate that the buffer has been prepared with the waveInPrepareHeader or waveOutPrepareHeader function.
///
///
///
///
public WHDR dwFlags;
/// Number of times to play the loop. This member is used only with output buffers.
public uint dwLoops;
/// Reserved.
public IntPtr lpNext;
/// Reserved.
public IntPtr reserved;
}
/// The WAVEINCAPS structure describes the capabilities of a waveform-audio input device.
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-waveincaps typedef struct waveincaps_tag { WORD wMid; WORD
// wPid; VERSION vDriverVersion; char szPname[MAXPNAMELEN]; DWORD dwFormats; WORD wChannels; } WAVEINCAPS, *PWAVEINCAPS,
// *NPWAVEINCAPS, *LPWAVEINCAPS;
[PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.waveincaps_tag")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WAVEINCAPS
{
///
/// Manufacturer identifier for the device driver for the waveform-audio input device. Manufacturer identifiers are defined in
/// Manufacturer and Product Identifiers.
///
public ushort wMid;
///
/// Product identifier for the waveform-audio input device. Product identifiers are defined in Manufacturer and Product Identifiers.
///
public ushort wPid;
///
/// Version number of the device driver for the waveform-audio input device. The high-order byte is the major version number,
/// and the low-order byte is the minor version number.
///
public uint vDriverVersion;
/// Product name in a null-terminated string.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szPname;
///
/// Standard formats that are supported. Can be a combination of the following:
///
///
/// Format
/// Description
///
/// -
/// WAVE_FORMAT_1M08
/// 11.025 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_1M16
/// 11.025 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_1S08
/// 11.025 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_1S16
/// 11.025 kHz, stereo, 16-bit
///
/// -
/// WAVE_FORMAT_2M08
/// 22.05 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_2M16
/// 22.05 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_2S08
/// 22.05 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_2S16
/// 22.05 kHz, stereo, 16-bit
///
/// -
/// WAVE_FORMAT_4M08
/// 44.1 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_4M16
/// 44.1 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_4S08
/// 44.1 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_4S16
/// 44.1 kHz, stereo, 16-bit
///
/// -
/// WAVE_FORMAT_96M08
/// 96 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_96M16
/// 96 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_96S08
/// 96 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_96S16
/// 96 kHz, stereo, 16-bit
///
///
///
public uint dwFormats;
/// Number specifying whether the device supports mono (1) or stereo (2) input.
public ushort wChannels;
}
/// The WAVEOUTCAPS structure describes the capabilities of a waveform-audio output device.
///
/// If a device supports volume changes, the WAVECAPS_VOLUME flag will be set for the dwSupport member. If a device supports
/// separate volume changes on the left and right channels, both the WAVECAPS_VOLUME and the WAVECAPS_LRVOLUME flags will be set for
/// this member.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-waveoutcaps typedef struct waveoutcaps_tag { WORD wMid; WORD
// wPid; VERSION vDriverVersion; char szPname[MAXPNAMELEN]; DWORD dwFormats; WORD wChannels; DWORD dwSupport; } WAVEOUTCAPS,
// *PWAVEOUTCAPS, *NPWAVEOUTCAPS, *LPWAVEOUTCAPS;
[PInvokeData("mmeapi.h", MSDNShortId = "NS:mmeapi.waveoutcaps_tag")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WAVEOUTCAPS
{
///
/// Manufacturer identifier for the device driver for the device. Manufacturer identifiers are defined in Manufacturer and
/// Product Identifiers.
///
public ushort wMid;
/// Product identifier for the device. Product identifiers are defined in Manufacturer and Product Identifiers.
public ushort wPid;
///
/// Version number of the device driver for the device. The high-order byte is the major version number, and the low-order byte
/// is the minor version number.
///
public uint vDriverVersion;
/// Product name in a null-terminated string.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szPname;
///
/// Standard formats that are supported. Can be a combination of the following:
///
///
/// Format
/// Description
///
/// -
/// WAVE_FORMAT_1M08
/// 11.025 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_1M16
/// 11.025 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_1S08
/// 11.025 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_1S16
/// 11.025 kHz, stereo, 16-bit
///
/// -
/// WAVE_FORMAT_2M08
/// 22.05 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_2M16
/// 22.05 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_2S08
/// 22.05 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_2S16
/// 22.05 kHz, stereo, 16-bit
///
/// -
/// WAVE_FORMAT_4M08
/// 44.1 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_4M16
/// 44.1 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_4S08
/// 44.1 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_4S16
/// 44.1 kHz, stereo, 16-bit
///
/// -
/// WAVE_FORMAT_96M08
/// 96 kHz, mono, 8-bit
///
/// -
/// WAVE_FORMAT_96M16
/// 96 kHz, mono, 16-bit
///
/// -
/// WAVE_FORMAT_96S08
/// 96 kHz, stereo, 8-bit
///
/// -
/// WAVE_FORMAT_96S16
/// 96 kHz, stereo, 16-bit
///
///
///
public uint dwFormats;
/// Number specifying whether the device supports mono (1) or stereo (2) output.
public ushort wChannels;
///
/// Optional functionality supported by the device. The following values are defined:
///
///
/// Flag
/// Description
///
/// -
/// WAVECAPS_LRVOLUME
/// Supports separate left and right volume control.
///
/// -
/// WAVECAPS_PITCH
/// Supports pitch control.
///
/// -
/// WAVECAPS_PLAYBACKRATE
/// Supports playback rate control.
///
/// -
/// WAVECAPS_SYNC
/// The driver is synchronous and will block while playing a buffer.
///
/// -
/// WAVECAPS_VOLUME
/// Supports volume control.
///
/// -
/// WAVECAPS_SAMPLEACCURATE
/// Returns sample-accurate position information.
///
///
///
public WAVECAPS dwSupport;
}
/// The MMTIME structure contains timing information for different types of multimedia data.
/// Provides a for that is disposed using .
public class SafeHWAVEIN : SafeHANDLE
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHWAVEIN(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHWAVEIN() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HWAVEIN(SafeHWAVEIN h) => h.handle;
///
protected override bool InternalReleaseHandle() => waveInClose(handle) == MMRESULT.MMSYSERR_NOERROR;
}
/// Provides a for that is disposed using .
public class SafeHWAVEOUT : SafeHANDLE
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHWAVEOUT(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHWAVEOUT() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HWAVEOUT(SafeHWAVEOUT h) => h.handle;
///
protected override bool InternalReleaseHandle() => waveOutClose(handle) == MMRESULT.MMSYSERR_NOERROR;
}
}
}