From f89c7349960ffd8dcdb99ac0918e3e269f8d582b Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sun, 7 Jun 2015 12:19:45 -0700 Subject: [PATCH] Refactor : excise various macro defs --- src/audio/mockingboard.c | 56 ++++++++++++++++++++-------------------- src/audio/soundcore.c | 10 +++---- src/audio/win-shim.h | 8 ------ 3 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/audio/mockingboard.c b/src/audio/mockingboard.c index 4b3fc5b8..b5209dab 100644 --- a/src/audio/mockingboard.c +++ b/src/audio/mockingboard.c @@ -1096,12 +1096,12 @@ static unsigned long SSI263Thread(void *lpParameter) g_nNumEvents, // number of handles in array g_hSSI263Event, // array of event handles FALSE, // wait until any one is signaled - INFINITE); + 0); - if((dwWaitResult < WAIT_OBJECT_0) || (dwWaitResult > WAIT_OBJECT_0+g_nNumEvents-1)) + if((dwWaitResult < 0x0L) || (dwWaitResult > 0x0L+g_nNumEvents-1)) continue; - dwWaitResult -= WAIT_OBJECT_0; // Determine event # that signaled + dwWaitResult -= 0x0L; // Determine event # that signaled if(dwWaitResult == (g_nNumEvents-1)) // Termination event break; @@ -1273,9 +1273,9 @@ static void SSI263_Play(unsigned int nPhoneme) static bool MB_DSInit() { #ifdef APPLE2IX - LogFileOutput("MB_DSInit : %d\n", g_bMBAvailable); + LOG("MB_DSInit : %d\n", g_bMBAvailable); #else - LogFileOutput("MB_DSInit\n", g_bMBAvailable); + LOG("MB_DSInit\n", g_bMBAvailable); #endif #ifdef NO_DIRECT_X @@ -1294,7 +1294,7 @@ static bool MB_DSInit() return false; int hr = DSGetSoundBuffer(&MockingboardVoice, DSBCAPS_CTRLVOLUME, g_dwDSBufferSize, SAMPLE_RATE, 2); - LogFileOutput("MB_DSInit: DSGetSoundBuffer(), hr=0x%08X\n", (unsigned int)hr); + LOG("MB_DSInit: DSGetSoundBuffer(), hr=0x%08X\n", (unsigned int)hr); if(FAILED(hr)) { LOG("MB: DSGetSoundBuffer failed (%08X)\n",(unsigned int)hr); @@ -1303,7 +1303,7 @@ static bool MB_DSInit() #ifndef APPLE2IX bool bRes = DSZeroVoiceBuffer(&MockingboardVoice, (char*)"MB", g_dwDSBufferSize); - LogFileOutput("MB_DSInit: DSZeroVoiceBuffer(), res=%d\n", bRes ? 1 : 0); + LOG("MB_DSInit: DSZeroVoiceBuffer(), res=%d\n", bRes ? 1 : 0); if (!bRes) return false; #endif @@ -1319,7 +1319,7 @@ static bool MB_DSInit() #else hr = MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.nVolume); #endif - LogFileOutput("MB_DSInit: SetVolume(), hr=0x%08X\n", (unsigned int)hr); + LOG("MB_DSInit: SetVolume(), hr=0x%08X\n", (unsigned int)hr); //--------------------------------- @@ -1353,13 +1353,13 @@ static bool MB_DSInit() FALSE, // bManualReset (FALSE = auto-reset) FALSE, // bInitialState (FALSE = non-signaled) NULL); // lpName - LogFileOutput("MB_DSInit: CreateEvent(), g_hSSI263Event[0]=0x%08X\n", (uint32_t)g_hSSI263Event[0]); + LOG("MB_DSInit: CreateEvent(), g_hSSI263Event[0]=0x%08X\n", (uint32_t)g_hSSI263Event[0]); g_hSSI263Event[1] = CreateEvent(NULL, // lpEventAttributes FALSE, // bManualReset (FALSE = auto-reset) FALSE, // bInitialState (FALSE = non-signaled) NULL); // lpName - LogFileOutput("MB_DSInit: CreateEvent(), g_hSSI263Event[1]=0x%08X\n", (uint32_t)g_hSSI263Event[1]); + LOG("MB_DSInit: CreateEvent(), g_hSSI263Event[1]=0x%08X\n", (uint32_t)g_hSSI263Event[1]); if((g_hSSI263Event[0] == NULL) || (g_hSSI263Event[1] == NULL)) { @@ -1391,7 +1391,7 @@ static bool MB_DSInit() // NB. DSBCAPS_LOCSOFTWARE required for hr = DSGetSoundBuffer(&SSI263Voice[i], DSBCAPS_CTRLVOLUME+DSBCAPS_CTRLPOSITIONNOTIFY+DSBCAPS_LOCSOFTWARE, nPhonemeByteLength, 22050, 1); - LogFileOutput("MB_DSInit: (%02d) DSGetSoundBuffer(), hr=0x%08X\n", i, (unsigned int)hr); + LOG("MB_DSInit: (%02d) DSGetSoundBuffer(), hr=0x%08X\n", i, (unsigned int)hr); if(FAILED(hr)) { LOG("SSI263: DSGetSoundBuffer failed (%08X)\n",(unsigned int)hr); @@ -1403,7 +1403,7 @@ static bool MB_DSInit() #else hr = DSGetLock(SSI263Voice[i].lpDSBvoice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0); #endif - //LogFileOutput("MB_DSInit: (%02d) DSGetLock(), res=%d\n", i, hr ? 1 : 0); // WARNING: Lock acquired && doing heavy-weight logging + //LOG("MB_DSInit: (%02d) DSGetLock(), res=%d\n", i, hr ? 1 : 0); // WARNING: Lock acquired && doing heavy-weight logging if(FAILED(hr)) { LOG("SSI263: DSGetLock failed (%08X)\n",(unsigned int)hr); @@ -1432,7 +1432,7 @@ static bool MB_DSInit() // Assume no way to get notification of sound finished, instead we will poll from mockingboard thread ... #else hr = SSI263Voice[i].lpDSBvoice->QueryInterface(IID_IDirectSoundNotify, (void **)&SSI263Voice[i].lpDSNotify); - //LogFileOutput("MB_DSInit: (%02d) QueryInterface(), hr=0x%08X\n", i, hr); // WARNING: Lock acquired && doing heavy-weight logging + //LOG("MB_DSInit: (%02d) QueryInterface(), hr=0x%08X\n", i, hr); // WARNING: Lock acquired && doing heavy-weight logging if(FAILED(hr)) { LOG("SSI263: QueryInterface failed (%08X)\n",hr); @@ -1446,7 +1446,7 @@ static bool MB_DSInit() PositionNotify.hEventNotify = g_hSSI263Event[0]; hr = SSI263Voice[i].lpDSNotify->SetNotificationPositions(1, &PositionNotify); - //LogFileOutput("MB_DSInit: (%02d) SetNotificationPositions(), hr=0x%08X\n", i, hr); // WARNING: Lock acquired && doing heavy-weight logging + //LOG("MB_DSInit: (%02d) SetNotificationPositions(), hr=0x%08X\n", i, hr); // WARNING: Lock acquired && doing heavy-weight logging if(FAILED(hr)) { LOG("SSI263: SetNotifyPos failed (%08X)\n",hr); @@ -1459,7 +1459,7 @@ static bool MB_DSInit() #else hr = SSI263Voice[i].lpDSBvoice->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0); #endif - LogFileOutput("MB_DSInit: (%02d) Unlock(),hr=0x%08X\n", i, (unsigned int)hr); + LOG("MB_DSInit: (%02d) Unlock(),hr=0x%08X\n", i, (unsigned int)hr); if(FAILED(hr)) { LOG("SSI263: DSUnlock failed (%08X)\n",(unsigned int)hr); @@ -1473,7 +1473,7 @@ static bool MB_DSInit() #else hr = SSI263Voice[i].lpDSBvoice->SetVolume(SSI263Voice[i].nVolume); #endif - LogFileOutput("MB_DSInit: (%02d) SetVolume(), hr=0x%08X\n", i, (unsigned int)hr); + LOG("MB_DSInit: (%02d) SetVolume(), hr=0x%08X\n", i, (unsigned int)hr); } // @@ -1486,10 +1486,10 @@ static bool MB_DSInit() NULL, // lpParameter 0, // dwCreationFlags : 0 = Run immediately &dwThreadId); // lpThreadId - LogFileOutput("MB_DSInit: CreateThread(), g_hThread=0x%08X\n", (uint32_t)g_hThread); + LOG("MB_DSInit: CreateThread(), g_hThread=0x%08X\n", (uint32_t)g_hThread); bool bRes2 = SetThreadPriority(g_hThread, THREAD_PRIORITY_TIME_CRITICAL); - LogFileOutput("MB_DSInit: SetThreadPriority(), bRes=%d\n", bRes2 ? 1 : 0); + LOG("MB_DSInit: SetThreadPriority(), bRes=%d\n", bRes2 ? 1 : 0); return true; @@ -1513,7 +1513,7 @@ static void MB_DSUninit() if(GetExitCodeThread(g_hThread, &dwExitCode)) { if(dwExitCode == STILL_ACTIVE) - Sleep(10); + usleep(10); else break; } @@ -1591,7 +1591,7 @@ void MB_Initialize() #ifdef APPLE2IX memset(SSI263Voice, 0x0, sizeof(VOICE)*MAX_VOICES); #endif - LogFileOutput("MB_Initialize: g_bDisableDirectSound=%d, g_bDisableDirectSoundMockingboard=%d\n", g_bDisableDirectSound, g_bDisableDirectSoundMockingboard); + LOG("MB_Initialize: g_bDisableDirectSound=%d, g_bDisableDirectSoundMockingboard=%d\n", g_bDisableDirectSound, g_bDisableDirectSoundMockingboard); if (g_bDisableDirectSound || g_bDisableDirectSoundMockingboard) { MockingboardVoice.bMute = true; @@ -1612,7 +1612,7 @@ void MB_Initialize() } AY8910_InitAll((int)cycles_persec_target, SAMPLE_RATE); - LogFileOutput("MB_Initialize: AY8910_InitAll()\n"); + LOG("MB_Initialize: AY8910_InitAll()\n"); for(i=0; i= 0x10000) { printf("OOPS!!! Mockingboard failed assert!\n"); return; diff --git a/src/audio/soundcore.c b/src/audio/soundcore.c index 533a1372..55b63a48 100644 --- a/src/audio/soundcore.c +++ b/src/audio/soundcore.c @@ -72,7 +72,7 @@ bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, unsigned long dwOffset, unsigned long { hr = pVoice->Restore(pVoice->_this); if(hr == DSERR_BUFFERLOST) - Sleep(10); + usleep(10); } while(hr != DS_OK); } @@ -133,7 +133,7 @@ int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBuffe // - _ASSERT(g_uNumVoices < uMAX_VOICES); + assert(g_uNumVoices < uMAX_VOICES); if(g_uNumVoices < uMAX_VOICES) g_pVoices[g_uNumVoices++] = pVoice; @@ -187,7 +187,7 @@ bool DSZeroVoiceBuffer(PVOICE Voice, char* pszDevName, unsigned long dwBufferSiz return false; } - _ASSERT(dwDSLockedBufferSize == dwBufferSize); + assert(dwDSLockedBufferSize == dwBufferSize); memset(pDSLockedBuffer, 0x00, dwDSLockedBufferSize); hr = Voice->lpDSBvoice->Unlock(Voice->lpDSBvoice->_this, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, argX); @@ -315,7 +315,7 @@ void DSUninit() if(!g_bDSAvailable) return; - _ASSERT(g_uDSInitRefCount); + assert(g_uDSInitRefCount); if(g_uDSInitRefCount == 0) return; @@ -327,7 +327,7 @@ void DSUninit() // - _ASSERT(g_uNumVoices == 0); + assert(g_uNumVoices == 0); SoundSystemDestroy((SoundSystemStruct**)&g_lpDS); g_bDSAvailable = false; diff --git a/src/audio/win-shim.h b/src/audio/win-shim.h index 55f36bb5..e67aded3 100644 --- a/src/audio/win-shim.h +++ b/src/audio/win-shim.h @@ -32,16 +32,8 @@ #define FALSE false #endif -#define _ASSERT assert -#define Sleep(x) usleep(x) - typedef void *IUnknown; -#define INFINITE 0 -#define WAIT_OBJECT_0 0x00000000L - -#define LogFileOutput(...) LOG(__VA_ARGS__) - typedef void *(*LPTHREAD_START_ROUTINE)(void *unused); pthread_t CreateThread(void* unused_lpThreadAttributes, int unused_dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter, unsigned long unused_dwCreationFlags, unsigned long *lpThreadId);