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 "precomp.h" 12 13 MMRESULT 14 QueryWaveDeviceFormatSupport( 15 IN PSOUND_DEVICE SoundDevice, 16 IN LPWAVEFORMATEX Format, 17 IN DWORD FormatSize) 18 { 19 MMRESULT Result; 20 MMDEVICE_TYPE DeviceType; 21 PMMFUNCTION_TABLE FunctionTable; 22 23 SND_TRACE(L"Querying wave format support\n"); 24 25 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) ); 26 VALIDATE_MMSYS_PARAMETER( Format ); 27 VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) ); 28 29 Result = GetSoundDeviceType(SoundDevice, &DeviceType); 30 SND_ASSERT( Result == MMSYSERR_NOERROR ); 31 32 /* Ensure we have a wave device (TODO: check if this applies to wavein as well) */ 33 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) ); 34 35 /* Obtain the function table */ 36 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable); 37 SND_ASSERT( Result == MMSYSERR_NOERROR ); 38 39 if ( ! MMSUCCESS(Result) ) 40 return TranslateInternalMmResult(Result); 41 42 if ( ! FunctionTable->QueryWaveFormatSupport ) 43 return MMSYSERR_NOTSUPPORTED; 44 45 return FunctionTable->QueryWaveFormatSupport(SoundDevice, Format, FormatSize); 46 } 47 48 MMRESULT 49 SetWaveDeviceFormat( 50 IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, 51 IN DWORD DeviceId, 52 IN LPWAVEFORMATEX Format, 53 IN DWORD FormatSize) 54 { 55 MMRESULT Result; 56 MMDEVICE_TYPE DeviceType; 57 PMMFUNCTION_TABLE FunctionTable; 58 PSOUND_DEVICE SoundDevice; 59 60 SND_TRACE(L"Setting wave format\n"); 61 62 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance) ); 63 64 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice); 65 if ( ! MMSUCCESS(Result) ) 66 return TranslateInternalMmResult(Result); 67 68 Result = GetSoundDeviceType(SoundDevice, &DeviceType); 69 SND_ASSERT( Result == MMSYSERR_NOERROR ); 70 if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE) 71 { 72 VALIDATE_MMSYS_PARAMETER( Format ); 73 VALIDATE_MMSYS_PARAMETER( FormatSize >= sizeof(WAVEFORMATEX) ); 74 } 75 76 /* Ensure we have a wave device (TODO: check if this applies to wavein as well) */ 77 VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) || IS_MIDI_DEVICE_TYPE(DeviceType) || IS_MIXER_DEVICE_TYPE(DeviceType)); 78 79 /* Obtain the function table */ 80 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable); 81 SND_ASSERT( Result == MMSYSERR_NOERROR ); 82 83 if ( ! MMSUCCESS(Result) ) 84 return TranslateInternalMmResult(Result); 85 86 if ( ! FunctionTable->SetWaveFormat ) 87 return MMSYSERR_NOTSUPPORTED; 88 89 return FunctionTable->SetWaveFormat(SoundDeviceInstance, DeviceId, Format, FormatSize); 90 } 91