Skip to content

Commit

Permalink
wokring on sfx probs
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Sep 3, 2024
1 parent 4f2af12 commit 7fd1bda
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 62 deletions.
Binary file added cart/c/sound/assets/sound.rfx
Binary file not shown.
78 changes: 72 additions & 6 deletions cart/c/sound/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,38 @@ u32 sfx;
u32 apache;
SfxParams* params;

// TODO: sfx seem broke
u32 preloaded_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.");
Expand All @@ -19,6 +50,35 @@ int main() {
sfx = new_sfx(params);
preset_sfx(params, SFX_POWERUP);

// example of a preloaded sound
SfxParams preloaded = (SfxParams) {
.randSeed=0,
.waveType=1,
.attackTime=0.000000f,
.sustainTime=0.357139f,
.sustainPunch=0.000000f,
.decayTime=0.425881f,
.startFrequency=0.331024f,
.minFrequency=0.000000f,
.slide=0.159528f,
.deltaSlide=0.000000f,
.vibratoDepth=0.000000f,
.vibratoSpeed=0.000000f,
.changeAmount=0.000000f,
.changeSpeed=0.000000f,
.squareDuty=1.000000f,
.dutySweep=0.000000f,
.repeatSpeed=0.000000f,
.phaserOffset=0.000000f,
.phaserSweep=0.000000f,
.lpfCutoff=1.000000f,
.lpfCutoffSweep=0.000000f,
.lpfResonance=0.000000f,
.hpfCutoff=0.000000f,
.hpfCutoffSweep=0.000000f
};
preloaded_sfx = new_sfx(&preloaded);

return 0;
}

Expand All @@ -29,6 +89,7 @@ void update() {
draw_text(0, "Press B for powerup sound.", 60, HEIGHT / 2 - 20, RAYWHITE);
draw_text(0, "Press X for coin sound.", 65, HEIGHT / 2, RAYWHITE);
draw_text(0, "Press Y for hurt sound.", 65, HEIGHT / 2 + 20, RAYWHITE);
draw_text(0, "Press START for hardcoded sfx struct", 18, HEIGHT / 2 + 40, RAYWHITE);
}

NULL0_EXPORT("buttonDown")
Expand All @@ -37,24 +98,29 @@ void buttonDown(GamepadButton button) {
play_sound(audioLogo, false);
}

// disabling unload until this lands: https://github.com/RobLoach/pntr_app/pull/106

if (button == GAMEPAD_BUTTON_B) {
// unload_sound(sfx);
unload_sound(sfx);
preset_sfx(params, SFX_POWERUP);
sfx = new_sfx(params);
play_sound(sfx, false);
print_sfx(*params);
}
if (button == GAMEPAD_BUTTON_X) {
// unload_sound(sfx);
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);
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);
}
}
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.
5 changes: 2 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
<null0-cart src="cart/flappybird.null0" fps></null0-cart>
<null0-cart src="cart/sound.null0" fps></null0-cart>
<null0-cart src="cart/typesizes.null0" fps></null0-cart>

<!-- <null0-cart src="cart/filesystem.null0"></null0-cart> -->
<!-- <null0-cart src="cart/justlog.null0"></null0-cart> -->
<null0-cart src="cart/filesystem.null0"></null0-cart>
<null0-cart src="cart/justlog.null0"></null0-cart>
</body>
</html>
9 changes: 5 additions & 4 deletions docs/wasm/null0.mjs

Large diffs are not rendered by default.

Binary file modified docs/wasm/null0.wasm
Binary file not shown.
49 changes: 0 additions & 49 deletions null0_api/src/null0_api_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,6 @@ typedef enum SfxPresetType {
SFX_SYNTH
} SfxPresetType;

// 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);
}

uint32_t null0_add_sound(pntr_sound* sound) {
uint32_t id = cvector_size(null0_sounds);
cvector_push_back(null0_sounds, sound);
Expand Down Expand Up @@ -79,68 +48,50 @@ void null0_unload_sound(uint32_t sound) {
uint32_t null0_new_sfx(SfxParams* params) {
uint32_t o = null0_add_sound(pntr_app_sfx_sound(null0_app, params));
params->randSeed = 0.5f;
printf("null0_new_sfx - %u\n", o);
print_sfx(*params);
return o;
}

void null0_preset_sfx(SfxParams* params, SfxPresetType type) {
switch (type) {
case SFX_COIN:
pntr_app_sfx_gen_pickup_coin(null0_app, params);
printf("null0_preset_sfx: coin\n");
break;
case SFX_LASER:
pntr_app_sfx_gen_laser_shoot(null0_app, params);
printf("null0_preset_sfx: laser\n");
break;
case SFX_EXPLOSION:
pntr_app_sfx_gen_explosion(null0_app, params);
printf("null0_preset_sfx: explosion\n");
break;
case SFX_POWERUP:
pntr_app_sfx_gen_powerup(null0_app, params);
printf("null0_preset_sfx: powerup\n");
break;
case SFX_HURT:
pntr_app_sfx_gen_hit_hurt(null0_app, params);
printf("null0_preset_sfx: hurt\n");
break;
case SFX_JUMP:
pntr_app_sfx_gen_jump(null0_app, params);
printf("null0_preset_sfx: jump\n");
break;
case SFX_SELECT:
pntr_app_sfx_gen_blip_select(null0_app, params);
printf("null0_preset_sfx: select\n");
break;
case SFX_SYNTH:
pntr_app_sfx_gen_synth(null0_app, params);
printf("null0_preset_sfx: synth\n");
break;
default:
printf("null0_preset_sfx: no type!\n");
}
print_sfx(*params);
}

void null0_randomize_sfx(SfxParams* params, enum SfxWaveType waveType) {
pntr_app_sfx_gen_randomize(null0_app, params, waveType);
printf("null0_randomize_sfx: %d\n", waveType);
print_sfx(*params);
}

void null0_mutate_sfx(SfxParams* params, float range, uint32_t mask) {
pntr_app_sfx_mutate(null0_app, params, range, mask);
printf("null0_mutate_sfx: %f %u\n", range, mask);
print_sfx(*params);
}

// Create a new sound-effect from a .rfx file
SfxParams null0_load_sfx(char* filename) {
SfxParams params = {0};
pntr_app_sfx_load_params(&params, filename);
printf("null0_load_sfx: %s\n", filename);
print_sfx(params);
return params;
}

0 comments on commit 7fd1bda

Please sign in to comment.