diff options
Diffstat (limited to 'apps/codecs/libpcm/linear_pcm.c')
-rw-r--r-- | apps/codecs/libpcm/linear_pcm.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/apps/codecs/libpcm/linear_pcm.c b/apps/codecs/libpcm/linear_pcm.c index 451154cc9b..2a37f3d2a8 100644 --- a/apps/codecs/libpcm/linear_pcm.c +++ b/apps/codecs/libpcm/linear_pcm.c | |||
@@ -20,13 +20,18 @@ | |||
20 | * | 20 | * |
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | #include "codeclib.h" | 22 | #include "codeclib.h" |
23 | #include "pcm_common.h" | ||
24 | #include "support_formats.h" | 23 | #include "support_formats.h" |
25 | 24 | ||
26 | /* | 25 | /* |
27 | * Linear PCM | 26 | * Linear PCM |
28 | */ | 27 | */ |
29 | 28 | ||
29 | #define INC_DEPTH_8 (PCM_OUTPUT_DEPTH - 8) | ||
30 | #define INC_DEPTH_16 (PCM_OUTPUT_DEPTH - 16) | ||
31 | #define INC_DEPTH_24 (PCM_OUTPUT_DEPTH - 24) | ||
32 | #define DEC_DEPTH_32 (32 - PCM_OUTPUT_DEPTH) | ||
33 | |||
34 | |||
30 | static struct pcm_format *fmt; | 35 | static struct pcm_format *fmt; |
31 | 36 | ||
32 | static bool set_format(struct pcm_format *format) | 37 | static bool set_format(struct pcm_format *format) |
@@ -73,7 +78,7 @@ static inline void decode_s8(const uint8_t *inbuf, size_t inbufsize, int32_t *ou | |||
73 | size_t i = 0; | 78 | size_t i = 0; |
74 | 79 | ||
75 | for ( ; i < inbufsize; i++) | 80 | for ( ; i < inbufsize; i++) |
76 | outbuf[i] = SE(inbuf[i])<<21; | 81 | outbuf[i] = SE(inbuf[i]) << INC_DEPTH_8; |
77 | } | 82 | } |
78 | 83 | ||
79 | static inline void decode_u8(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 84 | static inline void decode_u8(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -81,7 +86,7 @@ static inline void decode_u8(const uint8_t *inbuf, size_t inbufsize, int32_t *ou | |||
81 | size_t i = 0; | 86 | size_t i = 0; |
82 | 87 | ||
83 | for ( ; i < inbufsize; i++) | 88 | for ( ; i < inbufsize; i++) |
84 | outbuf[i] = SFT(inbuf[i])<<21; | 89 | outbuf[i] = SFT(inbuf[i]) << INC_DEPTH_8; |
85 | } | 90 | } |
86 | 91 | ||
87 | /* 16bit decode functions */ | 92 | /* 16bit decode functions */ |
@@ -90,7 +95,7 @@ static inline void decode_s16le(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
90 | size_t i = 0; | 95 | size_t i = 0; |
91 | 96 | ||
92 | for ( ; i < inbufsize; i += 2) | 97 | for ( ; i < inbufsize; i += 2) |
93 | outbuf[i/2] = (inbuf[i]<<13)|(SE(inbuf[i+1])<<21); | 98 | outbuf[i/2] = (inbuf[i] << INC_DEPTH_16)|(SE(inbuf[i+1]) << INC_DEPTH_16); |
94 | } | 99 | } |
95 | 100 | ||
96 | static inline void decode_u16le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 101 | static inline void decode_u16le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -98,7 +103,7 @@ static inline void decode_u16le(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
98 | size_t i = 0; | 103 | size_t i = 0; |
99 | 104 | ||
100 | for ( ; i < inbufsize; i += 2) | 105 | for ( ; i < inbufsize; i += 2) |
101 | outbuf[i/2] = (inbuf[i]<<13)|(SFT(inbuf[i+1])<<21); | 106 | outbuf[i/2] = (inbuf[i] << INC_DEPTH_16)|(SFT(inbuf[i+1]) << INC_DEPTH_8); |
102 | } | 107 | } |
103 | 108 | ||
104 | static inline void decode_s16be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 109 | static inline void decode_s16be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -106,7 +111,7 @@ static inline void decode_s16be(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
106 | size_t i = 0; | 111 | size_t i = 0; |
107 | 112 | ||
108 | for ( ; i < inbufsize; i += 2) | 113 | for ( ; i < inbufsize; i += 2) |
109 | outbuf[i/2] = (inbuf[i+1]<<13)|(SE(inbuf[i])<<21); | 114 | outbuf[i/2] = (inbuf[i+1] << INC_DEPTH_16)|(SE(inbuf[i]) << INC_DEPTH_8); |
110 | } | 115 | } |
111 | 116 | ||
112 | static inline void decode_u16be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 117 | static inline void decode_u16be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -114,7 +119,7 @@ static inline void decode_u16be(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
114 | size_t i = 0; | 119 | size_t i = 0; |
115 | 120 | ||
116 | for ( ; i < inbufsize; i += 2) | 121 | for ( ; i < inbufsize; i += 2) |
117 | outbuf[i/2] = (inbuf[i+1]<<13)|(SFT(inbuf[i])<<21); | 122 | outbuf[i/2] = (inbuf[i+1] << INC_DEPTH_16)|(SFT(inbuf[i]) << INC_DEPTH_8); |
118 | } | 123 | } |
119 | 124 | ||
120 | /* 24bit decode functions */ | 125 | /* 24bit decode functions */ |
@@ -123,7 +128,8 @@ static inline void decode_s24le(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
123 | size_t i = 0; | 128 | size_t i = 0; |
124 | 129 | ||
125 | for ( ; i < inbufsize; i += 3) | 130 | for ( ; i < inbufsize; i += 3) |
126 | outbuf[i/3] = (inbuf[i]<<5)|(inbuf[i+1]<<13)|(SE(inbuf[i+2])<<21); | 131 | outbuf[i/3] = (inbuf[i] << INC_DEPTH_24)|(inbuf[i+1] << INC_DEPTH_16)| |
132 | (SE(inbuf[i+2]) << INC_DEPTH_8); | ||
127 | } | 133 | } |
128 | 134 | ||
129 | static inline void decode_u24le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 135 | static inline void decode_u24le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -131,7 +137,8 @@ static inline void decode_u24le(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
131 | size_t i = 0; | 137 | size_t i = 0; |
132 | 138 | ||
133 | for ( ; i < inbufsize; i += 3) | 139 | for ( ; i < inbufsize; i += 3) |
134 | outbuf[i/3] = (inbuf[i]<<5)|(inbuf[i+1]<<13)|(SFT(inbuf[i+2])<<21); | 140 | outbuf[i/3] = (inbuf[i] << INC_DEPTH_24)|(inbuf[i+1] << INC_DEPTH_16)| |
141 | (SFT(inbuf[i+2]) << INC_DEPTH_8); | ||
135 | } | 142 | } |
136 | 143 | ||
137 | static inline void decode_s24be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 144 | static inline void decode_s24be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -139,7 +146,8 @@ static inline void decode_s24be(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
139 | size_t i = 0; | 146 | size_t i = 0; |
140 | 147 | ||
141 | for ( ; i < inbufsize; i += 3) | 148 | for ( ; i < inbufsize; i += 3) |
142 | outbuf[i/3] = (inbuf[i+2]<<5)|(inbuf[i+1]<<13)|(SE(inbuf[i])<<21); | 149 | outbuf[i/3] = (inbuf[i+2] << INC_DEPTH_24)|(inbuf[i+1] << INC_DEPTH_16)| |
150 | (SE(inbuf[i]) << INC_DEPTH_8); | ||
143 | } | 151 | } |
144 | 152 | ||
145 | static inline void decode_u24be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 153 | static inline void decode_u24be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -147,7 +155,8 @@ static inline void decode_u24be(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
147 | size_t i = 0; | 155 | size_t i = 0; |
148 | 156 | ||
149 | for ( ; i < inbufsize; i += 3) | 157 | for ( ; i < inbufsize; i += 3) |
150 | outbuf[i/3] = (inbuf[i+2]<<5)|(inbuf[i+1]<<13)|(SFT(inbuf[i])<<21); | 158 | outbuf[i/3] = (inbuf[i+2] << INC_DEPTH_24)|(inbuf[i+1] << INC_DEPTH_8)| |
159 | (SFT(inbuf[i]) << INC_DEPTH_8); | ||
151 | } | 160 | } |
152 | 161 | ||
153 | /* 32bit decode functions */ | 162 | /* 32bit decode functions */ |
@@ -156,7 +165,8 @@ static inline void decode_s32le(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
156 | size_t i = 0; | 165 | size_t i = 0; |
157 | 166 | ||
158 | for ( ; i < inbufsize; i += 4) | 167 | for ( ; i < inbufsize; i += 4) |
159 | outbuf[i/4] = (inbuf[i]>>3)|(inbuf[i+1]<<5)|(inbuf[i+2]<<13)|(SE(inbuf[i+3])<<21); | 168 | outbuf[i/4] = (inbuf[i] >> DEC_DEPTH_32)|(inbuf[i+1] << INC_DEPTH_24)| |
169 | (inbuf[i+2] << INC_DEPTH_16)|(SE(inbuf[i+3]) << INC_DEPTH_8); | ||
160 | } | 170 | } |
161 | 171 | ||
162 | static inline void decode_u32le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 172 | static inline void decode_u32le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -164,7 +174,8 @@ static inline void decode_u32le(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
164 | size_t i = 0; | 174 | size_t i = 0; |
165 | 175 | ||
166 | for ( ; i < inbufsize; i += 4) | 176 | for ( ; i < inbufsize; i += 4) |
167 | outbuf[i/4] = (inbuf[i]>>3)|(inbuf[i+1]<<5)|(inbuf[i+2]<<13)|(SFT(inbuf[i+3])<<21); | 177 | outbuf[i/4] = (inbuf[i] >> DEC_DEPTH_32)|(inbuf[i+1] << INC_DEPTH_24)| |
178 | (inbuf[i+2] << INC_DEPTH_16)|(SFT(inbuf[i+3]) << INC_DEPTH_8); | ||
168 | } | 179 | } |
169 | 180 | ||
170 | static inline void decode_s32be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 181 | static inline void decode_s32be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -172,7 +183,8 @@ static inline void decode_s32be(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
172 | size_t i = 0; | 183 | size_t i = 0; |
173 | 184 | ||
174 | for ( ; i < inbufsize; i += 4) | 185 | for ( ; i < inbufsize; i += 4) |
175 | outbuf[i/4] = (inbuf[i+3]>>3)|(inbuf[i+2]<<5)|(inbuf[i+1]<<13)|(SE(inbuf[i])<<21); | 186 | outbuf[i/4] = (inbuf[i+3] >> DEC_DEPTH_32)|(inbuf[i+2] << INC_DEPTH_24)| |
187 | (inbuf[i+1] << INC_DEPTH_16)|(SE(inbuf[i]) << INC_DEPTH_8); | ||
176 | } | 188 | } |
177 | 189 | ||
178 | static inline void decode_u32be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) | 190 | static inline void decode_u32be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) |
@@ -180,7 +192,8 @@ static inline void decode_u32be(const uint8_t *inbuf, size_t inbufsize, int32_t | |||
180 | size_t i = 0; | 192 | size_t i = 0; |
181 | 193 | ||
182 | for ( ; i < inbufsize; i += 4) | 194 | for ( ; i < inbufsize; i += 4) |
183 | outbuf[i/4] = (inbuf[i+3]>>3)|(inbuf[i+2]<<5)|(inbuf[i+1]<<13)|(SFT(inbuf[i])<<21); | 195 | outbuf[i/4] = (inbuf[i+3] >> DEC_DEPTH_32)|(inbuf[i+2] << INC_DEPTH_24)| |
196 | (inbuf[i+1] << INC_DEPTH_16)|(SFT(inbuf[i]) << INC_DEPTH_8); | ||
184 | } | 197 | } |
185 | 198 | ||
186 | static int decode(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf, int *outbufcount) | 199 | static int decode(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf, int *outbufcount) |