mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-02-23 03:29:03 +00:00
Refactor : begin excising use of uthash
- While uthash is excellent, it is too heavyweight for a custom collection that has a maximum of 4 elements
This commit is contained in:
parent
2824dfa752
commit
9a7090c3a4
@ -30,8 +30,7 @@
|
|||||||
typedef struct ALPlayBuf {
|
typedef struct ALPlayBuf {
|
||||||
const ALuint bufid; // the hash id
|
const ALuint bufid; // the hash id
|
||||||
ALuint bytes_count; // num bytes to play
|
ALuint bytes_count; // num bytes to play
|
||||||
UT_hash_handle hh; // make this struct hashable
|
struct ALPlayBuf *next;
|
||||||
struct ALPlayBuf *_avail_next;
|
|
||||||
} ALPlayBuf;
|
} ALPlayBuf;
|
||||||
|
|
||||||
typedef struct ALVoice {
|
typedef struct ALVoice {
|
||||||
@ -72,6 +71,7 @@ static AudioBackend_s openal_audio_backend = { 0 };
|
|||||||
// Buffer play list management (uthash of OpenAL buffers)
|
// Buffer play list management (uthash of OpenAL buffers)
|
||||||
|
|
||||||
static ALPlayBuf *PlaylistEnqueue(ALVoice *voice, ALuint bytes_count) {
|
static ALPlayBuf *PlaylistEnqueue(ALVoice *voice, ALuint bytes_count) {
|
||||||
|
// assert buffer is available
|
||||||
ALPlayBuf *node = voice->avail_buffers;
|
ALPlayBuf *node = voice->avail_buffers;
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
ERRLOG("OOPS, sound playback overflow!");
|
ERRLOG("OOPS, sound playback overflow!");
|
||||||
@ -79,62 +79,66 @@ static ALPlayBuf *PlaylistEnqueue(ALVoice *voice, ALuint bytes_count) {
|
|||||||
}
|
}
|
||||||
//LOG("Really enqueing OpenAL buffer %u", node->bufid);
|
//LOG("Really enqueing OpenAL buffer %u", node->bufid);
|
||||||
|
|
||||||
ALPlayBuf *node2 = NULL;
|
// assert bufid is not already queued
|
||||||
HASH_FIND_INT(voice->queued_buffers, &node->bufid, node2);
|
{
|
||||||
if (node2 != NULL) {
|
ALPlayBuf *n = voice->queued_buffers;
|
||||||
ERRLOG("OOPS, confused ... ALPlayBuf already added!");
|
while (n) {
|
||||||
return NULL;
|
if (node->bufid == n->bufid) {
|
||||||
|
ERRLOG("OOPS, confused ... ALPlayBuf already added!");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
n = n->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove from list / place on hash
|
// move to queued_buffers
|
||||||
voice->avail_buffers = node->_avail_next;
|
voice->avail_buffers = node->next;
|
||||||
node->_avail_next = NULL;
|
node->next = voice->queued_buffers;
|
||||||
HASH_ADD_INT(voice->queued_buffers, bufid, node);
|
voice->queued_buffers = node;
|
||||||
|
|
||||||
node->bytes_count = bytes_count;
|
node->bytes_count = bytes_count;
|
||||||
|
|
||||||
voice->_queued_total_bytes += node->bytes_count;
|
voice->_queued_total_bytes += node->bytes_count;
|
||||||
voice->index = 0;
|
voice->index = 0;
|
||||||
assert(voice->_queued_total_bytes > 0);
|
assert(voice->_queued_total_bytes > 0);
|
||||||
|
|
||||||
#if 0
|
|
||||||
ALPlayBuf *tmp = voice->queued_buffers;
|
|
||||||
unsigned int count = HASH_COUNT(voice->queued_buffers);
|
|
||||||
LOG("\t(numqueued: %d)", count);
|
|
||||||
for (unsigned int i = 0; i < count; i++, tmp = tmp->hh.next) {
|
|
||||||
LOG("\t(bufid : %u)", tmp->bufid);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ALPlayBuf *PlaylistGet(ALVoice *voice, ALuint bufid) {
|
static ALPlayBuf *PlaylistGet(ALVoice *voice, ALuint bufid) {
|
||||||
ALPlayBuf *node = NULL;
|
ALPlayBuf *node = voice->queued_buffers;
|
||||||
HASH_FIND_INT(voice->queued_buffers, &bufid, node);
|
while (node) {
|
||||||
|
if (node->bufid == bufid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PlaylistDequeue(ALVoice *voice, ALPlayBuf *node) {
|
static void PlaylistDequeue(ALVoice *voice, ALPlayBuf *node) {
|
||||||
//LOG("Dequeing OpenAL buffer %u", node->bufid);
|
//LOG("Dequeing OpenAL buffer %u", node->bufid);
|
||||||
|
|
||||||
// remove from hash / place on list
|
ALPlayBuf *prev = NULL;
|
||||||
HASH_DEL(voice->queued_buffers, node); // remove from hash
|
ALPlayBuf *curr = voice->queued_buffers;
|
||||||
node->_avail_next = voice->avail_buffers;
|
while (curr) {
|
||||||
|
if (curr == node) {
|
||||||
|
if (prev) {
|
||||||
|
prev->next = curr->next;
|
||||||
|
} else {
|
||||||
|
voice->queued_buffers = curr->next;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev = curr;
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
node->next = voice->avail_buffers;
|
||||||
voice->avail_buffers = node;
|
voice->avail_buffers = node;
|
||||||
|
|
||||||
voice->_queued_total_bytes -= node->bytes_count;
|
voice->_queued_total_bytes -= node->bytes_count;
|
||||||
assert(voice->_queued_total_bytes >= 0);
|
assert(voice->_queued_total_bytes >= 0);
|
||||||
node->bytes_count = 0;
|
node->bytes_count = 0;
|
||||||
|
|
||||||
#if 0
|
|
||||||
ALPlayBuf *tmp = voice->queued_buffers;
|
|
||||||
unsigned int count = HASH_COUNT(voice->queued_buffers);
|
|
||||||
LOG("\t(numqueued: %d)", count);
|
|
||||||
for (unsigned int i = 0; i < count; i++, tmp = tmp->hh.next) {
|
|
||||||
LOG("\t(bufid : %u)", tmp->bufid);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -152,12 +156,6 @@ static long _ALProcessPlayBuffers(ALVoice *voice, ALuint *bytes_queued) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
if ((processed == 0) && (HASH_COUNT(voice->queued_buffers) >= OPENAL_NUM_BUFFERS)) {
|
|
||||||
LOG("All audio buffers processing...");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (processed > 0) {
|
while (processed > 0) {
|
||||||
--processed;
|
--processed;
|
||||||
ALuint bufid = 0;
|
ALuint bufid = 0;
|
||||||
@ -173,14 +171,6 @@ static long _ALProcessPlayBuffers(ALVoice *voice, ALuint *bytes_queued) {
|
|||||||
PlaylistDequeue(voice, node);
|
PlaylistDequeue(voice, node);
|
||||||
} else {
|
} else {
|
||||||
ERRLOG("OOPS, OpenAL bufid %u not found in playlist...", bufid);
|
ERRLOG("OOPS, OpenAL bufid %u not found in playlist...", bufid);
|
||||||
#if 0
|
|
||||||
ALPlayBuf *tmp = voice->queued_buffers;
|
|
||||||
unsigned int count = HASH_COUNT(voice->queued_buffers);
|
|
||||||
LOG("\t(numqueued: %d)", count);
|
|
||||||
for (unsigned int i = 0; i < count; i++, tmp = tmp->hh.next) {
|
|
||||||
LOG("\t(bufid : %u)", tmp->bufid);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +269,7 @@ static long _ALSubmitBufferToOpenAL(ALVoice *voice) {
|
|||||||
err = -1;
|
err = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//LOG("Enqueing OpenAL buffer %u (%u bytes)", node->bufid, node->bytes_count);
|
//LOG("Enqueing OpenAL buffer %u (%u bytes)", node->bufid, node->bytes_count);
|
||||||
alBufferData(node->bufid, voice->format, voice->data, node->bytes_count, voice->rate);
|
alBufferData(node->bufid, voice->format, voice->data, node->bytes_count, voice->rate);
|
||||||
|
|
||||||
@ -335,9 +326,17 @@ static long ALUnlockBuffer(AudioBuffer_s *_this, unsigned long audio_bytes) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HASH_COUNT(voice->queued_buffers) >= (OPENAL_NUM_BUFFERS)) {
|
{
|
||||||
//LOG("no free audio buffers"); // keep accumulating ...
|
bool queued_buffers_count = 0;
|
||||||
break;
|
ALPlayBuf *node = voice->queued_buffers;
|
||||||
|
while (node) {
|
||||||
|
++queued_buffers_count;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
if (queued_buffers_count >= OPENAL_NUM_BUFFERS) {
|
||||||
|
//LOG("no free audio buffers"); // keep accumulating ...
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit working buffer to OpenAL
|
// Submit working buffer to OpenAL
|
||||||
@ -406,19 +405,17 @@ static void _openal_destroyVoice(ALVoice *voice) {
|
|||||||
FREE(voice->data);
|
FREE(voice->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALPlayBuf *node = NULL;
|
while (voice->queued_buffers) {
|
||||||
ALPlayBuf *tmp = NULL;
|
PlaylistDequeue(voice, voice->queued_buffers);
|
||||||
HASH_ITER(hh, voice->queued_buffers, node, tmp) {
|
|
||||||
PlaylistDequeue(voice, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (voice->avail_buffers) {
|
while (voice->avail_buffers) {
|
||||||
node = voice->avail_buffers;
|
ALPlayBuf *node = voice->avail_buffers;
|
||||||
alDeleteBuffers(1, &node->bufid);
|
alDeleteBuffers(1, &node->bufid);
|
||||||
if (alGetError() != AL_NO_ERROR) {
|
if (alGetError() != AL_NO_ERROR) {
|
||||||
ERRLOG("OOPS, Failed to delete object IDs");
|
ERRLOG("OOPS, Failed to delete object IDs");
|
||||||
}
|
}
|
||||||
voice->avail_buffers = node->_avail_next;
|
voice->avail_buffers = node->next;
|
||||||
FREE(node);
|
FREE(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +485,7 @@ static ALVoice *_openal_createVoice(const AudioParams_s *params) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memcpy(node, &immutableNode, sizeof(ALPlayBuf));
|
memcpy(node, &immutableNode, sizeof(ALPlayBuf));
|
||||||
node->_avail_next = voice->avail_buffers;
|
node->next = voice->avail_buffers;
|
||||||
voice->avail_buffers = node;
|
voice->avail_buffers = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user