Merge branch 'tizen_3.0' into tizen for sync
[apps/native/boot-animation.git] / inc / wav_parser.h
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #define __PACK          __attribute__((packed))
19
20 typedef struct chunk_header {
21         char chunkID[4];
22         long chunkSize;
23 } chunk_header;
24
25 #define RIFFID          "RIFF"
26 #define WAVEID          "WAVE"
27
28 typedef struct {
29         char type[4];           /* WAVE */
30 } __PACK RIFFChunk;
31
32 /* FMT Sub chunk */
33 #define FormatID        "fmt "
34 typedef struct {
35         short wFormatTag;       /* other than 1, compressed */
36         unsigned short wChannels;
37         unsigned long dwSamplesPerSec;  /* 11025, 22050, 44100 Khz ... */
38         unsigned long dwAvBytesPerSec;  /* dwSamplesPerSec * wBlockAlign */
39
40         /* 16-bit mono wave = 2 Bytes */
41         /* 16-bit stereo wave = 4 Bytes */
42         /* wChannels * (wBitsPerSample / 8)    == Size of a sample frame, in terms of byte */
43         unsigned short wBlockAlign;
44         unsigned short wBitsPerSample;  /* 16-bit waveform would have 16 */
45
46         /* NOTE: Depends on wFormatTag, here could be more fields exists */
47
48 } __PACK FormatChunk;
49
50 enum FORMAT {
51         IBM_FORMAT_MULAW = 0x0101,
52         IBM_FORMAT_ALAW = 0x0102,
53         IBM_FORMAT_ADPCM = 0x0103,
54 };
55
56 enum CHANNELS {
57         MONOPHONIC = 1,
58         STEREO = 2,
59         FOR_CHANNEL = 4,
60         /*  ...  ( 0x1 << nr of channels ) */
61 };
62
63 #define DataID          "DATA"
64
65 typedef struct {
66         unsigned char waveformData[1];
67 } __PACK DataChunk;
68
69 typedef struct {
70         long dwIdentifier;
71         long dwPosition;
72         unsigned long fccChunk;
73         long dwChunkStart;
74         long dwBlockStart;
75         long dwSampleOffset;
76 } __PACK CuePoint;
77
78 #define CueID   "cue "
79
80 typedef struct {
81         long dwCuePoints;
82         CuePoint points[];
83 } __PACK CueChunk;
84
85 typedef struct {
86         long dwIdentifier;
87         long dwLength;
88         long dwRepeats;
89 } __PACK Segment;
90
91 #define PlaylistID      "plst"
92
93 typedef struct {
94         long dwSegments;
95         Segment Segments[];
96 } __PACK PlaylistChunk;
97
98 typedef struct {
99         unsigned long typeID;
100 } __PACK ListHeader;
101
102 #define LabelID "labl"
103 typedef struct {
104         long dwIdentifier;
105         char dwText[];
106 } __PACK LabelChunk;
107
108 #define NoteID "note"
109 typedef struct {
110         long dwIdentifier;
111         char dwText[];
112 } __PACK NoteChunk;
113
114 #define LabelTextID     "ltxt"
115 typedef struct {
116         long dwIdentifier;
117         long dwSampleLength;
118         long dwPurpose;
119         short wCountry;
120         short wLanguage;
121         short wDialect;
122         short wCodePage;
123         char dwText[];
124 } __PACK LabelTextChunk;
125
126 #define SamplerID "smpl"
127
128 typedef struct {
129         long dwIdentifier;
130         long dwType;
131         long dwStart;
132         long dwEnd;
133         long dwFraction;
134         long dwPlayCount;
135 } __PACK SampleLoop;
136
137 typedef struct {
138         long dwManufacturer;
139         long dwProduct;
140         long dwSamplePeriod;
141         long dwMIDIUnityNote;
142         long dwMIDIPitchFraction;
143         long dwSMPTEFormat;
144         long dwSMPTEOffset;
145         long cSampleLoops;
146         long cbSamplerData;
147         SampleLoop Loops[];
148 } __PACK SamplerChunk;
149
150 enum SMPTE {
151         FRAME24 = 24,
152         FRAME25 = 25,
153         FRAME30_WITH_DROP = 29,
154         FRAME30 = 30,
155 };
156
157 enum LOOP_TYPE {
158         FORWARD_LOOP = 0,
159         ALTERNATE_LOOP = 1,
160         BACKWARD_LOOP = 2,
161 };
162
163 #define InstrumentID    "inst"
164 typedef struct {
165         unsigned char UnshiftedNote;
166         char FineTune;
167         char Gain;
168         unsigned char LowNote;
169         unsigned char HighNote;
170         unsigned char LowVelocity;
171         unsigned char HighVelocity;
172 } __PACK InstrumentChunk;
173
174 #define ListID  "list"
175 typedef struct {
176         char typeID[4];
177         char text[];
178 } __PACK ListChunk;
179
180 #define FactID "fact"
181 typedef struct {
182         char data[1];
183 } __PACK FactChunk;
184
185 struct wave {
186         char *filename;
187         int fd;
188
189         chunk_header riff_header;
190         off_t riff_off;
191         /* RIFFChunk *riff; */
192
193         chunk_header fmt_header;
194         off_t fmt_off;
195         /* FormatChunk *format; */
196
197         chunk_header data_header;
198         off_t data_off;
199         /* DataChunk *data; */
200
201         chunk_header list_header;
202         off_t list_off;
203         /* ListChunk *list; */
204 };
205
206 extern struct wave *open_wave_file(const char *filename);
207 extern int get_wave_channel(struct wave *handle);
208 extern int get_wave_samples_per_sec(struct wave *handle);
209 extern int get_wave_bits_per_sample(struct wave *handle);
210 extern int get_wave_data_size(struct wave *handle);
211 extern int get_wave_data(struct wave *handle, void *data, int off, int size);
212 extern void close_wave_file(struct wave *handle);