aboutsummaryrefslogtreecommitdiff
path: root/tinyplay.c
diff options
context:
space:
mode:
authortinyalsa <simonwilson@google.com>2012-02-10 14:26:41 -0800
committertinyalsa <simonwilson@google.com>2012-02-10 14:26:41 -0800
commit19eda2de961aced7365a31a02ec210a43f03efad (patch)
treea49b8868a1ad85a7b167332043b127f2daa1ca4c /tinyplay.c
parent350211381a270fc6f5e02d3a75cbf6bf99152ec8 (diff)
parent9989fc25deb22ba1dde0ad6c30d34e1aff1931ed (diff)
Merge pull request #9 from gabrbedd/topic/params
Topic/params - add parameters to select card, etc.
Diffstat (limited to 'tinyplay.c')
-rw-r--r--tinyplay.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/tinyplay.c b/tinyplay.c
index 915a1ea..2251cfe 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -54,17 +54,22 @@ struct wav_header {
uint32_t data_sz;
};
-void play_sample(FILE *file, unsigned int device, unsigned int channels,
- unsigned int rate, unsigned int bits);
+void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count);
int main(int argc, char **argv)
{
FILE *file;
struct wav_header header;
unsigned int device = 0;
+ unsigned int card = 0;
+ unsigned int period_size = 1024;
+ unsigned int period_count = 4;
if (argc < 2) {
- fprintf(stderr, "Usage: %s file.wav [-d device]\n", argv[0]);
+ fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-p period_size]"
+ " [-n n_periods] \n", argv[0]);
return 1;
}
@@ -79,9 +84,26 @@ int main(int argc, char **argv)
while (*argv) {
if (strcmp(*argv, "-d") == 0) {
argv++;
- device = atoi(*argv);
+ if (*argv)
+ device = atoi(*argv);
}
- argv++;
+ if (strcmp(*argv, "-p") == 0) {
+ argv++;
+ if (*argv)
+ period_size = atoi(*argv);
+ }
+ if (strcmp(*argv, "-n") == 0) {
+ argv++;
+ if (*argv)
+ period_count = atoi(*argv);
+ }
+ if (strcmp(*argv, "-D") == 0) {
+ argv++;
+ if (*argv)
+ card = atoi(*argv);
+ }
+ if (*argv)
+ argv++;
}
fread(&header, sizeof(struct wav_header), 1, file);
@@ -96,16 +118,17 @@ int main(int argc, char **argv)
return 1;
}
- play_sample(file, device, header.num_channels, header.sample_rate,
- header.bits_per_sample);
+ play_sample(file, card, device, header.num_channels, header.sample_rate,
+ header.bits_per_sample, period_size, period_count);
fclose(file);
return 0;
}
-void play_sample(FILE *file, unsigned int device, unsigned int channels,
- unsigned int rate, unsigned int bits)
+void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count)
{
struct pcm_config config;
struct pcm *pcm;
@@ -115,8 +138,8 @@ void play_sample(FILE *file, unsigned int device, unsigned int channels,
config.channels = channels;
config.rate = rate;
- config.period_size = 1024;
- config.period_count = 4;
+ config.period_size = period_size;
+ config.period_count = period_count;
if (bits == 32)
config.format = PCM_FORMAT_S32_LE;
else if (bits == 16)
@@ -125,7 +148,7 @@ void play_sample(FILE *file, unsigned int device, unsigned int channels,
config.stop_threshold = 0;
config.silence_threshold = 0;
- pcm = pcm_open(0, device, PCM_OUT, &config);
+ pcm = pcm_open(card, device, PCM_OUT, &config);
if (!pcm || !pcm_is_ready(pcm)) {
fprintf(stderr, "Unable to open PCM device %u (%s)\n",
device, pcm_get_error(pcm));