4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2011 Develer S.r.l. (http://www.develer.com/)
33 * \brief WAV audio utils.
35 * \author Daniele Basile <asterix@develer.com>
37 * $WIZ$ module_name = "wav"
43 #include <cfg/debug.h>
45 #include <cpu/types.h>
46 #include <cpu/byteorder.h>
57 uint8_t subchunk1_id[4];
58 uint32_t subchunk1_size;
59 uint16_t audio_format;
60 uint16_t num_channels;
64 uint16_t bits_per_sample;
66 uint8_t subchunk2_id[4];
67 uint32_t subchunk2_size;
71 INLINE int wav_checkHdr(WavHdr *wav, uint16_t audio_format, uint16_t num_channels, uint16_t sample_rate, uint16_t bits_per_sample)
75 if (strncmp(wav->chunk_id, "RIFF", 4))
77 kputs("RIFF tag not found\n");
81 if (strncmp(wav->format, "WAVE", 4))
83 kputs("WAVE tag not found\n");
87 if (le16_to_cpu(wav->audio_format) != audio_format)
89 kprintf("Audio format not valid, found [%d]\n", le16_to_cpu(wav->audio_format));
93 if (le16_to_cpu(wav->num_channels) != num_channels)
95 kprintf("Channels number not valid, found [%d]\n", le16_to_cpu(wav->num_channels));
100 if (le32_to_cpu(wav->sample_rate) != sample_rate)
102 kprintf("Sample rate not valid, found [%ld]\n", le32_to_cpu(wav->sample_rate));
106 if (le16_to_cpu(wav->bits_per_sample) != bits_per_sample)
108 kprintf("Bits per sample not valid, found [%d]\n", le16_to_cpu(wav->bits_per_sample));
118 INLINE void wav_writeHdr(WavHdr *wav, size_t sample_num, uint16_t audio_format, uint16_t num_channels, uint32_t sample_rate, uint16_t bits_per_sample)
122 uint32_t sub2 = sample_num * num_channels * bits_per_sample / 8;
124 memcpy(&wav->chunk_id, "RIFF", 4);
125 memcpy(&wav->format, "WAVE", 4);
127 memcpy(&wav->subchunk1_id, "fmt ", 4);
128 wav->subchunk1_size = cpu_to_le32(16);
130 memcpy(&wav->subchunk2_id, "data", 4);
131 wav->subchunk2_size = cpu_to_le32(sub2);
133 wav->audio_format = cpu_to_le16(audio_format);
134 wav->num_channels = cpu_to_le16(num_channels);
135 wav->sample_rate = cpu_to_le32(sample_rate);
136 wav->bits_per_sample = cpu_to_le16(bits_per_sample);
138 wav->chunk_size = cpu_to_le32(36 + sub2);
139 kprintf("CHUNK_SIZE %ld\n", 36 + sub2);
142 #endif /* ALGO_WAV_H */