| [e677b08] | 1 | /* | 
|---|
|  | 2 | * Copyright (c) 2011 Jan Vesely | 
|---|
|  | 3 | * All rights reserved. | 
|---|
|  | 4 | * | 
|---|
|  | 5 | * Redistribution and use in source and binary forms, with or without | 
|---|
|  | 6 | * modification, are permitted provided that the following conditions | 
|---|
|  | 7 | * are met: | 
|---|
|  | 8 | * | 
|---|
|  | 9 | * - Redistributions of source code must retain the above copyright | 
|---|
|  | 10 | *   notice, this list of conditions and the following disclaimer. | 
|---|
|  | 11 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
|  | 12 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
|  | 13 | *   documentation and/or other materials provided with the distribution. | 
|---|
|  | 14 | * - The name of the author may not be used to endorse or promote products | 
|---|
|  | 15 | *   derived from this software without specific prior written permission. | 
|---|
|  | 16 | * | 
|---|
|  | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
|  | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
|  | 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
|  | 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
|  | 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
|  | 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
|  | 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
|  | 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
|  | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
|  | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
|  | 27 | */ | 
|---|
|  | 28 | /** @addtogroup dplay | 
|---|
|  | 29 | * @{ | 
|---|
|  | 30 | */ | 
|---|
|  | 31 | /** @file | 
|---|
|  | 32 | * @brief .wav file format. | 
|---|
|  | 33 | */ | 
|---|
|  | 34 | #ifndef WAVE_H | 
|---|
|  | 35 | #define WAVE_H | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include <stdint.h> | 
|---|
| [0a4ad7d] | 38 | #include <pcm/format.h> | 
|---|
| [ea6c838] | 39 | #include <pcm/sample_format.h> | 
|---|
| [e677b08] | 40 |  | 
|---|
|  | 41 | /** Wave file header format. | 
|---|
|  | 42 | * | 
|---|
|  | 43 | * https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ | 
|---|
|  | 44 | * @note: 8-bit samples are stored as unsigned bytes, | 
|---|
|  | 45 | * 16-bit samples are stored as signed integers. | 
|---|
|  | 46 | * @note: The default byte ordering assumed for WAVE data files is | 
|---|
|  | 47 | * little-endian. Files written using the big-endian byte ordering scheme have | 
|---|
|  | 48 | * the identifier RIFX instead of RIFF. | 
|---|
|  | 49 | */ | 
|---|
|  | 50 | typedef struct wave_header { | 
|---|
|  | 51 | /** Should be 'R', 'I', 'F', 'F'. */ | 
|---|
|  | 52 | char chunk_id[4]; | 
|---|
|  | 53 | #define CHUNK_ID "RIFF" | 
|---|
|  | 54 |  | 
|---|
|  | 55 | /** Total size minus the first 8 bytes */ | 
|---|
|  | 56 | uint32_t chunk_size; | 
|---|
|  | 57 | /** Should be 'W', 'A', 'V', 'E'. */ | 
|---|
|  | 58 | char format[4]; | 
|---|
|  | 59 | #define FORMAT_STR "WAVE" | 
|---|
|  | 60 |  | 
|---|
|  | 61 | /** Should be 'f', 'm', 't', ' '. */ | 
|---|
|  | 62 | char subchunk1_id[4]; | 
|---|
|  | 63 | #define SUBCHUNK1_ID "fmt " | 
|---|
|  | 64 |  | 
|---|
|  | 65 | /** Size of the ret of this subchunk. 16 for PCM file. */ | 
|---|
|  | 66 | uint32_t subchunk1_size; | 
|---|
|  | 67 | #define PCM_SUBCHUNK1_SIZE 16 | 
|---|
|  | 68 | /** Format. 1 for Linear PCM */ | 
|---|
|  | 69 | uint16_t audio_format; | 
|---|
|  | 70 | #define FORMAT_LINEAR_PCM 1 | 
|---|
|  | 71 | /** Number of channels. */ | 
|---|
|  | 72 | uint16_t channels; | 
|---|
|  | 73 | /** Sampling rate. */ | 
|---|
|  | 74 | uint32_t sampling_rate; | 
|---|
|  | 75 | /** Byte rate. */ | 
|---|
|  | 76 | uint32_t byte_rate; | 
|---|
|  | 77 | /** Block align. Bytes in one block (samples for all channels). */ | 
|---|
|  | 78 | uint16_t block_align; | 
|---|
|  | 79 | /** Bits per sample (one channel). */ | 
|---|
|  | 80 | uint16_t sample_size; | 
|---|
|  | 81 |  | 
|---|
|  | 82 | /** Should be 'd', 'a', 't', 'a'. */ | 
|---|
|  | 83 | char subchunk2_id[4]; | 
|---|
|  | 84 | #define SUBCHUNK2_ID "data" | 
|---|
|  | 85 | /** Audio data size. */ | 
|---|
|  | 86 | uint32_t subchunk2_size; | 
|---|
|  | 87 | /** Audio data. */ | 
|---|
|  | 88 | uint8_t data[]; | 
|---|
|  | 89 |  | 
|---|
|  | 90 | } wave_header_t; | 
|---|
|  | 91 |  | 
|---|
| [0a4ad7d] | 92 | int wav_parse_header(const void *, const void**, size_t *, unsigned *, | 
|---|
|  | 93 | unsigned *, pcm_sample_format_t *, const char **); | 
|---|
| [e677b08] | 94 |  | 
|---|
| [0a4ad7d] | 95 | void wav_init_header(wave_header_t *, pcm_format_t , size_t); | 
|---|
| [e677b08] | 96 | #endif | 
|---|
|  | 97 | /** | 
|---|
|  | 98 | * @} | 
|---|
|  | 99 | */ | 
|---|