Skip to content

Commit

Permalink
fixed null0_load_sfx
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Sep 7, 2024
1 parent c88a21b commit 7c99f9b
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 79 deletions.
52 changes: 27 additions & 25 deletions cart/c/null0.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Binary file removed cart/c/sound/assets/apache.ogg
Binary file not shown.
58 changes: 9 additions & 49 deletions cart/c/sound/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand All @@ -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")
Expand All @@ -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);
// }
}
if (button == GAMEPAD_BUTTON_SELECT) {
play_sound(fileloaded_sfx, false);
}
}
Binary file modified docs/cart/colorbars.null0
Binary file not shown.
Binary file modified docs/cart/draw.null0
Binary file not shown.
Binary file modified docs/cart/filesystem.null0
Binary file not shown.
Binary file modified docs/cart/flappybird.null0
Binary file not shown.
Binary file modified docs/cart/hello.null0
Binary file not shown.
Binary file modified docs/cart/input.null0
Binary file not shown.
Binary file modified docs/cart/justlog.null0
Binary file not shown.
Binary file modified docs/cart/sound.null0
Binary file not shown.
Binary file modified docs/cart/tracker.null0
Binary file not shown.
Binary file modified docs/cart/typesizes.null0
Binary file not shown.
Binary file modified docs/wasm/null0.wasm
Binary file not shown.
31 changes: 31 additions & 0 deletions null0_api/src/null0_api_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
9 changes: 4 additions & 5 deletions null0_api/src/null0_api_wamr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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*)"},
Expand Down

0 comments on commit 7c99f9b

Please sign in to comment.