Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sound effects #108

Merged
merged 32 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9ee7626
Add sounds
Suprapote May 25, 2024
2bf696d
fix error sound
Suprapote May 25, 2024
ff89d5e
Use menu.h instead of another file
Suprapote May 26, 2024
901733e
Toogle sound option
Suprapote May 26, 2024
63a98ac
Update actions.c
Suprapote May 26, 2024
f6eda61
Delete filesystem/back.wav64
Suprapote May 26, 2024
3ed1067
Delete filesystem/cursorsound.wav64
Suprapote May 26, 2024
e15c083
Delete filesystem/enter.wav64
Suprapote May 26, 2024
7938403
Delete filesystem/error.wav64
Suprapote May 26, 2024
aa3bc27
Delete filesystem/settings.wav64
Suprapote May 26, 2024
38fcba2
Update menu.c
Suprapote May 27, 2024
75cb98f
Update README.md
Suprapote May 30, 2024
e65d30e
Merge branch 'Polprzewodnikowy:main' into sound-effects
Suprapote May 30, 2024
16df88a
Merge branch 'Polprzewodnikowy:main' into sound-effects
Suprapote Jun 2, 2024
342b73c
Merge Networkfusion's changes
Suprapote Jun 4, 2024
2cbe3e5
Merge branch 'sound-effects' of https://github.com/Suprapote/N64Flash…
Suprapote Jun 4, 2024
7c0125a
Convert sounds to mono
Suprapote Jun 4, 2024
64da00e
correct exit sound
Suprapote Jun 4, 2024
da3280a
Remove un-necessary changes
networkfusion Jun 5, 2024
b044d88
Improve SFX_CHANNEL name
networkfusion Jun 5, 2024
0be3082
Only play SFX if setting enabled.
networkfusion Jun 5, 2024
4647482
Updates the readme to make sound licenses clearer
networkfusion Jun 5, 2024
679b894
Merge pull request #1 from networkfusion/refactor-sfx2
Suprapote Jun 5, 2024
820a02f
Update README.md
Suprapote Jun 5, 2024
227033e
Update README.md
Suprapote Jun 5, 2024
9c5602a
Update sound.h
networkfusion Jun 5, 2024
30bd471
Update menu.c
networkfusion Jun 5, 2024
c443879
Update menu.h
networkfusion Jun 5, 2024
5faceb2
Update sound.c
networkfusion Jun 5, 2024
962e971
Update sound.c
networkfusion Jun 5, 2024
2d06ed6
Update README.md
Suprapote Jun 5, 2024
68603ab
Merge branch 'sound-effects' of https://github.com/Suprapote/N64Flash…
Suprapote Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,38 @@ SRCS = \
FONTS = \
FiraMonoBold.ttf

SOUNDS = \
cursorsound.wav \
back.wav \
enter.wav \
error.wav \
settings.wav

OBJS = $(addprefix $(BUILD_DIR)/, $(addsuffix .o,$(basename $(SRCS))))
MINIZ_OBJS = $(filter $(BUILD_DIR)/libs/miniz/%.o,$(OBJS))
SPNG_OBJS = $(filter $(BUILD_DIR)/libs/libspng/%.o,$(OBJS))
DEPS = $(OBJS:.o=.d)

FILESYSTEM = \
$(addprefix $(FILESYSTEM_DIR)/, $(notdir $(FONTS:%.ttf=%.font64)))
$(addprefix $(FILESYSTEM_DIR)/, $(notdir $(FONTS:%.ttf=%.font64))) \
$(addprefix $(FILESYSTEM_DIR)/, $(notdir $(SOUNDS:%.wav=%.wav64)))

$(MINIZ_OBJS): N64_CFLAGS+=-DMINIZ_NO_TIME -fcompare-debug-second
$(SPNG_OBJS): N64_CFLAGS+=-isystem $(SOURCE_DIR)/libs/miniz -DSPNG_USE_MINIZ -fcompare-debug-second
$(FILESYSTEM_DIR)/FiraMonoBold.font64: MKFONT_FLAGS+=-c 1 --size 16 -r 20-1FF -r 2026-2026 --ellipsis 2026,1
$(FILESYSTEM_DIR)/%.wav64: AUDIOCONV_FLAGS=--wav-compress 1


