From 98be0055ff47332102cf7b9fc35b962e3b69a22a Mon Sep 17 00:00:00 2001 From: Simon Wilson Date: Fri, 3 Jun 2011 18:27:08 -0700 Subject: Fix issues with tinyplay - Add to Android.mk - Add "all" rule to Makefile - Remove redundant old play code from tinyplay.c - Add error checking to tinyplay --- tinyplay.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tinyplay.c') diff --git a/tinyplay.c b/tinyplay.c index 63ced5b..2523e54 100644 --- a/tinyplay.c +++ b/tinyplay.c @@ -62,6 +62,11 @@ int main(int argc, char **argv) FILE *file; struct wav_header header; + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + file = fopen(argv[1], "rb"); if (!file) { fprintf(stderr, "Unable to open file '%s'\n", argv[1]); @@ -108,7 +113,8 @@ void play_sample(FILE *file, unsigned int channels, unsigned int rate, pcm = pcm_open(0, 0, PCM_OUT, &config); if (!pcm || !pcm_is_ready(pcm)) { - fprintf(stderr, "%s\n", pcm_get_error(pcm)); + fprintf(stderr, "Unable to open PCM device (%s)\n", + pcm_get_error(pcm)); return; } @@ -123,13 +129,6 @@ void play_sample(FILE *file, unsigned int channels, unsigned int rate, printf("Playing sample: %u ch, %u hz, %u bit\n", channels, rate, bits); - while (fread(buffer, 1, size, file) == size) { - if (pcm_write(pcm, buffer, size)) { - fprintf(stderr, "Error playing sample\n"); - break; - } - } - do { num_read = fread(buffer, 1, size, file); if (num_read > 0) { -- cgit v1.2.3