aboutsummaryrefslogtreecommitdiff
path: root/tinyplay.c
diff options
context:
space:
mode:
authorChris Kelly <c-kelly@ti.com>2011-07-21 14:07:24 -0500
committerSimon Wilson <simonwilson@google.com>2011-08-09 11:05:10 -0700
commit764d341b0c8f0030844752e5fe37554c44986a11 (patch)
treecf89350f2bdded85bcaed1efcd8666815006e131 /tinyplay.c
parentdf8ae90855392812518bb9da233a0fefc21d5297 (diff)
tinyplay: add support for device parameter
Change-Id: I8f04a5dec575bf20459968fb1f181071ae856ed0
Diffstat (limited to 'tinyplay.c')
-rw-r--r--tinyplay.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/tinyplay.c b/tinyplay.c
index 3eed64a..f52d76a 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -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;
@@ -114,10 +122,10 @@ void play_sample(FILE *file, unsigned int channels, unsigned int rate,
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;
}