fix syntax

This commit is contained in:
2026-02-17 09:12:48 -06:00
parent 6f6f987649
commit d509f7cbb8
21 changed files with 503 additions and 453 deletions

48
audio.c
View File

@@ -43,22 +43,24 @@ SDL_AudioSpec js2SDL_AudioSpec(JSContext *js, JSValue v) {
}
JSValue SDL_AudioSpec2js(JSContext *js, SDL_AudioSpec spec) {
JSValue obj = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(obj, JS_NewObject(js));
JS_SetPropertyStr(js, obj, "format", SDL_AudioFormat2js(js, spec.format));
JS_SetPropertyStr(js, obj, "channels", JS_NewInt32(js, spec.channels));
JS_SetPropertyStr(js, obj, "freq", JS_NewInt32(js, spec.freq));
return obj;
JS_RETURN(obj);
}
// Enum mappings for audio formats (simplified)
JSValue js_get_audio_drivers(JSContext *js, JSValue self, int argc, JSValue *argv) {
JS_FRAME(js);
int count = SDL_GetNumAudioDrivers();
JSValue arr = JS_NewArray(js);
JS_LOCAL(arr, JS_NewArray(js));
for (int i = 0; i < count; i++) {
const char *driver = SDL_GetAudioDriver(i);
JS_SetPropertyUint32(js, arr, i, JS_NewString(js, driver));
JS_SetPropertyNumber(js, arr, i, JS_NewString(js, driver));
}
return arr;
JS_RETURN(arr);
}
JSValue js_get_current_audio_driver(JSContext *js, JSValue self, int argc, JSValue *argv) {
@@ -69,23 +71,25 @@ JSValue js_get_current_audio_driver(JSContext *js, JSValue self, int argc, JSVal
JSValue js_get_audio_playback_devices(JSContext *js, JSValue self, int argc, JSValue *argv) {
SDL_AudioDeviceID *devices = SDL_GetAudioPlaybackDevices(NULL);
if (!devices) return JS_NULL;
JSValue arr = JS_NewArray(js);
JS_FRAME(js);
JS_LOCAL(arr, JS_NewArray(js));
for (int i = 0; devices[i]; i++) {
JS_SetPropertyUint32(js, arr, i, SDL_AudioDeviceID2js(js, devices[i]));
JS_SetPropertyNumber(js, arr, i, SDL_AudioDeviceID2js(js, devices[i]));
}
SDL_free(devices);
return arr;
JS_RETURN(arr);
}
JSValue js_get_audio_recording_devices(JSContext *js, JSValue self, int argc, JSValue *argv) {
SDL_AudioDeviceID *devices = SDL_GetAudioRecordingDevices(NULL);
if (!devices) return JS_NULL;
JSValue arr = JS_NewArray(js);
JS_FRAME(js);
JS_LOCAL(arr, JS_NewArray(js));
for (int i = 0; devices[i]; i++) {
JS_SetPropertyUint32(js, arr, i, SDL_AudioDeviceID2js(js, devices[i]));
JS_SetPropertyNumber(js, arr, i, SDL_AudioDeviceID2js(js, devices[i]));
}
SDL_free(devices);
return arr;
JS_RETURN(arr);
}
JSValue js_get_audio_device_name(JSContext *js, JSValue self, int argc, JSValue *argv) {
@@ -201,9 +205,11 @@ JSC_CCALL(audio_stream_get_format,
if (!SDL_GetAudioStreamFormat(stream, &src, &dst)) {
ret = JS_NULL;
} else {
JSValue obj = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(obj, JS_NewObject(js));
JS_SetPropertyStr(js, obj, "src", SDL_AudioSpec2js(js, src));
JS_SetPropertyStr(js, obj, "dst", SDL_AudioSpec2js(js, dst));
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame);
ret = obj;
}
)
@@ -317,12 +323,13 @@ JSValue js_load_wav(JSContext *js, JSValue self, int argc, JSValue *argv) {
return JS_ThrowInternalError(js, "Failed to load WAV: %s", SDL_GetError());
}
JS_FreeCString(js, path);
JSValue obj = JS_NewObject(js);
JS_FRAME(js);
JS_LOCAL(obj, JS_NewObject(js));
JS_SetPropertyStr(js, obj, "spec", SDL_AudioSpec2js(js, spec));
JS_SetPropertyStr(js, obj, "data", js_new_blob_stoned_copy(js, data, len));
SDL_free(data);
return obj;
JS_RETURN(obj);
}
JSC_CCALL(convert_audio_samples,
@@ -407,12 +414,13 @@ static const JSCFunctionListEntry js_sdl_audio_funcs[] = {
CELL_USE_INIT(
SDL_Init(SDL_INIT_AUDIO);
JS_NewClassID(&js_SDL_AudioStream_id);
JS_NewClass(JS_GetRuntime(js), js_SDL_AudioStream_id, &js_SDL_AudioStream_class);
JSValue proto = JS_NewObject(js);
JS_NewClass(js, js_SDL_AudioStream_id, &js_SDL_AudioStream_class);
JS_FRAME(js);
JS_LOCAL(proto, JS_NewObject(js));
JS_SetPropertyFunctionList(js, proto, js_SDL_AudioStream_funcs, countof(js_SDL_AudioStream_funcs));
JS_SetClassProto(js, js_SDL_AudioStream_id, proto);
JSValue export = JS_NewObject(js);
JS_SetPropertyFunctionList(js, export, js_sdl_audio_funcs, countof(js_sdl_audio_funcs));
return export;
JS_LOCAL(mod, JS_NewObject(js));
JS_SetPropertyFunctionList(js, mod, js_sdl_audio_funcs, countof(js_sdl_audio_funcs));
JS_RETURN(mod);
)