From d904f8e1c63faa75b7f5d576a385fc4c7134b5cc Mon Sep 17 00:00:00 2001 From: Nikos Chantziaras Date: Sun, 3 Oct 2010 07:11:11 +1100 Subject: package sdl_sound: add test program --- src/sdl_sound-test.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/sdl_sound-test.c diff --git a/src/sdl_sound-test.c b/src/sdl_sound-test.c new file mode 100644 index 0000000..46794fc --- /dev/null +++ b/src/sdl_sound-test.c @@ -0,0 +1,47 @@ +/* Simple test program for SDL_sound that tries to decode the file specified + * as the only command-line argument. + * + * This file is in the Public Domain. + */ +#include +#include + +int main( int argc, char** argv ) +{ + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + if (SDL_Init(SDL_INIT_AUDIO) != 0) { + fprintf(stderr, "Error: %s\n", SDL_GetError()); + return 1; + } + + if (Sound_Init() == 0) { + fprintf(stderr, "Error: %s\n", Sound_GetError()); + return 1; + } + + SDL_RWops* rw = SDL_RWFromFile(argv[1], "r"); + if (rw == NULL) { + fprintf(stderr, "Error: %s\n", SDL_GetError()); + return 1; + } + + Sound_AudioInfo wantedFormat; + wantedFormat.channels = 2; + wantedFormat.rate = 44100; + wantedFormat.format = AUDIO_S16LSB; + + Sound_Sample* sample = Sound_NewSample(rw, 0, &wantedFormat, 8192); + if (sample == 0) { + fprintf(stderr, "Error: %s\n", Sound_GetError()); + return 1; + } + + Sound_DecodeAll(sample); + printf("Format: %s\n", sample->decoder->description); + printf("Decoded %d bytes of data.\n", sample->buffer_size); + Sound_FreeSample(sample); +} -- cgit v0.12