vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / media / plugins / aiff_reader / aiff.h
blobd197d1a664d4a285b0a2b988dc12639b022d5e61
1 /*
2 * Copyright (c) 2003-2004, Marcus Overhagen
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23 * OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef _AIFF_H
26 #define _AIFF_H
28 // The complete size of a chunk is chunk_size + sizeof(chunk_struct)
29 // If the complete size of a chunk is not even, the chunk is padded with one byte
30 // sample order for multi channel sound:
31 // 2: left, right
32 // 3: left, right, center
33 // 4: front left, front right, rear left, rear right
34 // 4: left, center, right, surround
35 // 6: left center, left, center, right center, right, surround
37 // Apple maps Microsoft ACM formats into a compression code of the form "ms??",
38 // where the second two characters are the Microsoft Audio Compression Manager
39 // (ACM) code. For instance, Microsoft ADPCM, with ACM value of 1, is mapped
40 // to the code "ms\x00\x01".
42 struct chunk_struct
44 uint32 chunk_id;
45 uint32 chunk_size;
46 } _PACKED;
48 struct aiff_chunk
50 uint32 chunk_id; // 'FORM'
51 uint32 chunk_size;
52 uint32 aiff_id; // 'AIFF' or 'AIFC'
53 // chunks[]
54 } _PACKED;
56 struct comm_chunk
58 // uint32 chunk_id; // 'COMM'
59 // uint32 chunk_size;
60 uint16 channel_count;
61 uint32 frame_count;
62 uint16 bits_per_sample; // store as 8 bit entities
63 char sample_rate[10]; // 80 bit IEEE floating point, big endian
64 uint32 compression_id; // only present if chunk_size >= 22
65 } _PACKED;
67 struct ssnd_chunk
69 // uint32 chunk_id; // 'SSND'
70 // uint32 chunk_size;
71 uint32 offset;
72 uint32 block_size;
73 // samples[]
74 } _PACKED;
76 inline const char * string_for_compression(uint32 compression)
78 static char s[64];
79 switch (compression) {
80 case 'NONE': return "not compressed";
81 case 'ADP4': return "4:1 Intel/DVI ADPCM";
82 case 'DWVW': return "Delta With Variable Word Width";
83 case 'FL32': return "IEEE 32-bit floating point";
84 case 'fl32': return "IEEE 32-bit floating point";
85 case 'fl64': return "IEEE 64-bit floating point";
86 case 'alaw': return "8-bit ITU-T G.711 A-law";
87 case 'ALAW': return "8-bit ITU-T G.711 A-law";
88 case 'ulaw': return "8-bit ITU-T G.711 µ-law";
89 case 'ULAW': return "8-bit ITU-T G.711 µ-law";
90 case 'ima4': return "IMA 4:1";
91 case 'MAC3': return "MACE 3-to-1";
92 case 'MAC6': return "MACE 6-to-1";
93 case 'QDMC': return "QDesign Music";
94 case 'Qclp': return "Qualcomm PureVoice";
95 case 'rt24': return "RT24 50:1";
96 case 'rt29': return "RT29 50:1";
97 case 'G722': return "G722";
98 case 'G726': return "G726";
99 case 'G728': return "G728";
100 case 'GSM ': return "GSM";
101 default:
102 sprintf(s, "unknown compression %c%c%c%c",
103 (int)((compression >> 24) & 0xff),
104 (int)((compression >> 16) & 0xff),
105 (int)((compression >> 8) & 0xff),
106 (int)(compression & 0xff));
107 return s;
111 #endif