Implement SetPitch Support

This is hard as hell I ever had done. The upside is SetPitch function no
longer fail for DM3DScript sample! 🎆

Tested 12KHz, 48KHz, and 96KHz conversion to ratio and back to hertz
with success.

Any titles using SetPitch in the past should now play audio nicely.
This commit is contained in:
RadWolfie 2017-10-26 01:40:54 -05:00
parent 02a76ffc8d
commit 7fc65b57ce
2 changed files with 24 additions and 24 deletions

View File

@ -1195,20 +1195,12 @@ HRESULT WINAPI XTL::EMUPATCH(IDirectSoundBuffer_SetPitch)
{
FUNC_EXPORTS;
enterCriticalSection;
LOG_FUNC_BEGIN
LOG_FUNC_ARG(pThis)
LOG_FUNC_ARG(lPitch)
LOG_FUNC_END;
// TODO: Translate params, then make the PC DirectSound call
LOG_UNIMPLEMENTED_DSOUND();
leaveCriticalSection;
return DS_OK;
return HybridDirectSoundBuffer_SetPitch(pThis->EmuDirectSoundBuffer8, lPitch);
}
// ******************************************************************
@ -3043,20 +3035,12 @@ HRESULT WINAPI XTL::EMUPATCH(CDirectSoundStream_SetPitch)
{
FUNC_EXPORTS;
enterCriticalSection;
LOG_FUNC_BEGIN
LOG_FUNC_ARG(pThis)
LOG_FUNC_ARG(lPitch)
LOG_FUNC_END;
HRESULT hRet = S_OK;
LOG_UNIMPLEMENTED_DSOUND();
leaveCriticalSection;
return hRet;
return HybridDirectSoundBuffer_SetPitch(pThis->EmuDirectSoundBuffer8, lPitch);
}
// ******************************************************************

View File

@ -1139,8 +1139,7 @@ inline HRESULT HybridDirectSoundBuffer_SetOutputBuffer(
return DS_OK;
}
//TODO: PC DirectSound does not have SetPitch method function.
*/
//IDirectSoundStream
//IDirectSoundBuffer
inline HRESULT HybridDirectSoundBuffer_SetPitch(
@ -1148,12 +1147,29 @@ inline HRESULT HybridDirectSoundBuffer_SetPitch(
LONG lPitch)
{
// TODO: Translate params, then make the PC DirectSound call
// Convert pitch back to frequency
if (lPitch == 0) {
lPitch = 48000; // NOTE: pitch = 0 is equal to 48 KHz.
} else {
lPitch = static_cast<LONG>(exp((lPitch / 4096.0f) * log(2)) * 48000.0f);
}
return DS_OK;
/* For research purpose of how to convert frequency to pitch and back to frequency.
// Edit hertz variable to see the result.
float hertz = 12000.0f;
float hertzRatio = 48000.0f;
float pitchRatio = 4096.0f;
// Convert hertz to pitch
float pitch = log2(hertz / hertzRatio) * pitchRatio;
// Convert pitch to hertz
hertz = exp((pitch / pitchRatio) * log(2)) * hertzRatio;*/
RETURN_RESULT_CHECK(pDSBuffer->SetFrequency(lPitch));
}
//TODO: PC DirectSound does not have SetPitch method function.
/*
//Only has one function, this is not a requirement.
//IDirectSoundBuffer
inline HRESULT HybridDirectSoundBuffer_SetPlayRegion(