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 --- Android.mk | 9 +++++++++ Makefile | 4 +++- tinyplay.c | 15 +++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Android.mk b/Android.mk index 3266b93..d812319 100644 --- a/Android.mk +++ b/Android.mk @@ -8,3 +8,12 @@ LOCAL_SHARED_LIBRARIES:= libcutils libutils LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_C_INCLUDES:= external/tinyalsa/include +LOCAL_SRC_FILES:= tinyplay.c +LOCAL_MODULE := tinyplay +LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa +LOCAL_MODULE_TAGS := optional + +include $(BUILD_EXECUTABLE) diff --git a/Makefile b/Makefile index aa1310b..ac40b6b 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,12 @@ INC = include OBJECTS = mixer.o pcm.o LIB = libtinyalsa.so +all: $(LIB) tinyplay + tinyplay: $(LIB) tinyplay.o gcc tinyplay.o -L. -ltinyalsa -o tinyplay -libtinyalsa.so: $(OBJECTS) +$(LIB): $(OBJECTS) gcc -shared $(OBJECTS) -o $(LIB) .c.o: 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