aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.mk9
-rw-r--r--Makefile4
-rw-r--r--tinyplay.c15
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 <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) {