diff --git a/cart/c/null0.h b/cart/c/null0.h index e51fd6f..54a4857 100755 --- a/cart/c/null0.h +++ b/cart/c/null0.h @@ -54,48 +54,50 @@ typedef struct { i32 height; } Rectangle; -typedef struct { +// Sound parameters (96 bytes matching rFXGen WaveParams) +typedef struct SfxParams { // Random seed used to generate the wave - u32 randSeed; + uint32_t randSeed; // Wave type (square, sawtooth, sine, noise) - i32 waveType; + int waveType; // Wave envelope parameters - f32 attackTime; - f32 sustainTime; - f32 sustainPunch; - f32 decayTime; + float attackTime; + float sustainTime; + float sustainPunch; + float decayTime; // Frequency parameters - f32 startFrequency; - f32 minFrequency; - f32 slide; - f32 deltaSlide; - f32 vibratoDepth; - f32 vibratoSpeed; + float startFrequency; + float minFrequency; + float slide; + float deltaSlide; + float vibratoDepth; + float vibratoSpeed; + // float vibratoPhaseDelay; // Unused in sfxr code. // Tone change parameters - f32 changeAmount; - f32 changeSpeed; + float changeAmount; + float changeSpeed; // Square wave parameters - f32 squareDuty; - f32 dutySweep; + float squareDuty; + float dutySweep; // Repeat parameters - f32 repeatSpeed; + float repeatSpeed; // Phaser parameters - f32 phaserOffset; - f32 phaserSweep; + float phaserOffset; + float phaserSweep; // Filter parameters - f32 lpfCutoff; - f32 lpfCutoffSweep; - f32 lpfResonance; - f32 hpfCutoff; - f32 hpfCutoffSweep; + float lpfCutoff; + float lpfCutoffSweep; + float lpfResonance; + float hpfCutoff; + float hpfCutoffSweep; } SfxParams; typedef struct { diff --git a/cart/c/sound/assets/apache.ogg b/cart/c/sound/assets/apache.ogg deleted file mode 100755 index 554f617..0000000 Binary files a/cart/c/sound/assets/apache.ogg and /dev/null differ diff --git a/cart/c/sound/main.c b/cart/c/sound/main.c index 303f8fa..1d23023 100755 --- a/cart/c/sound/main.c +++ b/cart/c/sound/main.c @@ -2,49 +2,14 @@ u32 audioLogo; u32 sfx; -u32 apache; SfxParams* params; u32 preloaded_sfx; u32 fileloaded_sfx; -// debug function to print a SfxParams -void print_sfx(SfxParams sfx_params) { - trace("(SfxParams) {\n\ - .randSeed=%lu,\n\ - .waveType=%d,\n\ - .attackTime=%ff,\n\ - .sustainTime=%ff,\n\ - .sustainPunch=%ff,\n\ - .decayTime=%ff,\n\ - .startFrequency=%ff,\n\ - .minFrequency=%ff,\n\ - .slide=%ff,\n\ - .deltaSlide=%ff,\n\ - .vibratoDepth=%ff,\n\ - .vibratoSpeed=%ff,\n\ - .changeAmount=%ff,\n\ - .changeSpeed=%ff,\n\ - .squareDuty=%ff,\n\ - .dutySweep=%ff,\n\ - .repeatSpeed=%ff,\n\ - .phaserOffset=%ff,\n\ - .phaserSweep=%ff,\n\ - .lpfCutoff=%ff,\n\ - .lpfCutoffSweep=%ff,\n\ - .lpfResonance=%ff,\n\ - .hpfCutoff=%ff,\n\ - .hpfCutoffSweep=%ff \n\ -}", - (unsigned long)sfx_params.randSeed, sfx_params.waveType, sfx_params.attackTime, sfx_params.sustainTime, sfx_params.sustainPunch, sfx_params.decayTime, sfx_params.startFrequency, sfx_params.minFrequency, sfx_params.slide, sfx_params.deltaSlide, sfx_params.vibratoDepth, sfx_params.vibratoSpeed, sfx_params.changeAmount, sfx_params.changeSpeed, sfx_params.squareDuty, sfx_params.dutySweep, sfx_params.repeatSpeed, sfx_params.phaserOffset, sfx_params.phaserSweep, sfx_params.lpfCutoff, sfx_params.lpfCutoffSweep, sfx_params.lpfResonance, sfx_params.hpfCutoff, sfx_params.hpfCutoffSweep); -} - int main() { trace("Hello from sound."); - apache = load_sound("assets/apache.ogg"); - // play_sound(apache, true); - audioLogo = load_sound("assets/notnullgames.ogg"); params = malloc(sizeof(SfxParams)); @@ -76,16 +41,14 @@ int main() { .lpfCutoffSweep=0.000000f, .lpfResonance=0.000000f, .hpfCutoff=0.000000f, - .hpfCutoffSweep=0.000000f + .hpfCutoffSweep=0.000000f }; preloaded_sfx = new_sfx(&preloaded); // load a SFX from a file - // currently this is broke - // SfxParams* fileloaded = malloc(96); - // load_sfx(fileloaded, "assets/sound.rfx"); - // fileloaded_sfx = new_sfx(fileloaded); - // print_sfx(*fileloaded); + SfxParams* fileloaded = malloc(96); + load_sfx(fileloaded, "assets/sound.rfx"); + fileloaded_sfx = new_sfx(fileloaded); return 0; } @@ -98,7 +61,7 @@ void update() { draw_text(0, "Press X for coin sound.", 65, HEIGHT / 2 - 20, RAYWHITE); draw_text(0, "Press Y for hurt sound.", 65, HEIGHT / 2, RAYWHITE); draw_text(0, "Press START for hardcoded sfx struct", 18, HEIGHT / 2 + 20, RAYWHITE); - // draw_text(0, "Press SELECT for file sfx", 45, HEIGHT / 2 + 40, RAYWHITE); + draw_text(0, "Press SELECT for file sfx", 45, HEIGHT / 2 + 40, RAYWHITE); } NULL0_EXPORT("buttonDown") @@ -112,28 +75,25 @@ void buttonDown(GamepadButton button) { preset_sfx(params, SFX_POWERUP); sfx = new_sfx(params); play_sound(sfx, false); - // print_sfx(*params); } if (button == GAMEPAD_BUTTON_X) { unload_sound(sfx); preset_sfx(params, SFX_COIN); sfx = new_sfx(params); play_sound(sfx, false); - // print_sfx(*params); } if (button == GAMEPAD_BUTTON_Y) { unload_sound(sfx); preset_sfx(params, SFX_HURT); sfx = new_sfx(params); play_sound(sfx, false); - // print_sfx(*params); } if (button == GAMEPAD_BUTTON_START) { play_sound(preloaded_sfx, false); } - // if (button == GAMEPAD_BUTTON_SELECT) { - // play_sound(fileloaded_sfx, false); - // } -} \ No newline at end of file + if (button == GAMEPAD_BUTTON_SELECT) { + play_sound(fileloaded_sfx, false); + } +} diff --git a/docs/cart/colorbars.null0 b/docs/cart/colorbars.null0 index c5e48a0..e6d2c1b 100644 Binary files a/docs/cart/colorbars.null0 and b/docs/cart/colorbars.null0 differ diff --git a/docs/cart/draw.null0 b/docs/cart/draw.null0 index b9eefa4..7d1b48d 100644 Binary files a/docs/cart/draw.null0 and b/docs/cart/draw.null0 differ diff --git a/docs/cart/filesystem.null0 b/docs/cart/filesystem.null0 index 8a1f73f..e105570 100644 Binary files a/docs/cart/filesystem.null0 and b/docs/cart/filesystem.null0 differ diff --git a/docs/cart/flappybird.null0 b/docs/cart/flappybird.null0 index 91cc864..e328959 100644 Binary files a/docs/cart/flappybird.null0 and b/docs/cart/flappybird.null0 differ diff --git a/docs/cart/hello.null0 b/docs/cart/hello.null0 index f82ff71..8e8a3d4 100644 Binary files a/docs/cart/hello.null0 and b/docs/cart/hello.null0 differ diff --git a/docs/cart/input.null0 b/docs/cart/input.null0 index 74c81c2..f60d7e6 100644 Binary files a/docs/cart/input.null0 and b/docs/cart/input.null0 differ diff --git a/docs/cart/justlog.null0 b/docs/cart/justlog.null0 index 559e7fb..5772fe9 100644 Binary files a/docs/cart/justlog.null0 and b/docs/cart/justlog.null0 differ diff --git a/docs/cart/sound.null0 b/docs/cart/sound.null0 index f7b43e1..ad89534 100644 Binary files a/docs/cart/sound.null0 and b/docs/cart/sound.null0 differ diff --git a/docs/cart/tracker.null0 b/docs/cart/tracker.null0 index 31ef775..df0e12b 100644 Binary files a/docs/cart/tracker.null0 and b/docs/cart/tracker.null0 differ diff --git a/docs/cart/typesizes.null0 b/docs/cart/typesizes.null0 index c669019..f7cf8c2 100644 Binary files a/docs/cart/typesizes.null0 and b/docs/cart/typesizes.null0 differ diff --git a/docs/wasm/null0.wasm b/docs/wasm/null0.wasm index 03f53a0..dec5606 100755 Binary files a/docs/wasm/null0.wasm and b/docs/wasm/null0.wasm differ diff --git a/null0_api/src/null0_api_sound.h b/null0_api/src/null0_api_sound.h index dfeb4fd..3529416 100755 --- a/null0_api/src/null0_api_sound.h +++ b/null0_api/src/null0_api_sound.h @@ -93,3 +93,34 @@ void null0_mutate_sfx(SfxParams* params, float range, uint32_t mask) { void null0_load_sfx(SfxParams* params, char* filename) { pntr_app_sfx_load_params(params, filename); } + +// debug function to print a SfxParams +void print_sfx(SfxParams sfx_params) { + printf("(SfxParams) {\n\ + .randSeed=%lu,\n\ + .waveType=%d,\n\ + .attackTime=%ff,\n\ + .sustainTime=%ff,\n\ + .sustainPunch=%ff,\n\ + .decayTime=%ff,\n\ + .startFrequency=%ff,\n\ + .minFrequency=%ff,\n\ + .slide=%ff,\n\ + .deltaSlide=%ff,\n\ + .vibratoDepth=%ff,\n\ + .vibratoSpeed=%ff,\n\ + .changeAmount=%ff,\n\ + .changeSpeed=%ff,\n\ + .squareDuty=%ff,\n\ + .dutySweep=%ff,\n\ + .repeatSpeed=%ff,\n\ + .phaserOffset=%ff,\n\ + .phaserSweep=%ff,\n\ + .lpfCutoff=%ff,\n\ + .lpfCutoffSweep=%ff,\n\ + .lpfResonance=%ff,\n\ + .hpfCutoff=%ff,\n\ + .hpfCutoffSweep=%ff \n\ +}\n", + (unsigned long)sfx_params.randSeed, sfx_params.waveType, sfx_params.attackTime, sfx_params.sustainTime, sfx_params.sustainPunch, sfx_params.decayTime, sfx_params.startFrequency, sfx_params.minFrequency, sfx_params.slide, sfx_params.deltaSlide, sfx_params.vibratoDepth, sfx_params.vibratoSpeed, sfx_params.changeAmount, sfx_params.changeSpeed, sfx_params.squareDuty, sfx_params.dutySweep, sfx_params.repeatSpeed, sfx_params.phaserOffset, sfx_params.phaserSweep, sfx_params.lpfCutoff, sfx_params.lpfCutoffSweep, sfx_params.lpfResonance, sfx_params.hpfCutoff, sfx_params.hpfCutoffSweep); +} diff --git a/null0_api/src/null0_api_wamr.h b/null0_api/src/null0_api_wamr.h index 1811c75..f559ce4 100755 --- a/null0_api/src/null0_api_wamr.h +++ b/null0_api/src/null0_api_wamr.h @@ -134,10 +134,9 @@ static void wamr_null0_mutate_sfx(wasm_exec_env_t exec_env, SfxParams* params, f // Create a new sfxr from a .rfx file static void wamr_null0_load_sfx(wasm_exec_env_t exec_env, SfxParams* params, char* filename) { - SfxParams* hostRet = malloc(96); - null0_load_sfx(hostRet, filename); - memcpy(params, hostRet, 96); - free(hostRet); + SfxParams p = {}; + null0_load_sfx(&p, filename); + memcpy(params, &p, sizeof(SfxParams)); } // Unload a sound @@ -682,7 +681,7 @@ static NativeSymbol null0_wamr_callbacks[] = { {"mouse_button_released", wamr_null0_mouse_button_released, "(i)i"}, {"mouse_button_up", wamr_null0_mouse_button_up, "(i)i"}, {"new_image", wamr_null0_new_image, "(ii*)i"}, - {"image_copy", wamr_null0_image_copy, "(i)i"}, + {"image_copy", wamr_null0_image_copy, "(i)i"}, {"image_subimage", wamr_null0_image_subimage, "(iiiii)i"}, {"clear", wamr_null0_clear, "(*)"}, {"draw_point", wamr_null0_draw_point, "(ii*)"},