From b9b8d96606e5c381344a2468b462473b3020a5a3 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 26 May 2017 23:51:28 -0700 Subject: examples: add some example player programs These are intentionally left out of the build system, there's an example gcc line included in the sources. --- examples/playit-null.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 examples/playit-null.c (limited to 'examples/playit-null.c') diff --git a/examples/playit-null.c b/examples/playit-null.c new file mode 100644 index 0000000..f256e0a --- /dev/null +++ b/examples/playit-null.c @@ -0,0 +1,76 @@ +#include +#include + +#include "fmt.h" +#include "sndfile.h" + +/* + * gcc -O2 -o playit-null playit-null.c -I.. -I../src/include -DHAVE_CONFIG_H -lm -s ../src/libplayit.a + */ + +song_t * song_load_it(const char *file) +{ + slurp_t *s; + song_t *song; + + s = slurp(file, NULL, 0); + if (!s) { + printf("failed to open \"%s\"\n", file); + goto _fail; + } + + song = csf_allocate(); + if (!song) { + printf("failed to allocate song\n"); + goto _fail_slurp; + } + + if (fmt_it_load_song(song, s, 0) != LOAD_SUCCESS) + goto _fail_song; + + unslurp(s); + + return song; + +_fail_song: + csf_free(song); +_fail_slurp: + unslurp(s); +_fail: + return NULL; +} + + +int main(int argc, const char *argv[]) +{ + song_t *song; + uint8_t buf[8192]; + int len; + + if (argc != 2) { + printf("usage: %s song.it\n", argv[0]); + goto _fail; + } + + song = song_load_it(argv[1]); + if (!song) { + printf("failed to load song!\n"); + goto _fail; + } + + csf_set_current_order(song, 0); + song->repeat_count = 0; + song->buffer_count = 0; + song->stop_at_order = -1; + song->stop_at_row = -1; + song->flags &= ~(SONG_PAUSED | SONG_PATTERNLOOP | SONG_ENDREACHED); + csf_reset_playmarks(song); + + while ((len = csf_read(song, buf, sizeof(buf)))) + printf("mixed %i bytes\n", len); + + return EXIT_SUCCESS; + +_fail: + return EXIT_FAILURE; +} -- cgit v1.2.3