sounds work.. one time

This commit is contained in:
UnknownShadow200 2021-08-13 12:17:10 +10:00
parent 288fe4b2ce
commit c37f2ee0d4
2 changed files with 27 additions and 15 deletions

View File

@ -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

View File

@ -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;
},