From 08c730c6473ec4ebd5f38be4d5c78b4e9502cb76 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 17 Apr 2022 16:23:46 +0100 Subject: [PATCH] Cmd line: add -wav-speaker & -wav-mockingboard --- source/CmdLine.cpp | 12 ++++++++++++ source/CmdLine.h | 2 ++ source/Mockingboard.cpp | 15 +++++++++++--- source/Mockingboard.h | 1 + source/Riff.cpp | 18 ++++++++--------- source/Riff.h | 6 +++--- source/SoundCore.h | 4 ---- source/Speaker.cpp | 39 ++++++++++++++++++++----------------- source/Speaker.h | 1 + source/Windows/AppleWin.cpp | 19 ++++++++++-------- 10 files changed, 72 insertions(+), 45 deletions(-) diff --git a/source/CmdLine.cpp b/source/CmdLine.cpp index b901839d..12077d05 100644 --- a/source/CmdLine.cpp +++ b/source/CmdLine.cpp @@ -537,6 +537,18 @@ bool ProcessCmdLine(LPSTR lpCmdLine) { g_cmdLine.snesMaxAltControllerType[1] = true; } + else if (strcmp(lpCmdLine, "-wav-speaker") == 0) + { + lpCmdLine = GetCurrArg(lpNextArg); + lpNextArg = GetNextArg(lpNextArg); + g_cmdLine.wavFileSpeaker = lpCmdLine; + } + else if (strcmp(lpCmdLine, "-wav-mockingboard") == 0) + { + lpCmdLine = GetCurrArg(lpNextArg); + lpNextArg = GetNextArg(lpNextArg); + g_cmdLine.wavFileMockingboard = lpCmdLine; + } else // unsupported { LogFileOutput("Unsupported arg: %s\n", lpCmdLine); diff --git a/source/CmdLine.h b/source/CmdLine.h index d87d920b..9bb4853d 100644 --- a/source/CmdLine.h +++ b/source/CmdLine.h @@ -84,6 +84,8 @@ struct CmdLine bool bestFullScreenResolution; UINT userSpecifiedWidth; UINT userSpecifiedHeight; + std::string wavFileSpeaker; + std::string wavFileMockingboard; }; bool ProcessCmdLine(LPSTR lpCmdLine); diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index eb2622d4..fa480db3 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -185,6 +185,16 @@ static UINT g_cyclesThisAudioFrame = 0; // Forward refs: static int MB_SyncEventCallback(int id, int cycles, ULONG uExecutedCycles); + +//--------------------------------------------------------------------------- + +static bool g_bMBOutputToRiff = false; + +void MB_OutputToRiff(void) +{ + g_bMBOutputToRiff = true; +} + //--------------------------------------------------------------------------- static bool IsAnyTimer1Active(void) @@ -565,9 +575,8 @@ static void MB_UpdateInt(void) dwByteOffset = (dwByteOffset + (DWORD)nNumSamples*sizeof(short)*g_nMB_NumChannels) % g_dwDSBufferSize; -#ifdef RIFF_MB - RiffPutSamples(&g_nMixBuffer[0], nNumSamples); -#endif + if (g_bMBOutputToRiff) + RiffPutSamples(&g_nMixBuffer[0], nNumSamples); } static void MB_Update(void) diff --git a/source/Mockingboard.h b/source/Mockingboard.h index f4a2b37c..edd67d55 100644 --- a/source/Mockingboard.h +++ b/source/Mockingboard.h @@ -24,6 +24,7 @@ bool MB_IsActive(); DWORD MB_GetVolume(); void MB_SetVolume(DWORD dwVolume, DWORD dwVolumeMax); void MB_Get6522IrqDescription(std::string& desc); +void MB_OutputToRiff(void); void MB_UpdateIRQ(void); UINT64 MB_GetLastCumulativeCycles(void); diff --git a/source/Riff.cpp b/source/Riff.cpp index d7172c99..acb151ac 100644 --- a/source/Riff.cpp +++ b/source/Riff.cpp @@ -35,12 +35,12 @@ static DWORD dwDataOffset; static DWORD g_dwTotalNumberOfBytesWritten = 0; static unsigned int g_NumChannels = 2; -int RiffInitWriteFile(const char* pszFile, unsigned int sample_rate, unsigned int NumChannels) +bool RiffInitWriteFile(const char* pszFile, unsigned int sample_rate, unsigned int NumChannels) { g_hRiffFile = CreateFile(pszFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if(g_hRiffFile == INVALID_HANDLE_VALUE) - return 1; + return false; g_NumChannels = NumChannels; @@ -92,13 +92,13 @@ int RiffInitWriteFile(const char* pszFile, unsigned int sample_rate, unsigned in dwDataOffset = SetFilePointer(g_hRiffFile, 0, NULL, FILE_CURRENT); WriteFile(g_hRiffFile, &temp32, 4, &dwNumberOfBytesWritten, NULL); - return 0; + return true; } -int RiffFinishWriteFile() +bool RiffFinishWriteFile() { if(g_hRiffFile == INVALID_HANDLE_VALUE) - return 1; + return false; // @@ -114,13 +114,13 @@ int RiffFinishWriteFile() SetFilePointer(g_hRiffFile, dwDataOffset, NULL, FILE_BEGIN); WriteFile(g_hRiffFile, &temp32, 4, &dwNumberOfBytesWritten, NULL); - return CloseHandle(g_hRiffFile); + return CloseHandle(g_hRiffFile) ? true : false; } -int RiffPutSamples(const short* buf, unsigned int uSamples) +bool RiffPutSamples(const short* buf, unsigned int uSamples) { if(g_hRiffFile == INVALID_HANDLE_VALUE) - return 1; + return false; // @@ -135,5 +135,5 @@ int RiffPutSamples(const short* buf, unsigned int uSamples) g_dwTotalNumberOfBytesWritten += dwNumberOfBytesWritten; - return 0; + return true; } diff --git a/source/Riff.h b/source/Riff.h index 10186efe..8f114b43 100644 --- a/source/Riff.h +++ b/source/Riff.h @@ -1,5 +1,5 @@ #pragma once -int RiffInitWriteFile(const char* pszFile, unsigned int sample_rate, unsigned int NumChannels); -int RiffFinishWriteFile(); -int RiffPutSamples(const short* buf, unsigned int uSamples); +bool RiffInitWriteFile(const char* pszFile, unsigned int sample_rate, unsigned int NumChannels); +bool RiffFinishWriteFile(void); +bool RiffPutSamples(const short* buf, unsigned int uSamples); diff --git a/source/SoundCore.h b/source/SoundCore.h index 6c74d983..93f409e8 100644 --- a/source/SoundCore.h +++ b/source/SoundCore.h @@ -4,10 +4,6 @@ #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } -// Define max 1 of these: -//#define RIFF_SPKR -//#define RIFF_MB - struct VOICE { LPDIRECTSOUNDBUFFER lpDSBvoice; diff --git a/source/Speaker.cpp b/source/Speaker.cpp index 816ea5e8..fc972fd9 100644 --- a/source/Speaker.cpp +++ b/source/Speaker.cpp @@ -92,6 +92,15 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples); static void Spkr_SetActive(bool bActive); static void Spkr_DSUninit(); +//----------------------------------------------------------------------------- + +static bool g_bSpkrOutputToRiff = false; + +void Spkr_OutputToRiff(void) +{ + g_bSpkrOutputToRiff = true; +} + //============================================================================= static void DisplayBenchmarkResults () @@ -603,17 +612,15 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa } memcpy(pDSLockedBuffer0, &pSpeakerBuffer[0], dwBufferSize0); -#ifdef RIFF_SPKR - RiffPutSamples(pDSLockedBuffer0, dwBufferSize0/sizeof(short)); -#endif + if (g_bSpkrOutputToRiff) + RiffPutSamples(pDSLockedBuffer0, dwBufferSize0/sizeof(short)); nNumSamples = dwBufferSize0/sizeof(short); if(pDSLockedBuffer1 && dwBufferSize1) { memcpy(pDSLockedBuffer1, &pSpeakerBuffer[dwDSLockedBufferSize0/sizeof(short)], dwBufferSize1); -#ifdef RIFF_SPKR - RiffPutSamples(pDSLockedBuffer1, dwBufferSize1/sizeof(short)); -#endif + if (g_bSpkrOutputToRiff) + RiffPutSamples(pDSLockedBuffer1, dwBufferSize1/sizeof(short)); nNumSamples += dwBufferSize1/sizeof(short); } } @@ -628,17 +635,15 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa if(dwBufferSize0) { wmemset((wchar_t*)pDSLockedBuffer0, (wchar_t)DCFilter(g_nSpeakerData), dwBufferSize0/sizeof(wchar_t)); -#ifdef RIFF_SPKR - RiffPutSamples(pDSLockedBuffer0, dwBufferSize0/sizeof(short)); -#endif + if (g_bSpkrOutputToRiff) + RiffPutSamples(pDSLockedBuffer0, dwBufferSize0/sizeof(short)); } if(pDSLockedBuffer1) { wmemset((wchar_t*)pDSLockedBuffer1, (wchar_t)DCFilter(g_nSpeakerData), dwBufferSize1/sizeof(wchar_t)); -#ifdef RIFF_SPKR - RiffPutSamples(pDSLockedBuffer1, dwBufferSize1/sizeof(short)); -#endif + if (g_bSpkrOutputToRiff) + RiffPutSamples(pDSLockedBuffer1, dwBufferSize1/sizeof(short)); } } @@ -782,16 +787,14 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples) } memcpy(pDSLockedBuffer0, &pSpeakerBuffer[0], dwDSLockedBufferSize0); -#ifdef RIFF_SPKR - RiffPutSamples(pDSLockedBuffer0, dwDSLockedBufferSize0/sizeof(short)); -#endif + if (g_bSpkrOutputToRiff) + RiffPutSamples(pDSLockedBuffer0, dwDSLockedBufferSize0/sizeof(short)); if(pDSLockedBuffer1) { memcpy(pDSLockedBuffer1, &pSpeakerBuffer[dwDSLockedBufferSize0/sizeof(short)], dwDSLockedBufferSize1); -#ifdef RIFF_SPKR - RiffPutSamples(pDSLockedBuffer1, dwDSLockedBufferSize1/sizeof(short)); -#endif + if (g_bSpkrOutputToRiff) + RiffPutSamples(pDSLockedBuffer1, dwDSLockedBufferSize1/sizeof(short)); } // Commit sound buffer diff --git a/source/Speaker.h b/source/Speaker.h index 1cc26de1..013ff618 100644 --- a/source/Speaker.h +++ b/source/Speaker.h @@ -30,6 +30,7 @@ void Spkr_Mute(); void Spkr_Unmute(); bool Spkr_IsActive(); bool Spkr_DSInit(); +void Spkr_OutputToRiff(void); void SpkrSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); void SpkrLoadSnapshot(class YamlLoadHelper& yamlLoadHelper); diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index 9935d8b3..7af87e25 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -616,14 +616,17 @@ static void GetAppleWinVersion(void) // DO ONE-TIME INITIALIZATION static void OneTimeInitialization(HINSTANCE passinstance) { -#if 0 -#ifdef RIFF_SPKR - RiffInitWriteFile("Spkr.wav", SPKR_SAMPLE_RATE, 1); -#endif -#ifdef RIFF_MB - RiffInitWriteFile("Mockingboard.wav", 44100, 2); -#endif -#endif + // Currently only support one RIFF file + if (!g_cmdLine.wavFileSpeaker.empty()) + { + if (RiffInitWriteFile(g_cmdLine.wavFileSpeaker.c_str(), SPKR_SAMPLE_RATE, 1)) + Spkr_OutputToRiff(); + } + else if (!g_cmdLine.wavFileMockingboard.empty()) + { + if (RiffInitWriteFile(g_cmdLine.wavFileMockingboard.c_str(), 44100, 2)) + MB_OutputToRiff(); + } // Initialize COM - so we can use CoCreateInstance // . DSInit() & DIMouse::DirectInputInit are done when g_hFrameWindow is created (WM_CREATE)