]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-external-tinyalsa.git/commitdiff
Update to latest tinyalsa
authorSimon Wilson <simonwilson@google.com>
Fri, 5 Aug 2011 19:00:00 +0000 (12:00 -0700)
committerSimon Wilson <simonwilson@google.com>
Tue, 9 Aug 2011 18:13:51 +0000 (11:13 -0700)
764d341 tinyplay: add support for device parameter
df8ae90 tinymix: print mixer values when no mixer control is specified
7de3eaf Ensure threasholds are zeroed before opening pcm

Change-Id: Ie7b652b16b90d05fc9dee6ce31c7ffc3dc9a47f1

tinycap.c
tinymix.c
tinyplay.c

index 2f982d0d808da81da1b5a6f0155c4ddbcd67c57c..3eb5c60d5a27ed26686f067f1253389461a85282 100644 (file)
--- a/tinycap.c
+++ b/tinycap.c
@@ -157,6 +157,9 @@ unsigned int capture_sample(FILE *file, unsigned int device,
         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, device, PCM_IN, &config);
     if (!pcm || !pcm_is_ready(pcm)) {
index 3fc2e4125dbde1ec3607178d1d6b6eab1583db78..3b778e1aa869d27c0063c21bcf5183b942d6d7e8 100644 (file)
--- a/tinymix.c
+++ b/tinymix.c
 #include <ctype.h>
 
 static void tinymix_list_controls(struct mixer *mixer);
-static void tinymix_detail_control(struct mixer *mixer, unsigned int id);
+static void tinymix_detail_control(struct mixer *mixer, unsigned int id,
+                                   int print_all);
 static void tinymix_set_value(struct mixer *mixer, unsigned int id,
                               char *value);
+static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all);
 
 int main(int argc, char **argv)
 {
@@ -49,7 +51,7 @@ int main(int argc, char **argv)
     if (argc == 1)
         tinymix_list_controls(mixer);
     else if (argc == 2)
-        tinymix_detail_control(mixer, atoi(argv[1]));
+        tinymix_detail_control(mixer, atoi(argv[1]), 1);
     else if (argc == 3)
         tinymix_set_value(mixer, atoi(argv[1]), argv[2]);
     else
@@ -72,19 +74,19 @@ static void tinymix_list_controls(struct mixer *mixer)
 
     printf("Number of controls: %d\n", num_ctls);
 
-    printf("ctl\ttype\tnum\tname\n");
+    printf("ctl\ttype\tnum\t%-40s value\n", "name");
     for (i = 0; i < num_ctls; i++) {
         ctl = mixer_get_ctl(mixer, i);
 
         mixer_ctl_get_name(ctl, buffer, sizeof(buffer));
         type = mixer_ctl_get_type_string(ctl);
         num_values = mixer_ctl_get_num_values(ctl);
-
-        printf("%d\t%s\t%d\t%s\n", i, type, num_values, buffer);
+        printf("%d\t%s\t%d\t%-40s", i, type, num_values, buffer);
+        tinymix_detail_control(mixer, i, 0);
     }
 }
 
-static void tinymix_print_enum(struct mixer_ctl *ctl)
+static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all)
 {
     unsigned int num_enums;
     char buffer[256];
@@ -94,12 +96,16 @@ static void tinymix_print_enum(struct mixer_ctl *ctl)
 
     for (i = 0; i < num_enums; i++) {
         mixer_ctl_get_enum_string(ctl, i, buffer, sizeof(buffer));
-        printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "",
-               buffer);
+        if (print_all)
+            printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "",
+                   buffer);
+        else if (mixer_ctl_get_value(ctl, 0) == (int)i)
+            printf(" %-s", buffer);
     }
 }
 
-static void tinymix_detail_control(struct mixer *mixer, unsigned int id)
+static void tinymix_detail_control(struct mixer *mixer, unsigned int id,
+                                   int print_all)
 {
     struct mixer_ctl *ctl;
     enum mixer_ctl_type type;
@@ -119,7 +125,9 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id)
     type = mixer_ctl_get_type(ctl);
     num_values = mixer_ctl_get_num_values(ctl);
 
-    printf("%s:", buffer);
+    if (print_all)
+        printf("%s:", buffer);
+
     for (i = 0; i < num_values; i++) {
         switch (type)
         {
@@ -130,17 +138,20 @@ static void tinymix_detail_control(struct mixer *mixer, unsigned int id)
             printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off");
             break;
         case MIXER_CTL_TYPE_ENUM:
-            tinymix_print_enum(ctl);
+            tinymix_print_enum(ctl, print_all);
             break;
         default:
             printf(" unknown");
             break;
         };
     }
-    if (type == MIXER_CTL_TYPE_INT) {
-        min = mixer_ctl_get_range_min(ctl);
-        max = mixer_ctl_get_range_max(ctl);
-        printf(" (range %d->%d)", min, max);
+
+    if (print_all) {
+        if (type == MIXER_CTL_TYPE_INT) {
+            min = mixer_ctl_get_range_min(ctl);
+            max = mixer_ctl_get_range_max(ctl);
+            printf(" (range %d->%d)", min, max);
+        }
     }
     printf("\n");
 }
index 2523e5432127b3ff2c2e336f52d30de50410de9e..f52d76a40b6ff6c0102da358361ed58f89f50836 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,13 @@ int main(int argc, char **argv)
         return 1;
     }
 
+    /* parse command line arguments */
+    argv += 2;
+    if (strcmp(*argv, "-d") == 0) {
+        argv++;
+        device = atoi(*argv);
+    }
+
     fread(&header, sizeof(struct wav_header), 1, file);
 
     if ((header.riff_id != ID_RIFF) ||
@@ -85,7 +93,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 +101,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 +118,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;
     }