From 561aedd9303e46ac1136a12e874ab1c1a83c1cf8 Mon Sep 17 00:00:00 2001 From: Frank Villaro-Dixon Date: Thu, 1 Jan 2015 12:05:40 +0100 Subject: [PATCH] some beats --- Makefile | 2 +- beat_detector.sh | 13 +++++++++++++ sdl.c | 9 ++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 beat_detector.sh diff --git a/Makefile b/Makefile index 3526ba5..c703c40 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - clang *.c `sdl-config --cflags --libs` -lm -Wall -Wextra -o jeu + clang *.c `sdl-config --cflags --libs` -lSDL_mixer -lm -Wall -Wextra -o jeu clean: rm jeu diff --git a/beat_detector.sh b/beat_detector.sh new file mode 100755 index 0000000..78e62ea --- /dev/null +++ b/beat_detector.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +mplayer mus.mp3 > /dev/null & +START=$(date +%s.%N) + +> mus.beats + +while true; do + read n + END=$(date +%s.%N) + DIFF=$(echo "$END - $START" | bc) + echo $DIFF >> mus.beats +done diff --git a/sdl.c b/sdl.c index 17c43c8..7431b41 100644 --- a/sdl.c +++ b/sdl.c @@ -7,17 +7,24 @@ #include #include #include "SDL/SDL.h" +#include "SDL_mixer.h" #include "game.h" void init_SDL(struct s_game *g) { /* initialize SDL */ - SDL_Init(SDL_INIT_VIDEO); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); /* set the title bar */ SDL_WM_SetCaption("SDL Move", "SDL Move"); /* create window */ g->screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0); + + + Mix_OpenAudio(22050,AUDIO_S16SYS,2,640); + Mix_Music *mus; + mus = Mix_LoadMUS("./mus.mp3"); + Mix_PlayMusic(mus,1); }