uint32_t rate, uint16_t samplebits);
void size_wave_header(struct wave_header *header, uint32_t size);
+int parse_wave_header(struct wave_header *header, unsigned int *channels,
+ unsigned int *rate, unsigned int *format);
#endif
//
// Copyright 2021 NXP
+#include <stdio.h>
#include <stdint.h>
#include <string.h>
+#include <sound/asound.h>
#include "tinycompress/tinywave.h"
sizeof(header->riff.chunk) + size;
header->data.chunk.size = size;
}
+
+int parse_wave_header(struct wave_header *header, unsigned int *channels,
+ unsigned int *rate, unsigned int *format)
+{
+ if (strncmp(header->riff.chunk.desc, "RIFF", 4) != 0) {
+ fprintf(stderr, "RIFF magic not found\n");
+ return -1;
+ }
+
+ if (strncmp(header->riff.format, "WAVE", 4) != 0) {
+ fprintf(stderr, "WAVE magic not found\n");
+ return -1;
+ }
+
+ if (strncmp(header->fmt.chunk.desc, "fmt", 3) != 0) {
+ fprintf(stderr, "FMT section not found");
+ return -1;
+ }
+
+ *channels = header->fmt.channels;
+ *rate = header->fmt.rate;
+
+ switch(header->fmt.samplebits) {
+ case 8:
+ *format = SNDRV_PCM_FORMAT_U8;
+ break;
+ case 16:
+ *format = SNDRV_PCM_FORMAT_S16_LE;
+ break;
+ case 32:
+ *format = SNDRV_PCM_FORMAT_S32_LE;
+ break;
+ default:
+ fprintf(stderr, "Unsupported sample bits %d\n",
+ header->fmt.samplebits);
+ return -1;
+ }
+
+ return 0;
+}