diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-11 22:07:49 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-11 22:07:49 +0100 |
commit | 569c6508b2a39f60746ff0b0cbec963047d7b797 (patch) | |
tree | 0e00b77c290a3638b01a4fa642d45bf380191b82 | |
download | musiclab-569c6508b2a39f60746ff0b0cbec963047d7b797.tar.gz |
initial commit
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 27 | ||||
-rw-r--r-- | main.c | 41 |
3 files changed, 71 insertions, 0 deletions
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) @@ -0,0 +1,41 @@ +#include <SDL2/SDL.h> +#include <SDL2/SDL_mixer.h> +#include <stdio.h> + +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; +} |