aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Wilson2013-05-01 17:10:34 -0500
committerSimon Wilson2013-05-01 17:10:34 -0500
commit9673f5717d824137d64320d0bc98a6461a9383a8 (patch)
treeead060b279f7df6f6f6edbde620010159bb3e22c /tinyplay.c
parent42fc2d393c868d5db609e39551d64f1e60fefa0e (diff)
downloadplatform-external-tinyalsa-9673f5717d824137d64320d0bc98a6461a9383a8.tar.gz
platform-external-tinyalsa-9673f5717d824137d64320d0bc98a6461a9383a8.tar.xz
platform-external-tinyalsa-9673f5717d824137d64320d0bc98a6461a9383a8.zip
Update to latest tinyalsa
5089567 tinycap: convert size from frames to bytes 7a12d9c tinyplay: Make error messages more meaningful Change-Id: Id906c3827123616bd698dd93f575137b9e78e49c
Diffstat (limited to 'tinyplay.c')
-rw-r--r--tinyplay.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tinyplay.c b/tinyplay.c
index d7e7d46..f4fac9f 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -160,6 +160,54 @@ int main(int argc, char **argv)
160 return 0; 160 return 0;
161} 161}
162 162
163int check_param(struct pcm_params *params, unsigned int param, unsigned int value,
164 char *param_name, char *param_unit)
165{
166 unsigned int min;
167 unsigned int max;
168 int is_within_bounds = 1;
169
170 min = pcm_params_get_min(params, param);
171 if (value < min) {
172 fprintf(stderr, "%s is %u%s, device only supports >= %u%s\n", param_name, value,
173 param_unit, min, param_unit);
174 is_within_bounds = 0;
175 }
176
177 max = pcm_params_get_max(params, param);
178 if (value > max) {
179 fprintf(stderr, "%s is %u%s, device only supports <= %u%s\n", param_name, value,
180 param_unit, max, param_unit);
181 is_within_bounds = 0;
182 }
183
184 return is_within_bounds;
185}
186
187int sample_is_playable(unsigned int card, unsigned int device, unsigned int channels,
188 unsigned int rate, unsigned int bits, unsigned int period_size,
189 unsigned int period_count)
190{
191 struct pcm_params *params;
192 int can_play;
193
194 params = pcm_params_get(card, device, PCM_OUT);
195 if (params == NULL) {
196 fprintf(stderr, "Unable to open PCM device %u.\n", device);
197 return 0;
198 }
199
200 can_play = check_param(params, PCM_PARAM_RATE, rate, "Sample rate", "Hz");
201 can_play &= check_param(params, PCM_PARAM_CHANNELS, channels, "Sample", " channels");
202 can_play &= check_param(params, PCM_PARAM_SAMPLE_BITS, bits, "Bitrate", " bits");
203 can_play &= check_param(params, PCM_PARAM_PERIOD_SIZE, period_size, "Period size", "Hz");
204 can_play &= check_param(params, PCM_PARAM_PERIODS, period_count, "Period count", "Hz");
205
206 pcm_params_free(params);
207
208 return can_play;
209}
210
163void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels, 211void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
164 unsigned int rate, unsigned int bits, unsigned int period_size, 212 unsigned int rate, unsigned int bits, unsigned int period_size,
165 unsigned int period_count) 213 unsigned int period_count)
@@ -182,6 +230,10 @@ void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned in
182 config.stop_threshold = 0; 230 config.stop_threshold = 0;
183 config.silence_threshold = 0; 231 config.silence_threshold = 0;
184 232
233 if (!sample_is_playable(card, device, channels, rate, bits, period_size, period_count)) {
234 return;
235 }
236
185 pcm = pcm_open(card, device, PCM_OUT, &config); 237 pcm = pcm_open(card, device, PCM_OUT, &config);
186 if (!pcm || !pcm_is_ready(pcm)) { 238 if (!pcm || !pcm_is_ready(pcm)) {
187 fprintf(stderr, "Unable to open PCM device %u (%s)\n", 239 fprintf(stderr, "Unable to open PCM device %u (%s)\n",