gamesnd
changeset 0:14e265e1cad8 tip
initial
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sun, 09 Sep 2012 02:55:47 +0300 |
parents | |
children | |
files | Makefile include/gamesnd.h src/gamesnd.c src/gamesnd_impl.h |
diffstat | 4 files changed, 289 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Makefile Sun Sep 09 02:55:47 2012 +0300 1.3 @@ -0,0 +1,59 @@ 1.4 +src = $(wildcard src/*.c) \ 1.5 + $(wildcard src/filefmt/*.c) \ 1.6 + $(wildcard src/backend/*.c) 1.7 +hdr = gamesnd.h 1.8 +obj = $(src:.c=.o) 1.9 +dep = $(obj:.o=.d) 1.10 +name = gamesnd 1.11 +lib_a = lib$(name).a 1.12 + 1.13 +abimaj = 0 1.14 +abimin = 1 1.15 + 1.16 +CFLAGS = -pedantic -Wall $(pic) $(dbg) $(opt) 1.17 +LDFLAGS = $(libs) 1.18 + 1.19 +ifeq ($(shell uname -s), Darwin) 1.20 + lib_so = lib$(name).dylib 1.21 + shared = -dynamiclib 1.22 +else 1.23 + devlink = lib$(name).so 1.24 + soname = $(devlink).$(abimaj) 1.25 + lib_so = $(soname).$(abimin) 1.26 + shared = -shared -Wl,-soname=$(soname) 1.27 + pic = -fPIC 1.28 +endif 1.29 + 1.30 + 1.31 +$(lib_so): $(obj) 1.32 + $(CC) -o $@ $(shared) $(obj) $(LDFLAGS) 1.33 + 1.34 +-include $(dep) 1.35 + 1.36 +%.d: %.c 1.37 + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ 1.38 + 1.39 +.PHONY: clean 1.40 +clean: 1.41 + rm -f $(obj) $(bin) $(lib_so) $(lib_a) $(dep) 1.42 + 1.43 +.PHONY: install 1.44 +install: $(lib_so) 1.45 + mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib 1.46 + cp include/$(hdr) $(DESTDIR)$(PREFIX)/include/$(hdr) 1.47 + cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so) 1.48 + [ -n "$(soname)" ] \ 1.49 + && cd $(DESTDIR)$(PREFIX)/lib \ 1.50 + && rm -f $(soname) $(devlink) \ 1.51 + && ln -s $(lib_so) $(soname) \ 1.52 + && ln -s $(soname) $(devlink) \ 1.53 + || true 1.54 + 1.55 +.PHONY: uninstall 1.56 +uninstall: 1.57 + rm -f $(DESTDIR)$(PREFIX)/include/$(hdr) 1.58 + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so) 1.59 + [ -n "$(soname)" ] \ 1.60 + && rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) \ 1.61 + && rm -f $(DESTDIR)$(PREFIX)/lib/$(devlink) \ 1.62 + || true
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/include/gamesnd.h Sun Sep 09 02:55:47 2012 +0300 2.3 @@ -0,0 +1,62 @@ 2.4 +#ifndef GAMESND_H_ 2.5 +#define GAMESND_H_ 2.6 + 2.7 +#include <stdio.h> 2.8 + 2.9 +struct gsnd_sample; 2.10 +struct gsnd_source; 2.11 +struct gsnd_track; 2.12 +struct gsnd_io; 2.13 + 2.14 +typedef long (*gsnd_io_read_func)(void *file, void *buf, long sz); 2.15 +typedef long (*gsnd_io_seek_func)(void *file, long offs, int whence); 2.16 + 2.17 + 2.18 +/* ---- sound samples ---- */ 2.19 +int gsnd_init_sample(struct gsnd_sample *sam); 2.20 +void gsnd_destroy_sample(struct gsnd_sample *sam); 2.21 + 2.22 +struct gsnd_sample *gsnd_create_sample(void); 2.23 +void gsnd_free_sample(struct gsnd_sample *sam); 2.24 + 2.25 +int gsnd_load_sample(struct gsnd_sample *sam, const char *fname); 2.26 +int gsnd_load_sample_file(struct gsnd_sample *sam, FILE *fp); 2.27 +int gsnd_load_sample_io(struct gsnd_sample *sam, struct gsnd_io *io); 2.28 + 2.29 +void gsnd_play_sample(struct gsnd_sample *sam, float vol); 2.30 +void gsnd_stop_sample(struct gsnd_sample *sam); 2.31 + 2.32 +/* ---- sound source ---- */ 2.33 +int gsnd_init_source(struct gsnd_source *src); 2.34 +void gsnd_destroy_source(struct gsnd_source *src); 2.35 + 2.36 +struct gsnd_source *gsnd_create_source(void); 2.37 +void gsnd_free_source(struct gsnd_source *src); 2.38 + 2.39 +void gsnd_source_position(struct gsnd_source *src, float x, float y, float z); 2.40 +void gsnd_source_volume(struct gsnd_source *src, float vol); 2.41 +void gsnd_source_pitch(struct gsnd_source *src, float pitch); 2.42 + 2.43 +void gsnd_play_source(struct gsnd_sample *sam); 2.44 +void gsnd_stop_source(struct gsnd_sample *sam); 2.45 + 2.46 +/* ---- music tracks ---- */ 2.47 +int gsnd_init_track(struct gsnd_track *trk); 2.48 +void gsnd_destroy_track(struct gsnd_track *trk); 2.49 + 2.50 +struct gsnd_track *gsnd_create_sample(void); 2.51 +void gsnd_free_sample(struct gsnd_track *trk); 2.52 + 2.53 +int gsnd_open_track(struct gsnd_track *trk, const char *fname); 2.54 +int gsnd_open_track_file(struct gsnd_track *trk, FILE *fp); 2.55 +int gsnd_open_track_io(struct gsnd_track *trk, struct gsnd_io *io); 2.56 + 2.57 +void gsnd_play_track(struct gsnd_track *trk); 2.58 +void gsnd_stop_track(struct gsnd_track *trk); 2.59 + 2.60 + 2.61 +/* ---- file i/o ---- */ 2.62 +void gsnd_io(struct gsnd_io *io, void *file, gsnd_io_read_func rd, gsnd_io_seek_func seek); 2.63 + 2.64 + 2.65 +#endif /* GAMESND_H_ */
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/gamesnd.c Sun Sep 09 02:55:47 2012 +0300 3.3 @@ -0,0 +1,134 @@ 3.4 +#include "gamesnd.h" 3.5 + 3.6 +/* ---- sound samples ---- */ 3.7 +int gsnd_init_sample(struct gsnd_sample *sam) 3.8 +{ 3.9 + //return gsnd_ao_init_sample(sam->s); 3.10 +} 3.11 + 3.12 +void gsnd_destroy_sample(struct gsnd_sample *sam) 3.13 +{ 3.14 +} 3.15 + 3.16 + 3.17 +struct gsnd_sample *gsnd_create_sample(void) 3.18 +{ 3.19 +} 3.20 + 3.21 +void gsnd_free_sample(struct gsnd_sample *sam) 3.22 +{ 3.23 +} 3.24 + 3.25 + 3.26 +int gsnd_load_sample(struct gsnd_sample *sam, const char *fname) 3.27 +{ 3.28 +} 3.29 + 3.30 +int gsnd_load_sample_file(struct gsnd_sample *sam, FILE *fp) 3.31 +{ 3.32 +} 3.33 + 3.34 +int gsnd_load_sample_io(struct gsnd_sample *sam, struct gsnd_io *io) 3.35 +{ 3.36 +} 3.37 + 3.38 + 3.39 +void gsnd_play_sample(struct gsnd_sample *sam, float vol) 3.40 +{ 3.41 +} 3.42 + 3.43 +void gsnd_stop_sample(struct gsnd_sample *sam) 3.44 +{ 3.45 +} 3.46 + 3.47 + 3.48 +/* ---- sound source ---- */ 3.49 +int gsnd_init_source(struct gsnd_source *src) 3.50 +{ 3.51 +} 3.52 + 3.53 +void gsnd_destroy_source(struct gsnd_source *src) 3.54 +{ 3.55 +} 3.56 + 3.57 + 3.58 +struct gsnd_source *gsnd_create_source(void) 3.59 +{ 3.60 +} 3.61 + 3.62 +void gsnd_free_source(struct gsnd_source *src) 3.63 +{ 3.64 +} 3.65 + 3.66 + 3.67 +void gsnd_source_position(struct gsnd_source *src, float x, float y, float z) 3.68 +{ 3.69 +} 3.70 + 3.71 +void gsnd_source_volume(struct gsnd_source *src, float vol) 3.72 +{ 3.73 +} 3.74 + 3.75 +void gsnd_source_pitch(struct gsnd_source *src, float pitch) 3.76 +{ 3.77 +} 3.78 + 3.79 + 3.80 +void gsnd_play_source(struct gsnd_sample *sam) 3.81 +{ 3.82 +} 3.83 + 3.84 +void gsnd_stop_source(struct gsnd_sample *sam) 3.85 +{ 3.86 +} 3.87 + 3.88 + 3.89 +/* ---- music tracks ---- */ 3.90 +int gsnd_init_track(struct gsnd_track *trk) 3.91 +{ 3.92 +} 3.93 + 3.94 +void gsnd_destroy_track(struct gsnd_track *trk) 3.95 +{ 3.96 +} 3.97 + 3.98 + 3.99 +struct gsnd_track *gsnd_create_sample(void) 3.100 +{ 3.101 +} 3.102 + 3.103 +void gsnd_free_sample(struct gsnd_track *trk) 3.104 +{ 3.105 +} 3.106 + 3.107 + 3.108 +int gsnd_open_track(struct gsnd_track *trk, const char *fname) 3.109 +{ 3.110 +} 3.111 + 3.112 +int gsnd_open_track_file(struct gsnd_track *trk, FILE *fp) 3.113 +{ 3.114 +} 3.115 + 3.116 +int gsnd_open_track_io(struct gsnd_track *trk, struct gsnd_io *io) 3.117 +{ 3.118 +} 3.119 + 3.120 + 3.121 +void gsnd_play_track(struct gsnd_track *trk) 3.122 +{ 3.123 +} 3.124 + 3.125 +void gsnd_stop_track(struct gsnd_track *trk) 3.126 +{ 3.127 +} 3.128 + 3.129 + 3.130 + 3.131 +/* ---- file i/o ---- */ 3.132 +void gsnd_io(struct gsnd_io *io, void *file, gsnd_io_read rd, gsnd_io_seek seek) 3.133 +{ 3.134 + io->file = file; 3.135 + io->read = rd; 3.136 + io->seek = seek; 3.137 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/gamesnd_impl.h Sun Sep 09 02:55:47 2012 +0300 4.3 @@ -0,0 +1,34 @@ 4.4 +#ifndef GAMESND_IMPL_H_ 4.5 +#define GAMESND_IMPL_H_ 4.6 + 4.7 +#include "gamesnd.h" 4.8 + 4.9 +/* implementation structures defined by each backend */ 4.10 +struct sample; 4.11 +struct source; 4.12 +struct track; 4.13 + 4.14 +struct gsnd_sample { 4.15 + struct sample *ao_sam; 4.16 +}; 4.17 + 4.18 +struct gsnd_source { 4.19 + struct source *ao_src; 4.20 + struct gsnd_sample *sam; 4.21 + float volume, pitch; 4.22 + 4.23 + struct gsnd_source *next; 4.24 +}; 4.25 + 4.26 +struct gsnd_track { 4.27 + struct track *ao_trk; 4.28 + float volume; 4.29 +}; 4.30 + 4.31 +struct gsnd_io { 4.32 + void *file; 4.33 + gsnd_io_read_func read; 4.34 + gsnd_io_seek_func seek; 4.35 +}; 4.36 + 4.37 +#endif /* GAMESND_IMPL_H_ */