From cda9e14c32d71ce235feda6131044f971d64b9b6 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Mon, 13 Feb 2012 13:12:27 -0200 Subject: [PATCH] [xmp] Add -n option for no sound output Signed-off-by: Claudio Matsuoka --- src/Makefile | 2 +- src/common.h | 1 + src/main.c | 5 ++++ src/options.c | 60 +++++++++++++++++++++++++----------------------- src/sound_null.c | 40 ++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 src/sound_null.c diff --git a/src/Makefile b/src/Makefile index 95f6ce0..392154c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ #SRC_OBJS = getopt.o getopt1.o options.o drivers.o main.o -SRC_OBJS = sound_alsa.o terminal.o info.o options.o main.o +SRC_OBJS = sound_null.o sound_alsa.o terminal.o info.o options.o main.o SRC_DFILES = Makefile xmp.1 $(SRC_OBJS:.o=.c) common.h SRC_PATH = src diff --git a/src/common.h b/src/common.h index b5cb8f1..6052091 100644 --- a/src/common.h +++ b/src/common.h @@ -10,6 +10,7 @@ struct options { int random; /* play in random order */ int load_only; /* load module and exit */ int verbose; + int silent; /* silent output */ char *out_file; /* output file name */ char *ins_path; /* instrument path */ char mute[XMP_MAX_CHANNELS]; diff --git a/src/main.c b/src/main.c index df3571c..221cd01 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,7 @@ extern int optind; extern struct sound_driver sound_alsa; +extern struct sound_driver sound_null; struct sound_driver *sound = &sound_alsa; @@ -71,6 +72,10 @@ int main(int argc, char **argv) shuffle(argc - optind + 1, &argv[optind - 1]); } + if (options.silent) { + sound = &sound_null; + } + if (sound->init(44100, 2) < 0) { fprintf(stderr, "%s: can't initialize sound\n", argv[0]); exit(EXIT_FAILURE); diff --git a/src/options.c b/src/options.c index 77cfc41..acd33c9 100644 --- a/src/options.c +++ b/src/options.c @@ -129,38 +129,37 @@ static void usage(char *s) " -v --verbose Verbose mode (incremental)\n"); } +static struct option lopt[] = { + { "amplify", 1, 0, 'a' }, + { "bits", 1, 0, 'b' }, + { "driver", 1, 0, 'd' }, + { "frequency", 1, 0, 'f' }, + { "offset-bug-emulation", 0, 0, OPT_FX9BUG }, + { "help", 0, 0, 'h' }, + { "instrument-path", 1, 0, 'I' }, + { "load-only", 0, 0, OPT_LOADONLY }, + { "loop", 0, 0, 'l' }, + { "mono", 0, 0, 'm' }, + { "mute", 1, 0, 'M' }, + { "output-file", 1, 0, 'o' }, + { "pan", 1, 0, 'P' }, + { "quiet", 0, 0, 'q' }, + { "random", 0, 0, 'R' }, + { "solo", 1, 0, 'S' }, + { "start", 1, 0, 's' }, + { "stdout", 0, 0, 'c' }, + { "tempo", 1, 0, 'T' }, + { "time", 1, 0, 't' }, + { "unsigned", 0, 0, 'u' }, + { "version", 0, 0, 'V' }, + { "verbose", 0, 0, 'v' }, + { NULL, 0, 0, 0 } +}; + void get_options(int argc, char **argv, struct options *options) { int optidx = 0; -#define OPTIONS "a:b:cD:d:f:hI:lM:mo:qRS:s:T:t:uVv" - static struct option lopt[] = { - {"amplify", 1, 0, 'a'}, - {"bits", 1, 0, 'b'}, - {"driver", 1, 0, 'd'}, - {"frequency", 1, 0, 'f'}, - {"offset-bug-emulation", 0, 0, OPT_FX9BUG}, - {"help", 0, 0, 'h'}, - {"instrument-path", 1, 0, 'I'}, - {"load-only", 0, 0, OPT_LOADONLY}, - {"loop", 0, 0, 'l'}, - {"mono", 0, 0, 'm'}, - {"mute", 1, 0, 'M'}, - {"nocmd", 0, 0, OPT_NOCMD}, - {"output-file", 1, 0, 'o'}, - {"pan", 1, 0, 'P'}, - {"quiet", 0, 0, 'q'}, - {"random", 0, 0, 'R'}, - {"solo", 1, 0, 'S'}, - {"start", 1, 0, 's'}, - {"stdout", 0, 0, 'c'}, - {"tempo", 1, 0, 'T'}, - {"time", 1, 0, 't'}, - {"unsigned", 0, 0, 'u'}, - {"version", 0, 0, 'V'}, - {"verbose", 0, 0, 'v'}, - {NULL, 0, 0, 0} - }; - +#define OPTIONS "a:b:cD:d:f:hI:lM:mno:qRS:s:T:t:uVv" i = 0; while ((o = getopt_long(argc, argv, OPTIONS, lopt, &optidx)) != -1) { switch (o) { @@ -201,6 +200,9 @@ void get_options(int argc, char **argv, struct options *options) case 'm': options->format |= XMP_FORMAT_MONO; break; + case 'n': + options->silent = 1; + break; case 'o': options->out_file = optarg; if (strlen(optarg) >= 4 && diff --git a/src/sound_null.c b/src/sound_null.c new file mode 100644 index 0000000..257e565 --- /dev/null +++ b/src/sound_null.c @@ -0,0 +1,40 @@ + +#include +#include "sound.h" + +static int init(int sampling_rate, int channels) +{ +} + +static void play(void *b, int i) +{ +} + +static void deinit() +{ +} + +static void flush() +{ +} + +static void onpause() +{ +} + +static void onresume() +{ +} + + +struct sound_driver sound_null = { + "null", + "No output", + NULL, + init, + deinit, + play, + flush, + onpause, + onresume +};