diff --git a/audio/Makefile b/audio/Makefile new file mode 100644 index 0000000..e531390 --- /dev/null +++ b/audio/Makefile @@ -0,0 +1,16 @@ +# +# audio part of the phytotron +# + + +CC = gcc +CCOPT = -Wall -g -DDEBUG_LEVEL=1 +LIBS = -lao -lsndfile -lm +player.o: player.c Makefile + $(CC) ${CCOPT} -c $< + +t.o: t.c player.h Makefile + $(CC) ${CCOPT} -c $< + +t: player.o t.o Makefile + $(CC) t.o player.o ${LIBS} -o t diff --git a/audio/player.c b/audio/player.c new file mode 100644 index 0000000..82e7821 --- /dev/null +++ b/audio/player.c @@ -0,0 +1,98 @@ +/* + * Audio player for the phytotron + */ + +#include +#include +#include +#include + +#include +#include + +/* --------------------------------------------------------------------- */ + +#define T_BUFF_WAVES (8192*4) +#define T_FNAME 1000 +static ao_device *device; +static ao_sample_format format; +static int coefficient; +static int16_t buffer[T_BUFF_WAVES]; + +/* --------------------------------------------------------------------- */ +int init_waveout(int smplrate) +{ +int default_driver; + +ao_initialize(); + +default_driver = ao_default_driver_id(); +#if DEBUG_LEVEL +fprintf(stderr, "%s : ao default driver #%d\n", __func__, default_driver); +#endif + +memset(&format, 0, sizeof(format)); +format.bits = 16; +format.channels = 2; +format.rate = smplrate; +format.byte_format = AO_FMT_LITTLE; + +device = ao_open_live(default_driver, &format, NULL); +if (device == NULL) { + fprintf(stderr, "Error opening AO device.\n"); + return -1; + } + +return 0; +} + +/* --------------------------------------------------------------------- */ +int close_waveout(void) +{ +ao_close(device); +ao_shutdown(); +return 0; +} +/* --------------------------------------------------------------------- */ + +int blast_this_file(char *fname) +{ +SNDFILE *sndf; +SF_INFO sfinfo; +int foo, lus; + +sndf = sf_open(fname, SFM_READ, &sfinfo); +if (NULL==sndf) + { + perror("sf_open"); + abort(); + } + +#if DEBUG_LEVEL +fprintf(stderr, "samplerate : %d\n", sfinfo.samplerate); +fprintf(stderr, "frames : %ld\n", sfinfo.frames); +fprintf(stderr, "seekable : %d\n", sfinfo.seekable); +#endif + +while ((lus = sf_read_short(sndf, buffer, T_BUFF_WAVES))) + { +#if DEBUG_LEVEL + fprintf(stderr, "%s : %d bytes read\n", fname, lus); +#endif + + + } + +/* do some cleanup */ +sf_close(sndf); + +return -1; +} + + +/* --------------------------------------------------------------------- */ + + + + +/* --------------------------------------------------------------------- */ diff --git a/audio/player.h b/audio/player.h new file mode 100644 index 0000000..6914699 --- /dev/null +++ b/audio/player.h @@ -0,0 +1,3 @@ + + +int blast_this_file(char *fname); diff --git a/audio/t.c b/audio/t.c new file mode 100644 index 0000000..ac4f071 --- /dev/null +++ b/audio/t.c @@ -0,0 +1,23 @@ +/* + * Audio player for the phytotron + */ + +#include + + +#include "player.h" + +/* --------------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +char *wavname = "1337.wav"; +int foo; + + +foo = blast_this_file(wavname); +fprintf(stderr, "audio blaster -> %d\n", foo); + +return 0; +} +/* --------------------------------------------------------------------- */