Skip to content
Browse files

Merge pull request #69 from JaydeepDhole/master

Added raw file support in tinyplay
  • Loading branch information...
2 parents d131cf2 + bc0c23b commit ad66b45add9677c4a732fc3a020f7b5d19c38def @tinyalsa committed
Showing with 62 additions and 31 deletions.
  1. +62 −31 tinyplay.c
View
93 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);

0 comments on commit ad66b45

Please sign in to comment.
Something went wrong with that request. Please try again.