Mockingboard: define sample rate and number of channels only once. (PR #1223)

This commit is contained in:
Andrea 2023-05-05 21:49:26 +01:00 committed by GitHub
parent a53fbf212e
commit 4b18918e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 13 deletions

View File

@ -71,6 +71,9 @@ public:
static std::string GetSnapshotCardNameMegaAudio(void);
static std::string GetSnapshotCardNameSDMusic(void);
static const unsigned short NUM_MB_CHANNELS = 2;
static const DWORD SAMPLE_RATE = 44100; // Use a base freq so that DirectX (or sound h/w) doesn't have to up/down-sample
private:
enum MockingboardUnitState_e { AY_NOP0, AY_NOP1, AY_INACTIVE, AY_READ, AY_NOP4, AY_NOP5, AY_WRITE, AY_LATCH };
@ -151,8 +154,6 @@ private:
UINT64 m_lastCumulativeCycle;
static const DWORD SAMPLE_RATE = 44100; // Use a base freq so that DirectX (or sound h/w) doesn't have to up/down-sample
short* m_ppAYVoiceBuffer[NUM_VOICES];
UINT64 m_inActiveCycleCount;

View File

@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Core.h"
#include "CardManager.h"
#include "CPU.h"
#include "Mockingboard.h"
#include "MockingboardDefs.h"
#include "Riff.h"
@ -284,9 +283,7 @@ bool MockingboardCardManager::Init(void)
if (!g_bDSAvailable)
return false;
const DWORD SAMPLE_RATE = 44100; // Use a base freq so that DirectX (or sound h/w) doesn't have to up/down-sample
HRESULT hr = DSGetSoundBuffer(&m_mockingboardVoice, DSBCAPS_CTRLVOLUME, SOUNDBUFFER_SIZE, SAMPLE_RATE, NUM_MB_CHANNELS, "MB");
HRESULT hr = DSGetSoundBuffer(&m_mockingboardVoice, DSBCAPS_CTRLVOLUME, SOUNDBUFFER_SIZE, MockingboardCard::SAMPLE_RATE, MockingboardCard::NUM_MB_CHANNELS, "MB");
LogFileOutput("MBCardMgr: DSGetSoundBuffer(), hr=0x%08X\n", hr);
if (FAILED(hr))
{
@ -441,8 +438,8 @@ void MockingboardCardManager::MixAllAndCopyToRingBuffer(UINT nNumSamples)
else if (nDataR > WAVE_DATA_MAX)
nDataR = WAVE_DATA_MAX;
m_mixBuffer[i * NUM_MB_CHANNELS + 0] = (short)nDataL; // L
m_mixBuffer[i * NUM_MB_CHANNELS + 1] = (short)nDataR; // R
m_mixBuffer[i * MockingboardCard::NUM_MB_CHANNELS + 0] = (short)nDataL; // L
m_mixBuffer[i * MockingboardCard::NUM_MB_CHANNELS + 1] = (short)nDataR; // R
}
//
@ -451,7 +448,7 @@ void MockingboardCardManager::MixAllAndCopyToRingBuffer(UINT nNumSamples)
SHORT* pDSLockedBuffer0, * pDSLockedBuffer1;
HRESULT hr = DSGetLock(m_mockingboardVoice.lpDSBvoice,
m_byteOffset, (DWORD)nNumSamples * sizeof(short) * NUM_MB_CHANNELS,
m_byteOffset, (DWORD)nNumSamples * sizeof(short) * MockingboardCard::NUM_MB_CHANNELS,
&pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1);
if (FAILED(hr))
@ -465,7 +462,7 @@ void MockingboardCardManager::MixAllAndCopyToRingBuffer(UINT nNumSamples)
hr = m_mockingboardVoice.lpDSBvoice->Unlock((void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
(void*)pDSLockedBuffer1, dwDSLockedBufferSize1);
m_byteOffset = (m_byteOffset + (DWORD)nNumSamples * sizeof(short) * NUM_MB_CHANNELS) % SOUNDBUFFER_SIZE;
m_byteOffset = (m_byteOffset + (DWORD)nNumSamples * sizeof(short) * MockingboardCard::NUM_MB_CHANNELS) % SOUNDBUFFER_SIZE;
if (m_outputToRiff)
RiffPutSamples(&m_mixBuffer[0], nNumSamples);

View File

@ -2,6 +2,7 @@
#include "Core.h"
#include "SoundCore.h"
#include "Mockingboard.h"
class MockingboardCardManager
{
@ -54,8 +55,7 @@ private:
void MixAllAndCopyToRingBuffer(UINT nNumSamples);
bool IsMockingboardExtraCardType(UINT slot);
static const unsigned short NUM_MB_CHANNELS = 2;
static const DWORD SOUNDBUFFER_SIZE = MAX_SAMPLES * sizeof(short) * NUM_MB_CHANNELS;
static const DWORD SOUNDBUFFER_SIZE = MAX_SAMPLES * sizeof(short) * MockingboardCard::NUM_MB_CHANNELS;
static const SHORT WAVE_DATA_MIN = (SHORT)0x8000;
static const SHORT WAVE_DATA_MAX = (SHORT)0x7FFF;

View File

@ -632,7 +632,7 @@ static void OneTimeInitialization(HINSTANCE passinstance)
}
else if (!g_cmdLine.wavFileMockingboard.empty())
{
if (RiffInitWriteFile(g_cmdLine.wavFileMockingboard.c_str(), 44100, 2))
if (RiffInitWriteFile(g_cmdLine.wavFileMockingboard.c_str(), MockingboardCard::SAMPLE_RATE, MockingboardCard::NUM_MB_CHANNELS))
GetCardMgr().GetMockingboardCardMgr().OutputToRiff();
}