From 569c6508b2a39f60746ff0b0cbec963047d7b797 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 11 Mar 2023 22:07:49 +0100 Subject: initial commit --- .gitignore | 3 +++ Makefile | 27 +++++++++++++++++++++++++++ main.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4d469d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/*.o +/*.d +/musiclab diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e034e00 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +CC := gcc +LD := $(CC) +CFLAGS := -Os -std=c99 -Wall -Wextra -MMD $(shell sdl2-config --cflags) +LDFLAGS := -lm $(shell sdl2-config --libs) -lSDL2_mixer +SRC := $(wildcard *.c) +OBJ := $(patsubst %.c,%.o,$(wildcard $(SRC))) +DEP := $(patsubst %.o,%.d,$(wildcard $(OBJ))) +NAME := musiclab + +all: $(NAME) + +$(NAME): $(OBJ) + $(LD) $(OBJ) -o $(NAME) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(NAME) $(OBJ) $(DEP) + +re: + make --no-print-directory clean + make --no-print-directory all + +.PHONY: all run clean re + +-include $(DEP) diff --git a/main.c b/main.c new file mode 100644 index 0000000..df408e7 --- /dev/null +++ b/main.c @@ -0,0 +1,41 @@ +#include +#include +#include + +int main(int argc, char **argv) { + (void)argc, (void)argv; + + /* Initialize SDL and SDL_mixer. */ + if (SDL_Init(SDL_INIT_AUDIO)) { + fprintf(stderr, "%s\n", SDL_GetError()); + return 1; + } + if (atexit(SDL_Quit)) { + perror("atexit(SDL_Quit)"); + SDL_Quit(); + return 1; + } + if (Mix_Init(MIX_INIT_FLAC) != MIX_INIT_FLAC) { + fprintf(stderr, "%s\n", Mix_GetError()); + return 1; + } + if (atexit(Mix_Quit)) { + perror("atexit(Mix_Quit)"); + Mix_Quit(); + return 1; + } + + /* Open audio device. */ + if (Mix_OpenAudio(48000, AUDIO_F32SYS, 2, 4096)) { + fprintf(stderr, "%s\n", Mix_GetError()); + return 1; + } + if (atexit(Mix_CloseAudio)) { + perror("atexit(Mix_CloseAudio)"); + Mix_CloseAudio(); + return 1; + } + + /* All cleanup is handled through atexit. */ + return 0; +} -- cgit v1.2.3