$(@info $(shell mkdir -p ./$(FILESYSTEM_DIR) &> /dev/null))

$(FILESYSTEM_DIR)/%.font64: $(ASSETS_DIR)/%.ttf
@echo " [FONT] $@"
@$(N64_MKFONT) $(MKFONT_FLAGS) -o $(FILESYSTEM_DIR) "$<"

$(FILESYSTEM_DIR)/%.wav64: $(ASSETS_DIR)/%.wav
@echo " [AUDIO] $@"
@$(N64_AUDIOCONV) $(AUDIOCONV_FLAGS) -o $(FILESYSTEM_DIR) "$<"

$(BUILD_DIR)/$(PROJECT_NAME).dfs: $(FILESYSTEM)

$(BUILD_DIR)/menu/views/credits.o: .FORCE
Expand Down
Binary file added assets/back.wav
Binary file not shown.
Binary file added assets/cursorsound.wav
Binary file not shown.
Binary file added assets/enter.wav
Binary file not shown.
Binary file added assets/error.wav
Binary file not shown.
Binary file added assets/settings.wav
Binary file not shown.
5 changes: 5 additions & 0 deletions src/menu/components/context_menu.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../components.h"
#include "../fonts.h"
#include "../menu.h"
#include "constants.h"


Expand Down Expand Up @@ -41,6 +42,7 @@ bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm)
} else {
cm->hide_pending = true;
}
wav64_play(&sfx_exit, SFX_CHANNEL);
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
} else if (menu->actions.enter) {
if (cm->list[cm->selected].submenu) {
cm->submenu = cm->list[cm->selected].submenu;
Expand All @@ -51,16 +53,19 @@ bool component_context_menu_process (menu_t *menu, component_context_menu_t *cm)
cm->list[cm->selected].action(menu, cm->list[cm->selected].arg);
top->hide_pending = true;
}
wav64_play(&sfx_enter, SFX_CHANNEL);
} else if (menu->actions.go_up) {
cm->selected -= 1;
if (cm->selected < 0) {
cm->selected = 0;
}
wav64_play(&sfx_cursor, SFX_CHANNEL);
} else if (menu->actions.go_down) {
cm->selected += 1;
if (cm->selected >= cm->count) {
cm->selected = (cm->count - 1);
}
wav64_play(&sfx_cursor, SFX_CHANNEL);
}

return true;
Expand Down
13 changes: 13 additions & 0 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "mp3_player.h"
#include "png_decoder.h"
#include "settings.h"
#include "menu.h"
#include "sound.h"
#include "usb_comm.h"
#include "utils/fs.h"
Expand All @@ -34,6 +35,7 @@
static menu_t *menu;
static tv_type_t tv_type;
static volatile int frame_counter = 0;
wav64_t sfx_cursor, sfx_error, sfx_enter, sfx_exit, sfx_settings;

extern tv_type_t __boot_tvtype;

