fix music

This commit is contained in:
headshot2017 2024-03-14 21:33:02 -04:00
parent 413fa5e8de
commit c590975cdf
3 changed files with 29 additions and 7 deletions

View File

@ -941,6 +941,7 @@ static int channelIDs;
static struct AudioMemPools audioPools[64]; static struct AudioMemPools audioPools[64];
AudioDriver drv; AudioDriver drv;
bool switchAudio = false; bool switchAudio = false;
extern void* audrv_mutex;
static cc_bool AudioBackend_Init(void) { static cc_bool AudioBackend_Init(void) {
if (switchAudio) return true; if (switchAudio) return true;
@ -1046,18 +1047,23 @@ cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 data
for (int i = 0; i < ctx->count; i++) for (int i = 0; i < ctx->count; i++)
{ {
buf = &ctx->bufs[i]; buf = &ctx->bufs[i];
//Platform_Log2("QUEUE_CHUNK: %i = %i", &ctx->chanID, &buf->status); int state = buf->state;
cc_uint32 size = dataSize;
cc_uint32 endOffset = dataSize / (sizeof(cc_int16) * ((ctx->channels == 2) ? 2 : 1));
//Platform_Log3("QUEUE_CHUNK %i: %i = %i", &ctx->chanID, &i, &state);
if (buf->state == AudioDriverWaveBufState_Queued || buf->state == AudioDriverWaveBufState_Playing || buf->state == AudioDriverWaveBufState_Waiting) if (buf->state == AudioDriverWaveBufState_Queued || buf->state == AudioDriverWaveBufState_Playing || buf->state == AudioDriverWaveBufState_Waiting)
continue; continue;
buf->data_pcm16 = chunk; buf->data_pcm16 = chunk;
buf->size = dataSize; buf->size = size;
buf->start_sample_offset = 0; buf->start_sample_offset = 0;
buf->end_sample_offset = dataSize / (sizeof(cc_int16) * ((ctx->channels == 2) ? 2 : 1));; buf->end_sample_offset = endOffset;
//Platform_Log1("PLAYING ON: %i", &ctx->chanID); //Platform_Log3("PLAY %i: %i = %i", &ctx->chanID, &i, &state);
Mutex_Lock(audrv_mutex);
audrvVoiceAddWaveBuf(&drv, ctx->chanID, buf); audrvVoiceAddWaveBuf(&drv, ctx->chanID, buf);
audrvVoiceStart(&drv, ctx->chanID); Mutex_Unlock(audrv_mutex);
return 0; return 0;
} }
@ -1075,9 +1081,11 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
AudioDriverWaveBuf* buf; AudioDriverWaveBuf* buf;
int count = 0; int count = 0;
//int states[4];
for (int i = 0; i < ctx->count; i++) for (int i = 0; i < ctx->count; i++)
{ {
buf = &ctx->bufs[i]; buf = &ctx->bufs[i];
//states[i] = buf->state;
//Platform_Log2("CHECK_CHUNK: %i = %i", &ctx->chanID, &buf->status); //Platform_Log2("CHECK_CHUNK: %i = %i", &ctx->chanID, &buf->status);
if (buf->state == AudioDriverWaveBufState_Queued || buf->state == AudioDriverWaveBufState_Playing || buf->state == AudioDriverWaveBufState_Waiting) { if (buf->state == AudioDriverWaveBufState_Queued || buf->state == AudioDriverWaveBufState_Playing || buf->state == AudioDriverWaveBufState_Waiting) {
count++; continue; count++; continue;
@ -1085,6 +1093,12 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
} }
*inUse = count; *inUse = count;
/*
char abuf[64];
sprintf(abuf, "%d %d %d %d", states[0], states[1], states[2], states[3]);
Platform_Log2("%i inUse, %c", inUse, abuf);
*/
return 0; return 0;
} }

View File

@ -37,6 +37,8 @@ const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK;
const cc_result ReturnCode_DirectoryExists = EEXIST; const cc_result ReturnCode_DirectoryExists = EEXIST;
const char* Platform_AppNameSuffix = " Switch"; const char* Platform_AppNameSuffix = " Switch";
void* audrv_mutex;
alignas(16) u8 __nx_exception_stack[0x1000]; alignas(16) u8 __nx_exception_stack[0x1000];
u64 __nx_exception_stack_size = sizeof(__nx_exception_stack); u64 __nx_exception_stack_size = sizeof(__nx_exception_stack);
@ -519,9 +521,12 @@ void Platform_Init(void) {
// Configure our supported input layout: a single player with standard controller styles // Configure our supported input layout: a single player with standard controller styles
padConfigureInput(1, HidNpadStyleSet_NpadStandard); padConfigureInput(1, HidNpadStyleSet_NpadStandard);
hidInitializeTouchScreen(); hidInitializeTouchScreen();
audrv_mutex = Mutex_Create();
} }
void Platform_Free(void) { void Platform_Free(void) {
socketExit(); socketExit();
Mutex_Free(audrv_mutex);
} }
cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {

View File

@ -22,8 +22,9 @@
static EGLDisplay s_display; static EGLDisplay s_display;
static EGLContext s_context; static EGLContext s_context;
static EGLSurface s_surface; static EGLSurface s_surface;
extern AudioDriver drv; // temporary extern AudioDriver drv;
extern bool switchAudio; // temporary extern bool switchAudio;
extern void* audrv_mutex;
static cc_bool launcherMode; static cc_bool launcherMode;
static Framebuffer fb; static Framebuffer fb;
@ -138,8 +139,10 @@ void Window_ProcessEvents(double delta) {
// Scan the gamepad. This should be done once for each frame // Scan the gamepad. This should be done once for each frame
padUpdate(&pad); padUpdate(&pad);
Mutex_Lock(audrv_mutex);
if (switchAudio) if (switchAudio)
audrvUpdate(&drv); audrvUpdate(&drv);
Mutex_Unlock(audrv_mutex);
if (!appletMainLoop()) { if (!appletMainLoop()) {
Window_Main.Exists = false; Window_Main.Exists = false;