Merge freeldr from amd64 branch:
[reactos.git] / reactos / lib / drivers / sound / mmebuddy / wave / format.c
1 /*
2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/sound/mmebuddy/wave/format.c
5 *
6 * PURPOSE: Queries and sets wave device format (sample rate, etc.)
7 *
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
9 */
10
11 #include <windows.h>
12 #include <mmsystem.h>
13 #include <mmddk.h>
14 #include <ntddsnd.h>
15 #include <sndtypes.h>
16 #include <mmebuddy.h>
17
18 MMRESULT
19 QueryWaveDeviceFormatSupport(
20 IN PSOUND_DEVICE SoundDevice,
21 IN LPWAVEFORMATEX Format,
22 IN DWORD FormatSize)
23 {
24 MMRESULT Result;
25 MMDEVICE_TYPE DeviceType;
26 PMMFUNCTION_TABLE FunctionTable;
27
28 SND_TRACE(L"Querying wave format support\n");
29
30 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
31 VALIDATE_MMSYS_PARAMETER( Format );
32 VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) );
33
34 Result = GetSoundDeviceType(SoundDevice, &DeviceType);
35 SND_ASSERT( Result == MMSYSERR_NOERROR );
36
37 /* Ensure we have a wave device (TODO: check if this applies to wavein as well) */
38 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) );
39
40 /* Obtain the function table */
41 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
42 SND_ASSERT( Result == MMSYSERR_NOERROR );
43
44 if ( ! MMSUCCESS(Result) )
45 return TranslateInternalMmResult(Result);
46
47 if ( ! FunctionTable->QueryWaveFormatSupport )
48 return MMSYSERR_NOTSUPPORTED;
49
50 return FunctionTable->QueryWaveFormatSupport(SoundDevice, Format, FormatSize);
51 }
52
53 MMRESULT
54 SetWaveDeviceFormat(
55 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
56 IN LPWAVEFORMATEX Format,
57 IN DWORD FormatSize)
58 {
59 MMRESULT Result;
60 MMDEVICE_TYPE DeviceType;
61 PMMFUNCTION_TABLE FunctionTable;
62 PSOUND_DEVICE SoundDevice;
63
64 SND_TRACE(L"Setting wave format\n");
65
66 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance) );
67 VALIDATE_MMSYS_PARAMETER( Format );
68 VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) );
69
70 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
71 if ( ! MMSUCCESS(Result) )
72 return TranslateInternalMmResult(Result);
73
74 Result = GetSoundDeviceType(SoundDevice, &DeviceType);
75 SND_ASSERT( Result == MMSYSERR_NOERROR );
76
77 /* Ensure we have a wave device (TODO: check if this applies to wavein as well) */
78 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) );
79
80 /* Obtain the function table */
81 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
82 SND_ASSERT( Result == MMSYSERR_NOERROR );
83
84 if ( ! MMSUCCESS(Result) )
85 return TranslateInternalMmResult(Result);
86
87 if ( ! FunctionTable->SetWaveFormat )
88 return MMSYSERR_NOTSUPPORTED;
89
90 return FunctionTable->SetWaveFormat(SoundDeviceInstance, Format, FormatSize);
91 }