From c37f2ee0d4032349667154f7fa333d0288efc7f3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 13 Aug 2021 12:17:10 +1000 Subject: [PATCH] sounds work.. one time --- src/Audio.c | 25 ++++++++++++++----------- src/interop_web.js | 17 +++++++++++++---- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/Audio.c b/src/Audio.c index e861f82a1..eae537515 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -726,19 +726,16 @@ extern int interop_InitAudio(void); extern int interop_AudioCreate(void); extern void interop_AudioClose(int contextID); extern int interop_AudioPlay(int contextID, const char* name); +extern int interop_AudioPoll(int contetID, int* inUse); extern int interop_AudioDescribe(int res, char* buffer, int bufferLen); static cc_bool AudioBackend_Init(void) { cc_result res = interop_InitAudio(); if (res) { AudioWarn(res, "initing WebAudio context"); return false; } - - InitFakeSounds(); return true; } -void Audio_Init(struct AudioContext* ctx, int buffers) { -} - +void Audio_Init(struct AudioContext* ctx, int buffers) { } void Audio_Close(struct AudioContext* ctx) { if (ctx->contextID) interop_AudioClose(ctx->contextID); ctx->contextID = 0; @@ -747,17 +744,16 @@ void Audio_Close(struct AudioContext* ctx) { cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) { return ERR_NOT_SUPPORTED; } - cc_result Audio_QueueData(struct AudioContext* ctx, void* data, cc_uint32 size) { return ERR_NOT_SUPPORTED; } - -cc_result Audio_Play(struct AudioContext* ctx) { - return ERR_NOT_SUPPORTED; -} +cc_result Audio_Play(struct AudioContext* ctx) { return ERR_NOT_SUPPORTED; } cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) { - return ERR_NOT_SUPPORTED; + if (ctx->contextID) + return interop_AudioPoll(ctx->contextID, inUse); + + *inUse = 0; return 0; } cc_bool Audio_FastPlay(struct AudioContext* ctx, int channels, int sampleRate) { @@ -1053,6 +1049,13 @@ static void Sounds_LoadFile(const cc_string* path, void* obj) { /* TODO this is a pretty terrible solution */ #ifdef CC_BUILD_WEBAUDIO static void InitWebSounds(void) { + stepBoard.groups[SOUND_GRASS].sounds[0].data = "step_grass1"; + stepBoard.groups[SOUND_GRASS].sounds[1].data = "step_grass2"; + stepBoard.groups[SOUND_GRASS].count = 2; + + digBoard.groups[SOUND_GRASS].sounds[0].data = "dig_grass1"; + digBoard.groups[SOUND_GRASS].sounds[1].data = "dig_grass2"; + digBoard.groups[SOUND_GRASS].count = 2; } #endif diff --git a/src/interop_web.js b/src/interop_web.js index 365473b8e..12fbd2c79 100644 --- a/src/interop_web.js +++ b/src/interop_web.js @@ -705,19 +705,28 @@ mergeInto(LibraryManager.library, { source.stop(); AUDIO.sources[ctxID - 1|0] = null; }, + interop_AudioPoll: function(ctxID, inUse) { + var source = AUDIO.sources[ctxID - 1|0]; + HEAP32[inUse >> 2] = 0; + return 0; + }, interop_AudioPlay: function(ctxID, name) { var source = AUDIO.sources[ctxID - 1|0]; var name_ = UTF8ToString(name); - // have we already downloaded or are downloading this file? + // do we need to download this file? if (!AUDIO.seen.hasOwnProperty(name_)) { - Audio.seen[name_] = true; + AUDIO.seen[name_] = true; _interop_AudioDownload(name_); return 0; } + + // still downloading or failed to download this file + var buffer = AUDIO.buffers[name_]; + if (!buffer) return 0; - source.buffer = AUDIO.buffers[name_]; - source.connect(audioCtx.destination); + source.buffer = buffer; + source.connect(AUDIO.context.destination); source.start(); return 0; },