1 | /*
|
---|
2 | * Copyright (c) 2012 Jan Vesely
|
---|
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 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup audio
|
---|
30 | * @brief PCM sample format
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef PCM_SAMPLE_FORMAT_H_
|
---|
37 | #define PCM_SAMPLE_FORMAT_H_
|
---|
38 |
|
---|
39 | #include <bool.h>
|
---|
40 |
|
---|
41 | typedef enum {
|
---|
42 | PCM_SAMPLE_UINT8,
|
---|
43 | PCM_SAMPLE_SINT8,
|
---|
44 | PCM_SAMPLE_UINT16_LE,
|
---|
45 | PCM_SAMPLE_UINT16_BE,
|
---|
46 | PCM_SAMPLE_SINT16_LE,
|
---|
47 | PCM_SAMPLE_SINT16_BE,
|
---|
48 | PCM_SAMPLE_UINT24_LE,
|
---|
49 | PCM_SAMPLE_UINT24_BE,
|
---|
50 | PCM_SAMPLE_SINT24_LE,
|
---|
51 | PCM_SAMPLE_SINT24_BE,
|
---|
52 | PCM_SAMPLE_UINT24_32_LE,
|
---|
53 | PCM_SAMPLE_UINT24_32_BE,
|
---|
54 | PCM_SAMPLE_SINT24_32_LE,
|
---|
55 | PCM_SAMPLE_SINT24_32_BE,
|
---|
56 | PCM_SAMPLE_UINT32_LE,
|
---|
57 | PCM_SAMPLE_UINT32_BE,
|
---|
58 | PCM_SAMPLE_SINT32_LE,
|
---|
59 | PCM_SAMPLE_SINT32_BE,
|
---|
60 | PCM_SAMPLE_FLOAT32,
|
---|
61 | PCM_SAMPLE_FORMAT_LAST = PCM_SAMPLE_FLOAT32,
|
---|
62 | } pcm_sample_format_t;
|
---|
63 |
|
---|
64 | static inline bool pcm_sample_format_is_signed(pcm_sample_format_t format)
|
---|
65 | {
|
---|
66 | switch(format) {
|
---|
67 | case PCM_SAMPLE_SINT8:
|
---|
68 | case PCM_SAMPLE_SINT16_LE:
|
---|
69 | case PCM_SAMPLE_SINT16_BE:
|
---|
70 | case PCM_SAMPLE_SINT24_LE:
|
---|
71 | case PCM_SAMPLE_SINT24_BE:
|
---|
72 | case PCM_SAMPLE_SINT24_32_LE:
|
---|
73 | case PCM_SAMPLE_SINT24_32_BE:
|
---|
74 | case PCM_SAMPLE_SINT32_LE:
|
---|
75 | case PCM_SAMPLE_SINT32_BE:
|
---|
76 | return true;
|
---|
77 | case PCM_SAMPLE_UINT8:
|
---|
78 | case PCM_SAMPLE_UINT16_LE:
|
---|
79 | case PCM_SAMPLE_UINT16_BE:
|
---|
80 | case PCM_SAMPLE_UINT24_LE:
|
---|
81 | case PCM_SAMPLE_UINT24_BE:
|
---|
82 | case PCM_SAMPLE_UINT24_32_LE:
|
---|
83 | case PCM_SAMPLE_UINT24_32_BE:
|
---|
84 | case PCM_SAMPLE_UINT32_LE:
|
---|
85 | case PCM_SAMPLE_UINT32_BE:
|
---|
86 | case PCM_SAMPLE_FLOAT32:
|
---|
87 | default:
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | static inline size_t pcm_sample_format_size(pcm_sample_format_t format)
|
---|
93 | {
|
---|
94 | switch(format) {
|
---|
95 | case PCM_SAMPLE_UINT8:
|
---|
96 | case PCM_SAMPLE_SINT8:
|
---|
97 | return 1;
|
---|
98 | case PCM_SAMPLE_UINT16_LE:
|
---|
99 | case PCM_SAMPLE_UINT16_BE:
|
---|
100 | case PCM_SAMPLE_SINT16_LE:
|
---|
101 | case PCM_SAMPLE_SINT16_BE:
|
---|
102 | return 2;
|
---|
103 | case PCM_SAMPLE_UINT24_LE:
|
---|
104 | case PCM_SAMPLE_UINT24_BE:
|
---|
105 | case PCM_SAMPLE_SINT24_LE:
|
---|
106 | case PCM_SAMPLE_SINT24_BE:
|
---|
107 | return 3;
|
---|
108 | case PCM_SAMPLE_UINT24_32_LE:
|
---|
109 | case PCM_SAMPLE_UINT24_32_BE:
|
---|
110 | case PCM_SAMPLE_SINT24_32_LE:
|
---|
111 | case PCM_SAMPLE_SINT24_32_BE:
|
---|
112 | case PCM_SAMPLE_UINT32_LE:
|
---|
113 | case PCM_SAMPLE_UINT32_BE:
|
---|
114 | case PCM_SAMPLE_SINT32_LE:
|
---|
115 | case PCM_SAMPLE_SINT32_BE:
|
---|
116 | case PCM_SAMPLE_FLOAT32:
|
---|
117 | return 4;
|
---|
118 | default:
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | static inline const char * pcm_sample_format_str(pcm_sample_format_t format)
|
---|
124 | {
|
---|
125 | switch(format) {
|
---|
126 | case PCM_SAMPLE_UINT8:
|
---|
127 | return "8 bit unsinged";
|
---|
128 | case PCM_SAMPLE_SINT8:
|
---|
129 | return "8 bit singed";
|
---|
130 | case PCM_SAMPLE_UINT16_LE:
|
---|
131 | return "16 bit unsigned(LE)";
|
---|
132 | case PCM_SAMPLE_SINT16_LE:
|
---|
133 | return "16 bit singed(LE)";
|
---|
134 | case PCM_SAMPLE_UINT16_BE:
|
---|
135 | return "16 bit unsigned(BE)";
|
---|
136 | case PCM_SAMPLE_SINT16_BE:
|
---|
137 | return "16 bit signed(BE)";
|
---|
138 | case PCM_SAMPLE_UINT24_LE:
|
---|
139 | return "24 bit unsigned(LE)";
|
---|
140 | case PCM_SAMPLE_SINT24_LE:
|
---|
141 | return "24 bit signed(LE)";
|
---|
142 | case PCM_SAMPLE_UINT24_BE:
|
---|
143 | return "24 bit unsigned(BE)";
|
---|
144 | case PCM_SAMPLE_SINT24_BE:
|
---|
145 | return "24 bit signed(BE)";
|
---|
146 | case PCM_SAMPLE_UINT24_32_LE:
|
---|
147 | return "24 bit(4byte aligned) unsigned(LE)";
|
---|
148 | case PCM_SAMPLE_UINT24_32_BE:
|
---|
149 | return "24 bit(4byte aligned) unsigned(BE)";
|
---|
150 | case PCM_SAMPLE_SINT24_32_LE:
|
---|
151 | return "24 bit(4byte aligned) signed(LE)";
|
---|
152 | case PCM_SAMPLE_SINT24_32_BE:
|
---|
153 | return "24 bit(4byte aligned) signed(BE)";
|
---|
154 | case PCM_SAMPLE_UINT32_LE:
|
---|
155 | return "32 bit unsigned(LE)";
|
---|
156 | case PCM_SAMPLE_UINT32_BE:
|
---|
157 | return "32 bit unsigned(BE)";
|
---|
158 | case PCM_SAMPLE_SINT32_LE:
|
---|
159 | return "32 bit signed(LE)";
|
---|
160 | case PCM_SAMPLE_SINT32_BE:
|
---|
161 | return "32 bit signed(BE)";
|
---|
162 | case PCM_SAMPLE_FLOAT32:
|
---|
163 | return "32 bit float";
|
---|
164 | default:
|
---|
165 | return "Unknown sample format";
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * @}
|
---|
173 | */
|
---|
174 |
|
---|