Refactor : clarify _this and _internal parameters

This commit is contained in:
Aaron Culliney 2015-06-17 20:54:51 -07:00
parent 5beb1ce476
commit f353a11ec5
4 changed files with 56 additions and 57 deletions

View File

@ -974,7 +974,7 @@ static void MB_Update()
unsigned long dwCurrentPlayCursor, dwCurrentWriteCursor;
#ifdef APPLE2IX
int hr = MockingboardVoice->GetCurrentPosition(MockingboardVoice->_this, &dwCurrentPlayCursor, &dwCurrentWriteCursor);
int hr = MockingboardVoice->GetCurrentPosition(MockingboardVoice, &dwCurrentPlayCursor, &dwCurrentWriteCursor);
#else
int hr = MockingboardVoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
#endif
@ -1089,7 +1089,7 @@ static void MB_Update()
//
if(MockingboardVoice->Lock(MockingboardVoice->_this,
if(MockingboardVoice->Lock(MockingboardVoice,
/*unused*/0, (unsigned long)nNumSamples*sizeof(short)*g_nMB_NumChannels,
&pDSLockedBuffer0, &dwDSLockedBufferSize0,
&pDSLockedBuffer1, &dwDSLockedBufferSize1, 0))
@ -1105,7 +1105,7 @@ static void MB_Update()
// Commit sound buffer
#ifdef APPLE2IX
MockingboardVoice->Unlock(MockingboardVoice->_this, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
MockingboardVoice->Unlock(MockingboardVoice, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
#else
hr = MockingboardVoice->Unlock((void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
#endif
@ -1253,7 +1253,7 @@ 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]->Stop(SSI263Voice[g_nCurrentActivePhoneme]->_this);
hr = SSI263Voice[g_nCurrentActivePhoneme]->Stop(SSI263Voice[g_nCurrentActivePhoneme]);
#else
hr = SSI263Voice[g_nCurrentActivePhoneme]->Stop();
#endif
@ -1262,7 +1262,7 @@ static void SSI263_Play(unsigned int nPhoneme)
g_nCurrentActivePhoneme = nPhoneme;
#ifdef APPLE2IX
hr = SSI263Voice[g_nCurrentActivePhoneme]->Replay(SSI263Voice[g_nCurrentActivePhoneme]->_this);
hr = SSI263Voice[g_nCurrentActivePhoneme]->Replay(SSI263Voice[g_nCurrentActivePhoneme]);
#else
hr = SSI263Voice[g_nCurrentActivePhoneme]->SetCurrentPosition(0);
if(FAILED(hr))
@ -1329,7 +1329,7 @@ static void SSI263_Play(unsigned int nPhoneme)
#endif
#ifdef APPLE2IX
hr = SSI263Voice->Unlock(SSI263Voice->_this, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
hr = SSI263Voice->Unlock(SSI263Voice, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
#else
hr = SSI263Voice->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
#endif
@ -1474,7 +1474,7 @@ static bool MB_DSInit()
return false;
}
hr = SSI263Voice[i]->Lock(SSI263Voice[i]->_this, 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0, 0);
hr = SSI263Voice[i]->Lock(SSI263Voice[i], 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0, 0);
//LOG("MB_DSInit: (%02d) DSGetLock(), res=%d\n", i, hr ? 1 : 0); // WARNING: Lock acquired && doing heavy-weight logging
if(FAILED(hr))
{
@ -1527,7 +1527,7 @@ static bool MB_DSInit()
#endif
#ifdef APPLE2IX
hr = SSI263Voice[i]->UnlockStaticBuffer(SSI263Voice[i]->_this, dwDSLockedBufferSize);
hr = SSI263Voice[i]->UnlockStaticBuffer(SSI263Voice[i], dwDSLockedBufferSize);
#else
hr = SSI263Voice[i]->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
#endif
@ -1607,7 +1607,7 @@ static void MB_DSUninit()
if(MockingboardVoice && MockingboardVoice->bActive)
{
#ifdef APPLE2IX
MockingboardVoice->Stop(MockingboardVoice->_this);
MockingboardVoice->Stop(MockingboardVoice);
#else
MockingboardVoice->Stop();
#endif
@ -1623,7 +1623,7 @@ static void MB_DSUninit()
if(SSI263Voice[i] && SSI263Voice[i]->bActive)
{
#ifdef APPLE2IX
SSI263Voice[i]->Stop(SSI263Voice[i]->_this);
SSI263Voice[i]->Stop(SSI263Voice[i]);
#else
SSI263Voice[i]->Stop();
#endif

View File

@ -181,7 +181,7 @@ static long openal_systemSetup(const char *sound_device, AudioContext_s **audio_
break;
}
(*audio_context)->implementation_specific = ctx;
(*audio_context)->_internal = ctx;
(*audio_context)->CreateSoundBuffer = &OpenALCreateSoundBuffer;
(*audio_context)->DestroySoundBuffer = &OpenALDestroySoundBuffer;
@ -201,9 +201,9 @@ static long openal_systemShutdown(AudioContext_s **audio_context)
{
assert(*audio_context != NULL);
ALCcontext *ctx = (ALCcontext*) (*audio_context)->implementation_specific;
ALCcontext *ctx = (ALCcontext*) (*audio_context)->_internal;
assert(ctx != NULL);
(*audio_context)->implementation_specific = NULL;
(*audio_context)->_internal = NULL;
FREE(*audio_context);
CloseAL();
@ -411,7 +411,7 @@ static ALVoice *NewVoice(const AudioParams_s *params)
// ----------------------------------------------------------------------------
static long ALGetVolume(void *_this, long *volume)
static long ALGetVolume(AudioBuffer_s *_this, long *volume)
{
LOG("ALGetVolume ...");
if (volume)
@ -421,25 +421,25 @@ static long ALGetVolume(void *_this, long *volume)
return 0;
}
static long ALSetVolume(void *_this, long volume)
static long ALSetVolume(AudioBuffer_s *_this, long volume)
{
LOG("ALSetVolume ...");
return 0;
}
static long ALStop(void *_this)
static long ALStop(AudioBuffer_s *_this)
{
LOG("ALStop ...");
return 0;
}
static long ALRestore(void *_this)
static long ALRestore(AudioBuffer_s *_this)
{
LOG("ALRestore ...");
return 0;
}
static long ALPlay(void *_this, unsigned long reserved1, unsigned long reserved2, unsigned long flags)
static long ALPlay(AudioBuffer_s *_this, unsigned long reserved1, unsigned long reserved2, unsigned long flags)
{
LOG("ALPlay ...");
@ -512,9 +512,9 @@ static int _ALProcessPlayBuffers(ALVoice *voice, ALuint *bytes_queued)
}
// returns queued+working sound buffer size in bytes
static long ALGetPosition(void *_this, unsigned long *bytes_queued, unsigned long *unused_write_cursor)
static long ALGetPosition(AudioBuffer_s *_this, unsigned long *bytes_queued, unsigned long *unused_write_cursor)
{
ALVoice *voice = (ALVoice*)_this;
ALVoice *voice = (ALVoice*)_this->_internal;
*bytes_queued = 0;
if (unused_write_cursor)
{
@ -540,9 +540,9 @@ static long ALGetPosition(void *_this, unsigned long *bytes_queued, unsigned lon
}
// DS->Lock()
static long ALBegin(void *_this, unsigned long unused, unsigned long write_bytes, INOUT int16_t **audio_ptr1, INOUT unsigned long *audio_bytes1, void **unused_audio_ptr2, unsigned long *unused_audio_bytes2, unsigned long flags_unused)
static long ALBegin(AudioBuffer_s *_this, unsigned long unused, unsigned long write_bytes, INOUT int16_t **audio_ptr1, INOUT unsigned long *audio_bytes1, void **unused_audio_ptr2, unsigned long *unused_audio_bytes2, unsigned long flags_unused)
{
ALVoice *voice = (ALVoice*)_this;
ALVoice *voice = (ALVoice*)_this->_internal;
if (unused_audio_ptr2)
{
@ -635,9 +635,9 @@ static int _ALSubmitBufferToOpenAL(ALVoice *voice)
}
// DS->Unlock()
static long ALCommit(void *_this, void *unused_audio_ptr1, unsigned long audio_bytes1, void *unused_audio_ptr2, unsigned long unused_audio_bytes2)
static long ALCommit(AudioBuffer_s *_this, void *unused_audio_ptr1, unsigned long audio_bytes1, void *unused_audio_ptr2, unsigned long unused_audio_bytes2)
{
ALVoice *voice = (ALVoice*)_this;
ALVoice *voice = (ALVoice*)_this->_internal;
int err = 0;
ALuint bytes_queued = 0;
@ -681,17 +681,17 @@ static long ALCommit(void *_this, void *unused_audio_ptr1, unsigned long audio_b
}
// HACK Part I : done once for mockingboard that has semiauto repeating phonemes ...
static long ALCommitStaticBuffer(void *_this, unsigned long audio_bytes1)
static long ALCommitStaticBuffer(AudioBuffer_s *_this, unsigned long audio_bytes1)
{
ALVoice *voice = (ALVoice*)_this;
ALVoice *voice = (ALVoice*)_this->_internal;
voice->replay_index = (ALsizei)audio_bytes1;
return 0;
}
// HACK Part II : replay mockingboard phoneme ...
static long ALReplay(void *_this)
static long ALReplay(AudioBuffer_s *_this)
{
ALVoice *voice = (ALVoice*)_this;
ALVoice *voice = (ALVoice*)_this->_internal;
voice->index = voice->replay_index;
int err = 0;
@ -705,9 +705,9 @@ static long ALReplay(void *_this)
return 0;
}
static long ALGetStatus(void *_this, unsigned long *status)
static long ALGetStatus(AudioBuffer_s *_this, unsigned long *status)
{
ALVoice* voice = (ALVoice*)_this;
ALVoice* voice = (ALVoice*)_this->_internal;
int err = 0;
ALint state = 0;
@ -735,7 +735,7 @@ static long OpenALCreateSoundBuffer(const AudioParams_s *params, INOUT AudioBuff
LOG("OpenALCreateSoundBuffer ...");
assert(*soundbuf_struct == NULL);
ALCcontext *ctx = (ALCcontext*)(audio_context->implementation_specific);
ALCcontext *ctx = (ALCcontext*)(audio_context->_internal);
assert(ctx != NULL);
ALVoice *voice = NULL;
@ -765,7 +765,7 @@ static long OpenALCreateSoundBuffer(const AudioParams_s *params, INOUT AudioBuff
break;
}
(*soundbuf_struct)->_this = voice;
(*soundbuf_struct)->_internal = voice;
(*soundbuf_struct)->SetVolume = &ALSetVolume;
(*soundbuf_struct)->GetVolume = &ALGetVolume;
(*soundbuf_struct)->GetCurrentPosition = &ALGetPosition;
@ -801,7 +801,7 @@ static long OpenALDestroySoundBuffer(INOUT AudioBuffer_s **soundbuf_struct)
return 0;
}
LOG("OpenALDestroySoundBuffer ...");
ALVoice *voice = (*soundbuf_struct)->_this;
ALVoice *voice = (ALVoice *)((*soundbuf_struct)->_internal);
ALint source = voice->source;
DeleteVoice(voice);

View File

@ -26,36 +26,35 @@
#define SOUNDCORE_ERROR_MAX 200
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
bool bActive; // Mockingboard ... refactor?
bool bMute; // Mockingboard ... refactor?
long nVolume; // Mockingboard ... refactor?
PRIVATE void *_internal;
long (*SetVolume)(void* _this, long lVolume);
long (*SetVolume)(struct AudioBuffer_s *_this, long lVolume);
long (*GetVolume)(void* _this, long *lplVolume);
long (*GetVolume)(struct AudioBuffer_s *_this, long *lplVolume);
long (*GetCurrentPosition)(void* _this, unsigned long *lpdwCurrentPlayCursor, unsigned long *lpdwCurrentWriteCursor);
long (*GetCurrentPosition)(struct AudioBuffer_s *_this, unsigned long *lpdwCurrentPlayCursor, unsigned long *lpdwCurrentWriteCursor);
long (*Stop)(void* _this);
long (*Stop)(struct AudioBuffer_s *_this);
// This method restores the memory allocation for a lost sound buffer for the specified DirectSoundBuffer object.
long (*Restore)(void *_this);
long (*Restore)(struct AudioBuffer_s *_this);
long (*Play)(void* _this, unsigned long dwReserved1, unsigned long dwReserved2, unsigned long dwFlags);
long (*Play)(struct AudioBuffer_s *_this, unsigned long dwReserved1, unsigned long dwReserved2, unsigned long dwFlags);
// This method obtains a valid write pointer to the sound buffer's audio data
long (*Lock)(void* _this, unsigned long dwWriteCursor, unsigned long dwWriteBytes, INOUT int16_t **lplpvAudioPtr1, INOUT unsigned long *lpdwAudioBytes1, void **lplpvAudioPtr2, unsigned long *lpdwAudioBytes2, unsigned long dwFlags);
long (*Lock)(struct AudioBuffer_s *_this, unsigned long dwWriteCursor, unsigned long dwWriteBytes, INOUT int16_t **lplpvAudioPtr1, INOUT unsigned long *lpdwAudioBytes1, void **lplpvAudioPtr2, unsigned long *lpdwAudioBytes2, unsigned long dwFlags);
// This method releases a locked sound buffer.
long (*Unlock)(void* _this, int16_t *lpvAudioPtr1, unsigned long dwAudioBytes1, void *lpvAudioPtr2, unsigned long dwAudioBytes2);
long (*Unlock)(struct AudioBuffer_s *_this, int16_t *lpvAudioPtr1, unsigned long dwAudioBytes1, void *lpvAudioPtr2, unsigned long dwAudioBytes2);
long (*GetStatus)(void* _this, unsigned long *lpdwStatus);
long (*GetStatus)(struct AudioBuffer_s *_this, unsigned long *lpdwStatus);
// Mockingboard-specific HACKS
long (*UnlockStaticBuffer)(void* _this, unsigned long dwAudioBytes);
long (*Replay)(void* _this);
long (*UnlockStaticBuffer)(struct AudioBuffer_s *_this, unsigned long dwAudioBytes);
long (*Replay)(struct AudioBuffer_s *_this);
} AudioBuffer_s;
@ -107,7 +106,7 @@ typedef struct AudioParams_s {
} AudioParams_s;
typedef struct AudioContext_s {
void *implementation_specific;
PRIVATE void *_internal;
PRIVATE long (*CreateSoundBuffer)(const AudioParams_s *params, INOUT AudioBuffer_s **buffer, const struct AudioContext_s *sound_system);
PRIVATE long (*DestroySoundBuffer)(INOUT AudioBuffer_s **buffer);
} AudioContext_s;

View File

@ -203,7 +203,7 @@ static void _submit_samples_buffer_fullspeed(void) {
samples_adjustment_counter = 0;
unsigned long bytes_queued = 0;
long err = speakerBuffer->GetCurrentPosition(speakerBuffer->_this, &bytes_queued, NULL);
long err = speakerBuffer->GetCurrentPosition(speakerBuffer, &bytes_queued, NULL);
if (err) {
return;
}
@ -220,7 +220,7 @@ static void _submit_samples_buffer_fullspeed(void) {
unsigned long system_buffer_size = 0;
int16_t *system_samples_buffer = NULL;
if (speakerBuffer->Lock(speakerBuffer->_this, /*unused*/ 0, num_samples_pad*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL, 0)) {
if (speakerBuffer->Lock(speakerBuffer, /*unused*/ 0, num_samples_pad*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL, 0)) {
return;
}
assert(num_samples_pad*sizeof(int16_t) <= system_buffer_size);
@ -230,7 +230,7 @@ static void _submit_samples_buffer_fullspeed(void) {
system_samples_buffer[i] = speaker_data;
}
speakerBuffer->Unlock(speakerBuffer->_this, system_samples_buffer, system_buffer_size, NULL, 0);
speakerBuffer->Unlock(speakerBuffer, 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
@ -241,7 +241,7 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) {
assert(num_samples);
unsigned long bytes_queued = 0;
long err = speakerBuffer->GetCurrentPosition(speakerBuffer->_this, &bytes_queued, NULL);
long err = speakerBuffer->GetCurrentPosition(speakerBuffer, &bytes_queued, NULL);
if (err) {
return num_samples;
}
@ -284,13 +284,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 (speakerBuffer->Lock(speakerBuffer->_this, /*unused*/0, (unsigned long)num_samples_to_use*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL, 0)) {
if (speakerBuffer->Lock(speakerBuffer, /*unused*/0, (unsigned long)num_samples_to_use*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL, 0)) {
return num_samples;
}
memcpy(system_samples_buffer, &samples_buffer[0], system_buffer_size);
err = speakerBuffer->Unlock(speakerBuffer->_this, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
err = speakerBuffer->Unlock(speakerBuffer, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
if (err) {
return num_samples;
}
@ -304,7 +304,7 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) {
void speaker_destroy(void) {
if (speakerBuffer) {
speakerBuffer->Stop(speakerBuffer->_this);
speakerBuffer->Stop(speakerBuffer);
}
audio_destroySoundBuffer(&speakerBuffer);
}