summaryrefslogtreecommitdiff
path: root/src/Wav.h
blob: 7e274d8787561f16d588b65f9801e6c0e744d4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Copyright (c) 2005-2009, John Hurst
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*! \file    Wav.h
    \version $Id$
    \brief   Wave file common elements
*/

#ifndef _WAV_H_
#define _WAV_H_

#include <KM_fileio.h>
#include <AS_DCP.h>

namespace ASDCP
{
  //
  class fourcc
    {
    private:
      byte_t data[4];

    public:
      inline fourcc() { memset( data, 0, 4 ); }
      inline fourcc( const char* v )   { memcpy( this->data, v, 4 ); }
      inline fourcc( const byte_t* v ) { memcpy( this->data, v, 4 ); }
      inline fourcc& operator=(const fourcc & s) { memcpy( this->data, s.data, 4); return *this; }
      inline bool operator==(const fourcc &rhs)  { return memcmp(data, rhs.data, 4) == 0 ? true : false; }
      inline bool operator!=(const fourcc &rhs)  { return memcmp(data, rhs.data, 4) != 0 ? true : false; }
    };

  namespace AIFF
    {
      const fourcc FCC_FORM("FORM");
      const fourcc FCC_AIFF("AIFF");
      const fourcc FCC_COMM("COMM");
      const fourcc FCC_SSND("SSND");

      class SimpleAIFFHeader
	{
	public:
	  ui16_t  numChannels;
	  ui32_t  numSampleFrames;
	  ui16_t  sampleSize;
	  byte_t  sampleRate[10]; // 80-bit IEEE 754 float
	  ui32_t  data_len;

	  SimpleAIFFHeader() :
	    numChannels(0), numSampleFrames(0), sampleSize(0), data_len(0) {
	    memset(sampleRate, 0, 10);
	  }
      	  
	  Result_t  ReadFromBuffer(const byte_t* buf, ui32_t buf_len, ui32_t* data_start);
	  Result_t  ReadFromFile(const Kumu::FileReader& InFile, ui32_t* data_start);
	  void      FillADesc(ASDCP::PCM::AudioDescriptor& ADesc, Rational PictureRate) const;
	};

    } // namespace AIFF

  namespace Wav
    {
      const ui32_t MaxWavHeader = 1024*32; // must find "data" within this space or no happy

      const fourcc FCC_RIFF("RIFF");
      const fourcc FCC_WAVE("WAVE");
      const fourcc FCC_fmt_("fmt ");
      const fourcc FCC_data("data");

      const ui16_t ASDCP_WAVE_FORMAT_PCM = 1;
      const ui16_t ASDCP_WAVE_FORMAT_EXTENSIBLE = 65534;

      //
      class SimpleWaveHeader
	{
	public:
	  ui16_t	format;
	  ui16_t	nchannels;
	  ui32_t	samplespersec;
	  ui32_t	avgbps;
	  ui16_t	blockalign;
	  ui16_t	bitspersample;
	  ui16_t	cbsize;
	  ui32_t	data_len;

	  SimpleWaveHeader() :
	    format(0), nchannels(0), samplespersec(0), avgbps(0),
	    blockalign(0), bitspersample(0), cbsize(0), data_len(0) {}
      
	  SimpleWaveHeader(ASDCP::PCM::AudioDescriptor& ADesc);
	  
	  Result_t  ReadFromBuffer(const byte_t* buf, ui32_t buf_len, ui32_t* data_start);
	  Result_t  ReadFromFile(const Kumu::FileReader& InFile, ui32_t* data_start);
	  Result_t  WriteToFile(Kumu::FileWriter& OutFile) const;
	  void      FillADesc(ASDCP::PCM::AudioDescriptor& ADesc, Rational PictureRate) const;
	};

    } // namespace Wav

  namespace RF64
    {
      const fourcc FCC_RF64("RF64");
      const fourcc FCC_ds64("ds64");


      static const ui32_t MAX_RIFF_LEN = 0xFFFFFFFF;
      static const ui32_t DS64_HEADER_LEN = 28;
      static const ui32_t SIMPLE_RF64_HEADER_LEN = 82;
      //
      class SimpleRF64Header
	{
	public:
	  ui16_t	format;
	  ui16_t	nchannels;
	  ui32_t	samplespersec;
	  ui32_t	avgbps;
	  ui16_t	blockalign;
	  ui16_t	bitspersample;
	  ui16_t	cbsize;
	  ui64_t	data_len;

	  SimpleRF64Header() :
	    format(0), nchannels(0), samplespersec(0), avgbps(0),
	    blockalign(0), bitspersample(0), cbsize(0), data_len(0) {}

	  SimpleRF64Header(ASDCP::PCM::AudioDescriptor& ADesc);

	  Result_t  ReadFromBuffer(const byte_t* buf, ui32_t buf_len, ui32_t* data_start);
	  Result_t  ReadFromFile(const Kumu::FileReader& InFile, ui32_t* data_start);
	  Result_t  WriteToFile(Kumu::FileWriter& OutFile) const;
	  void      FillADesc(ASDCP::PCM::AudioDescriptor& ADesc, Rational PictureRate) const;

    private:
      static const ui64_t SAMPLE_COUNT = 0;
      static const ui32_t TABLE_LEN = 0;
	};

    } // namespace RF64
} // namespace ASDCP

#endif // _WAV_H_

//
// end Wav.h
//