Expand Down Expand Up @@ -67,6 +69,13 @@ static void menu_init (boot_params_t *boot_params) {

sound_init_default();

mixer_ch_set_vol(SFX_CHANNEL, 0.5f, 0.5f);
wav64_open(&sfx_cursor, "rom:/cursorsound.wav64");
wav64_open(&sfx_exit, "rom:/back.wav64");
wav64_open(&sfx_settings, "rom:/settings.wav64");
wav64_open(&sfx_enter, "rom:/enter.wav64");
wav64_open(&sfx_error, "rom:/error.wav64");

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved into sound_reconfigure. Don't forget about a flag to do loading only once.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done what I can to make this better, but might be a better way. Please let us know.

networkfusion marked this conversation as resolved.
Show resolved Hide resolved
menu = calloc(1, sizeof(menu_t));
assert(menu != NULL);

Expand Down Expand Up @@ -115,6 +124,10 @@ static void menu_init (boot_params_t *boot_params) {
__boot_tvtype = TV_NTSC;
}

if (!menu->settings.sound_enabled) {
mixer_ch_set_vol(SFX_CHANNEL, 0, 0);
}
networkfusion marked this conversation as resolved.
Show resolved Hide resolved

display_init(RESOLUTION_640x480, DEPTH_16_BPP, 2, GAMMA_NONE, FILTERS_DISABLED);

register_VI_handler(frame_counter_handler);
Expand Down
6 changes: 6 additions & 0 deletions src/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
#ifndef MENU_H__
#define MENU_H__

#include <libdragon.h>

networkfusion marked this conversation as resolved.
Show resolved Hide resolved
#include "boot/boot.h"

extern wav64_t sfx_cursor, sfx_error, sfx_enter, sfx_exit, sfx_settings;
networkfusion marked this conversation as resolved.
Show resolved Hide resolved

enum sfx_channels {
SFX_CHANNEL
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
};

void menu_run (boot_params_t *boot_params);

Expand Down
6 changes: 3 additions & 3 deletions src/menu/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ static settings_t init = {
.show_protected_entries = false,
.default_directory = "/",
.use_saves_folder = true,
.sound_enabled = true,

/* Beta feature flags (should always init to off) */
.bgm_enabled = false,
.sound_enabled = false,
.rumble_enabled = false,
};

Expand All @@ -39,10 +39,10 @@ void settings_load (settings_t *settings) {
settings->show_protected_entries = mini_get_bool(ini, "menu", "show_protected_entries", init.show_protected_entries);
settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory));
settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder);
settings->sound_enabled = mini_get_bool(ini, "menu", "sound_enabled", init.sound_enabled);

/* Beta feature flags, they might not be in the file */
settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled);
settings->sound_enabled = mini_get_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled);
settings->rumble_enabled = mini_get_bool(ini, "menu_beta_flag", "rumble_enabled", init.rumble_enabled);

mini_free(ini);
Expand All @@ -55,10 +55,10 @@ void settings_save (settings_t *settings) {
mini_set_bool(ini, "menu", "show_protected_entries", settings->show_protected_entries);
mini_set_string(ini, "menu", "default_directory", settings->default_directory);
mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder);
mini_set_bool(ini, "menu", "sound_enabled", settings->sound_enabled);

/* Beta feature flags, they should not save until production ready! */
// mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", settings->bgm_enabled);
// mini_set_bool(ini, "menu_beta_flag", "sound_enabled", settings->sound_enabled);
// mini_set_bool(ini, "menu_beta_flag", "rumble_enabled", settings->rumble_enabled);

mini_save(ini, MINI_FLAGS_SKIP_EMPTY_GROUPS);
Expand Down
7 changes: 7 additions & 0 deletions src/menu/views/browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../fonts.h"
#include "utils/fs.h"
#include "views.h"
#include "../menu.h"


static const char *rom_extensions[] = { "z64", "n64", "v64", "rom", NULL };
Expand Down Expand Up @@ -296,16 +297,19 @@ static void process (menu_t *menu) {
if (menu->browser.selected < 0) {
menu->browser.selected = 0;
}
wav64_play(&sfx_cursor, SFX_CHANNEL);
} else if (menu->actions.go_down) {
menu->browser.selected += scroll_speed;
if (menu->browser.selected >= menu->browser.entries) {
menu->browser.selected = menu->browser.entries - 1;
}
wav64_play(&sfx_cursor, SFX_CHANNEL);
}
menu->browser.entry = &menu->browser.list[menu->browser.selected];
}

