]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-external-tinyalsa.git/blobdiff - tinyplay.c
Update to latest tinyalsa
[android-sdk/platform-external-tinyalsa.git] / tinyplay.c
index 2523e5432127b3ff2c2e336f52d30de50410de9e..915a1eae953288c40cd4334304cb44eff6f0f04a 100644 (file)
@@ -54,16 +54,17 @@ struct wav_header {
     uint32_t data_sz;
 };
 
-void play_sample(FILE *file, unsigned int channels, unsigned int rate,
-                 unsigned int bits);
+void play_sample(FILE *file, unsigned int device, unsigned int channels,
+                 unsigned int rate, unsigned int bits);
 
 int main(int argc, char **argv)
 {
     FILE *file;
     struct wav_header header;
+    unsigned int device = 0;
 
-    if (argc != 2) {
-        fprintf(stderr, "Usage: %s <file.wav>\n", argv[0]);
+    if (argc < 2) {
+        fprintf(stderr, "Usage: %s file.wav [-d device]\n", argv[0]);
         return 1;
     }
 
@@ -73,6 +74,16 @@ int main(int argc, char **argv)
         return 1;
     }
 
+    /* parse command line arguments */
+    argv += 2;
+    while (*argv) {
+        if (strcmp(*argv, "-d") == 0) {
+            argv++;
+            device = atoi(*argv);
+        }
+        argv++;
+    }
+
     fread(&header, sizeof(struct wav_header), 1, file);
 
     if ((header.riff_id != ID_RIFF) ||
@@ -85,7 +96,7 @@ int main(int argc, char **argv)
         return 1;
     }
 
-    play_sample(file, header.num_channels, header.sample_rate,
+    play_sample(file, device, header.num_channels, header.sample_rate,
                 header.bits_per_sample);
 
     fclose(file);
@@ -93,8 +104,8 @@ int main(int argc, char **argv)
     return 0;
 }
 
-void play_sample(FILE *file, unsigned int channels, unsigned int rate,
-                 unsigned int bits)
+void play_sample(FILE *file, unsigned int device, unsigned int channels,
+                 unsigned int rate, unsigned int bits)
 {
     struct pcm_config config;
     struct pcm *pcm;
@@ -110,11 +121,14 @@ void play_sample(FILE *file, unsigned int channels, unsigned int rate,
         config.format = PCM_FORMAT_S32_LE;
     else if (bits == 16)
         config.format = PCM_FORMAT_S16_LE;
+    config.start_threshold = 0;
+    config.stop_threshold = 0;
+    config.silence_threshold = 0;
 
-    pcm = pcm_open(0, 0, PCM_OUT, &config);
+    pcm = pcm_open(0, device, PCM_OUT, &config);
     if (!pcm || !pcm_is_ready(pcm)) {
-        fprintf(stderr, "Unable to open PCM device (%s)\n",
-                pcm_get_error(pcm));
+        fprintf(stderr, "Unable to open PCM device %u (%s)\n",
+                device, pcm_get_error(pcm));
         return;
     }