now a main executable that can function as all the sounds, and can write

to stdout and/or a file
This commit is contained in:
Vincent Batts 2012-11-19 23:21:44 -05:00
parent 4ccc79ed1e
commit cbea4c53cf
5 changed files with 108 additions and 12 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.*.swp
*~

32
audio.c
View File

@ -1,20 +1,36 @@
#include <stdio.h>
const char* audio_dev = "/dev/audio";
FILE* audio;
#include "audio.h"
void init(char* dev_file_name) {
if (dev_file_name != NULL) {
audio = fopen(dev_file_name, "a");
//const char* audio_dev = "/dev/audio";
FILE* audio = NULL;
int quiet = 0;
void init(struct s_config s) {
if (s.filename != NULL) {
audio = fopen(s.filename, "a");
}
if (s.quiet == 1) {
quiet = 1;
} else {
audio = stdout;
quiet = 0;
}
}
void p(int i) {
//fputc(i, audio);
putchar(i);
if (audio != NULL) {
fputc(i, audio);
}
if (!quiet) {
putchar(i);
}
}
void quit() {
if (audio != stdout) {
fclose(audio);
}
}
// vim:set sw=2 sts=2 et ai:

14
audio.h
View File

@ -1,4 +1,16 @@
void init();
#ifndef BITORC_AUDIO_H
#define BITORC_AUDIO_H
struct s_config {
int quiet;
char* filename;
};
void init(struct s_config s);
void p(int i);
void quit();
#endif
// vim:set sw=2 sts=2 et ai:

67
main.c
View File

@ -1,9 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(int ac, char** av) {
//init();
return 0;
#include "audio.h"
#include "sounds.h"
void usage(char* name, int exit_stat) {
fprintf(stderr, "Usage: %s [-f filename] < -s 1-6 >\n", name);
exit(exit_stat);
}
int main(int ac, char* av[]) {
int opt;
int sound_choice = 0;
//int quiet = 0;
//char* filename = NULL;
struct s_config s;
while ((opt = getopt(ac, av, "hf:s:q")) != -1) {
switch (opt) {
case 'q':
s.quiet = 1;
break;
case 's':
sound_choice = atoi(optarg);
break;
case 'f':
s.filename = optarg;
break;
case 'h':
usage(av[0], EXIT_SUCCESS);
default:
usage(av[0], EXIT_FAILURE);
}
}
if (sound_choice == 0) {
fprintf(stderr, "ERROR: pleaese choice a sound (currently 1-6)\n");
usage(av[0], EXIT_FAILURE);
}
init(s);
switch (sound_choice) {
case 1:
sound_loop_1(sound_1, 0);
break;
case 2:
sound_loop_1(sound_2, 0);
break;
case 3:
sound_loop_1(sound_3, 0);
break;
case 4:
sound_loop_1(sound_4, 0);
break;
case 5:
sound_loop_1(sound_5, 0);
break;
case 6:
sound_loop_1(sound_6, 0);
break;
}
exit(EXIT_SUCCESS);
}
// vim:set sw=2 sts=2 et ai:

View File

@ -1,4 +1,7 @@
#ifndef BITORC_SOUNDS_H
#define BITORC_SOUNDS_H
void sound_loop_1(int (*sp)(int i), int t);
int sound_1(int t);
int sound_2(int t);
@ -7,4 +10,6 @@ int sound_4(int t);
int sound_5(int t);
int sound_6(int t);
#endif
// vim:set sw=2 sts=2 et ai: