mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-11 14:30:08 +00:00
Refactor : simplify audio buffer API
This commit is contained in:
parent
3ed43fa43c
commit
81941295e6
@ -974,7 +974,8 @@ static void MB_Update()
|
||||
|
||||
unsigned long dwCurrentPlayCursor, dwCurrentWriteCursor;
|
||||
#ifdef APPLE2IX
|
||||
int hr = MockingboardVoice->GetCurrentPosition(MockingboardVoice, &dwCurrentPlayCursor, &dwCurrentWriteCursor);
|
||||
dwCurrentWriteCursor = 0;
|
||||
int hr = MockingboardVoice->GetCurrentPosition(MockingboardVoice, &dwCurrentPlayCursor);
|
||||
#else
|
||||
int hr = MockingboardVoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
|
||||
#endif
|
||||
@ -1089,10 +1090,11 @@ static void MB_Update()
|
||||
|
||||
//
|
||||
|
||||
pDSLockedBuffer1 = NULL;
|
||||
dwDSLockedBufferSize1 = 0;
|
||||
if(MockingboardVoice->Lock(MockingboardVoice,
|
||||
/*unused*/0, (unsigned long)nNumSamples*sizeof(short)*g_nMB_NumChannels,
|
||||
&pDSLockedBuffer0, &dwDSLockedBufferSize0,
|
||||
&pDSLockedBuffer1, &dwDSLockedBufferSize1, 0))
|
||||
(unsigned long)nNumSamples*sizeof(short)*g_nMB_NumChannels,
|
||||
&pDSLockedBuffer0, &dwDSLockedBufferSize0))
|
||||
return;
|
||||
|
||||
#ifdef APPLE2IX
|
||||
@ -1105,11 +1107,10 @@ static void MB_Update()
|
||||
|
||||
// Commit sound buffer
|
||||
#ifdef APPLE2IX
|
||||
MockingboardVoice->Unlock(MockingboardVoice, (void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
|
||||
MockingboardVoice->Unlock(MockingboardVoice, dwDSLockedBufferSize0);
|
||||
#else
|
||||
hr = MockingboardVoice->Unlock((void*)pDSLockedBuffer0, dwDSLockedBufferSize0,
|
||||
hr = MockingboardVoice->Unlock((void*)pDSLockedBuffer0, dwDSLockedBufferSize0, (void*)pDSLockedBuffer1, dwDSLockedBufferSize1);
|
||||
#endif
|
||||
(void*)pDSLockedBuffer1, dwDSLockedBufferSize1);
|
||||
|
||||
#ifndef APPLE2IX
|
||||
dwByteOffset = (dwByteOffset + (unsigned long)nNumSamples*sizeof(short)*g_nMB_NumChannels) % g_dwDSBufferSize;
|
||||
@ -1252,9 +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]);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
hr = SSI263Voice[g_nCurrentActivePhoneme]->Stop();
|
||||
#endif
|
||||
}
|
||||
@ -1329,7 +1328,7 @@ static void SSI263_Play(unsigned int nPhoneme)
|
||||
#endif
|
||||
|
||||
#ifdef APPLE2IX
|
||||
hr = SSI263Voice->Unlock(SSI263Voice, (void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
|
||||
hr = SSI263Voice->Unlock(SSI263Voice, dwDSLockedBufferSize);
|
||||
#else
|
||||
hr = SSI263Voice->Unlock((void*)pDSLockedBuffer, dwDSLockedBufferSize, NULL, 0);
|
||||
#endif
|
||||
@ -1390,9 +1389,7 @@ static bool MB_DSInit()
|
||||
if(!MockingboardVoice->nVolume)
|
||||
MockingboardVoice->nVolume = DSBVOLUME_MAX;
|
||||
|
||||
#ifdef APPLE2IX
|
||||
hr = MockingboardVoice->SetVolume(MockingboardVoice, MockingboardVoice->nVolume);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
hr = MockingboardVoice->SetVolume(MockingboardVoice->nVolume);
|
||||
#endif
|
||||
LOG("MB_DSInit: SetVolume(), hr=0x%08X\n", (unsigned int)hr);
|
||||
@ -1474,7 +1471,7 @@ static bool MB_DSInit()
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = SSI263Voice[i]->Lock(SSI263Voice[i], 0, 0, &pDSLockedBuffer, &dwDSLockedBufferSize, NULL, 0, 0);
|
||||
hr = SSI263Voice[i]->Lock(SSI263Voice[i], 0, &pDSLockedBuffer, &dwDSLockedBufferSize);
|
||||
//LOG("MB_DSInit: (%02d) DSGetLock(), res=%d\n", i, hr ? 1 : 0); // WARNING: Lock acquired && doing heavy-weight logging
|
||||
if(FAILED(hr))
|
||||
{
|
||||
@ -1540,9 +1537,7 @@ static bool MB_DSInit()
|
||||
|
||||
SSI263Voice[i]->bActive = false;
|
||||
SSI263Voice[i]->nVolume = MockingboardVoice->nVolume; // Use same volume as MB
|
||||
#ifdef APPLE2IX
|
||||
hr = SSI263Voice[i]->SetVolume(SSI263Voice[i], SSI263Voice[i]->nVolume);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
hr = SSI263Voice[i]->SetVolume(SSI263Voice[i]->nVolume);
|
||||
#endif
|
||||
LOG("MB_DSInit: (%02d) SetVolume(), hr=0x%08X\n", i, (unsigned int)hr);
|
||||
@ -1606,9 +1601,7 @@ static void MB_DSUninit()
|
||||
|
||||
if(MockingboardVoice && MockingboardVoice->bActive)
|
||||
{
|
||||
#ifdef APPLE2IX
|
||||
MockingboardVoice->Stop(MockingboardVoice);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
MockingboardVoice->Stop();
|
||||
#endif
|
||||
MockingboardVoice->bActive = false;
|
||||
@ -1622,9 +1615,7 @@ static void MB_DSUninit()
|
||||
{
|
||||
if(SSI263Voice[i] && SSI263Voice[i]->bActive)
|
||||
{
|
||||
#ifdef APPLE2IX
|
||||
SSI263Voice[i]->Stop(SSI263Voice[i]);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
SSI263Voice[i]->Stop();
|
||||
#endif
|
||||
SSI263Voice[i]->bActive = false;
|
||||
@ -2026,18 +2017,14 @@ void MB_Mute()
|
||||
|
||||
if(MockingboardVoice->bActive && !MockingboardVoice->bMute)
|
||||
{
|
||||
#ifdef APPLE2IX
|
||||
MockingboardVoice->SetVolume(MockingboardVoice, DSBVOLUME_MIN);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
MockingboardVoice->SetVolume(DSBVOLUME_MIN);
|
||||
#endif
|
||||
MockingboardVoice->bMute = true;
|
||||
}
|
||||
|
||||
#if !defined(APPLE2IX)
|
||||
if(g_nCurrentActivePhoneme >= 0)
|
||||
#ifdef APPLE2IX
|
||||
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(SSI263Voice[g_nCurrentActivePhoneme], DSBVOLUME_MIN);
|
||||
#else
|
||||
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(DSBVOLUME_MIN);
|
||||
#endif
|
||||
}
|
||||
@ -2051,18 +2038,14 @@ void MB_Demute()
|
||||
|
||||
if(MockingboardVoice->bActive && MockingboardVoice->bMute)
|
||||
{
|
||||
#ifdef APPLE2IX
|
||||
MockingboardVoice->SetVolume(MockingboardVoice, MockingboardVoice->nVolume);
|
||||
#else
|
||||
#if !defined(APPLE2IX)
|
||||
MockingboardVoice->SetVolume(MockingboardVoice->nVolume);
|
||||
#endif
|
||||
MockingboardVoice->bMute = false;
|
||||
}
|
||||
|
||||
#if !defined(APPLE2IX)
|
||||
if(g_nCurrentActivePhoneme >= 0)
|
||||
#ifdef APPLE2IX
|
||||
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(SSI263Voice[g_nCurrentActivePhoneme], SSI263Voice[g_nCurrentActivePhoneme]->nVolume);
|
||||
#else
|
||||
SSI263Voice[g_nCurrentActivePhoneme]->SetVolume(SSI263Voice[g_nCurrentActivePhoneme]->nVolume);
|
||||
#endif
|
||||
}
|
||||
@ -2217,10 +2200,8 @@ void MB_SetVolume(unsigned long dwVolume, unsigned long dwVolumeMax)
|
||||
|
||||
MockingboardVoice->nVolume = NewVolume(dwVolume, dwVolumeMax);
|
||||
|
||||
#if !defined(APPLE2IX)
|
||||
if(MockingboardVoice->bActive)
|
||||
#ifdef APPLE2IX
|
||||
MockingboardVoice->SetVolume(MockingboardVoice, MockingboardVoice->nVolume);
|
||||
#else
|
||||
MockingboardVoice->SetVolume(MockingboardVoice->nVolume);
|
||||
#endif
|
||||
}
|
||||
|
@ -398,41 +398,6 @@ static ALVoice *NewVoice(const AudioParams_s *params)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static long ALGetVolume(AudioBuffer_s *_this, long *volume)
|
||||
{
|
||||
LOG("ALGetVolume ...");
|
||||
if (volume)
|
||||
{
|
||||
*volume = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long ALSetVolume(AudioBuffer_s *_this, long volume)
|
||||
{
|
||||
LOG("ALSetVolume ...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long ALStop(AudioBuffer_s *_this)
|
||||
{
|
||||
LOG("ALStop ...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long ALRestore(AudioBuffer_s *_this)
|
||||
{
|
||||
LOG("ALRestore ...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long ALPlay(AudioBuffer_s *_this, unsigned long reserved1, unsigned long reserved2, unsigned long flags)
|
||||
{
|
||||
LOG("ALPlay ...");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _ALProcessPlayBuffers(ALVoice *voice, ALuint *bytes_queued)
|
||||
{
|
||||
ALint processed = 0;
|
||||
@ -499,14 +464,10 @@ static int _ALProcessPlayBuffers(ALVoice *voice, ALuint *bytes_queued)
|
||||
}
|
||||
|
||||
// returns queued+working sound buffer size in bytes
|
||||
static long ALGetPosition(AudioBuffer_s *_this, unsigned long *bytes_queued, unsigned long *unused_write_cursor)
|
||||
static long ALGetPosition(AudioBuffer_s *_this, unsigned long *bytes_queued)
|
||||
{
|
||||
ALVoice *voice = (ALVoice*)_this->_internal;
|
||||
*bytes_queued = 0;
|
||||
if (unused_write_cursor)
|
||||
{
|
||||
*unused_write_cursor = 0;
|
||||
}
|
||||
|
||||
ALuint queued = 0;
|
||||
int err = _ALProcessPlayBuffers(voice, &queued);
|
||||
@ -527,15 +488,10 @@ static long ALGetPosition(AudioBuffer_s *_this, unsigned long *bytes_queued, uns
|
||||
}
|
||||
|
||||
// DS->Lock()
|
||||
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)
|
||||
static long ALBegin(AudioBuffer_s *_this, unsigned long write_bytes, INOUT int16_t **audio_ptr, INOUT unsigned long *audio_bytes)
|
||||
{
|
||||
ALVoice *voice = (ALVoice*)_this->_internal;
|
||||
|
||||
if (unused_audio_ptr2)
|
||||
{
|
||||
*unused_audio_ptr2 = NULL;
|
||||
}
|
||||
|
||||
if (write_bytes == 0)
|
||||
{
|
||||
write_bytes = voice->buffersize;
|
||||
@ -566,8 +522,8 @@ static long ALBegin(AudioBuffer_s *_this, unsigned long unused, unsigned long wr
|
||||
write_bytes = remaining;
|
||||
}
|
||||
|
||||
*audio_ptr1 = voice->data+voice->index;
|
||||
*audio_bytes1 = write_bytes;
|
||||
*audio_ptr = (int16_t *)(voice->data+voice->index);
|
||||
*audio_bytes = write_bytes;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -622,7 +578,7 @@ static int _ALSubmitBufferToOpenAL(ALVoice *voice)
|
||||
}
|
||||
|
||||
// DS->Unlock()
|
||||
static long ALCommit(AudioBuffer_s *_this, void *unused_audio_ptr1, unsigned long audio_bytes1, void *unused_audio_ptr2, unsigned long unused_audio_bytes2)
|
||||
static long ALCommit(AudioBuffer_s *_this, unsigned long audio_bytes)
|
||||
{
|
||||
ALVoice *voice = (ALVoice*)_this->_internal;
|
||||
int err = 0;
|
||||
@ -634,7 +590,7 @@ static long ALCommit(AudioBuffer_s *_this, void *unused_audio_ptr1, unsigned lon
|
||||
return err;
|
||||
}
|
||||
|
||||
voice->index += audio_bytes1;
|
||||
voice->index += audio_bytes;
|
||||
|
||||
while (voice->index > voice->buffersize)
|
||||
{
|
||||
@ -668,10 +624,10 @@ static long ALCommit(AudioBuffer_s *_this, void *unused_audio_ptr1, unsigned lon
|
||||
}
|
||||
|
||||
// HACK Part I : done once for mockingboard that has semiauto repeating phonemes ...
|
||||
static long ALCommitStaticBuffer(AudioBuffer_s *_this, unsigned long audio_bytes1)
|
||||
static long ALCommitStaticBuffer(AudioBuffer_s *_this, unsigned long audio_bytes)
|
||||
{
|
||||
ALVoice *voice = (ALVoice*)_this->_internal;
|
||||
voice->replay_index = (ALsizei)audio_bytes1;
|
||||
voice->replay_index = (ALsizei)audio_bytes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -753,12 +709,7 @@ static long OpenALCreateSoundBuffer(const AudioParams_s *params, INOUT AudioBuff
|
||||
}
|
||||
|
||||
(*soundbuf_struct)->_internal = voice;
|
||||
(*soundbuf_struct)->SetVolume = &ALSetVolume;
|
||||
(*soundbuf_struct)->GetVolume = &ALGetVolume;
|
||||
(*soundbuf_struct)->GetCurrentPosition = &ALGetPosition;
|
||||
(*soundbuf_struct)->Stop = &ALStop;
|
||||
(*soundbuf_struct)->Restore = &ALRestore;
|
||||
(*soundbuf_struct)->Play = &ALPlay;
|
||||
(*soundbuf_struct)->Lock = &ALBegin;
|
||||
(*soundbuf_struct)->Unlock = &ALCommit;
|
||||
(*soundbuf_struct)->GetStatus = &ALGetStatus;
|
||||
|
@ -31,29 +31,20 @@ typedef struct AudioBuffer_s {
|
||||
long nVolume; // Mockingboard ... refactor?
|
||||
PRIVATE void *_internal;
|
||||
|
||||
long (*SetVolume)(struct AudioBuffer_s *_this, long lVolume);
|
||||
|
||||
long (*GetVolume)(struct AudioBuffer_s *_this, long *lplVolume);
|
||||
|
||||
long (*GetCurrentPosition)(struct AudioBuffer_s *_this, unsigned long *lpdwCurrentPlayCursor, unsigned long *lpdwCurrentWriteCursor);
|
||||
|
||||
long (*Stop)(struct AudioBuffer_s *_this);
|
||||
|
||||
// This method restores the memory allocation for a lost sound buffer for the specified DirectSoundBuffer object.
|
||||
long (*Restore)(struct AudioBuffer_s *_this);
|
||||
|
||||
long (*Play)(struct AudioBuffer_s *_this, unsigned long dwReserved1, unsigned long dwReserved2, unsigned long dwFlags);
|
||||
// Get current number of queued bytes
|
||||
long (*GetCurrentPosition)(struct AudioBuffer_s *_this, unsigned long *bytes_queued);
|
||||
|
||||
// This method obtains a valid write pointer to the sound buffer's audio data
|
||||
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);
|
||||
long (*Lock)(struct AudioBuffer_s *_this, unsigned long write_bytes, INOUT int16_t **audio_ptr, INOUT unsigned long *audio_bytes);
|
||||
|
||||
// This method releases a locked sound buffer.
|
||||
long (*Unlock)(struct AudioBuffer_s *_this, void *lpvAudioPtr1, unsigned long dwAudioBytes1, void *lpvAudioPtr2, unsigned long dwAudioBytes2);
|
||||
long (*Unlock)(struct AudioBuffer_s *_this, unsigned long audio_bytes);
|
||||
|
||||
long (*GetStatus)(struct AudioBuffer_s *_this, unsigned long *lpdwStatus);
|
||||
// Get status (playing or not)
|
||||
long (*GetStatus)(struct AudioBuffer_s *_this, unsigned long *status);
|
||||
|
||||
// Mockingboard-specific HACKS
|
||||
long (*UnlockStaticBuffer)(struct AudioBuffer_s *_this, unsigned long dwAudioBytes);
|
||||
// Mockingboard-specific buffer replay
|
||||
long (*UnlockStaticBuffer)(struct AudioBuffer_s *_this, unsigned long audio_bytes);
|
||||
long (*Replay)(struct AudioBuffer_s *_this);
|
||||
|
||||
} AudioBuffer_s;
|
||||
|
@ -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, &bytes_queued, NULL);
|
||||
long err = speakerBuffer->GetCurrentPosition(speakerBuffer, &bytes_queued);
|
||||
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, /*unused*/ 0, num_samples_pad*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL, 0)) {
|
||||
if (speakerBuffer->Lock(speakerBuffer, num_samples_pad*sizeof(int16_t), &system_samples_buffer, &system_buffer_size)) {
|
||||
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, system_samples_buffer, system_buffer_size, NULL, 0);
|
||||
speakerBuffer->Unlock(speakerBuffer, system_buffer_size);
|
||||
}
|
||||
|
||||
// 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, &bytes_queued, NULL);
|
||||
long err = speakerBuffer->GetCurrentPosition(speakerBuffer, &bytes_queued);
|
||||
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, /*unused*/0, (unsigned long)num_samples_to_use*sizeof(int16_t), &system_samples_buffer, &system_buffer_size, NULL, NULL, 0)) {
|
||||
if (speakerBuffer->Lock(speakerBuffer, (unsigned long)num_samples_to_use*sizeof(int16_t), &system_samples_buffer, &system_buffer_size)) {
|
||||
return num_samples;
|
||||
}
|
||||
|
||||
memcpy(system_samples_buffer, &samples_buffer[0], system_buffer_size);
|
||||
|
||||
err = speakerBuffer->Unlock(speakerBuffer, (void*)system_samples_buffer, system_buffer_size, NULL, 0);
|
||||
err = speakerBuffer->Unlock(speakerBuffer, system_buffer_size);
|
||||
if (err) {
|
||||
return num_samples;
|
||||
}
|
||||
@ -303,9 +303,6 @@ static unsigned int _submit_samples_buffer(const unsigned int num_samples) {
|
||||
// speaker public API functions
|
||||
|
||||
void speaker_destroy(void) {
|
||||
if (speakerBuffer) {
|
||||
speakerBuffer->Stop(speakerBuffer);
|
||||
}
|
||||
audio_destroySoundBuffer(&speakerBuffer);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user