FAudio: Had to pass function pointers from the struct FAudioVoiceCallBack

In Short, audio works. Just gotta deal with the windows event system
pthreads might have what I need, winpthreads can even be used on windows

Signed-off-by: Zach Bacon <zachbacon@vba-m.com>
This commit is contained in:
Zach Bacon 2024-03-04 12:49:11 -05:00
parent 56056f1e9d
commit d458f0f29e
1 changed files with 22 additions and 11 deletions

View File

@ -155,6 +155,13 @@ public:
hBufferEndEvent = NULL;
//I'm still figuring out how to deal with pthreads, so I'm going to leave this empty for now.
//hBufferEndEvent = pthread_cond_init();
OnBufferEnd = &FAudio_BufferNotify::StaticOnBufferEnd;
OnVoiceProcessingPassStart = &FAudio_BufferNotify::StaticOnVoiceProcessingPassStart;
OnVoiceProcessingPassEnd = &FAudio_BufferNotify::StaticOnVoiceProcessingPassEnd;
OnStreamEnd = &FAudio_BufferNotify::StaticOnStreamEnd;
OnBufferStart = &FAudio_BufferNotify::StaticOnBufferStart;
OnLoopEnd = &FAudio_BufferNotify::StaticOnLoopEnd;
OnVoiceError = &FAudio_BufferNotify::StaticOnVoiceError;
}
~FAudio_BufferNotify()
{
@ -162,16 +169,20 @@ public:
//pthread_cond_destroy(hBufferEndEvent);
}
void OnBufferEnd(void* pBufferContext)
{
static void StaticOnBufferEnd(FAudioVoiceCallback* callback, void * pBufferContext) {
FAudio_BufferNotify* self = static_cast<FAudio_BufferNotify*>(callback);
if (self != nullptr && self->hBufferEndEvent != NULL)
{
SetEvent(self->hBufferEndEvent);
}
}
void OnVoiceProcessingPassStart(uint32_t BytesRequired) {}
void OnVoiceProcessingPassEnd() {}
void OnStreamEnd() {}
void OnBufferStart(void* pBufferContext) {}
void OnLoopEnd(void* pBufferContext) {}
void OnVoiceError(void* pBufferContext, uint32_t Error) {}
static void StaticOnVoiceProcessingPassStart(FAudioVoiceCallback* callback, uint32_t BytesRequired) {}
static void StaticOnVoiceProcessingPassEnd(FAudioVoiceCallback* callback) {}
static void StaticOnStreamEnd(FAudioVoiceCallback* callback) {}
static void StaticOnBufferStart(FAudioVoiceCallback* callback, void * pBufferContext) {}
static void StaticOnLoopEnd(FAudioVoiceCallback* callback, void * pBufferContext) {}
static void StaticOnVoiceError(FAudioVoiceCallback* callback, void * pBufferContext, uint32_t Error) {}
};
// Class Declaration
@ -329,7 +340,7 @@ bool FAudio_Output::init(long sampleRate)
// create sound emitter
//This should be FAudio_CreateSourceVoice()
//hr = faud->CreateSourceVoice(&sVoice, &wfx, 0, 4.0f, &notify);
hr = FAudio_CreateSourceVoice(faud, &sVoice, &wfx, 0, 4.0f, &notify);
hr = FAudio_CreateSourceVoice(faud, &sVoice, &wfx, 0, 4.0f, &notify, NULL, NULL);
if (hr != 0) {
wxLogError(_("FAudio: Creating source voice failed!"));
@ -482,7 +493,7 @@ void FAudio_Output::write(uint16_t* finalWave, int length)
// there is at least one free buffer
break;
} //else {
} else {
// the maximum number of buffers is currently queued
if (!coreOptions.speedup && coreOptions.throttle && !gba_joybus_active) {
// wait for one buffer to finish playing