diff options
-rw-r--r-- | Android.mk | 9 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | tinyplay.c | 15 |
3 files changed, 19 insertions, 9 deletions
@@ -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) @@ -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: @@ -62,6 +62,11 @@ int main(int argc, char **argv) FILE *file; struct wav_header header; + if (argc != 2) { + fprintf(stderr, "Usage: %s <file.wav>\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) { |