aboutsummaryrefslogtreecommitdiff
path: root/tinyplay.c
diff options
context:
space:
mode:
authorSimon Wilson <simonwilson@google.com>2011-06-03 18:27:08 -0700
committerSimon Wilson <simonwilson@google.com>2011-06-03 18:28:26 -0700
commit98be0055ff47332102cf7b9fc35b962e3b69a22a (patch)
treef0afe4e510db0cf36c0d9691fa84b14769ce163c /tinyplay.c
parenta0ef465b3140a827b149146cd51c9489859db33d (diff)
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
Diffstat (limited to 'tinyplay.c')
-rw-r--r--tinyplay.c15
1 files changed, 7 insertions, 8 deletions
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) {