Clean up math functions

- Remove checking for standard functions from the build system
- Prefix all invocations with std::
- Replace suffixed functions with unprefixed versions
- Include <cmath> in all files that use it and remove the global include

e.g. floorf(x) -> std::floor(x)
This commit is contained in:
Martin Natano
2023-04-19 19:31:40 +02:00
parent f39ed52dbf
commit b68ca517e6
111 changed files with 1831 additions and 1785 deletions
@@ -20,6 +20,7 @@
#pragma comment(lib, "xinput.lib")
#endif
#include <cmath>
#include <XInput.h>
#include <WbemIdl.h>
#include <OleAuto.h>
@@ -72,13 +73,13 @@ static BOOL IsXInputDevice(const GUID* pGuidProductFromDirectInput)
bstrClassName = SysAllocString(L"Win32_PNPEntity"); if (bstrClassName == nullptr) goto LCleanup;
bstrDeviceID = SysAllocString(L"DeviceID"); if (bstrDeviceID == nullptr) goto LCleanup;
// Connect to WMI
// Connect to WMI
hr = pIWbemLocator->ConnectServer(bstrNamespace, nullptr, nullptr, 0L,
0L, nullptr, nullptr, &pIWbemServices);
if (FAILED(hr) || pIWbemServices == nullptr)
goto LCleanup;
// Switch security level to IMPERSONATE.
// Switch security level to IMPERSONATE.
CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr,
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE);
@@ -103,7 +104,7 @@ static BOOL IsXInputDevice(const GUID* pGuidProductFromDirectInput)
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != nullptr)
{
// Check if the device ID contains "IG_". If it does, then it's an XInput device
// This information can not be found from DirectInput
// This information can not be found from DirectInput
if (wcsstr(var.bstrVal, L"IG_"))
{
// If it does, then get the VID/PID from var.bstrVal
@@ -499,7 +500,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
{ neg = JOY_AUX_1; pos = JOY_AUX_2; val = state.rglSlider[0]; }
else if( in.ofs == DIJOFS_SLIDER(1) )
{ neg = JOY_AUX_3; pos = JOY_AUX_4; val = state.rglSlider[1]; }
else LOG->MapLog( "unknown input",
else LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs );
@@ -586,7 +587,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
ButtonPressed( DeviceInput(dev, pos, 0, tm) );
}
}
else LOG->MapLog( "unknown input",
else LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset, %i",
device.m_sName.c_str(), in.ofs );
break;
@@ -651,7 +652,7 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
if( in.ofs == DIMOFS_BUTTON0 ) mouseInput = MOUSE_LEFT;
else if( in.ofs == DIMOFS_BUTTON1 ) mouseInput = MOUSE_RIGHT;
else if( in.ofs == DIMOFS_BUTTON2 ) mouseInput = MOUSE_MIDDLE;
else LOG->MapLog( "unknown input",
else LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset [button], %i",
device.m_sName.c_str(), in.ofs );
ButtonPressed( DeviceInput(dev, mouseInput, !!evtbuf[i].dwData, tm) );
@@ -723,7 +724,7 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
}
}
}
else LOG->MapLog( "unknown input",
else LOG->MapLog( "unknown input",
"Mouse '%s' is returning an unknown mouse offset [axis], %i",
device.m_sName.c_str(), in.ofs );
}
@@ -738,10 +739,10 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
else if( in.ofs == DIJOFS_RZ ) { up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; }
else if( in.ofs == DIJOFS_SLIDER(0) ) { up = JOY_AUX_1; down = JOY_AUX_2; }
else if( in.ofs == DIJOFS_SLIDER(1) ) { up = JOY_AUX_3; down = JOY_AUX_4; }
else LOG->MapLog( "unknown input",
else LOG->MapLog( "unknown input",
"Controller '%s' is returning an unknown joystick offset, %i",
device.m_sName.c_str(), in.ofs );
float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f );
if(GamePreferences::m_AxisFix)
{
@@ -783,7 +784,7 @@ void InputHandler_DInput::UpdateXInput( XIDevice &device, const RageTimer &tm )
// map joysticks
float lx = 0.f;
float ly = 0.f;
if (sqrt(pow(state.Gamepad.sThumbLX, 2) + pow(state.Gamepad.sThumbLY, 2)) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
if (std::sqrt(std::pow(state.Gamepad.sThumbLX, 2) + std::pow(state.Gamepad.sThumbLY, 2)) > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
{
lx = SCALE(state.Gamepad.sThumbLX + 0.f, XINPUT_GAMEPAD_THUMB_MIN + 0.f, XINPUT_GAMEPAD_THUMB_MAX + 0.f, -1.0f, 1.0f);
ly = SCALE(state.Gamepad.sThumbLY + 0.f, XINPUT_GAMEPAD_THUMB_MIN + 0.f, XINPUT_GAMEPAD_THUMB_MAX + 0.f, -1.0f, 1.0f);
@@ -795,7 +796,7 @@ void InputHandler_DInput::UpdateXInput( XIDevice &device, const RageTimer &tm )
float rx = 0.f;
float ry = 0.f;
if (sqrt(pow(state.Gamepad.sThumbRX, 2) + pow(state.Gamepad.sThumbRY, 2)) > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
if (std::sqrt(std::pow(state.Gamepad.sThumbRX, 2) + std::pow(state.Gamepad.sThumbRY, 2)) > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
{
rx = SCALE(state.Gamepad.sThumbRX + 0.f, XINPUT_GAMEPAD_THUMB_MIN + 0.f, XINPUT_GAMEPAD_THUMB_MAX + 0.f, -1.0f, 1.0f);
ry = SCALE(state.Gamepad.sThumbRY + 0.f, XINPUT_GAMEPAD_THUMB_MIN + 0.f, XINPUT_GAMEPAD_THUMB_MAX + 0.f, -1.0f, 1.0f);
@@ -816,7 +817,7 @@ void InputHandler_DInput::UpdateXInput( XIDevice &device, const RageTimer &tm )
ButtonPressed(DeviceInput(device.dev, JOY_BUTTON_8, !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB), tm));
ButtonPressed(DeviceInput(device.dev, JOY_BUTTON_9, !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER), tm));
ButtonPressed(DeviceInput(device.dev, JOY_BUTTON_10, !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER), tm));
// map triggers to buttons
ButtonPressed(DeviceInput(device.dev, JOY_BUTTON_11, !!(state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD), tm));
ButtonPressed(DeviceInput(device.dev, JOY_BUTTON_12, !!(state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD), tm));
@@ -1087,7 +1088,7 @@ wchar_t InputHandler_DInput::DeviceButtonToChar( DeviceButton button, bool bUseC
/*
* (c) 2003-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -1097,7 +1098,7 @@ wchar_t InputHandler_DInput::DeviceButtonToChar( DeviceButton button, bool bUseC
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -9,6 +9,8 @@
#include "InputMapper.h"
#include "Game.h"
#include <cmath>
// xxx: don't hardcode the port address. -aj
static const int PORT_ADDRESS = 0x378;
static const bool SCREEN_DEBUG = false;
@@ -46,7 +48,7 @@ void LightsDriver_LinuxParallel::Set( const LightsState *ls )
{
s += ls->m_bCabinetLights[cl] ? '1' : '0';
if ( ls->m_bCabinetLights[cl] )
output += (unsigned char)pow((double)2,i);
output += std::pow((double)2,i);
i++;
}
s += "\n";
@@ -74,7 +76,7 @@ void LightsDriver_LinuxParallel::Set( const LightsState *ls )
/*
* (c) 2004 Hugo Hromic M. <[email protected]>
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -84,7 +86,7 @@ void LightsDriver_LinuxParallel::Set( const LightsState *ls )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+11 -9
View File
@@ -12,11 +12,13 @@
#include "RageSurface_Load.h"
#include "RageSurface.h"
#include "RageSurfaceUtils.h"
#include "RageSurfaceUtils_Zoom.h"
#include "RageLog.h"
#include "ProductInfo.h"
#include "LocalizedString.h"
#include "RageSurfaceUtils_Zoom.h"
#include <cmath>
static HBITMAP g_hBitmap = nullptr;
/* Load a RageSurface into a GDI surface. */
@@ -34,7 +36,7 @@ static HBITMAP LoadWin32Surface( const RageSurface *pSplash, HWND hWnd )
int iWidth = r.right;
float fRatio = (float) iWidth / s->w;
int iHeight = lrintf( s->h * fRatio );
int iHeight = std::lrint( s->h * fRatio );
RageSurfaceUtils::Zoom( s, iWidth, iHeight );
}
@@ -55,7 +57,7 @@ static HBITMAP LoadWin32Surface( const RageSurface *pSplash, HWND hWnd )
for( int x = 0; x < s->w; ++x )
{
unsigned const char *data = line + (x*s->format->BytesPerPixel);
SetPixelV( BitmapDC, x, y, RGB( data[3], data[2], data[1] ) );
}
}
@@ -94,10 +96,10 @@ INT_PTR CALLBACK LoadingWindow_Win32::WndProc( HWND hWnd, UINT msg, WPARAM wPara
}
if( g_hBitmap == nullptr )
g_hBitmap = LoadWin32Surface( "Data/splash.bmp", hWnd );
SendMessage(
GetDlgItem(hWnd,IDC_SPLASH),
STM_SETIMAGE,
(WPARAM) IMAGE_BITMAP,
SendMessage(
GetDlgItem(hWnd,IDC_SPLASH),
STM_SETIMAGE,
(WPARAM) IMAGE_BITMAP,
(LPARAM) (HANDLE) g_hBitmap );
SetWindowTextA( hWnd, PRODUCT_ID );
break;
@@ -226,7 +228,7 @@ void LoadingWindow_Win32::SetIndeterminate(bool indeterminate)
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -236,7 +238,7 @@ void LoadingWindow_Win32::SetIndeterminate(bool indeterminate)
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -12,8 +12,8 @@
using namespace RageDisplay_Legacy_Helpers;
using namespace X11Helper;
#include <cmath>
#include <set>
#include <math.h> // ceil()
#include <GL/glxew.h>
#define GLX_GLXEXT_PROTOTYPES
#include <GL/glx.h> // All sorts of stuff...
@@ -410,7 +410,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
}
}
}
rate = roundf(fRefreshRate);
rate = std::round(fRefreshRate);
g_usedCrtc = tgtOutCrtc;
g_originalRandRMode = oldConf->mode;
@@ -559,7 +559,7 @@ RString LowLevelWindow_X11::TryVideoMode( const VideoModeParams &p, bool &bNewDe
CurrentParams.windowHeight = windowHeight;
CurrentParams.renderOffscreen = renderOffscreen;
ASSERT( rate > 0 );
CurrentParams.rate = static_cast<int> (roundf(rate));
CurrentParams.rate = std::round(rate);
if (!p.windowed)
{
@@ -6,6 +6,8 @@
#include "PlayerNumber.h"
#include "MemoryCardManager.h"
#include <cmath>
MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows()
{
m_dwLastLogicalDrives = 0;
@@ -23,7 +25,7 @@ static bool TestReady( const RString &sDrive, RString &sVolumeLabelOut )
DWORD lpFileSystemFlags;
TCHAR szFileSystemNameBuffer[MAX_PATH];
if( !GetVolumeInformation(
if( !GetVolumeInformation(
sDrive,
szVolumeNameBuffer,
sizeof(szVolumeNameBuffer),
@@ -117,7 +119,7 @@ void MemoryCardDriverThreaded_Windows::GetUSBStorageDevices( std::vector<UsbStor
continue;
}
// Testing hack: Allow non-removable drive letters to be used if that
// Testing hack: Allow non-removable drive letters to be used if that
// driver letter is specified as a m_sMemoryCardOsMountPoint.
bool bIsSpecifiedMountPoint = false;
@@ -135,7 +137,7 @@ void MemoryCardDriverThreaded_Windows::GetUSBStorageDevices( std::vector<UsbStor
if( GetDriveType(sDrivePath) != DRIVE_REMOVABLE )
{
LOG->Trace( "not DRIVE_REMOVABLE" );
continue;
continue;
}
}
@@ -143,7 +145,7 @@ void MemoryCardDriverThreaded_Windows::GetUSBStorageDevices( std::vector<UsbStor
if( !TestReady(sDrivePath, sVolumeLabel) )
{
LOG->Trace( "not TestReady" );
continue;
continue;
}
vDevicesOut.push_back( UsbStorageDevice() );
@@ -172,7 +174,7 @@ void MemoryCardDriverThreaded_Windows::GetUSBStorageDevices( std::vector<UsbStor
&dwNumberOfFreeClusters,
&dwTotalNumberOfClusters ) )
{
usbd.iVolumeSizeMB = (int)roundf( dwTotalNumberOfClusters * (float)dwSectorsPerCluster * dwBytesPerSector / (1024*1024) );
usbd.iVolumeSizeMB = std::round( dwTotalNumberOfClusters * (float)dwSectorsPerCluster * dwBytesPerSector / (1024*1024) );
}
}
}
@@ -209,7 +211,7 @@ void MemoryCardDriverThreaded_Windows::Unmount( UsbStorageDevice* pDevice )
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -219,7 +221,7 @@ void MemoryCardDriverThreaded_Windows::Unmount( UsbStorageDevice* pDevice )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -4,6 +4,8 @@
#include "RageLog.h"
#include "archutils/Win32/DirectXHelpers.h"
#include <cmath>
//-----------------------------------------------------------------------------
// Define GUID for Texture Renderer
// {71771540-2017-11cf-AE26-0020AFD79767}
@@ -12,7 +14,7 @@ struct __declspec(uuid("{71771540-2017-11cf-ae26-0020afd79767}")) CLSID_TextureR
static HRESULT CBV_ret;
CTextureRenderer::CTextureRenderer():
CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer),
CBaseVideoRenderer(__uuidof(CLSID_TextureRenderer),
NAME("Texture Renderer"), nullptr, &CBV_ret),
m_OneFrameDecoded( "m_OneFrameDecoded", 0 )
{
@@ -47,14 +49,14 @@ HRESULT CTextureRenderer::CheckMediaType(const CMediaType *pmt)
}
// SetMediaType: Graph connection has been made.
// SetMediaType: Graph connection has been made.
HRESULT CTextureRenderer::SetMediaType(const CMediaType *pmt)
{
// Retrive the size of this media type
VIDEOINFO *pviBmp; // Bitmap info header
pviBmp = (VIDEOINFO *)pmt->Format();
m_lVidWidth = pviBmp->bmiHeader.biWidth;
m_lVidHeight = abs(pviBmp->bmiHeader.biHeight);
m_lVidHeight = std::abs(pviBmp->bmiHeader.biHeight);
m_lVidPitch = (m_lVidWidth * 3 + 3) + ~3; // We are forcing RGB24
return S_OK;
@@ -98,7 +100,7 @@ void CTextureRenderer::OnReceiveFirstSample( IMediaSample * pSample )
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -108,7 +110,7 @@ void CTextureRenderer::OnReceiveFirstSample( IMediaSample * pSample )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+11 -9
View File
@@ -9,6 +9,8 @@
#include "RageUtil.h"
#include "Sprite.h"
#include <cmath>
#if defined(WIN32)
#include "archutils/Win32/ErrorStrings.h"
#include <windows.h>
@@ -77,7 +79,7 @@ MovieTexture_Generic::~MovieTexture_Generic()
/* m_pSprite may reference the texture; delete it before DestroyTexture. */
delete m_pSprite;
DestroyTexture();
delete m_pDecoder;
@@ -108,7 +110,7 @@ void MovieTexture_Generic::DestroyTexture()
class RageMovieTexture_Generic_Intermediate : public RageTexture
{
public:
RageMovieTexture_Generic_Intermediate( RageTextureID ID, int iWidth, int iHeight,
RageMovieTexture_Generic_Intermediate( RageTextureID ID, int iWidth, int iHeight,
int iImageWidth, int iImageHeight, int iTextureWidth, int iTextureHeight,
RageSurfaceFormat SurfaceFormat, RagePixelFormat pixfmt ):
RageTexture(ID),
@@ -123,7 +125,7 @@ public:
m_iTextureWidth = power_of_two( m_iImageWidth );
m_iTextureHeight = power_of_two( m_iImageHeight );
*/
m_iImageWidth = iImageWidth;
m_iImageHeight = iImageHeight;
m_iTextureWidth = iTextureWidth;
@@ -193,9 +195,9 @@ void MovieTexture_Generic::CreateTexture()
/* Adjust m_iSourceWidth to support different source aspect ratios. */
float fSourceAspectRatio = m_pDecoder->GetSourceAspectRatio();
if( fSourceAspectRatio < 1 )
m_iSourceHeight = lrintf( m_iSourceHeight / fSourceAspectRatio );
m_iSourceHeight = std::lrint( m_iSourceHeight / fSourceAspectRatio );
else if( fSourceAspectRatio > 1 )
m_iSourceWidth = lrintf( m_iSourceWidth * fSourceAspectRatio );
m_iSourceWidth = std::lrint( m_iSourceWidth * fSourceAspectRatio );
/* HACK: Don't cap movie textures to the max texture size, since we
* render them onto the texture at the source dimensions. If we find a
@@ -381,7 +383,7 @@ float MovieTexture_Generic::CheckFrameTime()
}
/*
* We're behind by -Offset seconds.
* We're behind by -Offset seconds.
*
* If we're just slightly behind, don't worry about it; we'll simply
* not sleep, so we'll move as fast as we can to catch up.
@@ -487,7 +489,7 @@ void MovieTexture_Generic::UpdateFrame()
}
}
static EffectMode EffectModes[] =
static EffectMode EffectModes[] =
{
EffectMode_YUYV422,
};
@@ -529,7 +531,7 @@ uintptr_t MovieTexture_Generic::GetTexHandle() const
/*
* (c) 2003-2005 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -539,7 +541,7 @@ uintptr_t MovieTexture_Generic::GetTexHandle() const
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+8 -6
View File
@@ -5,6 +5,8 @@
#include "archutils/Win32/DirectXHelpers.h"
#include "archutils/Win32/GetFileInformation.h"
#include <cmath>
#if defined(_WINDOWS)
#include <mmsystem.h>
#endif
@@ -78,7 +80,7 @@ void DSound::SetPrimaryBufferMode()
/*
* MS docs:
*
* When there are no sounds playing, DirectSound stops the mixer engine and halts DMA
* When there are no sounds playing, DirectSound stops the mixer engine and halts DMA
* (direct memory access) activity. If your application has frequent short intervals of
* silence, the overhead of starting and stopping the mixer each time a sound is played
* may be worse than the DMA overhead if you kept the mixer active. Also, some sound
@@ -280,10 +282,10 @@ void DSoundBuf::SetSampleRate( int hz )
void DSoundBuf::SetVolume( float fVolume )
{
ASSERT_M( fVolume >= 0 && fVolume <= 1, ssprintf("%f",fVolume) );
if( fVolume == 0 )
fVolume = 0.001f; // fix log10f(0) == -INF
float iVolumeLog2 = log10f(fVolume) / log10f(2); /* vol log 2 */
fVolume = 0.001f; // fix log10(0) == -INF
float iVolumeLog2 = std::log10(fVolume) / std::log10(2); /* vol log 2 */
/* Volume is a multiplier; SetVolume wants attenuation in hundredths of a decibel. */
const int iNewVolume = std::max( int(1000 * iVolumeLog2), DSBVOLUME_MIN );
@@ -630,7 +632,7 @@ void DSoundBuf::Stop()
/*
* (c) 2002-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -640,7 +642,7 @@ void DSoundBuf::Stop()
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
@@ -7,6 +7,8 @@
#include "RageSoundMixBuffer.h"
#include "RageSoundReader.h"
#include <cmath>
static const int channels = 2;
static int frames_to_buffer;
@@ -479,7 +481,7 @@ int64_t RageSoundDriver::ClampHardwareFrame( int64_t iHardwareFrame ) const
/* New extra logic for devices and drivers that cant return large numbers in their sample position
* calculate a diff and if the current sample # is >= 0 and less than a minute based on sample rate
* check if the user set soundDriverMaxSamples to a value, if they did
* check if the user set soundDriverMaxSamples to a value, if they did
* (this is usually 134217728 aka 2^27 for some reason) hndle the wrap around to a rolling counter
* otherwise do the old logic for underrun
*/
@@ -509,14 +511,14 @@ int64_t RageSoundDriver::ClampHardwareFrame( int64_t iHardwareFrame ) const
//try to hand hold the user if their audio driver is possibly bad
int p = 21; // save some time, assume the buffer has at least a minute of cd quality audio -- 2^21
while (pow(2,p) < m_iMaxHardwareFrame)
while (std::pow(2,p) < m_iMaxHardwareFrame)
{
if (p == 31) break; //do not want to go beyond signed DWORD size
p++;
}
LOG->Trace("RageSoundDriver: driver returned a lesser position (%d < %d). If this is a recurrent driver problem with your sound card and not an underrun, try setting the preference RageSoundSampleCountClamp to %d",
(int)iHardwareFrame, (int)m_iMaxHardwareFrame, (int)floor(pow(2.0, p)));
(int)iHardwareFrame, (int)m_iMaxHardwareFrame, (int)std::floor(std::pow(2.0, p)));
last.Touch();
}
@@ -524,7 +526,7 @@ int64_t RageSoundDriver::ClampHardwareFrame( int64_t iHardwareFrame ) const
}
}
m_iMaxHardwareFrame = iHardwareFrame = std::max( iHardwareFrame, m_iMaxHardwareFrame );
//return iHardwareFrame;
m_iVMaxHardwareFrame += diff;
@@ -569,7 +571,7 @@ int64_t RageSoundDriver::GetHardwareFrame( RageTimer *pTimestamp=nullptr ) const
/*
* (c) 2002-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -579,7 +581,7 @@ int64_t RageSoundDriver::GetHardwareFrame( RageTimer *pTimestamp=nullptr ) const
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF