builds on Darwin
[asdcplib.git] / src / Wav.h
1 /*
2 Copyright (c) 2005, John Hurst
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 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.
15
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.
26 */
27 /*! \file    Wav.h
28     \version $Id$
29     \brief   Wave file common elements
30 */
31
32 #ifndef _WAV_H_
33 #define _WAV_H_
34
35 #include <FileIO.h>
36
37 namespace ASDCP
38 {
39 namespace Wav
40 {
41   const ui32_t MaxWavHeader = 1024*32; // must find "data" within this space or no happy
42
43   //
44   class fourcc
45     {
46     private:
47       byte_t data[4];
48
49     public:
50       inline fourcc() { memset( data, 0, 4 ); }
51       inline fourcc( const char* v )   { memcpy( this->data, v, 4 ); }
52       inline fourcc( const byte_t* v ) { memcpy( this->data, v, 4 ); }
53       inline fourcc& operator=(const fourcc & s) { memcpy( this->data, s.data, 4); return *this; }
54       inline bool operator==(const fourcc &rhs)  { return memcmp(data, rhs.data, 4) == 0 ? true : false; }
55       inline bool operator!=(const fourcc &rhs)  { return memcmp(data, rhs.data, 4) != 0 ? true : false; }
56     };
57
58   const fourcc FCC_RIFF("RIFF");
59   const fourcc FCC_WAVE("WAVE");
60   const fourcc FCC_fmt_("fmt ");
61   const fourcc FCC_data("data");
62
63   //
64   class SimpleWaveHeader
65     {
66     public:
67       ui16_t    format;
68       ui16_t    nchannels;
69       ui32_t    samplespersec;
70       ui32_t    avgbps;
71       ui16_t    blockalign;
72       ui16_t    bitspersample;
73       ui16_t    cbsize;
74       ui32_t    data_len;
75
76       SimpleWaveHeader() :
77         format(0), nchannels(0), samplespersec(0), avgbps(0),
78         blockalign(0), bitspersample(0), cbsize(0), data_len(0) {}
79       
80       SimpleWaveHeader(ASDCP::PCM::AudioDescriptor& ADesc);
81
82       Result_t  ReadFromBuffer(const byte_t* buf, ui32_t buf_len, ui32_t* data_start);
83       Result_t  ReadFromFile(const ASDCP::FileReader& InFile, ui32_t* data_start);
84       Result_t  WriteToFile(ASDCP::FileWriter& OutFile) const;
85       void      FillADesc(ASDCP::PCM::AudioDescriptor& ADesc, Rational PictureRate) const;
86    };
87
88 } // namespace Wav
89 } // namespace ASDCP
90
91 #endif // _WAV_H_
92
93 //
94 // end Wav.h
95 //