Refactor : coalesce two structs into one for clarity

This commit is contained in:
Aaron Culliney 2015-06-16 21:18:52 -07:00
parent ba42037473
commit a2663298d1
4 changed files with 103 additions and 129 deletions

View File

@ -246,15 +246,11 @@ static short g_nMixBuffer[g_dwDSBufferSize / sizeof(short)];
#endif
static VOICE MockingboardVoice = {0};
static AudioBuffer_s *MockingboardVoice = NULL;
// HACK FIXME TODO : why 64? do we really need this much?!
#define MAX_VOICES 64
#ifdef APPLE2IX
static VOICE SSI263Voice[MAX_VOICES];
#else
static VOICE SSI263Voice[MAX_VOICES] = {0};
#endif
static AudioBuffer_s *SSI263Voice[MAX_VOICES] = { 0 };
#ifdef APPLE2IX
static pthread_cond_t mockingboard_cond = PTHREAD_COND_INITIALIZER;
@ -898,14 +894,14 @@ static void MB_Update()
{
#ifdef APPLE2IX
static int nNumSamplesError = 0;
if (!MockingboardVoice.bActive || !g_bMB_Active)
if (!MockingboardVoice->bActive || !g_bMB_Active)
{
nNumSamplesError = 0;
return;
}
#else
char szDbg[200];
if (!MockingboardVoice.bActive)
if (!MockingboardVoice->bActive)
return;
#endif
@ -978,9 +974,9 @@ static void MB_Update()
unsigned long dwCurrentPlayCursor, dwCurrentWriteCursor;
#ifdef APPLE2IX
int hr = MockingboardVoice.lpDSBvoice->GetCurrentPosition(MockingboardVoice.lpDSBvoice->_this, &dwCurrentPlayCursor, &dwCurrentWriteCursor);
int hr = MockingboardVoice->GetCurrentPosition(MockingboardVoice->_this, &dwCurrentPlayCursor, &dwCurrentWriteCursor);
#else
int hr = MockingboardVoice.lpDSBvoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
int hr = MockingboardVoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
#endif
if(FAILED(hr))
return;
@ -1096,10 +1092,10 @@ static void MB_Update()
//
#ifdef APPLE2IX
if(!DSGetLock(MockingboardVoice.lpDSBvoice,
if(!DSGetLock(MockingboardVoice,
/*unused*/0, (unsigned long)nNumSamples*sizeof(short)*g_nMB_NumChannels,
#else
if(DSGetLock(MockingboardVoice.lpDSBvoice,
if(DSGetLock(MockingboardVoice,
dwByteOffset, (unsigned long)nNumSamples*sizeof(short)*g_nMB_NumChannels,
#endif
&pDSLockedBuffer0, &dwDSLockedBufferSize0,
@ -1116,9 +1112,9 @@ static void MB_Update()
// Commit sound buffer
#ifdef APPLE2IX
MockingboardVoice.lpDSBvoice->Unlock(MockingboardVoice.lpDSBvoice->_this, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
MockingboardVoice->Unlock(MockingboardVoice->_this, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
#else
hr = MockingboardVoice.lpDSBvoice->Unlock((void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
hr = MockingboardVoice->Unlock((void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
#endif
(void*)pDSLockedBuffer1, dwDSLockedBufferSize1);
@ -1162,10 +1158,10 @@ static unsigned long SSI263Thread(void *lpParameter)
bool sample_finished = false;
for (unsigned int i=0; i<MAX_VOICES; i++)
{
if (SSI263Voice[i].lpDSBvoice && SSI263Voice[i].bActive)
if (SSI263Voice[i] && SSI263Voice[i]->bActive)
{
unsigned long status = 0;
SSI263Voice[i].lpDSBvoice->GetStatus(SSI263Voice[i].lpDSBvoice, &status);
SSI263Voice[i]->GetStatus(SSI263Voice[i], &status);
if (status & AUDIO_STATUS_NOTPLAYING)
{
@ -1205,7 +1201,7 @@ static unsigned long SSI263Thread(void *lpParameter)
//if(g_fh) fprintf(g_fh, "IRQ: Phoneme complete (0x%02X)\n\n", g_nCurrentActivePhoneme);
#endif
SSI263Voice[g_nCurrentActivePhoneme].bActive = false;
SSI263Voice[g_nCurrentActivePhoneme]->bActive = false;
g_nCurrentActivePhoneme = -1;
// Phoneme complete, so generate IRQ if necessary
@ -1264,27 +1260,27 @@ static void SSI263_Play(unsigned int nPhoneme)
// A write to DURPHON before previous phoneme has completed
g_bStopPhoneme = true;
#ifdef APPLE2IX
hr = SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->Stop(SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->_this);
hr = SSI263Voice[g_nCurrentActivePhoneme]->Stop(SSI263Voice[g_nCurrentActivePhoneme]->_this);
#else
hr = SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->Stop();
hr = SSI263Voice[g_nCurrentActivePhoneme]->Stop();
#endif
}
g_nCurrentActivePhoneme = nPhoneme;
#ifdef APPLE2IX
hr = SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->Replay(SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->_this);
hr = SSI263Voice[g_nCurrentActivePhoneme]->Replay(SSI263Voice[g_nCurrentActivePhoneme]->_this);
#else
hr = SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->SetCurrentPosition(0);
hr = SSI263Voice[g_nCurrentActivePhoneme]->SetCurrentPosition(0);
if(FAILED(hr))
return;
hr = SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->Play(0,0,0); // Not looping
hr = SSI263Voice[g_nCurrentActivePhoneme]->Play(0,0,0); // Not looping
#endif
if(FAILED(hr))
return;
SSI263Voice[g_nCurrentActivePhoneme].bActive = true;
SSI263Voice[g_nCurrentActivePhoneme]->bActive = true;
#else
int hr;
bool bPause;
@ -1306,9 +1302,9 @@ static void SSI263_Play(unsigned int nPhoneme)
unsigned long dwDSLockedBufferSize = 0; // Size of the locked DirectSound buffer
int16_t* pDSLockedBuffer;
hr = SSI263Voice.lpDSBvoice->Stop();
hr = SSI263Voice->Stop();
if(!DSGetLock(SSI263Voice.lpDSBvoice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0))
if(!DSGetLock(SSI263Voice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0))
return;
unsigned int nPhonemeShortLength = g_nPhonemeInfo[nPhoneme].nLength;
@ -1340,14 +1336,14 @@ static void SSI263_Play(unsigned int nPhoneme)
#endif
#ifdef APPLE2IX
hr = SSI263Voice.lpDSBvoice->Unlock(SSI263Voice.lpDSBvoice->_this, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
hr = SSI263Voice->Unlock(SSI263Voice->_this, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
#else
hr = SSI263Voice.lpDSBvoice->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
hr = SSI263Voice->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
#endif
if(FAILED(hr))
return;
hr = SSI263Voice.lpDSBvoice->Play(0,0,0); // Not looping
hr = SSI263Voice->Play(0,0,0); // Not looping
if(FAILED(hr))
return;
@ -1395,16 +1391,16 @@ static bool MB_DSInit()
return false;
#endif
MockingboardVoice.bActive = true;
MockingboardVoice->bActive = true;
// Volume might've been setup from value in Registry
if(!MockingboardVoice.nVolume)
MockingboardVoice.nVolume = DSBVOLUME_MAX;
if(!MockingboardVoice->nVolume)
MockingboardVoice->nVolume = DSBVOLUME_MAX;
#ifdef APPLE2IX
hr = MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.lpDSBvoice, MockingboardVoice.nVolume);
hr = MockingboardVoice->SetVolume(MockingboardVoice, MockingboardVoice->nVolume);
#else
hr = MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.nVolume);
hr = MockingboardVoice->SetVolume(MockingboardVoice->nVolume);
#endif
LOG("MB_DSInit: SetVolume(), hr=0x%08X\n", (unsigned int)hr);
@ -1486,9 +1482,9 @@ static bool MB_DSInit()
}
#ifdef APPLE2IX
hr = !DSGetLock(SSI263Voice[i].lpDSBvoice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0);
hr = !DSGetLock(SSI263Voice[i], 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0);
#else
hr = DSGetLock(SSI263Voice[i].lpDSBvoice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0);
hr = DSGetLock(SSI263Voice[i], 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0);
#endif
//LOG("MB_DSInit: (%02d) DSGetLock(), res=%d\n", i, hr ? 1 : 0); // WARNING: Lock acquired && doing heavy-weight logging
if(FAILED(hr))
@ -1518,7 +1514,7 @@ static bool MB_DSInit()
#ifdef APPLE2IX
// 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);
hr = SSI263Voice[i]->QueryInterface(IID_IDirectSoundNotify, (void **)&SSI263Voice[i]->lpDSNotify);
//LOG("MB_DSInit: (%02d) QueryInterface(), hr=0x%08X\n", i, hr); // WARNING: Lock acquired && doing heavy-weight logging
if(FAILED(hr))
{
@ -1532,7 +1528,7 @@ static bool MB_DSInit()
PositionNotify.dwOffset = DSBPN_OFFSETSTOP; // End of buffer
PositionNotify.hEventNotify = g_hSSI263Event[0];
hr = SSI263Voice[i].lpDSNotify->SetNotificationPositions(1, &PositionNotify);
hr = SSI263Voice[i]->lpDSNotify->SetNotificationPositions(1, &PositionNotify);
//LOG("MB_DSInit: (%02d) SetNotificationPositions(), hr=0x%08X\n", i, hr); // WARNING: Lock acquired && doing heavy-weight logging
if(FAILED(hr))
{
@ -1542,9 +1538,9 @@ static bool MB_DSInit()
#endif
#ifdef APPLE2IX
hr = SSI263Voice[i].lpDSBvoice->UnlockStaticBuffer(SSI263Voice[i].lpDSBvoice->_this, dwDSLockedBufferSize);
hr = SSI263Voice[i]->UnlockStaticBuffer(SSI263Voice[i]->_this, dwDSLockedBufferSize);
#else
hr = SSI263Voice[i].lpDSBvoice->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
hr = SSI263Voice[i]->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
#endif
LOG("MB_DSInit: (%02d) Unlock(),hr=0x%08X\n", i, (unsigned int)hr);
if(FAILED(hr))
@ -1553,12 +1549,12 @@ static bool MB_DSInit()
return false;
}
SSI263Voice[i].bActive = false;
SSI263Voice[i].nVolume = MockingboardVoice.nVolume; // Use same volume as MB
SSI263Voice[i]->bActive = false;
SSI263Voice[i]->nVolume = MockingboardVoice->nVolume; // Use same volume as MB
#ifdef APPLE2IX
hr = SSI263Voice[i].lpDSBvoice->SetVolume(SSI263Voice[i].lpDSBvoice, SSI263Voice[i].nVolume);
hr = SSI263Voice[i]->SetVolume(SSI263Voice[i], SSI263Voice[i]->nVolume);
#else
hr = SSI263Voice[i].lpDSBvoice->SetVolume(SSI263Voice[i].nVolume);
hr = SSI263Voice[i]->SetVolume(SSI263Voice[i]->nVolume);
#endif
LOG("MB_DSInit: (%02d) SetVolume(), hr=0x%08X\n", i, (unsigned int)hr);
}
@ -1619,14 +1615,14 @@ static void MB_DSUninit()
//
if(MockingboardVoice.lpDSBvoice && MockingboardVoice.bActive)
if(MockingboardVoice && MockingboardVoice->bActive)
{
#ifdef APPLE2IX
MockingboardVoice.lpDSBvoice->Stop(MockingboardVoice.lpDSBvoice->_this);
MockingboardVoice->Stop(MockingboardVoice->_this);
#else
MockingboardVoice.lpDSBvoice->Stop();
MockingboardVoice->Stop();
#endif
MockingboardVoice.bActive = false;
MockingboardVoice->bActive = false;
}
DSReleaseSoundBuffer(&MockingboardVoice);
@ -1635,14 +1631,14 @@ static void MB_DSUninit()
for(int i=0; i<MAX_VOICES; i++)
{
if(SSI263Voice[i].lpDSBvoice && SSI263Voice[i].bActive)
if(SSI263Voice[i] && SSI263Voice[i]->bActive)
{
#ifdef APPLE2IX
SSI263Voice[i].lpDSBvoice->Stop(SSI263Voice[i].lpDSBvoice->_this);
SSI263Voice[i]->Stop(SSI263Voice[i]->_this);
#else
SSI263Voice[i].lpDSBvoice->Stop();
SSI263Voice[i]->Stop();
#endif
SSI263Voice[i].bActive = false;
SSI263Voice[i]->bActive = false;
}
DSReleaseSoundBuffer(&SSI263Voice[i]);
@ -1676,11 +1672,11 @@ static void MB_DSUninit()
void MB_Initialize()
{
#ifdef APPLE2IX
memset(SSI263Voice, 0x0, sizeof(VOICE)*MAX_VOICES);
memset(SSI263Voice, 0x0, sizeof(AudioBuffer_s)*MAX_VOICES);
#endif
if (g_bDisableDirectSoundMockingboard)
{
MockingboardVoice.bMute = true;
MockingboardVoice->bMute = true;
g_SoundcardType = CT_Empty;
}
else
@ -2039,21 +2035,21 @@ void MB_Mute()
if(g_SoundcardType == CT_Empty)
return;
if(MockingboardVoice.bActive && !MockingboardVoice.bMute)
if(MockingboardVoice->bActive && !MockingboardVoice->bMute)
{
#ifdef APPLE2IX
MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.lpDSBvoice, DSBVOLUME_MIN);
MockingboardVoice->SetVolume(MockingboardVoice, DSBVOLUME_MIN);
#else
MockingboardVoice.lpDSBvoice->SetVolume(DSBVOLUME_MIN);
MockingboardVoice->SetVolume(DSBVOLUME_MIN);
#endif
MockingboardVoice.bMute = true;
MockingboardVoice->bMute = true;
}
if(g_nCurrentActivePhoneme >= 0)
#ifdef APPLE2IX
SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->SetVolume(SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice, DSBVOLUME_MIN);
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(SSI263Voice[g_nCurrentActivePhoneme], DSBVOLUME_MIN);
#else
SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->SetVolume(DSBVOLUME_MIN);
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(DSBVOLUME_MIN);
#endif
}
@ -2064,21 +2060,21 @@ void MB_Demute()
if(g_SoundcardType == CT_Empty)
return;
if(MockingboardVoice.bActive && MockingboardVoice.bMute)
if(MockingboardVoice->bActive && MockingboardVoice->bMute)
{
#ifdef APPLE2IX
MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.lpDSBvoice, MockingboardVoice.nVolume);
MockingboardVoice->SetVolume(MockingboardVoice, MockingboardVoice->nVolume);
#else
MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.nVolume);
MockingboardVoice->SetVolume(MockingboardVoice->nVolume);
#endif
MockingboardVoice.bMute = false;
MockingboardVoice->bMute = false;
}
if(g_nCurrentActivePhoneme >= 0)
#ifdef APPLE2IX
SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->SetVolume(SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice, SSI263Voice[g_nCurrentActivePhoneme].nVolume);
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(SSI263Voice[g_nCurrentActivePhoneme], SSI263Voice[g_nCurrentActivePhoneme]->nVolume);
#else
SSI263Voice[g_nCurrentActivePhoneme].lpDSBvoice->SetVolume(SSI263Voice[g_nCurrentActivePhoneme].nVolume);
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(SSI263Voice[g_nCurrentActivePhoneme]->nVolume);
#endif
}
@ -2205,7 +2201,7 @@ double MB_GetFramePeriod()
bool MB_IsActive()
{
if(!MockingboardVoice.bActive)
if(!MockingboardVoice->bActive)
return false;
// Ignore /g_bMBTimerIrqActive/ as timer's irq handler will access 6522 regs affecting /g_bMB_Active/
@ -2230,13 +2226,13 @@ void MB_SetVolume(unsigned long dwVolume, unsigned long dwVolumeMax)
dwVolumeMax >>= 2;
#endif
MockingboardVoice.nVolume = NewVolume(dwVolume, dwVolumeMax);
MockingboardVoice->nVolume = NewVolume(dwVolume, dwVolumeMax);
if(MockingboardVoice.bActive)
if(MockingboardVoice->bActive)
#ifdef APPLE2IX
MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.lpDSBvoice, MockingboardVoice.nVolume);
MockingboardVoice->SetVolume(MockingboardVoice, MockingboardVoice->nVolume);
#else
MockingboardVoice.lpDSBvoice->SetVolume(MockingboardVoice.nVolume);
MockingboardVoice->SetVolume(MockingboardVoice->nVolume);
#endif
}

View File

@ -43,7 +43,7 @@ static AudioContext_s *g_lpDS = NULL;
#define uMAX_VOICES 66
static unsigned int g_uNumVoices = 0;
static VOICE* g_pVoices[uMAX_VOICES] = {NULL};
static AudioBuffer_s* g_pVoices[uMAX_VOICES] = {NULL};
//-------------------------------------
@ -85,7 +85,7 @@ bool DSGetLock(AudioBuffer_s *pVoice, unsigned long dwOffset, unsigned long dwBy
//-----------------------------------------------------------------------------
int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels)
long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels)
{
AudioParams_s params = { 0 };
@ -96,34 +96,27 @@ int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBuffe
params.nAvgBytesPerSec = params.nBlockAlign * params.nSamplesPerSec;
params.dwBufferBytes = dwBufferSize;
// Are buffers released when g_lpDS OR pVoice->lpDSBvoice is released?
// . From DirectX doc:
// "Buffer objects are owned by the device object that created them. When the
// device object is released, all buffers created by that object are also released..."
if (pVoice->lpDSBvoice)
if (*pVoice)
{
g_lpDS->DestroySoundBuffer(&pVoice->lpDSBvoice);
//DSReleaseSoundBuffer(pVoice);
DSReleaseSoundBuffer(pVoice);
}
int hr = g_lpDS->CreateSoundBuffer(&params, &pVoice->lpDSBvoice, g_lpDS);
int hr = g_lpDS->CreateSoundBuffer(&params, pVoice, g_lpDS);
if(hr)
return hr;
//
assert(g_uNumVoices < uMAX_VOICES);
if(g_uNumVoices < uMAX_VOICES)
g_pVoices[g_uNumVoices++] = pVoice;
g_pVoices[g_uNumVoices++] = *pVoice;
return hr;
}
void DSReleaseSoundBuffer(VOICE* pVoice)
void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice)
{
for(unsigned int i=0; i<g_uNumVoices; i++)
{
if(g_pVoices[i] == pVoice)
if(g_pVoices[i] == *pVoice)
{
g_pVoices[i] = g_pVoices[g_uNumVoices-1];
g_pVoices[g_uNumVoices-1] = NULL;
@ -134,26 +127,26 @@ void DSReleaseSoundBuffer(VOICE* pVoice)
if (g_lpDS)
{
g_lpDS->DestroySoundBuffer(&pVoice->lpDSBvoice);
g_lpDS->DestroySoundBuffer(pVoice);
}
}
//-----------------------------------------------------------------------------
bool DSZeroVoiceBuffer(VOICE *Voice, char* pszDevName, unsigned long dwBufferSize)
bool DSZeroVoiceBuffer(AudioBuffer_s *pVoice, char* pszDevName, unsigned long dwBufferSize)
{
unsigned long dwDSLockedBufferSize = 0; // Size of the locked DirectSound buffer
int16_t* pDSLockedBuffer;
unsigned long argX = 0;
int hr = Voice->lpDSBvoice->Stop(Voice->lpDSBvoice->_this);
int hr = pVoice->Stop(pVoice->_this);
if(hr)
{
LOG("%s: DSStop failed (%08X)\n",pszDevName,(unsigned int)hr);
return false;
}
hr = !DSGetLock(Voice->lpDSBvoice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, &argX);
hr = !DSGetLock(pVoice, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, &argX);
if(hr)
{
LOG("%s: DSGetLock failed (%08X)\n",pszDevName,(unsigned int)hr);
@ -163,14 +156,14 @@ bool DSZeroVoiceBuffer(VOICE *Voice, char* pszDevName, unsigned long dwBufferSiz
assert(dwDSLockedBufferSize == dwBufferSize);
memset(pDSLockedBuffer, 0x00, dwDSLockedBufferSize);
hr = Voice->lpDSBvoice->Unlock(Voice->lpDSBvoice->_this, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, argX);
hr = pVoice->Unlock(pVoice->_this, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, argX);
if(hr)
{
LOG("%s: DSUnlock failed (%08X)\n",pszDevName,(unsigned int)hr);
return false;
}
hr = Voice->lpDSBvoice->Play(Voice->lpDSBvoice->_this,0,0,0);
hr = pVoice->Play(pVoice->_this,0,0,0);
if(hr)
{
LOG("%s: DSPlay failed (%08X)\n",pszDevName,(unsigned int)hr);
@ -182,13 +175,13 @@ bool DSZeroVoiceBuffer(VOICE *Voice, char* pszDevName, unsigned long dwBufferSiz
//-----------------------------------------------------------------------------
bool DSZeroVoiceWritableBuffer(VOICE *Voice, char* pszDevName, unsigned long dwBufferSize)
bool DSZeroVoiceWritableBuffer(AudioBuffer_s *pVoice, char* pszDevName, unsigned long dwBufferSize)
{
unsigned long dwDSLockedBufferSize0=0, dwDSLockedBufferSize1=0;
int16_t *pDSLockedBuffer0, *pDSLockedBuffer1;
int hr = DSGetLock(Voice->lpDSBvoice,
int hr = DSGetLock(pVoice,
0, dwBufferSize,
&pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1);
@ -203,7 +196,7 @@ bool DSZeroVoiceWritableBuffer(VOICE *Voice, char* pszDevName, unsigned long dwB
if(pDSLockedBuffer1)
memset(pDSLockedBuffer1, 0x00, dwDSLockedBufferSize1);
hr = Voice->lpDSBvoice->Unlock(Voice->lpDSBvoice->_this, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
hr = pVoice->Unlock(pVoice->_this, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
(void*)pDSLockedBuffer1, dwDSLockedBufferSize1);
if(hr)
{

View File

@ -22,8 +22,11 @@
#define AUDIO_STATUS_NOTPLAYING 0x08000000
typedef struct AudioBuffer_s {
bool bActive; // Playback is active
bool bMute;
long nVolume; // Current volume (as used by DirectSound)
void *_this;
#warning TODO rename _this variable to indicate that it is implementation_specific
long (*SetVolume)(void* _this, long lVolume);
@ -67,24 +70,16 @@ typedef struct AudioContext_s {
long (*DestroySoundBuffer)(INOUT AudioBuffer_s **buffer);
} AudioContext_s;
typedef struct
{
AudioBuffer_s *lpDSBvoice;
bool bActive; // Playback is active
bool bMute;
long nVolume; // Current volume (as used by DirectSound)
} VOICE;
bool DSGetLock(AudioBuffer_s *pVoice, unsigned long dwOffset, unsigned long dwBytes,
int16_t** ppDSLockedBuffer0, unsigned long* pdwDSLockedBufferSize0,
int16_t** ppDSLockedBuffer1, unsigned long* pdwDSLockedBufferSize1);
int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels);
void DSReleaseSoundBuffer(VOICE* pVoice);
long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels);
void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice);
bool DSZeroVoiceBuffer(VOICE *Voice, char* pszDevName, unsigned long dwBufferSize);
bool DSZeroVoiceWritableBuffer(VOICE *Voice, char* pszDevName, unsigned long dwBufferSize);
bool DSZeroVoiceBuffer(AudioBuffer_s *pVoice, char *pszDevName, unsigned long dwBufferSize);
bool DSZeroVoiceWritableBuffer(AudioBuffer_s *pVoice, char *pszDevName, unsigned long dwBufferSize);
typedef enum eFADE {FADE_NONE, FADE_IN, FADE_OUT} eFADE;
void SoundCore_SetFade(eFADE FadeType);

View File

@ -57,7 +57,7 @@ static unsigned int speaker_silent_step = 0;
static int samples_adjustment_counter = 0;
static VOICE SpeakerVoice = { 0 };
static AudioBuffer_s *speakerBuffer = NULL;
// --------------------------------------------------------------------------------------------------------------------
@ -202,12 +202,8 @@ static void _speaker_update(/*bool toggled*/) {
static void _submit_samples_buffer_fullspeed(void) {
samples_adjustment_counter = 0;
if (!SpeakerVoice.bActive) {
return;
}
unsigned long bytes_queued = 0;
long err = SpeakerVoice.lpDSBvoice->GetCurrentPosition(SpeakerVoice.lpDSBvoice->_this, &bytes_queued, NULL);
long err = speakerBuffer->GetCurrentPosition(speakerBuffer->_this, &bytes_queued, NULL);
if (err) {
return;
}
@ -224,7 +220,7 @@ static void _submit_samples_buffer_fullspeed(void) {
unsigned long system_buffer_size = 0;
int16_t *system_samples_buffer = NULL;
if (!DSGetLock(SpeakerVoice.lpDSBvoice, /*unused*/ 0, num_samples_pad*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL)) {
if (!DSGetLock(speakerBuffer, /*unused*/ 0, num_samples_pad*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL)) {
return;
}
assert(num_samples_pad*sizeof(int16_t) <= system_buffer_size);
@ -234,7 +230,7 @@ static void _submit_samples_buffer_fullspeed(void) {
system_samples_buffer[i] = speaker_data;
}
SpeakerVoice.lpDSBvoice->Unlock(SpeakerVoice.lpDSBvoice->_this, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
speakerBuffer->Unlock(speakerBuffer->_this, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
}
// Submits samples from the samples_buffer to the audio system backend when running at a normal scaled-speed. This also
@ -244,12 +240,8 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) {
assert(num_samples);
if (!SpeakerVoice.bActive) {
return num_samples;
}
unsigned long bytes_queued = 0;
long err = SpeakerVoice.lpDSBvoice->GetCurrentPosition(SpeakerVoice.lpDSBvoice->_this, &bytes_queued, NULL);
long err = speakerBuffer->GetCurrentPosition(speakerBuffer->_this, &bytes_queued, NULL);
if (err) {
return num_samples;
}
@ -295,13 +287,13 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) {
unsigned long system_buffer_size = 0;
int16_t *system_samples_buffer = NULL;
if (!DSGetLock(SpeakerVoice.lpDSBvoice, /*unused*/0, (unsigned long)num_samples_to_use*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL)) {
if (!DSGetLock(speakerBuffer, /*unused*/0, (unsigned long)num_samples_to_use*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL)) {
return num_samples;
}
memcpy(system_samples_buffer, &samples_buffer[0], system_buffer_size);
err = SpeakerVoice.lpDSBvoice->Unlock(SpeakerVoice.lpDSBvoice->_this, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
err = speakerBuffer->Unlock(speakerBuffer->_this, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
if (err) {
return num_samples;
}
@ -314,16 +306,14 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) {
// speaker public API functions
void speaker_destroy(void) {
if (SpeakerVoice.lpDSBvoice && SpeakerVoice.bActive) {
SpeakerVoice.lpDSBvoice->Stop(SpeakerVoice.lpDSBvoice->_this);
SpeakerVoice.bActive = false;
if (speakerBuffer) {
speakerBuffer->Stop(speakerBuffer->_this);
}
DSReleaseSoundBuffer(&SpeakerVoice);
DSReleaseSoundBuffer(&speakerBuffer);
}
void speaker_init(void) {
SpeakerVoice.bActive = true;
long err = DSGetSoundBuffer(&SpeakerVoice, 0, SOUNDCORE_BUFFER_SIZE, SPKR_SAMPLE_RATE, 1);
long err = DSGetSoundBuffer(&speakerBuffer, 0, SOUNDCORE_BUFFER_SIZE, SPKR_SAMPLE_RATE, 1);
assert(!err);
_speaker_init_timing();
}
@ -382,7 +372,7 @@ void speaker_flush(void) {
}
bool speaker_is_active(void) {
return SpeakerVoice.bActive && speaker_recently_active;
return speaker_recently_active;
}
void speaker_set_volume(int16_t amplitude) {