43 ASSERT(BytesPerSample == 1 || BytesPerSample == 2 || BytesPerSample == 4);
45 NumSamples =
BufferLength / (BytesPerSample * NumChannels);
53 NewSamples = ((((
ULONG64)NumSamples * NewRate) + (OldRate / 2)) / OldRate) + 2;
80 if (BytesPerSample == 1)
85 else if (BytesPerSample == 2)
89 else if (BytesPerSample == 4)
94 Data.data_in = FloatIn;
95 Data.data_out = FloatOut;
96 Data.input_frames = NumSamples;
97 Data.output_frames = NewSamples;
98 Data.src_ratio = (
double)NewRate / (
double)OldRate;
110 if (BytesPerSample == 1)
117 else if (BytesPerSample == 2)
123 else if (BytesPerSample == 4)
150 ULONG NewIndex, OldIndex;
152 Samples =
BufferLength / (BitsPerSample / 8) / OldChannels;
154 SND_TRACE(
L"PerformChannelConversion OldChannels %u NewChannels %u\n", OldChannels, NewChannels);
156 if (NewChannels > OldChannels)
158 if (BitsPerSample == 8)
164 for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
173 BufferOut[NewIndex+OldChannels + SubIndex] =
Buffer[OldIndex + (SubIndex % OldChannels)];
174 }
while(SubIndex++ < NewChannels - OldChannels);
179 else if (BitsPerSample == 16)
185 for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
193 BufferOut[NewIndex+OldChannels + SubIndex] =
Buffer[OldIndex + (SubIndex % OldChannels)];
194 }
while(SubIndex++ < NewChannels - OldChannels);
199 else if (BitsPerSample == 24)
205 for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
213 RtlMoveMemory(&BufferOut[(NewIndex+OldChannels + SubIndex) * 3], &
Buffer[(OldIndex + (SubIndex % OldChannels)) * 3], 3);
214 }
while(SubIndex++ < NewChannels - OldChannels);
219 else if (BitsPerSample == 32)
225 for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
233 BufferOut[NewIndex+OldChannels + SubIndex] =
Buffer[OldIndex + (SubIndex % OldChannels)];
234 }
while(SubIndex++ < NewChannels - OldChannels);
247 for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
274 ASSERT(OldWidth != NewWidth);
281 if (OldWidth == 8 && NewWidth == 16)
295 BufferOut[
Index] = Sample;
300 else if (OldWidth == 8 && NewWidth == 32)
314 BufferOut[
Index] = Sample;
319 else if (OldWidth == 16 && NewWidth == 32)
329 Sample = BufferIn[
Index];
334 BufferOut[
Index] = Sample;
340 else if (OldWidth == 16 && NewWidth == 8)
350 Sample = BufferIn[
Index];
355 BufferOut[
Index] = (Sample & 0xFF);
360 else if (OldWidth == 32 && NewWidth == 8)
370 Sample = BufferIn[
Index];
375 BufferOut[
Index] = (Sample & 0xFF);
380 else if (OldWidth == 32 && NewWidth == 16)
390 Sample = BufferIn[
Index];
395 BufferOut[
Index] = (Sample & 0xFFFF);
402 DPRINT1(
"Not implemented conversion OldWidth %u NewWidth %u\n", OldWidth, NewWidth);
413 IN DWORD dwNumberOfBytesTransferred,
433 PVOID BufferOut, BufferOutTemp;
446 BufferOut = OffsetPtr;
449 if (SoundDeviceInstance->WaveFormatEx.wBitsPerSample != 16)
453 SoundDeviceInstance->WaveFormatEx.wBitsPerSample,
459 SND_TRACE(
L"PerformQualityConversion failed\n");
464 if (SoundDeviceInstance->WaveFormatEx.nChannels != 2)
468 SoundDeviceInstance->WaveFormatEx.nChannels,
474 if (BufferOut != OffsetPtr)
481 SND_TRACE(
L"PerformChannelConversion failed\n");
485 BufferOut = BufferOutTemp;
489 if (SoundDeviceInstance->WaveFormatEx.nSamplesPerSec != 44100)
493 SoundDeviceInstance->WaveFormatEx.nSamplesPerSec,
500 if (BufferOut != OffsetPtr)
507 SND_TRACE(
L"PerformSampleRateConversion failed\n");
511 BufferOut = BufferOutTemp;
522 DeviceInfo.Header.PresentationTime.Numerator = 1;
523 DeviceInfo.Header.PresentationTime.Denominator = 1;
#define ERROR_NOT_ENOUGH_MEMORY
#define ERROR_NOT_SUPPORTED
#define HeapFree(x, y, z)
BOOL WINAPI WriteFileEx(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, IN LPOVERLAPPED lpOverlapped, IN LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
DWORD PerformChannelConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldChannels, ULONG NewChannels, ULONG BitsPerSample, PVOID *Result, PULONG ResultLength)
DWORD PerformQualityConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldWidth, ULONG NewWidth, PVOID *Result, PULONG ResultLength)
VOID CALLBACK MixerCompletionRoutine(IN DWORD dwErrorCode, IN DWORD dwNumberOfBytesTransferred, IN LPOVERLAPPED lpOverlapped)
DWORD PerformSampleRateConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldRate, ULONG NewRate, ULONG BytesPerSample, ULONG NumChannels, PVOID *Result, PULONG ResultLength)
MMRESULT WriteFileEx_Remixer(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID OffsetPtr, IN DWORD Length, IN PSOUND_OVERLAPPED Overlap, IN LPOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine)
_Check_return_ __CRT_INLINE long lrintf(_In_ float x)
_Check_return_ unsigned long __cdecl _byteswap_ulong(_In_ unsigned long)
_Check_return_ unsigned short __cdecl _byteswap_ushort(_In_ unsigned short)
struct _SOUND_OVERLAPPED * PSOUND_OVERLAPPED
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
MMRESULT GetSoundDeviceInstanceHandle(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PVOID *Handle)
#define SND_ASSERT(condition)
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
_In_ ULONG _In_ ULONG _In_ ULONG Length
void src_int_to_float_array(const int *in, float *out, int len)
void src_float_to_short_array(const float *in, short *out, int len)
void src_short_to_float_array(const short *in, float *out, int len)
void src_float_to_int_array(const float *in, int *out, int len)
int src_process(SRC_STATE *state, SRC_DATA *data)
SRC_STATE * src_delete(SRC_STATE *state)
SRC_STATE * src_new(int converter_type, int channels, int *error)
struct SRC_STATE_tag SRC_STATE
WCHAR Data[ANYSIZE_ARRAY]
LPOVERLAPPED_COMPLETION_ROUTINE OriginalCompletionRoutine
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
#define RtlMoveMemory(Destination, Source, Length)
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
_In_ WDFREQUEST _In_opt_ PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine
void(CALLBACK * LPOVERLAPPED_COMPLETION_ROUTINE)(DWORD, DWORD, LPOVERLAPPED)
DWORD WINAPI GetLastError(void)
#define ERROR_INVALID_DATA
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO