diff --git a/tinyplay.c b/tinyplay.c
index 2523e5432127b3ff2c2e336f52d30de50410de9e..915a1eae953288c40cd4334304cb44eff6f0f04a 100644 (file)
--- a/tinyplay.c
+++ b/tinyplay.c
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;
}
return 1;
}
+ /* parse command line arguments */
+ argv += 2;
+ while (*argv) {
+ if (strcmp(*argv, "-d") == 0) {
+ argv++;
+ device = atoi(*argv);
+ }
+ argv++;
+ }
+
fread(&header, sizeof(struct wav_header), 1, file);
if ((header.riff_id != ID_RIFF) ||
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);
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;
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;
}