diff options
Diffstat (limited to 'plugins/pluginWinAudioDSP')
8 files changed, 676 insertions, 758 deletions
diff --git a/plugins/pluginWinAudioDSP/dllmain_audio_dsp.cxx b/plugins/pluginWinAudioDSP/dllmain_audio_dsp.cxx index dcb9005..a252d04 100755 --- a/plugins/pluginWinAudioDSP/dllmain_audio_dsp.cxx +++ b/plugins/pluginWinAudioDSP/dllmain_audio_dsp.cxx @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -55,103 +55,92 @@ PLUGIN_AUDIO_DSP_END_DECLS /* END */ BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved - ) + ) { - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - break; - case DLL_THREAD_ATTACH: - break; - case DLL_THREAD_DETACH: - break; - case DLL_PROCESS_DETACH: - break; - } - return TRUE; + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + break; + } + return TRUE; } -typedef enum PLUGIN_INDEX_E -{ +typedef enum PLUGIN_INDEX_E { #if PLUGIN_AUDIO_DSP_RESAMPLER_ENABLE - PLUGIN_INDEX_RESAMPLER, + PLUGIN_INDEX_RESAMPLER, #endif #if PLUGIN_AUDIO_DSP_DENOISER_ENABLE - PLUGIN_INDEX_DENOISER, + PLUGIN_INDEX_DENOISER, #endif - - PLUGIN_INDEX_COUNT + + PLUGIN_INDEX_COUNT } PLUGIN_INDEX_T; int __plugin_get_def_count() { - return PLUGIN_INDEX_COUNT; + return PLUGIN_INDEX_COUNT; } tsk_plugin_def_type_t __plugin_get_def_type_at(int index) { - switch(index) - { + switch(index) { #if PLUGIN_AUDIO_DSP_RESAMPLER_ENABLE - case PLUGIN_INDEX_RESAMPLER: - { - return tsk_plugin_def_type_resampler; - } + case PLUGIN_INDEX_RESAMPLER: { + return tsk_plugin_def_type_resampler; + } #endif #if PLUGIN_AUDIO_DSP_DENOISER_ENABLE - case PLUGIN_INDEX_DENOISER: - { - return tsk_plugin_def_type_denoiser; - } + case PLUGIN_INDEX_DENOISER: { + return tsk_plugin_def_type_denoiser; + } #endif - } - TSK_DEBUG_ERROR("No plugin at index %d", index); - return tsk_plugin_def_type_none; + } + TSK_DEBUG_ERROR("No plugin at index %d", index); + return tsk_plugin_def_type_none; } tsk_plugin_def_media_type_t __plugin_get_def_media_type_at(int index) { - switch(index) - { + switch(index) { #if PLUGIN_AUDIO_DSP_RESAMPLER_ENABLE - case PLUGIN_INDEX_RESAMPLER: - { - return tsk_plugin_def_media_type_audio; - } + case PLUGIN_INDEX_RESAMPLER: { + return tsk_plugin_def_media_type_audio; + } #endif #if PLUGIN_AUDIO_DSP_DENOISER_ENABLE - case PLUGIN_INDEX_DENOISER: - { - return tsk_plugin_def_media_type_audio; - } + case PLUGIN_INDEX_DENOISER: { + return tsk_plugin_def_media_type_audio; + } #endif - } + } - TSK_DEBUG_ERROR("No plugin at index %d", index); - return tsk_plugin_def_media_type_none; + TSK_DEBUG_ERROR("No plugin at index %d", index); + return tsk_plugin_def_media_type_none; } tsk_plugin_def_ptr_const_t __plugin_get_def_at(int index) { - switch(index) - { + switch(index) { #if PLUGIN_AUDIO_DSP_RESAMPLER_ENABLE - case PLUGIN_INDEX_RESAMPLER: - { - return plugin_audio_dsp_resampler_plugin_def_t; - } + case PLUGIN_INDEX_RESAMPLER: { + return plugin_audio_dsp_resampler_plugin_def_t; + } #endif #if PLUGIN_AUDIO_DSP_DENOISER_ENABLE - case PLUGIN_INDEX_DENOISER: - { - return plugin_audio_dsp_denoise_plugin_def_t; - } + case PLUGIN_INDEX_DENOISER: { + return plugin_audio_dsp_denoise_plugin_def_t; + } #endif - } + } - TSK_DEBUG_ERROR("No plugin at index %d", index); - return tsk_null; + TSK_DEBUG_ERROR("No plugin at index %d", index); + return tsk_null; } diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_config.h b/plugins/pluginWinAudioDSP/plugin_audio_dsp_config.h index 7730bc8..100f0f8 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_config.h +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_config.h @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -48,12 +48,12 @@ # define PLUGIN_AUDIO_DSP_UNDER_X86 1 #endif -// Guards against C++ name mangling +// Guards against C++ name mangling #ifdef __cplusplus # define PLUGIN_AUDIO_DSP_BEGIN_DECLS extern "C" { # define PLUGIN_AUDIO_DSP_END_DECLS } #else -# define PLUGIN_AUDIO_DSP_BEGIN_DECLS +# define PLUGIN_AUDIO_DSP_BEGIN_DECLS # define PLUGIN_AUDIO_DSP_END_DECLS #endif @@ -69,7 +69,7 @@ #endif #if HAVE_CONFIG_H - #include <config.h> +#include <config.h> #endif #endif // PLUGIN_AUDIO_DSP_CONFIG_H diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_denoiser.cxx b/plugins/pluginWinAudioDSP/plugin_audio_dsp_denoiser.cxx index 574c5ac..74d713f 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_denoiser.cxx +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_denoiser.cxx @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -44,201 +44,189 @@ static const UINT32 g_nChannles = 1; // FIXME static const UINT32 g_nFrameDuration = 20; // FIXME /** Speex denoiser*/ -typedef struct plugin_audio_dsp_denoise_s -{ - TMEDIA_DECLARE_DENOISE; - - bool bOpened; +typedef struct plugin_audio_dsp_denoise_s { + TMEDIA_DECLARE_DENOISE; + + bool bOpened; - LONGLONG rtStart; + LONGLONG rtStart; UINT64 rtDuration; - uint32_t echo_tail; - tsk_size_t playback_size_samples; - tsk_size_t playback_size_bytes; - tsk_size_t playback_channels; - tsk_size_t record_size_samples; - tsk_size_t record_size_bytes; - tsk_size_t record_channels; - - IMediaObject* pInst; - IMediaBuffer *pBufferIn; - IMediaBuffer *pBufferOut; + uint32_t echo_tail; + tsk_size_t playback_size_samples; + tsk_size_t playback_size_bytes; + tsk_size_t playback_channels; + tsk_size_t record_size_samples; + tsk_size_t record_size_bytes; + tsk_size_t record_channels; + + IMediaObject* pInst; + IMediaBuffer *pBufferIn; + IMediaBuffer *pBufferOut; } plugin_audio_dsp_denoise_t; static int plugin_audio_dsp_denoise_set(tmedia_denoise_t* _self, const tmedia_param_t* param) { - plugin_audio_dsp_denoise_t *self = (plugin_audio_dsp_denoise_t *)_self; - if(!self || !param) - { - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - - if(param->value_type == tmedia_pvt_int32) - { - if(tsk_striequals(param->key, "echo-tail")) - { - _self->echo_tail = *((int32_t*)param->value); - TSK_DEBUG_INFO("ms_voice_dsp_set_echo_tail(%d)", _self->echo_tail); - if(self->pInst) - { - IPropertyStore* pPropStore = NULL; - HRESULT hr = self->pInst->QueryInterface(IID_PPV_ARGS(&pPropStore)); - if(SUCCEEDED(hr)) - { - DMO_MEDIA_TYPE mt = {0}; - PROPVARIANT var = {0}; - var.vt = VT_UI4; - var.ulVal = _self->echo_tail; - hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_ECHO_LENGTH , var); - } - SafeRelease(&pPropStore); - } - return 0; - } - } - return -1; + plugin_audio_dsp_denoise_t *self = (plugin_audio_dsp_denoise_t *)_self; + if(!self || !param) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + + if(param->value_type == tmedia_pvt_int32) { + if(tsk_striequals(param->key, "echo-tail")) { + _self->echo_tail = *((int32_t*)param->value); + TSK_DEBUG_INFO("ms_voice_dsp_set_echo_tail(%d)", _self->echo_tail); + if(self->pInst) { + IPropertyStore* pPropStore = NULL; + HRESULT hr = self->pInst->QueryInterface(IID_PPV_ARGS(&pPropStore)); + if(SUCCEEDED(hr)) { + DMO_MEDIA_TYPE mt = {0}; + PROPVARIANT var = {0}; + var.vt = VT_UI4; + var.ulVal = _self->echo_tail; + hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_ECHO_LENGTH , var); + } + SafeRelease(&pPropStore); + } + return 0; + } + } + return -1; } static int plugin_audio_dsp_denoise_open(tmedia_denoise_t* self, uint32_t record_frame_size_samples, uint32_t record_sampling_rate, uint32_t playback_frame_size_samples, uint32_t playback_sampling_rate) { - plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; - - HRESULT hr = S_OK; - DMO_MEDIA_TYPE mt = {0}; - PROPVARIANT var = {0}; - IPropertyStore* pPropStore = NULL; - - TSK_DEBUG_INFO("[MS Voice Capture DSP] AEC_ENABLED=%d ECHO_TAIL=%d,\nAGC_ENABLED=%d,\nNOISE_SUPP_ENABLED=%d,\nVAD_ENABLED=%d", - self->echo_supp_enabled, self->echo_tail, - self->agc_enabled, - self->noise_supp_enabled, - self->vad_enabled - ); - - if(denoiser->bOpened) - { - TSK_DEBUG_ERROR("Denoiser already opened"); - CHECK_HR(hr = E_FAIL); - } - - CHECK_HR(hr = AudioDSPUtils::MoInitMediaType( - record_sampling_rate, - g_nBitsPerSample, - g_nChannles, - &mt)); - - CHECK_HR(hr = CoCreateInstance(CLSID_CWMAudioAEC, NULL, - CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&denoiser->pInst))); - CHECK_HR(hr = denoiser->pInst->QueryInterface(IID_PPV_ARGS(&pPropStore))); - - // If the input format does not match the output format, the DMO automatically performs sample-rate conversion. - CHECK_HR(hr = denoiser->pInst->SetInputType(0, &mt, 0)); - CHECK_HR(hr = denoiser->pInst->SetOutputType(0, &mt, 0)); - - // Enables the application to override the default settings on various properties of the Voice Capture DSP - // http://msdn.microsoft.com/en-us/library/windows/desktop/ff819422(v=vs.85).aspx - var.vt = VT_BOOL; - var.boolVal = VARIANT_TRUE; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATURE_MODE, var)); - - // Switch to filter mode: http://msdn.microsoft.com/en-us/library/windows/desktop/ff819410(v=vs.85).aspx - var.vt = VT_BOOL; - var.boolVal = VARIANT_FALSE; /* VARIANT_FALSE: Filter, VARIANT_TRUE: Source */ - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_DMO_SOURCE_MODE, var)); - - // Enable AEC - if(self->echo_supp_enabled) - { - // Enable AEC: http://msdn.microsoft.com/en-us/library/windows/desktop/ff819427(v=vs.85).aspx - var.vt = VT_I4; - var.lVal = SINGLE_CHANNEL_AEC; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_SYSTEM_MODE, var)); - - // Echo Tail (milliseconds): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819414(v=vs.85).aspx - if(!self->echo_tail) - { - self->echo_tail = tmedia_defaults_get_echo_tail(); - } - var.vt = VT_I4; - var.lVal = self->echo_tail ? self->echo_tail : 256; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_ECHO_LENGTH, var)); - } - - // Automatic Gain Control (AGC): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819412(v=vs.85).aspx - var.vt = VT_BOOL; - var.boolVal = self->agc_enabled ? VARIANT_TRUE : VARIANT_FALSE; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_AGC, var)); - - // Noise suppression (NS): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819420(v=vs.85).aspx - var.vt = VT_I4; - var.lVal = self->noise_supp_enabled ? 1 : 0; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_NS, var)); - - // Automatic Gain Control (AGC): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819412(v=vs.85).aspx - var.vt = VT_BOOL; - var.boolVal = self->agc_enabled ? VARIANT_TRUE : VARIANT_FALSE; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_AGC, var)); - - // Voice Activity Detection (VAD): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819421(v=vs.85).aspx - var.vt = VT_I4; - var.lVal = self->vad_enabled ? AEC_VAD_FOR_SILENCE_SUPPRESSION : AEC_VAD_DISABLED; - CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_VAD, var)); - - // Recommended to allocate resources - CHECK_HR(hr = denoiser->pInst->AllocateStreamingResources()); // FIXME: returns E_FAIL - - denoiser->record_channels = g_nChannles; - denoiser->record_size_samples = ((record_sampling_rate * g_nFrameDuration) / 1000) << (denoiser->record_channels == 2 ? 1 : 0); - denoiser->record_size_bytes = (denoiser->record_size_samples * (g_nBitsPerSample >> 3)); - - denoiser->playback_channels = g_nChannles; - denoiser->playback_size_samples = ((playback_sampling_rate * g_nFrameDuration) / 1000) << (denoiser->playback_channels == 2 ? 1 : 0); - denoiser->playback_size_bytes = (denoiser->playback_size_samples * (g_nBitsPerSample >> 3)); - - denoiser->rtStart = 0; - denoiser->rtDuration = PLUGIN_AUDIO_DSP_MILLIS_TO_100NS(g_nFrameDuration); // milliseconds -> 100ns + plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; + + HRESULT hr = S_OK; + DMO_MEDIA_TYPE mt = {0}; + PROPVARIANT var = {0}; + IPropertyStore* pPropStore = NULL; + + TSK_DEBUG_INFO("[MS Voice Capture DSP] AEC_ENABLED=%d ECHO_TAIL=%d,\nAGC_ENABLED=%d,\nNOISE_SUPP_ENABLED=%d,\nVAD_ENABLED=%d", + self->echo_supp_enabled, self->echo_tail, + self->agc_enabled, + self->noise_supp_enabled, + self->vad_enabled + ); + + if(denoiser->bOpened) { + TSK_DEBUG_ERROR("Denoiser already opened"); + CHECK_HR(hr = E_FAIL); + } + + CHECK_HR(hr = AudioDSPUtils::MoInitMediaType( + record_sampling_rate, + g_nBitsPerSample, + g_nChannles, + &mt)); + + CHECK_HR(hr = CoCreateInstance(CLSID_CWMAudioAEC, NULL, + CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&denoiser->pInst))); + CHECK_HR(hr = denoiser->pInst->QueryInterface(IID_PPV_ARGS(&pPropStore))); + + // If the input format does not match the output format, the DMO automatically performs sample-rate conversion. + CHECK_HR(hr = denoiser->pInst->SetInputType(0, &mt, 0)); + CHECK_HR(hr = denoiser->pInst->SetOutputType(0, &mt, 0)); + + // Enables the application to override the default settings on various properties of the Voice Capture DSP + // http://msdn.microsoft.com/en-us/library/windows/desktop/ff819422(v=vs.85).aspx + var.vt = VT_BOOL; + var.boolVal = VARIANT_TRUE; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATURE_MODE, var)); + + // Switch to filter mode: http://msdn.microsoft.com/en-us/library/windows/desktop/ff819410(v=vs.85).aspx + var.vt = VT_BOOL; + var.boolVal = VARIANT_FALSE; /* VARIANT_FALSE: Filter, VARIANT_TRUE: Source */ + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_DMO_SOURCE_MODE, var)); + + // Enable AEC + if(self->echo_supp_enabled) { + // Enable AEC: http://msdn.microsoft.com/en-us/library/windows/desktop/ff819427(v=vs.85).aspx + var.vt = VT_I4; + var.lVal = SINGLE_CHANNEL_AEC; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_SYSTEM_MODE, var)); + + // Echo Tail (milliseconds): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819414(v=vs.85).aspx + if(!self->echo_tail) { + self->echo_tail = tmedia_defaults_get_echo_tail(); + } + var.vt = VT_I4; + var.lVal = self->echo_tail ? self->echo_tail : 256; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_ECHO_LENGTH, var)); + } + + // Automatic Gain Control (AGC): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819412(v=vs.85).aspx + var.vt = VT_BOOL; + var.boolVal = self->agc_enabled ? VARIANT_TRUE : VARIANT_FALSE; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_AGC, var)); + + // Noise suppression (NS): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819420(v=vs.85).aspx + var.vt = VT_I4; + var.lVal = self->noise_supp_enabled ? 1 : 0; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_NS, var)); + + // Automatic Gain Control (AGC): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819412(v=vs.85).aspx + var.vt = VT_BOOL; + var.boolVal = self->agc_enabled ? VARIANT_TRUE : VARIANT_FALSE; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_AGC, var)); + + // Voice Activity Detection (VAD): http://msdn.microsoft.com/en-us/library/windows/desktop/ff819421(v=vs.85).aspx + var.vt = VT_I4; + var.lVal = self->vad_enabled ? AEC_VAD_FOR_SILENCE_SUPPRESSION : AEC_VAD_DISABLED; + CHECK_HR(hr = pPropStore->SetValue(MFPKEY_WMAAECMA_FEATR_VAD, var)); + + // Recommended to allocate resources + CHECK_HR(hr = denoiser->pInst->AllocateStreamingResources()); // FIXME: returns E_FAIL + + denoiser->record_channels = g_nChannles; + denoiser->record_size_samples = ((record_sampling_rate * g_nFrameDuration) / 1000) << (denoiser->record_channels == 2 ? 1 : 0); + denoiser->record_size_bytes = (denoiser->record_size_samples * (g_nBitsPerSample >> 3)); + + denoiser->playback_channels = g_nChannles; + denoiser->playback_size_samples = ((playback_sampling_rate * g_nFrameDuration) / 1000) << (denoiser->playback_channels == 2 ? 1 : 0); + denoiser->playback_size_bytes = (denoiser->playback_size_samples * (g_nBitsPerSample >> 3)); + + denoiser->rtStart = 0; + denoiser->rtDuration = PLUGIN_AUDIO_DSP_MILLIS_TO_100NS(g_nFrameDuration); // milliseconds -> 100ns bail: - denoiser->bOpened = SUCCEEDED(hr); + denoiser->bOpened = SUCCEEDED(hr); - MoFreeMediaType(&mt); - SafeRelease(&pPropStore); + MoFreeMediaType(&mt); + SafeRelease(&pPropStore); - return denoiser->bOpened ? 0 : -1; + return denoiser->bOpened ? 0 : -1; } // playback = "stream 1" // /!\Thread safety: could be called at the same time as plugin_audio_dsp_denoise_process_record() static int plugin_audio_dsp_denoise_echo_playback(tmedia_denoise_t* self, const void* echo_frame, uint32_t echo_frame_size_bytes) { - plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; + plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; + + HRESULT hr = S_OK; - HRESULT hr = S_OK; + if(!self || !echo_frame || !echo_frame_size_bytes) { + CHECK_HR(hr = E_POINTER); + } - if(!self || !echo_frame || !echo_frame_size_bytes) - { - CHECK_HR(hr = E_POINTER); - } + if(!denoiser->bOpened) { + TSK_DEBUG_ERROR("Denoiser not opened"); + CHECK_HR(hr = E_FAIL); + } + + if(denoiser->record_size_bytes != echo_frame_size_bytes) { + TSK_DEBUG_ERROR("Size mismatch: %u<>%u", denoiser->record_size_bytes, echo_frame_size_bytes); + CHECK_HR(hr = E_INVALIDARG); + } - if(!denoiser->bOpened) - { - TSK_DEBUG_ERROR("Denoiser not opened"); - CHECK_HR(hr = E_FAIL); - } - if(denoiser->record_size_bytes != echo_frame_size_bytes) - { - TSK_DEBUG_ERROR("Size mismatch: %u<>%u", denoiser->record_size_bytes, echo_frame_size_bytes); - CHECK_HR(hr = E_INVALIDARG); - } - - bail: - return SUCCEEDED(hr) ? 0 : -1; + return SUCCEEDED(hr) ? 0 : -1; } @@ -246,97 +234,89 @@ bail: // /!\Thread safety: could be called at the same time as plugin_audio_dsp_denoise_echo_playback() static int plugin_audio_dsp_denoise_process_record(tmedia_denoise_t* self, void* audio_frame, uint32_t audio_frame_size_bytes, tsk_bool_t* silence_or_noise) { - plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; - - HRESULT hr = S_OK; - BYTE* pBufferInPtr = NULL; - DWORD dwBufferInSize = 0; - - if(!self || !audio_frame || !audio_frame_size_bytes || !silence_or_noise) - { - CHECK_HR(hr = E_POINTER); - } - - if(!denoiser->bOpened) - { - TSK_DEBUG_ERROR("Denoiser not opened"); - CHECK_HR(hr = E_FAIL); - } - - if(denoiser->record_size_bytes != audio_frame_size_bytes) - { - TSK_DEBUG_ERROR("Size mismatch: %u<>%u", denoiser->record_size_bytes, audio_frame_size_bytes); - CHECK_HR(hr = E_INVALIDARG); - } - - if(!denoiser->pBufferIn) - { - CHECK_HR(hr = AudioDSPMediaBuffer::Create(denoiser->record_size_bytes, &denoiser->pBufferIn)); - } - else - { - DWORD dwMaxLength = 0; - CHECK_HR(hr = denoiser->pBufferIn->GetMaxLength(&dwMaxLength)); - if(dwMaxLength < denoiser->record_size_bytes) - { - SafeRelease(&denoiser->pBufferIn); - CHECK_HR(hr = AudioDSPMediaBuffer::Create(denoiser->record_size_bytes, &denoiser->pBufferIn)); - } - } - - // Get memory pointer to the input buffer - CHECK_HR(hr = denoiser->pBufferIn->GetBufferAndLength(&pBufferInPtr, NULL)); - // Copy data - dwBufferInSize = TSK_MIN(audio_frame_size_bytes, denoiser->record_size_bytes); - memcpy(pBufferInPtr, audio_frame, dwBufferInSize); - CHECK_HR(hr = denoiser->pBufferIn->SetLength(dwBufferInSize)); - - // Process input - hr = denoiser->pInst->ProcessInput( - g_nMicrophoneStreamIndex, - denoiser->pBufferIn, - (/*DMO_INPUT_DATA_BUFFERF_TIME | DMO_INPUT_DATA_BUFFERF_TIMELENGTH*/0), - denoiser->rtStart, - denoiser->rtDuration); - if(hr == DMO_E_NOTACCEPTING) - { - hr = S_OK; - } - CHECK_HR(hr); - - denoiser->rtStart += denoiser->rtDuration; + plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; + + HRESULT hr = S_OK; + BYTE* pBufferInPtr = NULL; + DWORD dwBufferInSize = 0; + + if(!self || !audio_frame || !audio_frame_size_bytes || !silence_or_noise) { + CHECK_HR(hr = E_POINTER); + } + + if(!denoiser->bOpened) { + TSK_DEBUG_ERROR("Denoiser not opened"); + CHECK_HR(hr = E_FAIL); + } + + if(denoiser->record_size_bytes != audio_frame_size_bytes) { + TSK_DEBUG_ERROR("Size mismatch: %u<>%u", denoiser->record_size_bytes, audio_frame_size_bytes); + CHECK_HR(hr = E_INVALIDARG); + } + + if(!denoiser->pBufferIn) { + CHECK_HR(hr = AudioDSPMediaBuffer::Create(denoiser->record_size_bytes, &denoiser->pBufferIn)); + } + else { + DWORD dwMaxLength = 0; + CHECK_HR(hr = denoiser->pBufferIn->GetMaxLength(&dwMaxLength)); + if(dwMaxLength < denoiser->record_size_bytes) { + SafeRelease(&denoiser->pBufferIn); + CHECK_HR(hr = AudioDSPMediaBuffer::Create(denoiser->record_size_bytes, &denoiser->pBufferIn)); + } + } + + // Get memory pointer to the input buffer + CHECK_HR(hr = denoiser->pBufferIn->GetBufferAndLength(&pBufferInPtr, NULL)); + // Copy data + dwBufferInSize = TSK_MIN(audio_frame_size_bytes, denoiser->record_size_bytes); + memcpy(pBufferInPtr, audio_frame, dwBufferInSize); + CHECK_HR(hr = denoiser->pBufferIn->SetLength(dwBufferInSize)); + + // Process input + hr = denoiser->pInst->ProcessInput( + g_nMicrophoneStreamIndex, + denoiser->pBufferIn, + (/*DMO_INPUT_DATA_BUFFERF_TIME | DMO_INPUT_DATA_BUFFERF_TIMELENGTH*/0), + denoiser->rtStart, + denoiser->rtDuration); + if(hr == DMO_E_NOTACCEPTING) { + hr = S_OK; + } + CHECK_HR(hr); + + denoiser->rtStart += denoiser->rtDuration; bail: - return SUCCEEDED(hr) ? 0 : -1; + return SUCCEEDED(hr) ? 0 : -1; } static int plugin_audio_dsp_denoise_process_playback(tmedia_denoise_t* self, void* audio_frame, uint32_t audio_frame_size_bytes) { - plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; - - (void)(denoiser); + plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; + + (void)(denoiser); - // Not mandatory to denoise audio before playback. - // All Doubango clients support noise suppression. - return 0; + // Not mandatory to denoise audio before playback. + // All Doubango clients support noise suppression. + return 0; } static int plugin_audio_dsp_denoise_close(tmedia_denoise_t* self) { - plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; - - if(!self) - { - TSK_DEBUG_ERROR("Invalid parameter"); - return -1; - } - - denoiser->bOpened = false; - SafeRelease(&denoiser->pBufferIn); - SafeRelease(&denoiser->pBufferOut); - SafeRelease(&denoiser->pInst); - return 0; + plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t *)self; + + if(!self) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + + denoiser->bOpened = false; + SafeRelease(&denoiser->pBufferIn); + SafeRelease(&denoiser->pBufferOut); + SafeRelease(&denoiser->pInst); + return 0; } @@ -348,55 +328,51 @@ static int plugin_audio_dsp_denoise_close(tmedia_denoise_t* self) /* constructor */ static tsk_object_t* plugin_audio_dsp_denoise_ctor(tsk_object_t * self, va_list * app) { - plugin_audio_dsp_denoise_t *denoise = (plugin_audio_dsp_denoise_t*)self; - if(denoise) - { - AudioDSPUtils::Startup(); - - /* init base */ - tmedia_denoise_init(TMEDIA_DENOISE(denoise)); - /* init self */ - } - return self; + plugin_audio_dsp_denoise_t *denoise = (plugin_audio_dsp_denoise_t*)self; + if(denoise) { + AudioDSPUtils::Startup(); + + /* init base */ + tmedia_denoise_init(TMEDIA_DENOISE(denoise)); + /* init self */ + } + return self; } /* destructor */ static tsk_object_t* plugin_audio_dsp_denoise_dtor(tsk_object_t * self) -{ - plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t*)self; - if(denoiser) - { - /* deinit base */ - tmedia_denoise_deinit(TMEDIA_DENOISE(denoiser)); - /* deinit self */ - SafeRelease(&denoiser->pBufferIn); - SafeRelease(&denoiser->pBufferOut); - SafeRelease(&denoiser->pInst); - - TSK_DEBUG_INFO("*** MS Voice Capture DSP destroyed ***"); - } - - return self; +{ + plugin_audio_dsp_denoise_t *denoiser = (plugin_audio_dsp_denoise_t*)self; + if(denoiser) { + /* deinit base */ + tmedia_denoise_deinit(TMEDIA_DENOISE(denoiser)); + /* deinit self */ + SafeRelease(&denoiser->pBufferIn); + SafeRelease(&denoiser->pBufferOut); + SafeRelease(&denoiser->pInst); + + TSK_DEBUG_INFO("*** MS Voice Capture DSP destroyed ***"); + } + + return self; } /* object definition */ -static const tsk_object_def_t plugin_audio_dsp_denoise_def_s = -{ - sizeof(plugin_audio_dsp_denoise_t), - plugin_audio_dsp_denoise_ctor, - plugin_audio_dsp_denoise_dtor, - tsk_null, +static const tsk_object_def_t plugin_audio_dsp_denoise_def_s = { + sizeof(plugin_audio_dsp_denoise_t), + plugin_audio_dsp_denoise_ctor, + plugin_audio_dsp_denoise_dtor, + tsk_null, }; /* plugin definition*/ -static const tmedia_denoise_plugin_def_t plugin_audio_dsp_denoise_plugin_def_s = -{ - &plugin_audio_dsp_denoise_def_s, +static const tmedia_denoise_plugin_def_t plugin_audio_dsp_denoise_plugin_def_s = { + &plugin_audio_dsp_denoise_def_s, - "MS Voice Capture DSP", /* http://msdn.microsoft.com/en-us/library/windows/desktop/ff819492(v=vs.85).aspx */ + "MS Voice Capture DSP", /* http://msdn.microsoft.com/en-us/library/windows/desktop/ff819492(v=vs.85).aspx */ - plugin_audio_dsp_denoise_set, - plugin_audio_dsp_denoise_open, - plugin_audio_dsp_denoise_echo_playback, - plugin_audio_dsp_denoise_process_record, - plugin_audio_dsp_denoise_process_playback, - plugin_audio_dsp_denoise_close, + plugin_audio_dsp_denoise_set, + plugin_audio_dsp_denoise_open, + plugin_audio_dsp_denoise_echo_playback, + plugin_audio_dsp_denoise_process_record, + plugin_audio_dsp_denoise_process_playback, + plugin_audio_dsp_denoise_close, }; const tmedia_denoise_plugin_def_t *plugin_audio_dsp_denoise_plugin_def_t = &plugin_audio_dsp_denoise_plugin_def_s; diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.cxx b/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.cxx index 34e5b4d..b4a1726 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.cxx +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.cxx @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -25,48 +25,42 @@ AudioDSPMediaBuffer::AudioDSPMediaBuffer(DWORD cbMaxLength, HRESULT& hr) : m_pbData(NULL) { m_pbData = new BYTE[cbMaxLength]; - if (!m_pbData) - { + if (!m_pbData) { hr = E_OUTOFMEMORY; } } AudioDSPMediaBuffer::~AudioDSPMediaBuffer() { - if (m_pbData) - { + if (m_pbData) { delete [] m_pbData; } } -// Function to create a new IMediaBuffer object and return +// Function to create a new IMediaBuffer object and return // an AddRef'd interface pointer. HRESULT AudioDSPMediaBuffer::Create(long cbMaxLen, IMediaBuffer **ppBuffer) { HRESULT hr = S_OK; AudioDSPMediaBuffer *pBuffer = NULL; - if (ppBuffer == NULL) - { + if (ppBuffer == NULL) { return E_POINTER; } pBuffer = new AudioDSPMediaBuffer(cbMaxLen, hr); - if (pBuffer == NULL) - { + if (pBuffer == NULL) { hr = E_OUTOFMEMORY; } - if (SUCCEEDED(hr)) - { - *ppBuffer = pBuffer; - (*ppBuffer)->AddRef(); + if (SUCCEEDED(hr)) { + *ppBuffer = pBuffer; + (*ppBuffer)->AddRef(); } - if (pBuffer) - { + if (pBuffer) { pBuffer->Release(); } return hr; @@ -75,18 +69,15 @@ HRESULT AudioDSPMediaBuffer::Create(long cbMaxLen, IMediaBuffer **ppBuffer) // IUnknown methods. STDMETHODIMP AudioDSPMediaBuffer::QueryInterface(REFIID riid, void **ppv) { - if (ppv == NULL) - { + if (ppv == NULL) { return E_POINTER; } - else if (riid == IID_IMediaBuffer || riid == IID_IUnknown) - { + else if (riid == IID_IMediaBuffer || riid == IID_IUnknown) { *ppv = static_cast<IMediaBuffer *>(this); AddRef(); return S_OK; } - else - { + else { *ppv = NULL; return E_NOINTERFACE; } @@ -100,19 +91,17 @@ STDMETHODIMP_(ULONG) AudioDSPMediaBuffer::AddRef() STDMETHODIMP_(ULONG) AudioDSPMediaBuffer::Release() { LONG lRef = InterlockedDecrement(&m_nRefCount); - if (lRef == 0) - { + if (lRef == 0) { delete this; // m_cRef is no longer valid! Return lRef. } - return lRef; + return lRef; } // IMediaBuffer methods. STDMETHODIMP AudioDSPMediaBuffer::SetLength(DWORD cbLength) { - if (cbLength > m_cbMaxLength) - { + if (cbLength > m_cbMaxLength) { return E_INVALIDARG; } m_cbLength = cbLength; @@ -121,8 +110,7 @@ STDMETHODIMP AudioDSPMediaBuffer::SetLength(DWORD cbLength) STDMETHODIMP AudioDSPMediaBuffer::GetMaxLength(DWORD *pcbMaxLength) { - if (pcbMaxLength == NULL) - { + if (pcbMaxLength == NULL) { return E_POINTER; } *pcbMaxLength = m_cbMaxLength; @@ -132,16 +120,13 @@ STDMETHODIMP AudioDSPMediaBuffer::GetMaxLength(DWORD *pcbMaxLength) STDMETHODIMP AudioDSPMediaBuffer::GetBufferAndLength(BYTE **ppbBuffer, DWORD *pcbLength) { // Either parameter can be NULL, but not both. - if (ppbBuffer == NULL && pcbLength == NULL) - { + if (ppbBuffer == NULL && pcbLength == NULL) { return E_POINTER; } - if (ppbBuffer) - { + if (ppbBuffer) { *ppbBuffer = m_pbData; } - if (pcbLength) - { + if (pcbLength) { *pcbLength = m_cbLength; } return S_OK; diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.h b/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.h index a8d603b..486c273 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.h +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_mediabuffer.h @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -34,7 +34,7 @@ private: AudioDSPMediaBuffer(DWORD cbMaxLength, HRESULT& hr); ~AudioDSPMediaBuffer(); -public: +public: static HRESULT Create(long cbMaxLen, IMediaBuffer **ppBuffer); // IUnknown methods. diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_resampler.cxx b/plugins/pluginWinAudioDSP/plugin_audio_dsp_resampler.cxx index 3e5a291..4fe636f 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_resampler.cxx +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_resampler.cxx @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -37,268 +37,246 @@ static const UINT32 g_nBitsPerSample = 16; static HRESULT ProcessOutput(struct plugin_audio_dsp_resampler_s *resampler, IMFSample **ppSample); -typedef struct plugin_audio_dsp_resampler_s -{ - TMEDIA_DECLARE_RESAMPLER; - - bool bOpened; - - tsk_size_t in_size_samples; - tsk_size_t in_size_bytes; - tsk_size_t out_size_samples; - tsk_size_t out_size_bytes; - uint32_t in_channels; - uint32_t out_channels; - - LONGLONG rtStart; +typedef struct plugin_audio_dsp_resampler_s { + TMEDIA_DECLARE_RESAMPLER; + + bool bOpened; + + tsk_size_t in_size_samples; + tsk_size_t in_size_bytes; + tsk_size_t out_size_samples; + tsk_size_t out_size_bytes; + uint32_t in_channels; + uint32_t out_channels; + + LONGLONG rtStart; UINT64 rtDuration; - - IMFTransform* pMFT; - IMFSample *pSampleIn; - IMFSample *pSampleOut; + + IMFTransform* pMFT; + IMFSample *pSampleIn; + IMFSample *pSampleOut; } plugin_audio_dsp_resampler_t; // Doubango engine uses quality from [1 - 10]. static int plugin_audio_dsp_resampler_open(tmedia_resampler_t* self, uint32_t in_freq, uint32_t out_freq, uint32_t frame_duration, uint32_t in_channels, uint32_t out_channels, uint32_t quality) { - plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; - - IMFMediaType* pTypeIn = NULL; - IMFMediaType* pTypeOut = NULL; - IWMResamplerProps* pProps = NULL; - HRESULT hr = S_OK; - - if(in_channels != 1 && in_channels != 2) - { - TSK_DEBUG_ERROR("%d not valid as input channel", in_channels); - CHECK_HR(hr = E_INVALIDARG); - } - if(out_channels != 1 && out_channels != 2) - { - TSK_DEBUG_ERROR("%d not valid as output channel", out_channels); - CHECK_HR(hr = E_INVALIDARG); - } - - if(resampler->bOpened) - { - TSK_DEBUG_ERROR("Resampler already opened"); - CHECK_HR(hr = E_FAIL); - } - - resampler->in_size_samples = ((in_freq * frame_duration) / 1000) << (in_channels == 2 ? 1 : 0); - resampler->out_size_samples = ((out_freq * frame_duration) / 1000) << (out_channels == 2 ? 1 : 0); - resampler->in_channels = in_channels; - resampler->out_channels = out_channels; - - resampler->in_size_bytes = (resampler->in_size_samples * (g_nBitsPerSample >> 3)); - resampler->out_size_bytes = (resampler->out_size_samples * (g_nBitsPerSample >> 3)); - - resampler->rtStart = 0; - resampler->rtDuration = PLUGIN_AUDIO_DSP_MILLIS_TO_100NS(frame_duration); // milliseconds -> 100ns - - CHECK_HR(hr = CoCreateInstance(CLSID_CResamplerMediaObject, NULL, - CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&resampler->pMFT))); - - CHECK_HR(hr = AudioDSPUtils::CreatePCMAudioType(in_freq, g_nBitsPerSample, in_channels, &pTypeIn)); - CHECK_HR(hr = AudioDSPUtils::CreatePCMAudioType(out_freq, g_nBitsPerSample, out_channels, &pTypeOut)); - - CHECK_HR(hr = resampler->pMFT->SetInputType(0, pTypeIn, 0)); - CHECK_HR(hr = resampler->pMFT->SetOutputType(0, pTypeOut, 0)); - - CHECK_HR(hr = resampler->pMFT->QueryInterface(IID_PPV_ARGS(&pProps))); + plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; + + IMFMediaType* pTypeIn = NULL; + IMFMediaType* pTypeOut = NULL; + IWMResamplerProps* pProps = NULL; + HRESULT hr = S_OK; + + if(in_channels != 1 && in_channels != 2) { + TSK_DEBUG_ERROR("%d not valid as input channel", in_channels); + CHECK_HR(hr = E_INVALIDARG); + } + if(out_channels != 1 && out_channels != 2) { + TSK_DEBUG_ERROR("%d not valid as output channel", out_channels); + CHECK_HR(hr = E_INVALIDARG); + } + + if(resampler->bOpened) { + TSK_DEBUG_ERROR("Resampler already opened"); + CHECK_HR(hr = E_FAIL); + } + + resampler->in_size_samples = ((in_freq * frame_duration) / 1000) << (in_channels == 2 ? 1 : 0); + resampler->out_size_samples = ((out_freq * frame_duration) / 1000) << (out_channels == 2 ? 1 : 0); + resampler->in_channels = in_channels; + resampler->out_channels = out_channels; + + resampler->in_size_bytes = (resampler->in_size_samples * (g_nBitsPerSample >> 3)); + resampler->out_size_bytes = (resampler->out_size_samples * (g_nBitsPerSample >> 3)); + + resampler->rtStart = 0; + resampler->rtDuration = PLUGIN_AUDIO_DSP_MILLIS_TO_100NS(frame_duration); // milliseconds -> 100ns + + CHECK_HR(hr = CoCreateInstance(CLSID_CResamplerMediaObject, NULL, + CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&resampler->pMFT))); + + CHECK_HR(hr = AudioDSPUtils::CreatePCMAudioType(in_freq, g_nBitsPerSample, in_channels, &pTypeIn)); + CHECK_HR(hr = AudioDSPUtils::CreatePCMAudioType(out_freq, g_nBitsPerSample, out_channels, &pTypeOut)); + + CHECK_HR(hr = resampler->pMFT->SetInputType(0, pTypeIn, 0)); + CHECK_HR(hr = resampler->pMFT->SetOutputType(0, pTypeOut, 0)); + + CHECK_HR(hr = resampler->pMFT->QueryInterface(IID_PPV_ARGS(&pProps))); CHECK_HR(hr = pProps->SetHalfFilterLength((quality * PLUGIN_AUDIO_DSP_RESAMPLER_MAX_QUALITY) / 10)); // [1 - 10] -> [1 - 60] - CHECK_HR(hr = resampler->pMFT->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, NULL)); + CHECK_HR(hr = resampler->pMFT->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, NULL)); CHECK_HR(hr = resampler->pMFT->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL)); CHECK_HR(hr = resampler->pMFT->ProcessMessage(MFT_MESSAGE_NOTIFY_START_OF_STREAM, NULL)); bail: - resampler->bOpened = SUCCEEDED(hr); - if(!resampler->bOpened) - { - SafeRelease(&resampler->pMFT); - } - SafeRelease(&pTypeIn); - SafeRelease(&pTypeOut); - SafeRelease(&pProps); - return resampler->bOpened ? 0 : -1; + resampler->bOpened = SUCCEEDED(hr); + if(!resampler->bOpened) { + SafeRelease(&resampler->pMFT); + } + SafeRelease(&pTypeIn); + SafeRelease(&pTypeOut); + SafeRelease(&pProps); + return resampler->bOpened ? 0 : -1; } static tsk_size_t plugin_audio_dsp_resampler_process(tmedia_resampler_t* self, const uint16_t* in_data, tsk_size_t in_size, uint16_t* out_data, tsk_size_t out_size) { - plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; - - HRESULT hr = S_OK; - tsk_size_t retSize = 0; - - if(!resampler || !out_data) - { - CHECK_HR(hr = E_POINTER); - } - - if(!resampler->bOpened) - { - TSK_DEBUG_ERROR("Resampler not opened"); - CHECK_HR(hr = E_FAIL); - } - - if(in_size != resampler->in_size_samples) - { - TSK_DEBUG_ERROR("Input data has wrong size"); - CHECK_HR(hr = E_FAIL); - } - - if(out_size < resampler->out_size_samples) - { - TSK_DEBUG_ERROR("Output data is too short"); - CHECK_HR(hr = E_FAIL); - } - - IMFMediaBuffer* pBufferIn = NULL; - IMFMediaBuffer* pBufferOut = NULL; - IMFSample *pSampleOut = NULL; - BYTE* pBufferPtr = NULL; - - if(!resampler->pSampleIn) - { - CHECK_HR(hr = AudioDSPUtils::CreateMediaSample(resampler->in_size_bytes, &resampler->pSampleIn)); - hr = resampler->pSampleIn->GetBufferByIndex(0, &pBufferIn); - if(FAILED(hr)) - { - SafeRelease(&resampler->pSampleIn); - CHECK_HR(hr); - } - } - else - { - DWORD dwMaxLength = 0; - CHECK_HR(hr = resampler->pSampleIn->GetBufferByIndex(0, &pBufferIn)); - CHECK_HR(hr = pBufferIn->GetMaxLength(&dwMaxLength)); - if(dwMaxLength < resampler->in_size_bytes) - { - CHECK_HR(hr = resampler->pSampleIn->RemoveAllBuffers()); - SafeRelease(&pBufferIn); - CHECK_HR(hr = MFCreateMemoryBuffer(resampler->in_size_bytes, &pBufferIn)); - CHECK_HR(hr = resampler->pSampleIn->AddBuffer(pBufferIn)); - } - } - - CHECK_HR(hr = pBufferIn->Lock(&pBufferPtr, NULL, NULL)); - memcpy(pBufferPtr, in_data, resampler->in_size_bytes); - CHECK_HR(hr = pBufferIn->Unlock()); - CHECK_HR(hr = pBufferIn->SetCurrentLength(resampler->in_size_bytes)); - - CHECK_HR(hr = resampler->pSampleIn->SetSampleDuration(resampler->rtDuration)); - CHECK_HR(hr = resampler->pSampleIn->SetSampleTime(resampler->rtStart)); - - // Process input - hr = resampler->pMFT->ProcessInput(0, resampler->pSampleIn, 0); - if(hr == MF_E_NOTACCEPTING) - { - hr = S_OK; - } - CHECK_HR(hr); - - resampler->rtStart += resampler->rtDuration; - - // Process output - CHECK_HR(hr = ProcessOutput(resampler, &pSampleOut)); - if(pSampleOut) - { - CHECK_HR(hr = pSampleOut->GetBufferByIndex(0, &pBufferOut)); - - BYTE* pBufferOutPtr = NULL; - DWORD dwDataLength = 0; - CHECK_HR(hr = pBufferOut->GetCurrentLength(&dwDataLength)); - //if(dwDataLength == resampler->out_size_bytes) - { - CHECK_HR(hr = pBufferOut->Lock(&pBufferOutPtr, NULL, NULL)); - { - memcpy(out_data, pBufferOutPtr, TSK_MIN(dwDataLength, resampler->out_size_bytes)); - if(dwDataLength < resampler->out_size_bytes) - { - TSK_DEBUG_INFO("[MS Resampler DSP] Output too short filling with silence"); - memset(&((uint8_t*)out_data)[dwDataLength], 0, (resampler->out_size_bytes - dwDataLength)); - } - retSize = (tsk_size_t)resampler->out_size_bytes; - } - CHECK_HR(hr = pBufferOut->Unlock()); - } - } - - + plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; + + HRESULT hr = S_OK; + tsk_size_t retSize = 0; + + if(!resampler || !out_data) { + CHECK_HR(hr = E_POINTER); + } + + if(!resampler->bOpened) { + TSK_DEBUG_ERROR("Resampler not opened"); + CHECK_HR(hr = E_FAIL); + } + + if(in_size != resampler->in_size_samples) { + TSK_DEBUG_ERROR("Input data has wrong size"); + CHECK_HR(hr = E_FAIL); + } + + if(out_size < resampler->out_size_samples) { + TSK_DEBUG_ERROR("Output data is too short"); + CHECK_HR(hr = E_FAIL); + } + + IMFMediaBuffer* pBufferIn = NULL; + IMFMediaBuffer* pBufferOut = NULL; + IMFSample *pSampleOut = NULL; + BYTE* pBufferPtr = NULL; + + if(!resampler->pSampleIn) { + CHECK_HR(hr = AudioDSPUtils::CreateMediaSample(resampler->in_size_bytes, &resampler->pSampleIn)); + hr = resampler->pSampleIn->GetBufferByIndex(0, &pBufferIn); + if(FAILED(hr)) { + SafeRelease(&resampler->pSampleIn); + CHECK_HR(hr); + } + } + else { + DWORD dwMaxLength = 0; + CHECK_HR(hr = resampler->pSampleIn->GetBufferByIndex(0, &pBufferIn)); + CHECK_HR(hr = pBufferIn->GetMaxLength(&dwMaxLength)); + if(dwMaxLength < resampler->in_size_bytes) { + CHECK_HR(hr = resampler->pSampleIn->RemoveAllBuffers()); + SafeRelease(&pBufferIn); + CHECK_HR(hr = MFCreateMemoryBuffer(resampler->in_size_bytes, &pBufferIn)); + CHECK_HR(hr = resampler->pSampleIn->AddBuffer(pBufferIn)); + } + } + + CHECK_HR(hr = pBufferIn->Lock(&pBufferPtr, NULL, NULL)); + memcpy(pBufferPtr, in_data, resampler->in_size_bytes); + CHECK_HR(hr = pBufferIn->Unlock()); + CHECK_HR(hr = pBufferIn->SetCurrentLength(resampler->in_size_bytes)); + + CHECK_HR(hr = resampler->pSampleIn->SetSampleDuration(resampler->rtDuration)); + CHECK_HR(hr = resampler->pSampleIn->SetSampleTime(resampler->rtStart)); + + // Process input + hr = resampler->pMFT->ProcessInput(0, resampler->pSampleIn, 0); + if(hr == MF_E_NOTACCEPTING) { + hr = S_OK; + } + CHECK_HR(hr); + + resampler->rtStart += resampler->rtDuration; + + // Process output + CHECK_HR(hr = ProcessOutput(resampler, &pSampleOut)); + if(pSampleOut) { + CHECK_HR(hr = pSampleOut->GetBufferByIndex(0, &pBufferOut)); + + BYTE* pBufferOutPtr = NULL; + DWORD dwDataLength = 0; + CHECK_HR(hr = pBufferOut->GetCurrentLength(&dwDataLength)); + //if(dwDataLength == resampler->out_size_bytes) + { + CHECK_HR(hr = pBufferOut->Lock(&pBufferOutPtr, NULL, NULL)); + { + memcpy(out_data, pBufferOutPtr, TSK_MIN(dwDataLength, resampler->out_size_bytes)); + if(dwDataLength < resampler->out_size_bytes) { + TSK_DEBUG_INFO("[MS Resampler DSP] Output too short filling with silence"); + memset(&((uint8_t*)out_data)[dwDataLength], 0, (resampler->out_size_bytes - dwDataLength)); + } + retSize = (tsk_size_t)resampler->out_size_bytes; + } + CHECK_HR(hr = pBufferOut->Unlock()); + } + } + + bail: - SafeRelease(&pBufferIn); - SafeRelease(&pBufferOut); - SafeRelease(&pSampleOut); - - return retSize; + SafeRelease(&pBufferIn); + SafeRelease(&pBufferOut); + SafeRelease(&pSampleOut); + + return retSize; } static int plugin_audio_dsp_resampler_close(tmedia_resampler_t* self) { - plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; + plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; - HRESULT hr = S_OK; + HRESULT hr = S_OK; + + if(resampler->pMFT) { + hr = resampler->pMFT->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, NULL); + } - if(resampler->pMFT) - { - hr = resampler->pMFT->ProcessMessage(MFT_MESSAGE_NOTIFY_END_OF_STREAM, NULL); - } + SafeRelease(&resampler->pMFT); + SafeRelease(&resampler->pSampleIn); + SafeRelease(&resampler->pSampleOut); - SafeRelease(&resampler->pMFT); - SafeRelease(&resampler->pSampleIn); - SafeRelease(&resampler->pSampleOut); + resampler->bOpened = false; - resampler->bOpened = false; - - return 0; + return 0; } static HRESULT ProcessOutput(plugin_audio_dsp_resampler_t *resampler, IMFSample **ppSample) { - *ppSample = NULL; + *ppSample = NULL; IMFMediaBuffer* pBufferOut = NULL; DWORD dwStatus; - HRESULT hr = S_OK; + HRESULT hr = S_OK; MFT_OUTPUT_DATA_BUFFER mftOutputData = { 0 }; - if(!resampler || !ppSample) - { - CHECK_HR(hr = E_POINTER); - } - - if(!resampler->pSampleOut) - { - CHECK_HR(hr = AudioDSPUtils::CreateMediaSample(resampler->out_size_bytes, &resampler->pSampleOut)); - hr = resampler->pSampleOut->GetBufferByIndex(0, &pBufferOut); - if(FAILED(hr)) - { - SafeRelease(&resampler->pSampleOut); - CHECK_HR(hr); - } - } - else - { - DWORD dwMaxLength = 0; - CHECK_HR(hr = resampler->pSampleOut->GetBufferByIndex(0, &pBufferOut)); - CHECK_HR(hr = pBufferOut->GetMaxLength(&dwMaxLength)); - if(dwMaxLength < resampler->out_size_bytes) - { - CHECK_HR(hr = resampler->pSampleOut->RemoveAllBuffers()); - SafeRelease(&pBufferOut); - CHECK_HR(hr = MFCreateMemoryBuffer(resampler->out_size_bytes, &pBufferOut)); - CHECK_HR(hr = resampler->pSampleOut->AddBuffer(pBufferOut)); - } - } - - CHECK_HR(hr = pBufferOut->SetCurrentLength(0)); - + if(!resampler || !ppSample) { + CHECK_HR(hr = E_POINTER); + } + + if(!resampler->pSampleOut) { + CHECK_HR(hr = AudioDSPUtils::CreateMediaSample(resampler->out_size_bytes, &resampler->pSampleOut)); + hr = resampler->pSampleOut->GetBufferByIndex(0, &pBufferOut); + if(FAILED(hr)) { + SafeRelease(&resampler->pSampleOut); + CHECK_HR(hr); + } + } + else { + DWORD dwMaxLength = 0; + CHECK_HR(hr = resampler->pSampleOut->GetBufferByIndex(0, &pBufferOut)); + CHECK_HR(hr = pBufferOut->GetMaxLength(&dwMaxLength)); + if(dwMaxLength < resampler->out_size_bytes) { + CHECK_HR(hr = resampler->pSampleOut->RemoveAllBuffers()); + SafeRelease(&pBufferOut); + CHECK_HR(hr = MFCreateMemoryBuffer(resampler->out_size_bytes, &pBufferOut)); + CHECK_HR(hr = resampler->pSampleOut->AddBuffer(pBufferOut)); + } + } + + CHECK_HR(hr = pBufferOut->SetCurrentLength(0)); + //Set the output sample mftOutputData.pSample = resampler->pSampleOut; //Set the output id @@ -306,16 +284,14 @@ static HRESULT ProcessOutput(plugin_audio_dsp_resampler_t *resampler, IMFSample //Generate the output sample hr = resampler->pMFT->ProcessOutput(0, 1, &mftOutputData, &dwStatus); - if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) - { + if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) { hr = S_OK; goto bail; } // TODO: Handle MF_E_TRANSFORM_STREAM_CHANGE - if (FAILED(hr)) - { + if (FAILED(hr)) { goto bail; } @@ -336,53 +312,49 @@ bail: /* constructor */ static tsk_object_t* plugin_audio_dsp_resampler_ctor(tsk_object_t * self, va_list * app) { - plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; - if(resampler) - { - AudioDSPUtils::Startup(); - - /* init base */ - tmedia_resampler_init(TMEDIA_RESAMPLER(resampler)); - /* init self */ - } - return self; + plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; + if(resampler) { + AudioDSPUtils::Startup(); + + /* init base */ + tmedia_resampler_init(TMEDIA_RESAMPLER(resampler)); + /* init self */ + } + return self; } /* destructor */ static tsk_object_t* plugin_audio_dsp_resampler_dtor(tsk_object_t * self) -{ - plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; - if(resampler) - { - /* deinit base */ - tmedia_resampler_deinit(TMEDIA_RESAMPLER(resampler)); - /* deinit self */ - // tmedia_resampler_deinit() already closed the resampler and freed the resources...but do it again - SafeRelease(&resampler->pMFT); - SafeRelease(&resampler->pSampleIn); - SafeRelease(&resampler->pSampleOut); - - TSK_DEBUG_INFO("*** MS Audio Resampler DSP (plugin) destroyed ***"); - } - - return self; +{ + plugin_audio_dsp_resampler_t *resampler = (plugin_audio_dsp_resampler_t *)self; + if(resampler) { + /* deinit base */ + tmedia_resampler_deinit(TMEDIA_RESAMPLER(resampler)); + /* deinit self */ + // tmedia_resampler_deinit() already closed the resampler and freed the resources...but do it again + SafeRelease(&resampler->pMFT); + SafeRelease(&resampler->pSampleIn); + SafeRelease(&resampler->pSampleOut); + + TSK_DEBUG_INFO("*** MS Audio Resampler DSP (plugin) destroyed ***"); + } + + return self; } /* object definition */ -static const tsk_object_def_t plugin_audio_dsp_resampler_def_s = -{ - sizeof(plugin_audio_dsp_resampler_t), - plugin_audio_dsp_resampler_ctor, - plugin_audio_dsp_resampler_dtor, - tsk_null, +static const tsk_object_def_t plugin_audio_dsp_resampler_def_s = { + sizeof(plugin_audio_dsp_resampler_t), + plugin_audio_dsp_resampler_ctor, + plugin_audio_dsp_resampler_dtor, + tsk_null, }; /* plugin definition*/ -static const tmedia_resampler_plugin_def_t plugin_audio_dsp_resampler_plugin_def_s = -{ - &plugin_audio_dsp_resampler_def_s, - - "MS Audio Resampler DSP", /* http://msdn.microsoft.com/en-us/library/windows/desktop/ff819070(v=vs.85).aspx */ - - plugin_audio_dsp_resampler_open, - plugin_audio_dsp_resampler_process, - plugin_audio_dsp_resampler_close, +static const tmedia_resampler_plugin_def_t plugin_audio_dsp_resampler_plugin_def_s = { + &plugin_audio_dsp_resampler_def_s, + + "MS Audio Resampler DSP", /* http://msdn.microsoft.com/en-us/library/windows/desktop/ff819070(v=vs.85).aspx */ + + plugin_audio_dsp_resampler_open, + plugin_audio_dsp_resampler_process, + plugin_audio_dsp_resampler_close, }; const tmedia_resampler_plugin_def_t *plugin_audio_dsp_resampler_plugin_def_t = &plugin_audio_dsp_resampler_plugin_def_s; diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.cxx b/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.cxx index 67cf3cf..d549336 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.cxx +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.cxx @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -28,22 +28,20 @@ bool AudioDSPUtils::g_bStarted = false; HRESULT AudioDSPUtils::Startup() { - if(!g_bStarted) - { - HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); - if(SUCCEEDED(hr) || hr == 0x80010106) // 0x80010106 when called from managed code (e.g. Boghe) - More info: http://support.microsoft.com/kb/824480 - { - hr = MFStartup(MF_VERSION); - } - g_bStarted = SUCCEEDED(hr); - return hr; - } - return S_OK; + if(!g_bStarted) { + HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + if(SUCCEEDED(hr) || hr == 0x80010106) { // 0x80010106 when called from managed code (e.g. Boghe) - More info: http://support.microsoft.com/kb/824480 + hr = MFStartup(MF_VERSION); + } + g_bStarted = SUCCEEDED(hr); + return hr; + } + return S_OK; } HRESULT AudioDSPUtils::Shutdown() { - return S_OK; + return S_OK; } HRESULT AudioDSPUtils::CreatePCMAudioType( @@ -51,7 +49,7 @@ HRESULT AudioDSPUtils::CreatePCMAudioType( UINT32 bitsPerSample, // Bits per sample UINT32 cChannels, // Number of channels IMFMediaType **ppType // Receives a pointer to the media type. - ) +) { HRESULT hr = S_OK; @@ -62,27 +60,27 @@ HRESULT AudioDSPUtils::CreatePCMAudioType( UINT32 bytesPerSecond = blockAlign * sampleRate; // Create the empty media type. - CHECK_HR(hr = MFCreateMediaType(&pType)); + CHECK_HR(hr = MFCreateMediaType(&pType)); // Set attributes on the type. CHECK_HR(hr = pType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio)); - - CHECK_HR(hr = pType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, cChannels)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, sampleRate)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, blockAlign)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, bytesPerSecond)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, bitsPerSample)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE)); - - CHECK_HR(hr = pType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE)); - + + CHECK_HR(hr = pType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, cChannels)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, sampleRate)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, blockAlign)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, bytesPerSecond)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, bitsPerSample)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE)); + + CHECK_HR(hr = pType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, TRUE)); + *ppType = pType; (*ppType)->AddRef(); @@ -92,24 +90,23 @@ bail: } HRESULT AudioDSPUtils::CreateMediaSample( - DWORD cbData, // Maximum buffer size - IMFSample **ppSample // Receives the sample + DWORD cbData, // Maximum buffer size + IMFSample **ppSample // Receives the sample ) { - HRESULT hr = S_OK; + HRESULT hr = S_OK; - if(!ppSample) - { - CHECK_HR(hr = E_POINTER); - } + if(!ppSample) { + CHECK_HR(hr = E_POINTER); + } IMFSample *pSample = NULL; IMFMediaBuffer *pBuffer = NULL; - CHECK_HR(hr = MFCreateSample(&pSample)); - CHECK_HR(hr = MFCreateMemoryBuffer(cbData, &pBuffer)); + CHECK_HR(hr = MFCreateSample(&pSample)); + CHECK_HR(hr = MFCreateMemoryBuffer(cbData, &pBuffer)); CHECK_HR(hr = pSample->AddBuffer(pBuffer)); - + *ppSample = pSample; (*ppSample)->AddRef(); @@ -120,38 +117,37 @@ bail: } HRESULT AudioDSPUtils::MoInitMediaType( - UINT32 sampleRate, // Samples per second - UINT32 bitsPerSample, // Bits per sample - UINT32 cChannels, // Number of channels - DMO_MEDIA_TYPE *pType // The media type to initialize. Must be freed using MoFreeMediaType. - ) + UINT32 sampleRate, // Samples per second + UINT32 bitsPerSample, // Bits per sample + UINT32 cChannels, // Number of channels + DMO_MEDIA_TYPE *pType // The media type to initialize. Must be freed using MoFreeMediaType. +) { - HRESULT hr = S_OK; - WAVEFORMATEX *pWAV = NULL; + HRESULT hr = S_OK; + WAVEFORMATEX *pWAV = NULL; - if(!pType) - { - CHECK_HR(hr = E_POINTER); - } + if(!pType) { + CHECK_HR(hr = E_POINTER); + } - pType->majortype = MEDIATYPE_Audio; - pType->subtype = MEDIASUBTYPE_PCM; - pType->lSampleSize = 0; - pType->bFixedSizeSamples = TRUE; - pType->bTemporalCompression = FALSE; - pType->formattype = FORMAT_WaveFormatEx; + pType->majortype = MEDIATYPE_Audio; + pType->subtype = MEDIASUBTYPE_PCM; + pType->lSampleSize = 0; + pType->bFixedSizeSamples = TRUE; + pType->bTemporalCompression = FALSE; + pType->formattype = FORMAT_WaveFormatEx; - CHECK_HR(hr = ::MoInitMediaType(pType, sizeof(WAVEFORMATEX))); + CHECK_HR(hr = ::MoInitMediaType(pType, sizeof(WAVEFORMATEX))); - pWAV = (WAVEFORMATEX*)pType->pbFormat; + pWAV = (WAVEFORMATEX*)pType->pbFormat; pWAV->wFormatTag = WAVE_FORMAT_PCM; pWAV->nChannels = 1; pWAV->nSamplesPerSec = sampleRate; - pWAV->nBlockAlign = cChannels * (bitsPerSample >> 3); + pWAV->nBlockAlign = cChannels * (bitsPerSample >> 3); pWAV->nAvgBytesPerSec = pWAV->nBlockAlign * pWAV->nSamplesPerSec; pWAV->wBitsPerSample = bitsPerSample; pWAV->cbSize = 0; bail: - return hr; + return hr; } diff --git a/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.h b/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.h index 7daff31..b2236f2 100755 --- a/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.h +++ b/plugins/pluginWinAudioDSP/plugin_audio_dsp_utils.h @@ -1,18 +1,18 @@ /* Copyright (C) 2013 Mamadou DIOP * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. */ @@ -40,32 +40,32 @@ (*ppT)->Release(); \ *ppT = NULL; \ } \ -} +} class AudioDSPUtils { public: - static HRESULT Startup(); - static HRESULT Shutdown(); - static HRESULT CreatePCMAudioType( - UINT32 sampleRate, // Samples per second - UINT32 bitsPerSample, // Bits per sample - UINT32 cChannels, // Number of channels - IMFMediaType **ppType // Receives a pointer to the media type. + static HRESULT Startup(); + static HRESULT Shutdown(); + static HRESULT CreatePCMAudioType( + UINT32 sampleRate, // Samples per second + UINT32 bitsPerSample, // Bits per sample + UINT32 cChannels, // Number of channels + IMFMediaType **ppType // Receives a pointer to the media type. + ); + static HRESULT CreateMediaSample( + DWORD cbData, // Maximum buffer size + IMFSample **ppSample // Receives the sample + ); + static HRESULT MoInitMediaType( + UINT32 sampleRate, // Samples per second + UINT32 bitsPerSample, // Bits per sample + UINT32 cChannels, // Number of channels + DMO_MEDIA_TYPE *pType // The media type to initialize. Must be freed using MoFreeMediaType. ); - static HRESULT CreateMediaSample( - DWORD cbData, // Maximum buffer size - IMFSample **ppSample // Receives the sample - ); - static HRESULT MoInitMediaType( - UINT32 sampleRate, // Samples per second - UINT32 bitsPerSample, // Bits per sample - UINT32 cChannels, // Number of channels - DMO_MEDIA_TYPE *pType // The media type to initialize. Must be freed using MoFreeMediaType. - ); private: - static bool g_bStarted; + static bool g_bStarted; }; #endif /* PLUGIN_AUDIO_DSP_UTILS_H */ |