aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wilson <ksattic@gmail.com>2016-01-09 13:47:13 -0800
committerSimon Wilson <ksattic@gmail.com>2016-01-09 13:47:13 -0800
commitad66b45add9677c4a732fc3a020f7b5d19c38def (patch)
tree6c6048f98b26c1b2b9f37d18ca41106e1491f495
parentd131cf241b256f55df8d36699f41e630edd78701 (diff)
parentbc0c23b0f6af65e54801285b02542900957b64b5 (diff)
Merge pull request #69 from JaydeepDhole/master
Added raw file support in tinyplay
-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);