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 25 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Ignore generated files in the libdragon FS
/filesystem/FiraMonoBold.font64
/filesystem/*.wav64

# Ignore external development tools
/tools/*
Expand Down
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ An open source menu for N64 flashcarts.
* Comprehensive ROM information display.
* Real Time Clock support.
* Music playback (MP3).
* Menu sound effects.


### Video showcase (as of Oct 12 2023)
Expand Down Expand Up @@ -160,3 +161,9 @@ Once merged, they can be viewed [here](https://polprzewodnikowy.github.io/N64Fla
- [mini.c](https://github.com/univrsal/mini.c) (BSD 2-Clause License)
- [minimp3](https://github.com/lieff/minimp3) (CC0 1.0 Universal)
- [miniz](https://github.com/richgel999/miniz) (MIT License)

## Sounds
See [License](https://pixabay.com/es/service/license-summary/) for the following sounds.
networkfusion marked this conversation as resolved.
Show resolved Hide resolved
- [Cursor sound](https://pixabay.com/en/sound-effects/click-buttons-ui-menu-sounds-effects-button-7-203601/) by Skyscraper_seven (Free to use)
- [Actions (Enter, back) sound](https://pixabay.com/en/sound-effects/menu-button-user-interface-pack-190041/) by Liecio (Free to use)
- [Error sound](https://pixabay.com/en/sound-effects/error-call-to-attention-129258/) by Universfield (Free to use)
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 "../sound.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;
}
sound_play_effect(SFX_EXIT);
} 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;
}
sound_play_effect(SFX_ENTER);
} else if (menu->actions.go_up) {
cm->selected -= 1;
if (cm->selected < 0) {
cm->selected = 0;
}
sound_play_effect(SFX_CURSOR);
} else if (menu->actions.go_down) {
cm->selected += 1;
if (cm->selected >= cm->count) {
cm->selected = (cm->count - 1);
}
sound_play_effect(SFX_CURSOR);
}

return true;
Expand Down
5 changes: 5 additions & 0 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static void menu_init (boot_params_t *boot_params) {

sound_init_default();


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 +116,10 @@ static void menu_init (boot_params_t *boot_params) {
__boot_tvtype = TV_NTSC;
}

if (menu->settings.sound_enabled) {
sound_init_sfx();
}
Comment on lines +118 to +120
Copy link
Owner

Choose a reason for hiding this comment

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

Minor nitpick because changing this setting live will not enable sounds and will require complete reboot of the menu. It's okay for now because we don't have a settings editor yet.


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

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


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


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
45 changes: 43 additions & 2 deletions src/menu/sound.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include <stdbool.h>

networkfusion marked this conversation as resolved.
Show resolved Hide resolved
#include <libdragon.h>

#include "mp3_player.h"
#include "sound.h"


#define DEFAULT_FREQUENCY (44100)
#define NUM_BUFFERS (4)
#define NUM_CHANNELS (2)
#define NUM_CHANNELS (3)

static wav64_t sfx_cursor, sfx_error, sfx_enter, sfx_exit, sfx_setting;


static bool sound_initialized = false;
static bool sfx_enabled = false;


static void sound_reconfigure (int frequency) {
Expand All @@ -31,10 +34,48 @@ void sound_init_default (void) {
sound_reconfigure(DEFAULT_FREQUENCY);
}


networkfusion marked this conversation as resolved.
Show resolved Hide resolved
void sound_init_mp3_playback (void) {
sound_reconfigure(mp3player_get_samplerate());
}


void sound_init_sfx (void) {
mixer_ch_set_vol(SOUND_SFX_CHANNEL, 0.5f, 0.5f);
wav64_open(&sfx_cursor, "rom:/cursorsound.wav64");
wav64_open(&sfx_exit, "rom:/back.wav64");
wav64_open(&sfx_setting, "rom:/settings.wav64");
wav64_open(&sfx_enter, "rom:/enter.wav64");
wav64_open(&sfx_error, "rom:/error.wav64");
sfx_enabled = true;
}


void sound_play_effect(sound_effect_t sfx) {
if(sfx_enabled) {
switch (sfx) {
case SFX_CURSOR:
wav64_play(&sfx_cursor, SOUND_SFX_CHANNEL);
break;
case SFX_EXIT:
wav64_play(&sfx_exit, SOUND_SFX_CHANNEL);
break;
case SFX_SETTING:
wav64_play(&sfx_setting, SOUND_SFX_CHANNEL);
break;
case SFX_ENTER:
wav64_play(&sfx_enter, SOUND_SFX_CHANNEL);
break;
case SFX_ERROR:
wav64_play(&sfx_error, SOUND_SFX_CHANNEL);
break;
default:
break;
}
}
}


void sound_deinit (void) {
if (sound_initialized) {
mixer_close();
Expand Down
13 changes: 11 additions & 2 deletions src/menu/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@
#ifndef SOUND_H__
#define SOUND_H__


networkfusion marked this conversation as resolved.
Show resolved Hide resolved
#define SOUND_MP3_PLAYER_CHANNEL (0)
#define SOUND_SFX_CHANNEL (2)

typedef enum {
SFX_CURSOR,
SFX_ERROR,
SFX_ENTER,
SFX_EXIT,
SFX_SETTING,
} sound_effect_t;


void sound_init_default (void);
void sound_init_mp3_playback (void);
void sound_init_sfx (void);
void sound_play_effect(sound_effect_t sfx);
void sound_deinit (void);
void sound_poll (void);


#endif
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 "../sound.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;
}
sound_play_effect(SFX_CURSOR);
} 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;
}
sound_play_effect(SFX_CURSOR);
}
menu->browser.entry = &menu->browser.list[menu->browser.selected];
}

if (menu->actions.enter && menu->browser.entry) {
sound_play_effect(SFX_ENTER);
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");
}
sound_play_effect(SFX_EXIT);
} else if (menu->actions.options && menu->browser.entry) {
component_context_menu_show(&entry_context_menu);
sound_play_effect(SFX_SETTING);
} else if (menu->actions.settings) {
component_context_menu_show(&settings_context_menu);
sound_play_effect(SFX_SETTING);
}
}

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 "../sound.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;
sound_play_effect(SFX_EXIT);
}
}

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 "../sound.h"


static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
sound_play_effect(SFX_EXIT);
}
}

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) {
sound_play_effect(SFX_ERROR);
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 "../sound.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;
sound_play_effect(SFX_EXIT);
}
}

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 "../sound.h"


static void process (menu_t *menu) {
if (menu->actions.back) {
menu->next_mode = MENU_MODE_BROWSER;
sound_play_effect(SFX_EXIT);
}
}

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 "../sound.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;
}
sound_play_effect(SFX_EXIT);
} 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;
}
sound_play_effect(SFX_ENTER);
}
}

Expand Down
Loading