if (menu->actions.enter && menu->browser.entry) {
wav64_play(&sfx_enter, SFX_CHANNEL);
switch (menu->browser.entry->type) {
case ENTRY_TYPE_DIR:
if (push_directory(menu, menu->browser.entry->name)) {
Expand Down Expand Up @@ -340,10 +344,13 @@ static void process (menu_t *menu) {
menu->browser.valid = false;
menu_show_error(menu, "Couldn't open last directory");
}
wav64_play(&sfx_exit, SFX_CHANNEL);
} else if (menu->actions.options && menu->browser.entry) {
component_context_menu_show(&entry_context_menu);
wav64_play(&sfx_settings, SFX_CHANNEL);
} else if (menu->actions.settings) {
component_context_menu_show(&settings_context_menu);
wav64_play(&sfx_settings, SFX_CHANNEL);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/menu/views/credits.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "views.h"

#include "../menu.h"

#ifndef MENU_VERSION
#define MENU_VERSION "Unknown"
Expand All @@ -13,6 +13,7 @@
static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/menu/views/error.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "views.h"
#include "../menu.h"


static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down Expand Up @@ -48,6 +50,7 @@ void view_error_display (menu_t *menu, surface_t *display) {
}

void menu_show_error (menu_t *menu, char *error_message) {
wav64_play(&sfx_error, SFX_CHANNEL);
menu->next_mode = MENU_MODE_ERROR;
menu->error_message = error_message;
}
2 changes: 2 additions & 0 deletions src/menu/views/file_info.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sys/stat.h>
#include "../menu.h"

#include "utils/fs.h"
#include "views.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ static char *format_file_type (char *name, bool is_directory) {
static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/menu/views/flashcart_info.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "views.h"
#include "../menu.h"


static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/menu/views/image_viewer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdlib.h>
#include "../menu.h"

#include "../png_decoder.h"
#include "views.h"
Expand Down Expand Up @@ -40,6 +41,7 @@ static void process (menu_t *menu) {
} else {
menu->next_mode = MENU_MODE_BROWSER;
}
wav64_play(&sfx_exit, SFX_CHANNEL);
} else if (menu->actions.enter && image) {
if (show_message) {
show_message = false;
Expand All @@ -48,6 +50,7 @@ static void process (menu_t *menu) {
} else {
show_message = true;
}
wav64_play(&sfx_enter, SFX_CHANNEL);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/menu/views/load_disk.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../cart_load.h"
#include "../disk_info.h"
#include "boot/boot.h"
#include "../menu.h"
#include "views.h"


Expand Down Expand Up @@ -34,8 +35,10 @@ static void process (menu_t *menu) {
} else if (menu->actions.options && menu->load.rom_path) {
load_pending = true;
load_rom = true;
wav64_play(&sfx_settings, SFX_CHANNEL);
} else if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/menu/views/load_emulator.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../cart_load.h"
#include "boot/boot.h"
#include "utils/fs.h"
#include "../menu.h"
#include "views.h"


Expand Down Expand Up @@ -36,6 +37,7 @@ static void process (menu_t *menu) {
load_pending = true;
} else if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/menu/views/load_rom.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../cart_load.h"
#include "../rom_info.h"
#include "boot/boot.h"
#include "../menu.h"
#include "views.h"


Expand Down Expand Up @@ -197,8 +198,10 @@ static void process (menu_t *menu) {
load_pending = true;
} else if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
} else if (menu->actions.options) {
component_context_menu_show(&options_context_menu);
wav64_play(&sfx_settings, SFX_CHANNEL);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/menu/views/music_player.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../mp3_player.h"
#include "../sound.h"
#include "../menu.h"
#include "views.h"


Expand Down Expand Up @@ -42,6 +43,7 @@ static void process (menu_t *menu) {
menu_show_error(menu, convert_error_message(err));
} else if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
} else if (menu->actions.enter) {
err = mp3player_toggle();
if (err != MP3PLAYER_OK) {
Expand Down
2 changes: 2 additions & 0 deletions src/menu/views/rtc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <time.h>
#include "../menu.h"
#include "views.h"

// FIXME: add implementation!
Expand All @@ -18,6 +19,7 @@
static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/menu/views/settings_editor.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../menu.h"
#include "views.h"


Expand All @@ -12,6 +13,7 @@ static const char *format_switch (bool state) {
static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
wav64_play(&sfx_exit, SFX_CHANNEL);
}
}

Expand Down
Loading