aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2011-08-05 14:00:00 -0500
committerSimon Wilson2011-08-09 13:13:51 -0500
commit621047309242d04a6186230e7a337de8642ec754 (patch)
treed2b838ea1123922f29e1bbc354840f58c342e18b /tinyplay.c
parentc1239623c178f0142352c28a0f968d826afcb078 (diff)
downloadplatform-external-tinyalsa-621047309242d04a6186230e7a337de8642ec754.tar.gz
platform-external-tinyalsa-621047309242d04a6186230e7a337de8642ec754.tar.xz
platform-external-tinyalsa-621047309242d04a6186230e7a337de8642ec754.zip
Update to latest tinyalsa
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
Diffstat (limited to 'tinyplay.c')
-rw-r--r--tinyplay.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/tinyplay.c b/tinyplay.c
index 2523e54..f52d76a 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -54,16 +54,17 @@ struct wav_header {
54 uint32_t data_sz; 54 uint32_t data_sz;
55}; 55};
56 56
57void play_sample(FILE *file, unsigned int channels, unsigned int rate, 57void play_sample(FILE *file, unsigned int device, unsigned int channels,
58 unsigned int bits); 58 unsigned int rate, unsigned int bits);
59 59
60int main(int argc, char **argv) 60int main(int argc, char **argv)
61{ 61{
62 FILE *file; 62 FILE *file;
63 struct wav_header header; 63 struct wav_header header;
64 unsigned int device = 0;
64 65
65 if (argc != 2) { 66 if (argc < 2) {
66 fprintf(stderr, "Usage: %s <file.wav>\n", argv[0]); 67 fprintf(stderr, "Usage: %s file.wav [-d device]\n", argv[0]);
67 return 1; 68 return 1;
68 } 69 }
69 70
@@ -73,6 +74,13 @@ int main(int argc, char **argv)
73 return 1; 74 return 1;
74 } 75 }
75 76
77 /* parse command line arguments */
78 argv += 2;
79 if (strcmp(*argv, "-d") == 0) {
80 argv++;
81 device = atoi(*argv);
82 }
83
76 fread(&header, sizeof(struct wav_header), 1, file); 84 fread(&header, sizeof(struct wav_header), 1, file);
77 85
78 if ((header.riff_id != ID_RIFF) || 86 if ((header.riff_id != ID_RIFF) ||
@@ -85,7 +93,7 @@ int main(int argc, char **argv)
85 return 1; 93 return 1;
86 } 94 }
87 95
88 play_sample(file, header.num_channels, header.sample_rate, 96 play_sample(file, device, header.num_channels, header.sample_rate,
89 header.bits_per_sample); 97 header.bits_per_sample);
90 98
91 fclose(file); 99 fclose(file);
@@ -93,8 +101,8 @@ int main(int argc, char **argv)
93 return 0; 101 return 0;
94} 102}
95 103
96void play_sample(FILE *file, unsigned int channels, unsigned int rate, 104void play_sample(FILE *file, unsigned int device, unsigned int channels,
97 unsigned int bits) 105 unsigned int rate, unsigned int bits)
98{ 106{
99 struct pcm_config config; 107 struct pcm_config config;
100 struct pcm *pcm; 108 struct pcm *pcm;
@@ -110,11 +118,14 @@ void play_sample(FILE *file, unsigned int channels, unsigned int rate,
110 config.format = PCM_FORMAT_S32_LE; 118 config.format = PCM_FORMAT_S32_LE;
111 else if (bits == 16) 119 else if (bits == 16)
112 config.format = PCM_FORMAT_S16_LE; 120 config.format = PCM_FORMAT_S16_LE;
121 config.start_threshold = 0;
122 config.stop_threshold = 0;
123 config.silence_threshold = 0;
113 124
114 pcm = pcm_open(0, 0, PCM_OUT, &config); 125 pcm = pcm_open(0, device, PCM_OUT, &config);
115 if (!pcm || !pcm_is_ready(pcm)) { 126 if (!pcm || !pcm_is_ready(pcm)) {
116 fprintf(stderr, "Unable to open PCM device (%s)\n", 127 fprintf(stderr, "Unable to open PCM device %u (%s)\n",
117 pcm_get_error(pcm)); 128 device, pcm_get_error(pcm));
118 return; 129 return;
119 } 130 }
120 131