34541c4fa0c19222f575cac6c4ff9a0c6782ec8c
[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
69 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
70 if ( ! MMSUCCESS(Result) )
71 return TranslateInternalMmResult(Result);
72
73 Result = GetSoundDeviceType(SoundDevice, &DeviceType);
74 SND_ASSERT( Result == MMSYSERR_NOERROR );
75 if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE)
76 {
77 VALIDATE_MMSYS_PARAMETER( Format );
78 VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) );
79 }
80
81 /* Ensure we have a wave device (TODO: check if this applies to wavein as well) */
82 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) || IS_MIDI_DEVICE_TYPE(DeviceType) || IS_MIXER_DEVICE_TYPE(DeviceType));
83
84 /* Obtain the function table */
85 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
86 SND_ASSERT( Result == MMSYSERR_NOERROR );
87
88 if ( ! MMSUCCESS(Result) )
89 return TranslateInternalMmResult(Result);
90
91 if ( ! FunctionTable->SetWaveFormat )
92 return MMSYSERR_NOTSUPPORTED;
93
94 return FunctionTable->SetWaveFormat(SoundDeviceInstance, DeviceId, Format, FormatSize);
95 }