aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaydeep Dhole <jaydeepdhole@gmail.com>2015-12-18 23:22:10 +0530
committerJaydeep Dhole <jaydeepdhole@gmail.com>2015-12-18 23:22:10 +0530
commitbc0c23b0f6af65e54801285b02542900957b64b5 (patch)
treefd81009bb359d7b74fbafb0975f44efdb8d765ec
parent1f8145a46a7386369e771bc5abac8cefed6e945f (diff)
Added raw file support in tinyplay
-Added raw file support in tinyplay to play PCM raw files Signed-off-by: Jaydeep Dhole <jaydeepdhole@gmail.com>
-rw-r--r--tinyplay.c93
1 files changed, 62 insertions, 31 deletions
diff --git a/tinyplay.c b/tinyplay.c
index 88c54ae..920b0e8 100644
--- a/tinyplay.c
+++ b/tinyplay.c
@@ -81,12 +81,18 @@ int main(int argc, char **argv)
unsigned int card = 0;
unsigned int period_size = 1024;
unsigned int period_count = 4;
+ unsigned int channels = 2;
+ unsigned int rate = 48000;
+ unsigned int bits = 16;
+ unsigned int is_raw = 0; /* Default wav file */
char *filename;
int more_chunks = 1;
if (argc < 2) {
- fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-p period_size]"
+ fprintf(stderr, "Usage1: %s file.wav [-D card] [-d device] [-p period_size]"
" [-n n_periods] \n", argv[0]);
+ fprintf(stderr, "Usage2: %s file.raw [-D card] [-d device] [-p period_size] "
+ "[-n n_periods] [-c channels] [-r rate] [-b bits] -i raw \n", argv[0]);
return 1;
}
@@ -97,34 +103,6 @@ int main(int argc, char **argv)
return 1;
}
- fread(&riff_wave_header, sizeof(riff_wave_header), 1, file);
- if ((riff_wave_header.riff_id != ID_RIFF) ||
- (riff_wave_header.wave_id != ID_WAVE)) {
- fprintf(stderr, "Error: '%s' is not a riff/wave file\n", filename);
- fclose(file);
- return 1;
- }
-
- do {
- fread(&chunk_header, sizeof(chunk_header), 1, file);
-
- switch (chunk_header.id) {
- case ID_FMT:
- fread(&chunk_fmt, sizeof(chunk_fmt), 1, file);
- /* If the format header is larger, skip the rest */
- if (chunk_header.sz > sizeof(chunk_fmt))
- fseek(file, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
- break;
- case ID_DATA:
- /* Stop looking for chunks */
- more_chunks = 0;
- break;
- default:
- /* Unknown chunk, skip bytes */
- fseek(file, chunk_header.sz, SEEK_CUR);
- }
- } while (more_chunks);
-
/* parse command line arguments */
argv += 2;
while (*argv) {
@@ -148,12 +126,65 @@ int main(int argc, char **argv)
if (*argv)
card = atoi(*argv);
}
+ if (strcmp(*argv, "-c") == 0) {
+ argv++;
+ if (*argv)
+ channels = atoi(*argv);
+ }
+ if (strcmp(*argv, "-r") == 0) {
+ argv++;
+ if (*argv)
+ rate = atoi(*argv);
+ }
+ if (strcmp(*argv, "-b") == 0) {
+ argv++;
+ if (*argv)
+ bits = atoi(*argv);
+ }
+ if (strcmp(*argv, "-i") == 0) {
+ argv++;
+ if (*argv) {
+ if (strcasecmp(*argv, "raw") == 0) {
+ is_raw = 1;
+ }
+ }
+ }
if (*argv)
argv++;
}
- play_sample(file, card, device, chunk_fmt.num_channels, chunk_fmt.sample_rate,
- chunk_fmt.bits_per_sample, period_size, period_count);
+ if ( !is_raw ) {
+ fread(&riff_wave_header, sizeof(riff_wave_header), 1, file);
+ if ((riff_wave_header.riff_id != ID_RIFF) ||
+ (riff_wave_header.wave_id != ID_WAVE)) {
+ fprintf(stderr, "Error: '%s' is not a riff/wave file\n", filename);
+ fclose(file);
+ return 1;
+ }
+ do {
+ fread(&chunk_header, sizeof(chunk_header), 1, file);
+ switch (chunk_header.id) {
+ case ID_FMT:
+ fread(&chunk_fmt, sizeof(chunk_fmt), 1, file);
+ /* If the format header is larger, skip the rest */
+ if (chunk_header.sz > sizeof(chunk_fmt))
+ fseek(file, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
+ break;
+ case ID_DATA:
+ /* Stop looking for chunks */
+ more_chunks = 0;
+ break;
+ default:
+ /* Unknown chunk, skip bytes */
+ fseek(file, chunk_header.sz, SEEK_CUR);
+ }
+ } while (more_chunks);
+ channels = chunk_fmt.num_channels;
+ rate = chunk_fmt.sample_rate;
+ bits = chunk_fmt.bits_per_sample;
+ }
+
+ play_sample(file, card, device, channels, rate, bits, period_size, period_count);
fclose(file);