From: David Griffith Date: Thu, 5 Dec 2013 00:43:07 +0000 (-0800) Subject: Messy, and needs much more work, but sound effects work. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=05c3f6f27d8c4b6b369a8d18100eb9d4da7f50d0;p=liskon_frotz.git Messy, and needs much more work, but sound effects work. --- diff --git a/Makefile b/Makefile index d11f102..927424a 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ CURSES_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \ FLAGS = $(OPTS) $(CURSES_DEFS) $(INCL) -SOUND_LIB = -lao -ldl -lm +SOUND_LIB = -lao -ldl -lm -lsndfile $(NAME): $(NAME)-curses curses: $(NAME)-curses diff --git a/src/curses/ux_audio.c b/src/curses/ux_audio.c index 8f9c7de..4a702bc 100644 --- a/src/curses/ux_audio.c +++ b/src/curses/ux_audio.c @@ -26,8 +26,10 @@ #include #endif +#include #include #include +#include #include #include "ux_frotz.h" @@ -41,7 +43,7 @@ typedef struct EFFECT { int type; int active; int voice; - char *buffer; + int *buffer; int buflen; int repeats; int volume; @@ -64,7 +66,7 @@ static EFFECT *getaiff(FILE *, size_t, int, int); static EFFECT *geteffect(int); static EFFECT *new_effect(int, int); - +/* int ux_initsound(void) { ao_sample_format format; @@ -100,6 +102,7 @@ void ux_stopsound(void) ao_close(device); ao_shutdown(); } +*/ static EFFECT *geteffect(int num) { @@ -154,37 +157,77 @@ static EFFECT *new_effect(int type, int num) } -static EFFECT *getaiff(FILE *f, size_t pos, int len, int num) +static EFFECT *getaiff(FILE *fp, size_t pos, int len, int num) { + ao_device *device; + ao_sample_format format; + int default_driver; + SNDFILE *sndfile; + SF_INFO sf_info; + EFFECT *sample; void *data; int size; int count; + int frames_read; + + int *buffer; + + sample = new_effect(SFX_TYPE, num); if (sample == NULL || sample == 0) return sample; - if (fseek(f, pos, SEEK_SET) != 0) + if (fseek(fp, pos, SEEK_SET) != 0) return NULL; - count = 0; - sample->buffer = malloc(sizeof(int) * len); + ao_initialize(); + default_driver = ao_default_driver_id(); + + sf_info.format = 0; + sndfile = sf_open_fd(fileno(fp), SFM_READ, &sf_info, 1); + + memset(&format, 0, sizeof(ao_sample_format)); + + format.byte_format = AO_FMT_NATIVE; + format.bits = 32; + format.channels = sf_info.channels; + format.rate = sf_info.samplerate; + device = ao_open_live(default_driver, &format, NULL /* no options */); + if (device == NULL) { + printf("Error opening sound device.\n"); + exit(1); + } + + buffer = malloc(sizeof(int) * sf_info.frames * sf_info.channels); + + sf_read_int(sndfile, buffer, sf_info.frames); + + ao_play(device, (char *)buffer, sf_info.frames * sizeof(int)); + ao_close(device); + ao_shutdown(); + + sf_close(sndfile); + +/* while (count <= len) { fread(sample->buffer + count, 1, 1, f); count++; } sample->buflen = count; - +*/ return sample; } static void startsample() { +/* if (e_sfx == NULL) return; ao_play(device, e_sfx->buffer, e_sfx->buflen); +*/ } static void stopsample() @@ -266,7 +309,7 @@ void os_start_sample (int number, int volume, int repeats, zword eos) { EFFECT *e; - if (!audiorunning) return; +// if (!audiorunning) return; e = geteffect(number); if (e == NULL) return; // if (e->type == SFX_TYPE) stopsample(); diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index ab52389..6b74f2f 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -543,7 +543,7 @@ FILE *os_load_story(void) break; } - ux_initsound(); +// ux_initsound(); // os_start_sample(3, 8, 1, 0); // exit(1);