ecc5bbc1d9ae336c6dcd94a9d5cda5288832e881
[reactos.git] / 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 DWORD DeviceId,
57 IN LPWAVEFORMATEX Format,
58 IN DWORD FormatSize)
59 {
60 MMRESULT Result;
61 MMDEVICE_TYPE DeviceType;
62 PMMFUNCTION_TABLE FunctionTable;
63 PSOUND_DEVICE SoundDevice;
64
65 SND_TRACE(L"Setting wave format\n");
66
67 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance) );
68 VALIDATE_MMSYS_PARAMETER( Format );
69 VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) );
70
71 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
72 if ( ! MMSUCCESS(Result) )
73 return TranslateInternalMmResult(Result);
74
75 Result = GetSoundDeviceType(SoundDevice, &DeviceType);
76 SND_ASSERT( Result == MMSYSERR_NOERROR );
77
78 /* Ensure we have a wave device (TODO: check if this applies to wavein as well) */
79 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) );
80
81 /* Obtain the function table */
82 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
83 SND_ASSERT( Result == MMSYSERR_NOERROR );
84
85 if ( ! MMSUCCESS(Result) )
86 return TranslateInternalMmResult(Result);
87
88 if ( ! FunctionTable->SetWaveFormat )
89 return MMSYSERR_NOTSUPPORTED;
90
91 return FunctionTable->SetWaveFormat(SoundDeviceInstance, DeviceId, Format, FormatSize);
92 }