summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-03-06 05:51:24 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-03-06 05:51:24 +0000
commitff733b5f896b76b0678b7cdc178ee805f377b7b4 (patch)
treeaf976e5d9a834e19ab64827e89b96f2a2f17bcd7
parentf1b209c057b8470cb32c221438f7c123a4bf1392 (diff)
downloadrockbox-ff733b5f896b76b0678b7cdc178ee805f377b7b4.tar.gz
rockbox-ff733b5f896b76b0678b7cdc178ee805f377b7b4.zip
libpcm: decoded pcm depth corrects.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25040 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/aiff.c2
-rw-r--r--apps/codecs/au.c2
-rw-r--r--apps/codecs/libpcm/dialogic_oki_adpcm.c5
-rw-r--r--apps/codecs/libpcm/dvi_adpcm.c31
-rw-r--r--apps/codecs/libpcm/ima_adpcm_common.h2
-rw-r--r--apps/codecs/libpcm/itut_g711.c5
-rw-r--r--apps/codecs/libpcm/linear_pcm.c43
-rw-r--r--apps/codecs/libpcm/ms_adpcm.c5
-rw-r--r--apps/codecs/libpcm/pcm_common.h3
-rw-r--r--apps/codecs/libpcm/qt_ima_adpcm.c5
-rw-r--r--apps/codecs/libpcm/swf_adpcm.c11
-rw-r--r--apps/codecs/libpcm/yamaha_adpcm.c5
-rw-r--r--apps/codecs/smaf.c2
-rw-r--r--apps/codecs/vox.c2
-rw-r--r--apps/codecs/wav.c2
-rw-r--r--apps/codecs/wav64.c2
16 files changed, 70 insertions, 57 deletions
diff --git a/apps/codecs/aiff.c b/apps/codecs/aiff.c
index fbe814a645..e4d1059ed9 100644
--- a/apps/codecs/aiff.c
+++ b/apps/codecs/aiff.c
@@ -87,7 +87,7 @@ enum codec_status codec_main(void)
87 const struct pcm_codec *codec; 87 const struct pcm_codec *codec;
88 88
89 /* Generic codec initialisation */ 89 /* Generic codec initialisation */
90 ci->configure(DSP_SET_SAMPLE_DEPTH, 28); 90 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
91 91
92next_track: 92next_track:
93 if (codec_init()) { 93 if (codec_init()) {
diff --git a/apps/codecs/au.c b/apps/codecs/au.c
index 924b29088d..0f4da3d3bb 100644
--- a/apps/codecs/au.c
+++ b/apps/codecs/au.c
@@ -138,7 +138,7 @@ enum codec_status codec_main(void)
138 int offset = 0; 138 int offset = 0;
139 139
140 /* Generic codec initialisation */ 140 /* Generic codec initialisation */
141 ci->configure(DSP_SET_SAMPLE_DEPTH, 28); 141 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
142 142
143next_track: 143next_track:
144 if (codec_init()) { 144 if (codec_init()) {
diff --git a/apps/codecs/libpcm/dialogic_oki_adpcm.c b/apps/codecs/libpcm/dialogic_oki_adpcm.c
index 5b643f0e34..62d092e677 100644
--- a/apps/codecs/libpcm/dialogic_oki_adpcm.c
+++ b/apps/codecs/libpcm/dialogic_oki_adpcm.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "codeclib.h" 21#include "codeclib.h"
22#include "pcm_common.h"
23#include "adpcm_seek.h" 22#include "adpcm_seek.h"
24#include "support_formats.h" 23#include "support_formats.h"
25 24
@@ -117,8 +116,8 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
117 116
118 while (inbufsize) 117 while (inbufsize)
119 { 118 {
120 *outbuf++ = create_pcmdata(*inbuf >> 4) << 17; 119 *outbuf++ = create_pcmdata(*inbuf >> 4) << (PCM_OUTPUT_DEPTH - 12);
121 *outbuf++ = create_pcmdata(*inbuf ) << 17; 120 *outbuf++ = create_pcmdata(*inbuf ) << (PCM_OUTPUT_DEPTH - 12);
122 nsamples += 2; 121 nsamples += 2;
123 122
124 inbuf++; 123 inbuf++;
diff --git a/apps/codecs/libpcm/dvi_adpcm.c b/apps/codecs/libpcm/dvi_adpcm.c
index c1b90e04e7..6774b14473 100644
--- a/apps/codecs/libpcm/dvi_adpcm.c
+++ b/apps/codecs/libpcm/dvi_adpcm.c
@@ -20,7 +20,6 @@
20 * 20 *
21 ****************************************************************************/ 21 ****************************************************************************/
22#include "codeclib.h" 22#include "codeclib.h"
23#include "pcm_common.h"
24#include "ima_adpcm_common.h" 23#include "ima_adpcm_common.h"
25#include "support_formats.h" 24#include "support_formats.h"
26 25
@@ -85,13 +84,13 @@ static inline void decode_2bit(const uint8_t **inbuf,
85 pcmbuf = *outbuf + ch; 84 pcmbuf = *outbuf + ch;
86 for (i = 0; i < 4; i++) 85 for (i = 0; i < 4; i++)
87 { 86 {
88 *pcmbuf = create_pcmdata(ch, **inbuf ) << 13; 87 *pcmbuf = create_pcmdata(ch, **inbuf ) << IMA_ADPCM_INC_DEPTH;
89 pcmbuf += fmt->channels; 88 pcmbuf += fmt->channels;
90 *pcmbuf = create_pcmdata(ch, **inbuf >> 2) << 13; 89 *pcmbuf = create_pcmdata(ch, **inbuf >> 2) << IMA_ADPCM_INC_DEPTH;
91 pcmbuf += fmt->channels; 90 pcmbuf += fmt->channels;
92 *pcmbuf = create_pcmdata(ch, **inbuf >> 4) << 13; 91 *pcmbuf = create_pcmdata(ch, **inbuf >> 4) << IMA_ADPCM_INC_DEPTH;
93 pcmbuf += fmt->channels; 92 pcmbuf += fmt->channels;
94 *pcmbuf = create_pcmdata(ch, **inbuf >> 6) << 13; 93 *pcmbuf = create_pcmdata(ch, **inbuf >> 6) << IMA_ADPCM_INC_DEPTH;
95 pcmbuf += fmt->channels; 94 pcmbuf += fmt->channels;
96 (*inbuf)++; 95 (*inbuf)++;
97 } 96 }
@@ -123,7 +122,7 @@ static inline void decode_3bit(const uint8_t **inbuf,
123 adpcms |= (*adpcmbuf++) << 16; 122 adpcms |= (*adpcmbuf++) << 16;
124 for (i = 0; i < 8; i++) 123 for (i = 0; i < 8; i++)
125 { 124 {
126 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << 13; 125 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << IMA_ADPCM_INC_DEPTH;
127 pcmbuf += fmt->channels; 126 pcmbuf += fmt->channels;
128 } 127 }
129 adpcms = *adpcmbuf++; 128 adpcms = *adpcmbuf++;
@@ -132,7 +131,7 @@ static inline void decode_3bit(const uint8_t **inbuf,
132 adpcms |= (*adpcmbuf++) << 16; 131 adpcms |= (*adpcmbuf++) << 16;
133 for (i = 0; i < 8; i++) 132 for (i = 0; i < 8; i++)
134 { 133 {
135 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << 13; 134 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << IMA_ADPCM_INC_DEPTH;
136 pcmbuf += fmt->channels; 135 pcmbuf += fmt->channels;
137 } 136 }
138 adpcms = *adpcmbuf++; 137 adpcms = *adpcmbuf++;
@@ -141,7 +140,7 @@ static inline void decode_3bit(const uint8_t **inbuf,
141 adpcms |= (*adpcmbuf++) << 16; 140 adpcms |= (*adpcmbuf++) << 16;
142 for (i = 0; i < 8; i++) 141 for (i = 0; i < 8; i++)
143 { 142 {
144 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << 13; 143 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << IMA_ADPCM_INC_DEPTH;
145 pcmbuf += fmt->channels; 144 pcmbuf += fmt->channels;
146 } 145 }
147 adpcms = *adpcmbuf++; 146 adpcms = *adpcmbuf++;
@@ -149,7 +148,7 @@ static inline void decode_3bit(const uint8_t **inbuf,
149 adpcms |= (*adpcmbuf++) << 16; 148 adpcms |= (*adpcmbuf++) << 16;
150 for (i = 0; i < 8; i++) 149 for (i = 0; i < 8; i++)
151 { 150 {
152 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << 13; 151 *pcmbuf = create_pcmdata(ch, adpcms >> (3 * i)) << IMA_ADPCM_INC_DEPTH;
153 pcmbuf += fmt->channels; 152 pcmbuf += fmt->channels;
154 } 153 }
155 } 154 }
@@ -175,9 +174,9 @@ static inline void decode_4bit(const uint8_t **inbuf,
175 pcmbuf = *outbuf + ch; 174 pcmbuf = *outbuf + ch;
176 for (i = 0; i < 4; i++) 175 for (i = 0; i < 4; i++)
177 { 176 {
178 *pcmbuf = create_pcmdata_size4(ch, **inbuf ) << 13; 177 *pcmbuf = create_pcmdata_size4(ch, **inbuf ) << IMA_ADPCM_INC_DEPTH;
179 pcmbuf += fmt->channels; 178 pcmbuf += fmt->channels;
180 *pcmbuf = create_pcmdata_size4(ch, **inbuf >> 4) << 13; 179 *pcmbuf = create_pcmdata_size4(ch, **inbuf >> 4) << IMA_ADPCM_INC_DEPTH;
181 pcmbuf += fmt->channels; 180 pcmbuf += fmt->channels;
182 (*inbuf)++; 181 (*inbuf)++;
183 } 182 }
@@ -212,7 +211,7 @@ static inline void decode_5bit(const uint8_t **inbuf,
212 adpcms |= (uint64_t)(*adpcmbuf++) << 32; 211 adpcms |= (uint64_t)(*adpcmbuf++) << 32;
213 for (i = 0; i < 8; i++) 212 for (i = 0; i < 8; i++)
214 { 213 {
215 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << 13; 214 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << IMA_ADPCM_INC_DEPTH;
216 pcmbuf += fmt->channels; 215 pcmbuf += fmt->channels;
217 } 216 }
218 adpcms = *adpcmbuf++; 217 adpcms = *adpcmbuf++;
@@ -223,7 +222,7 @@ static inline void decode_5bit(const uint8_t **inbuf,
223 adpcms |= (uint64_t)(*adpcmbuf++) << 32; 222 adpcms |= (uint64_t)(*adpcmbuf++) << 32;
224 for (i = 0; i < 8; i++) 223 for (i = 0; i < 8; i++)
225 { 224 {
226 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << 13; 225 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << IMA_ADPCM_INC_DEPTH;
227 pcmbuf += fmt->channels; 226 pcmbuf += fmt->channels;
228 } 227 }
229 adpcms = *adpcmbuf++; 228 adpcms = *adpcmbuf++;
@@ -234,7 +233,7 @@ static inline void decode_5bit(const uint8_t **inbuf,
234 adpcms |= (uint64_t)(*adpcmbuf++) << 32; 233 adpcms |= (uint64_t)(*adpcmbuf++) << 32;
235 for (i = 0; i < 8; i++) 234 for (i = 0; i < 8; i++)
236 { 235 {
237 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << 13; 236 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << IMA_ADPCM_INC_DEPTH;
238 pcmbuf += fmt->channels; 237 pcmbuf += fmt->channels;
239 } 238 }
240 adpcms = *adpcmbuf++; 239 adpcms = *adpcmbuf++;
@@ -245,7 +244,7 @@ static inline void decode_5bit(const uint8_t **inbuf,
245 adpcms |= (uint64_t)(*adpcmbuf++) << 32; 244 adpcms |= (uint64_t)(*adpcmbuf++) << 32;
246 for (i = 0; i < 8; i++) 245 for (i = 0; i < 8; i++)
247 { 246 {
248 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << 13; 247 *pcmbuf = create_pcmdata(ch, adpcms >> (5 * i)) << IMA_ADPCM_INC_DEPTH;
249 pcmbuf += fmt->channels; 248 pcmbuf += fmt->channels;
250 } 249 }
251 } 250 }
@@ -283,7 +282,7 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
283 } 282 }
284 inbuf += 4; 283 inbuf += 4;
285 284
286 *outbuf++ = init_pcmdata[ch] << 13; 285 *outbuf++ = init_pcmdata[ch] << IMA_ADPCM_INC_DEPTH;
287 } 286 }
288 287
289 *outbufcount += 1; 288 *outbufcount += 1;
diff --git a/apps/codecs/libpcm/ima_adpcm_common.h b/apps/codecs/libpcm/ima_adpcm_common.h
index 65cfefcfa3..0a2129bdf2 100644
--- a/apps/codecs/libpcm/ima_adpcm_common.h
+++ b/apps/codecs/libpcm/ima_adpcm_common.h
@@ -25,6 +25,8 @@
25#include <stdbool.h> 25#include <stdbool.h>
26#include <inttypes.h> 26#include <inttypes.h>
27 27
28#define IMA_ADPCM_INC_DEPTH (PCM_OUTPUT_DEPTH - 16)
29
28void init_ima_adpcm_decoder(int bit, const int *index_table); 30void init_ima_adpcm_decoder(int bit, const int *index_table);
29void set_decode_parameters(int channels, int32_t *init_pcmdata, int8_t *init_index); 31void set_decode_parameters(int channels, int32_t *init_pcmdata, int8_t *init_index);
30int16_t create_pcmdata(int ch, uint8_t nibble); 32int16_t create_pcmdata(int ch, uint8_t nibble);
diff --git a/apps/codecs/libpcm/itut_g711.c b/apps/codecs/libpcm/itut_g711.c
index 9a38031882..4644a9c694 100644
--- a/apps/codecs/libpcm/itut_g711.c
+++ b/apps/codecs/libpcm/itut_g711.c
@@ -20,7 +20,6 @@
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/*
@@ -154,7 +153,7 @@ static int decode_alaw(const uint8_t *inbuf, size_t inbufsize,
154 uint32_t i; 153 uint32_t i;
155 154
156 for (i = 0; i < inbufsize; i++) 155 for (i = 0; i < inbufsize; i++)
157 outbuf[i] = alaw2linear16[inbuf[i]] << 13; 156 outbuf[i] = alaw2linear16[inbuf[i]] << (PCM_OUTPUT_DEPTH - 16);
158 157
159 *outbufsize = (fmt->channels == 2) ? (inbufsize >> 1) : inbufsize; 158 *outbufsize = (fmt->channels == 2) ? (inbufsize >> 1) : inbufsize;
160 159
@@ -167,7 +166,7 @@ static int decode_mulaw(const uint8_t *inbuf, size_t inbufsize,
167 uint32_t i; 166 uint32_t i;
168 167
169 for (i = 0; i < inbufsize; i++) 168 for (i = 0; i < inbufsize; i++)
170 outbuf[i] = ulaw2linear16[inbuf[i]] << 13; 169 outbuf[i] = ulaw2linear16[inbuf[i]] << (PCM_OUTPUT_DEPTH - 16);
171 170
172 *outbufsize = (fmt->channels == 2) ? (inbufsize >> 1) : inbufsize; 171 *outbufsize = (fmt->channels == 2) ? (inbufsize >> 1) : inbufsize;
173 172
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
30static struct pcm_format *fmt; 35static struct pcm_format *fmt;
31 36
32static bool set_format(struct pcm_format *format) 37static 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
79static inline void decode_u8(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 84static 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
96static inline void decode_u16le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 101static 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
104static inline void decode_s16be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 109static 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
112static inline void decode_u16be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 117static 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
129static inline void decode_u24le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 135static 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
137static inline void decode_s24be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 144static 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
145static inline void decode_u24be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 153static 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
162static inline void decode_u32le(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 172static 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
170static inline void decode_s32be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 181static 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
178static inline void decode_u32be(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf) 190static 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
186static int decode(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf, int *outbufcount) 199static int decode(const uint8_t *inbuf, size_t inbufsize, int32_t *outbuf, int *outbufcount)
diff --git a/apps/codecs/libpcm/ms_adpcm.c b/apps/codecs/libpcm/ms_adpcm.c
index 7f1cb1c811..79365807ef 100644
--- a/apps/codecs/libpcm/ms_adpcm.c
+++ b/apps/codecs/libpcm/ms_adpcm.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "codeclib.h" 21#include "codeclib.h"
22#include "pcm_common.h"
23#include "support_formats.h" 22#include "support_formats.h"
24 23
25/* 24/*
@@ -138,8 +137,8 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
138 137
139 while (size-- > 0) 138 while (size-- > 0)
140 { 139 {
141 *outbuf++ = create_pcmdata(0, *inbuf >> 4 ) << 13; 140 *outbuf++ = create_pcmdata(0, *inbuf >> 4 ) << (PCM_OUTPUT_DEPTH - 16);
142 *outbuf++ = create_pcmdata(ch, *inbuf & 0xf) << 13; 141 *outbuf++ = create_pcmdata(ch, *inbuf & 0xf) << (PCM_OUTPUT_DEPTH - 16);
143 nsamples += 2; 142 nsamples += 2;
144 143
145 inbuf++; 144 inbuf++;
diff --git a/apps/codecs/libpcm/pcm_common.h b/apps/codecs/libpcm/pcm_common.h
index 7dcacbd19a..b303273667 100644
--- a/apps/codecs/libpcm/pcm_common.h
+++ b/apps/codecs/libpcm/pcm_common.h
@@ -25,6 +25,9 @@
25#include <stdbool.h> 25#include <stdbool.h>
26#include <inttypes.h> 26#include <inttypes.h>
27 27
28/* decoded pcm sample depth */
29#define PCM_OUTPUT_DEPTH 28
30
28/* Macro that sign extends an unsigned byte */ 31/* Macro that sign extends an unsigned byte */
29#define SE(x) ((int32_t)((int8_t)(x))) 32#define SE(x) ((int32_t)((int8_t)(x)))
30 33
diff --git a/apps/codecs/libpcm/qt_ima_adpcm.c b/apps/codecs/libpcm/qt_ima_adpcm.c
index e99a91796d..003de22dd8 100644
--- a/apps/codecs/libpcm/qt_ima_adpcm.c
+++ b/apps/codecs/libpcm/qt_ima_adpcm.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "codeclib.h" 21#include "codeclib.h"
22#include "pcm_common.h"
23#include "ima_adpcm_common.h" 22#include "ima_adpcm_common.h"
24#include "support_formats.h" 23#include "support_formats.h"
25 24
@@ -107,9 +106,9 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
107 pcmbuf = outbuf + ch; 106 pcmbuf = outbuf + ch;
108 for (block_size = 32; block_size > 0 && inbufsize > 0; block_size--, inbufsize--) 107 for (block_size = 32; block_size > 0 && inbufsize > 0; block_size--, inbufsize--)
109 { 108 {
110 *pcmbuf = create_pcmdata_size4(ch, *inbuf ) << 13; 109 *pcmbuf = create_pcmdata_size4(ch, *inbuf ) << IMA_ADPCM_INC_DEPTH;
111 pcmbuf += fmt->channels; 110 pcmbuf += fmt->channels;
112 *pcmbuf = create_pcmdata_size4(ch, *inbuf >> 4) << 13; 111 *pcmbuf = create_pcmdata_size4(ch, *inbuf >> 4) << IMA_ADPCM_INC_DEPTH;
113 pcmbuf += fmt->channels; 112 pcmbuf += fmt->channels;
114 nsamples += 2; 113 nsamples += 2;
115 inbuf++; 114 inbuf++;
diff --git a/apps/codecs/libpcm/swf_adpcm.c b/apps/codecs/libpcm/swf_adpcm.c
index 9acab5cb4b..3441c667d4 100644
--- a/apps/codecs/libpcm/swf_adpcm.c
+++ b/apps/codecs/libpcm/swf_adpcm.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "codeclib.h" 21#include "codeclib.h"
22#include "pcm_common.h"
23#include "ima_adpcm_common.h" 22#include "ima_adpcm_common.h"
24#include "support_formats.h" 23#include "support_formats.h"
25 24
@@ -193,18 +192,20 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
193 init_pcmdata[1] -= 65536; 192 init_pcmdata[1] -= 65536;
194 } 193 }
195 194
196 *outbuf++ = init_pcmdata[0] << 13; 195 *outbuf++ = init_pcmdata[0] << IMA_ADPCM_INC_DEPTH;
197 if (ch > 0) 196 if (ch > 0)
198 *outbuf++ = init_pcmdata[1] << 13; 197 *outbuf++ = init_pcmdata[1] << IMA_ADPCM_INC_DEPTH;
199 198
200 set_decode_parameters(fmt->channels, init_pcmdata, init_index); 199 set_decode_parameters(fmt->channels, init_pcmdata, init_index);
201 200
202 /* read block data */ 201 /* read block data */
203 while (--count > 0) 202 while (--count > 0)
204 { 203 {
205 *outbuf++ = create_pcmdata(0, get_data(&inbuf, fmt->bitspersample)) << 13; 204 *outbuf++ = create_pcmdata(0, get_data(&inbuf, fmt->bitspersample))
205 << IMA_ADPCM_INC_DEPTH;
206 if (ch > 0) 206 if (ch > 0)
207 *outbuf++ = create_pcmdata(ch, get_data(&inbuf, fmt->bitspersample)) << 13; 207 *outbuf++ = create_pcmdata(ch, get_data(&inbuf, fmt->bitspersample))
208 << IMA_ADPCM_INC_DEPTH;
208 } 209 }
209 210
210 *outbufcount = fmt->samplesperblock; 211 *outbufcount = fmt->samplesperblock;
diff --git a/apps/codecs/libpcm/yamaha_adpcm.c b/apps/codecs/libpcm/yamaha_adpcm.c
index 073a1dc703..9f1a4742ee 100644
--- a/apps/codecs/libpcm/yamaha_adpcm.c
+++ b/apps/codecs/libpcm/yamaha_adpcm.c
@@ -19,7 +19,6 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "codeclib.h" 21#include "codeclib.h"
22#include "pcm_common.h"
23#include "adpcm_seek.h" 22#include "adpcm_seek.h"
24#include "support_formats.h" 23#include "support_formats.h"
25 24
@@ -173,8 +172,8 @@ static int decode(const uint8_t *inbuf, size_t inbufsize,
173 ch = fmt->channels - 1; 172 ch = fmt->channels - 1;
174 while (inbufsize) 173 while (inbufsize)
175 { 174 {
176 *outbuf++ = create_pcmdata(0, *inbuf ) << 13; 175 *outbuf++ = create_pcmdata(0, *inbuf ) << (PCM_OUTPUT_DEPTH - 16);
177 *outbuf++ = create_pcmdata(ch, *inbuf >> 4) << 13; 176 *outbuf++ = create_pcmdata(ch, *inbuf >> 4) << (PCM_OUTPUT_DEPTH - 16);
178 nsamples += 2; 177 nsamples += 2;
179 178
180 inbuf++; 179 inbuf++;
diff --git a/apps/codecs/smaf.c b/apps/codecs/smaf.c
index cd1155bf7b..019552ed4b 100644
--- a/apps/codecs/smaf.c
+++ b/apps/codecs/smaf.c
@@ -285,7 +285,7 @@ enum codec_status codec_main(void)
285 const struct pcm_codec *codec; 285 const struct pcm_codec *codec;
286 286
287 /* Generic codec initialisation */ 287 /* Generic codec initialisation */
288 ci->configure(DSP_SET_SAMPLE_DEPTH, 28); 288 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
289 289
290next_track: 290next_track:
291 if (codec_init()) { 291 if (codec_init()) {
diff --git a/apps/codecs/vox.c b/apps/codecs/vox.c
index 44701fafb8..290fae0800 100644
--- a/apps/codecs/vox.c
+++ b/apps/codecs/vox.c
@@ -57,7 +57,7 @@ enum codec_status codec_main(void)
57 int offset = 0; 57 int offset = 0;
58 58
59 /* Generic codec initialisation */ 59 /* Generic codec initialisation */
60 ci->configure(DSP_SET_SAMPLE_DEPTH, 28); 60 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
61 61
62next_track: 62next_track:
63 if (codec_init()) { 63 if (codec_init()) {
diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c
index c2564231c1..412d548817 100644
--- a/apps/codecs/wav.c
+++ b/apps/codecs/wav.c
@@ -165,7 +165,7 @@ enum codec_status codec_main(void)
165 const struct pcm_codec *codec; 165 const struct pcm_codec *codec;
166 166
167 /* Generic codec initialisation */ 167 /* Generic codec initialisation */
168 ci->configure(DSP_SET_SAMPLE_DEPTH, 28); 168 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
169 169
170next_track: 170next_track:
171 if (codec_init()) { 171 if (codec_init()) {
diff --git a/apps/codecs/wav64.c b/apps/codecs/wav64.c
index e607a86a96..bd2311cc8e 100644
--- a/apps/codecs/wav64.c
+++ b/apps/codecs/wav64.c
@@ -174,7 +174,7 @@ enum codec_status codec_main(void)
174 uint64_t size; 174 uint64_t size;
175 175
176 /* Generic codec initialisation */ 176 /* Generic codec initialisation */
177 ci->configure(DSP_SET_SAMPLE_DEPTH, 28); 177 ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
178 178
179next_track: 179next_track:
180 if (codec_init()) { 180 if (codec_init()) {