diff options
author | zlago | 2024-09-02 10:58:10 +0200 |
---|---|---|
committer | zlago | 2024-09-02 10:58:10 +0200 |
commit | aa759ff708196e5ea0f39bedabfbecb8f164294e (patch) | |
tree | d5660e7edca437ce819d15e98cda466ae26631df | |
parent | 3b284977d433ea4e39553bda329c4643c646cbc4 (diff) |
cleanup
-rw-r--r-- | GNUmakefile | 8 | ||||
-rw-r--r-- | src/SDL2.c (renamed from src/sdl.c) | 11 | ||||
-rw-r--r-- | src/include.h | 4 | ||||
-rw-r--r-- | src/modules/fluidsynth.c | 2 | ||||
-rw-r--r-- | src/modules/openmpt.c | 2 |
5 files changed, 19 insertions, 8 deletions
diff --git a/GNUmakefile b/GNUmakefile index 58990fd..a9e2537 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -3,7 +3,7 @@ GLAD ?= glad MKDIR ?= mkdir -p -libs ::= SDL2 openmpt fluidsynth +libs ::= openmpt fluidsynth cflags ::= -I . -g -Og ${CFLAGS} ldflags ::= -Wl,--rpath,'$$ORIGIN' $(addprefix -l,${libs}) ${LDFLAGS} @@ -13,9 +13,9 @@ deps ::= $(addprefix out/,$(notdir ${srcs:.c=.d})) .PHONY: all run clean -all: out/mu-sdl +all: out/mu-SDL2 -run: out/mu-sdl +run: out/mu-SDL2 ./$< clean: @@ -37,6 +37,6 @@ out/%.d: src/%.c | out/ ${CC} ${cflags} ${CPPFLAGS} -MM -MG -MF $@ -MT "${@:.d=.o} $@" $< out/mu-%: out/%.o ${objs} | out/ - ${CC} -o $@ $^ ${cflags} ${ldflags} + ${CC} -o $@ $^ ${cflags} ${ldflags} -l${<:out/%.o=%} include ${deps} diff --git a/src/sdl.c b/src/SDL2.c index 21ce1a8..4e51269 100644 --- a/src/sdl.c +++ b/src/SDL2.c @@ -16,6 +16,8 @@ static const int WINDOW_WIDTH = 160, WINDOW_HEIGHT = 90; SDL_Window *window = NULL; +int paused = 0; + struct blob load_file(char const *const name); struct userdata userdata = { @@ -65,9 +67,9 @@ int main(int argc, char **argv) { SDL_RenderPresent(renderer); SDL_AudioSpec desired = { - .freq = 48000, + .freq = SAMPLE_RATE, .format = AUDIO_F32SYS, - .channels = 2, + .channels = OUT_CHANNELS, .samples = 8096, .callback = audio_callback, .userdata = &userdata, @@ -111,6 +113,11 @@ int main(int argc, char **argv) { if (evt.key.keysym.sym == SDLK_ESCAPE) { goto done; } + + if (evt.key.keysym.sym == SDLK_SPACE) { + paused = !paused; + SDL_PauseAudioDevice(audio, paused); + } break; case SDL_DROPFILE: diff --git a/src/include.h b/src/include.h index 389aaf2..6bd52ff 100644 --- a/src/include.h +++ b/src/include.h @@ -1,6 +1,10 @@ #pragma once #include <stddef.h> +#define SAMPLE_RATE 48000 +#define IN_CHANNELS 0 +#define OUT_CHANNELS 2 + struct blob { void *data; size_t size; diff --git a/src/modules/fluidsynth.c b/src/modules/fluidsynth.c index fd3c874..9eedc2c 100644 --- a/src/modules/fluidsynth.c +++ b/src/modules/fluidsynth.c @@ -36,7 +36,7 @@ int module_fluidsynth(struct blob *file, struct userdata *userdata) { fs->settings = new_fluid_settings(); // wasteful, but when trying to 'fix' it it just caused more errors fluid_settings_setnum(fs->settings, "synth.gain", 0.5); fluid_settings_setint(fs->settings, "player.reset-synth", 0); - fluid_settings_setnum(fs->settings, "synth.sample-rate", 48000); + fluid_settings_setnum(fs->settings, "synth.sample-rate", SAMPLE_RATE); fs->synth = new_fluid_synth(fs->settings); char *soundfont_path = getenv("SOUNDFONT"); if (soundfont_path == NULL) { diff --git a/src/modules/openmpt.c b/src/modules/openmpt.c index 58c3994..027519f 100644 --- a/src/modules/openmpt.c +++ b/src/modules/openmpt.c @@ -4,7 +4,7 @@ #include <libopenmpt/libopenmpt.h> static void openmpt_callback(void *mod, unsigned char *stream, int const length) { - openmpt_module_read_interleaved_float_stereo(mod, 48000, length / sizeof (float) / 2, (float *) stream); + openmpt_module_read_interleaved_float_stereo(mod, SAMPLE_RATE, length / sizeof (float) / 2, (float *) stream); } static void libopenmpt_example_logfunc( const char * message, void * userdata ); |