2 Copyright (c) 2005-2009, John Hurst
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \brief Wave file common elements
35 #include <KM_fileio.h>
47 inline fourcc() { memset( data, 0, 4 ); }
48 inline fourcc( const char* v ) { memcpy( this->data, v, 4 ); }
49 inline fourcc( const byte_t* v ) { memcpy( this->data, v, 4 ); }
50 inline fourcc& operator=(const fourcc & s) { memcpy( this->data, s.data, 4); return *this; }
51 inline bool operator==(const fourcc &rhs) { return memcmp(data, rhs.data, 4) == 0 ? true : false; }
52 inline bool operator!=(const fourcc &rhs) { return memcmp(data, rhs.data, 4) != 0 ? true : false; }
57 const fourcc FCC_FORM("FORM");
58 const fourcc FCC_AIFF("AIFF");
59 const fourcc FCC_COMM("COMM");
60 const fourcc FCC_SSND("SSND");
62 class SimpleAIFFHeader
66 ui32_t numSampleFrames;
68 byte_t sampleRate[10]; // 80-bit IEEE 754 float
72 numChannels(0), numSampleFrames(0), sampleSize(0), data_len(0) {
73 memset(sampleRate, 0, 10);
76 Result_t ReadFromBuffer(const byte_t* buf, ui32_t buf_len, ui32_t* data_start);
77 Result_t ReadFromFile(const Kumu::FileReader& InFile, ui32_t* data_start);
78 void FillADesc(ASDCP::PCM::AudioDescriptor& ADesc, Rational PictureRate) const;
85 const ui32_t MaxWavHeader = 1024*32; // must find "data" within this space or no happy
87 const fourcc FCC_RIFF("RIFF");
88 const fourcc FCC_WAVE("WAVE");
89 const fourcc FCC_fmt_("fmt ");
90 const fourcc FCC_data("data");
92 const ui16_t WAVE_FORMAT_PCM = 1;
93 const ui16_t WAVE_FORMAT_EXTENSIBLE = 65534;
96 class SimpleWaveHeader
101 ui32_t samplespersec;
104 ui16_t bitspersample;
109 format(0), nchannels(0), samplespersec(0), avgbps(0),
110 blockalign(0), bitspersample(0), cbsize(0), data_len(0) {}
112 SimpleWaveHeader(ASDCP::PCM::AudioDescriptor& ADesc);
114 Result_t ReadFromBuffer(const byte_t* buf, ui32_t buf_len, ui32_t* data_start);
115 Result_t ReadFromFile(const Kumu::FileReader& InFile, ui32_t* data_start);
116 Result_t WriteToFile(Kumu::FileWriter& OutFile) const;
117 void FillADesc(ASDCP::PCM::AudioDescriptor& ADesc, Rational PictureRate) const;