From 2ddb925d27dc64ef375be6f760d778eca9c95209 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 19 Nov 2012 14:42:33 -0500 Subject: [PATCH] working towards unifying the sounds to a single command --- Makefile | 3 ++- all.c | 9 +++++++++ audio.c | 13 +++++++++---- f1.c | 11 +++-------- f2.c | 10 ++++------ f3.c | 11 ++++------- f4.c | 20 ++++++++++---------- f5.c | 10 ++++------ f6.c | 26 ++++++++++++++------------ sounds.c | 26 ++++++++++++++++++++++++++ sounds.h | 8 ++++++++ 11 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 all.c create mode 100644 sounds.c create mode 100644 sounds.h diff --git a/Makefile b/Makefile index 22abc83..4e628cc 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,9 @@ LDFLAGS += -static -s all: $(MUSIC_FILES) audio.o: audio.c audio.h +sounds.o: sounds.c sounds.h -%: %.c audio.o +%: %.c audio.o sounds.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ clean: diff --git a/all.c b/all.c new file mode 100644 index 0000000..a2e2899 --- /dev/null +++ b/all.c @@ -0,0 +1,9 @@ +#include +#include + +int main(int ac, char** av) { + //init(); + return 0; +} + +// vim:set sw=2 sts=2 et ai: diff --git a/audio.c b/audio.c index eab7d9e..b987b85 100644 --- a/audio.c +++ b/audio.c @@ -4,12 +4,17 @@ const char* audio_dev = "/dev/audio"; FILE* audio; -void init() { - audio = fopen(audio_dev, "w"); +void init(char* dev_file_name) { + if (dev_file_name != NULL) { + audio = fopen(dev_file_name, "a"); + } else { + audio = stdout; + } } void p(int i) { - //fputc(i, audio); - putchar(i); + //fputc(i, audio); + putchar(i); } +// vim:set sw=2 sts=2 et ai: diff --git a/f1.c b/f1.c index 02f130c..7363585 100644 --- a/f1.c +++ b/f1.c @@ -1,10 +1,5 @@ -#include "audio.h" - +#include "sounds.h" int main() { - //init(); - int t; - for (t = 0;;t++) { - p((t >> 6 | t | t >> (t >> 16)) * 10 + ((t >> 11) & 7)); - } + sound_loop_1(sound_1,0); } - +// vim:set sw=2 sts=2 et ai: diff --git a/f2.c b/f2.c index 3d7b9e4..d240a7c 100644 --- a/f2.c +++ b/f2.c @@ -1,7 +1,5 @@ -#include "audio.h" -int main(t){ - //init(); - for(t=0;;t++) { - p(t*(((t>>12)|(t>>8))&(63&(t>>4)))); - } +#include "sounds.h" +int main(){ + sound_loop_1(sound_2,0); } +// vim:set sw=2 sts=2 et ai: diff --git a/f3.c b/f3.c index 0f89578..42a701f 100644 --- a/f3.c +++ b/f3.c @@ -1,8 +1,5 @@ -#include "audio.h" -main(int t) { - //init(); - for(;;t++) { - p(t*9&t>>4|t*5&t>>7|t*3&t/1024); - - } +#include "sounds.h" +int main() { + sound_loop_1(sound_3,0); } +// vim:set sw=2 sts=2 et ai: diff --git a/f4.c b/f4.c index e3092e2..61394b6 100644 --- a/f4.c +++ b/f4.c @@ -1,12 +1,12 @@ #include "audio.h" -int main(int t) { - //init(); - for (t = 0;;t++) { - int i; - i = (t>>7-(t>>15)&-t>>7-(t>>15)); - if (i==0) - continue; - p(t>>4|t&(t>>5)/i); - } +int main() { + int t; + for (t = 0;;t++) { + int i; + i = (t>>7-(t>>15)&-t>>7-(t>>15)); + if (i==0) + continue; + p(t>>4|t&(t>>5)/i); + } } - +// vim:set sw=2 sts=2 et ai: diff --git a/f5.c b/f5.c index f203438..7fea5e4 100644 --- a/f5.c +++ b/f5.c @@ -1,7 +1,5 @@ -#include "audio.h" -main(t){ - //init(); - for(t=0;;t++) { - p(((t*("36364689"[t>>13&7]&15))/12&128)+(((((t>>12)^(t>>12)-2)%11*t)/4|t>>13)&127)); - } +#include "sounds.h" +main(){ + sound_loop_1(sound_5,0); } +// vim:set sw=2 sts=2 et ai: diff --git a/f6.c b/f6.c index a17fdaa..c527aaf 100644 --- a/f6.c +++ b/f6.c @@ -1,15 +1,17 @@ #include "audio.h" -main(t){ - int y,x; - //init(); - for(t=0;;t++) - { - x=t*"6689"[t>>16&3]/24&127; - y=t&16383; - if (y==0 || x==0) - continue; - - p((30000000000/(y)&1)*35+(x)*y/400000000+((t>>8^t>>10|1>>14|x)&63)); - } +main(int ac, char** av){ + long t, y, x; + + //init(); + for(t=0;;t++) + { + x=t*"6689"[t>>16&3]/24&127; + y=t&16383; + if (y==0 || x==0) + continue; + + p((30000000000/(y)&1)*35+(x)*y/400000000+((t>>8^t>>10|1>>14|x)&63)); + } } +// vim:set sw=2 sts=2 et ai: diff --git a/sounds.c b/sounds.c new file mode 100644 index 0000000..f58ba33 --- /dev/null +++ b/sounds.c @@ -0,0 +1,26 @@ + +#include "audio.h" +#include "sounds.h" + +void sound_loop_1(int (*sp)(int i), int t) { + for (t = 0;;t++) { + p((*sp)(t)); + } +} + +int sound_1(int t) { + return (t >> 6 | t | t >> (t >> 16)) * 10 + ((t >> 11) & 7); +} + +int sound_2(int t) { + return (t*(((t>>12)|(t>>8))&(63&(t>>4)))); +} + +int sound_3(int t) { + return (t*9&t>>4|t*5&t>>7|t*3&t/1024); +} +int sound_5(int t) { + return (((t*("36364689"[t>>13&7]&15))/12&128)+(((((t>>12)^(t>>12)-2)%11*t)/4|t>>13)&127)); +} + +// vim:set sw=2 sts=2 et ai: diff --git a/sounds.h b/sounds.h new file mode 100644 index 0000000..577aaa4 --- /dev/null +++ b/sounds.h @@ -0,0 +1,8 @@ + +void sound_loop_1(int (*sp)(int i), int t); +int sound_1(int t); +int sound_2(int t); +int sound_3(int t); +int sound_5(int t); + +// vim:set sw=2 sts=2 et ai: