diff options
author | Tom Ross <midgey@rockbox.org> | 2010-02-03 00:37:24 +0000 |
---|---|---|
committer | Tom Ross <midgey@rockbox.org> | 2010-02-03 00:37:24 +0000 |
commit | db64bf9ea47e8e3fca22f428e3289e1618cdaeac (patch) | |
tree | 0c34a44c58bbcb3d1da13212f481e00e11f84394 /apps/codecs/libalac/alac.c | |
parent | b2ffb3e08f3154b61f35b2eb1243e8e57e62f298 (diff) | |
download | rockbox-db64bf9ea47e8e3fca22f428e3289e1618cdaeac.tar.gz rockbox-db64bf9ea47e8e3fca22f428e3289e1618cdaeac.zip |
FS #10690: Add support for 24 bit ALAC files based on libalac 0.2.0
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24475 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libalac/alac.c')
-rw-r--r-- | apps/codecs/libalac/alac.c | 467 |
1 files changed, 280 insertions, 187 deletions
diff --git a/apps/codecs/libalac/alac.c b/apps/codecs/libalac/alac.c index 1f7867b648..a7d7448b97 100644 --- a/apps/codecs/libalac/alac.c +++ b/apps/codecs/libalac/alac.c | |||
@@ -38,6 +38,8 @@ | |||
38 | #include "codeclib.h" | 38 | #include "codeclib.h" |
39 | #include "decomp.h" | 39 | #include "decomp.h" |
40 | 40 | ||
41 | #define SIGNEXTEND24(val) (((signed)val<<8)>>8) | ||
42 | |||
41 | int16_t predictor_coef_table[32] IBSS_ATTR; | 43 | int16_t predictor_coef_table[32] IBSS_ATTR; |
42 | int16_t predictor_coef_table_a[32] IBSS_ATTR; | 44 | int16_t predictor_coef_table_a[32] IBSS_ATTR; |
43 | int16_t predictor_coef_table_b[32] IBSS_ATTR; | 45 | int16_t predictor_coef_table_b[32] IBSS_ATTR; |
@@ -168,143 +170,128 @@ static inline void unreadbits(alac_file *alac, int bits) | |||
168 | 170 | ||
169 | #define count_leading_zeros(x) bs_generic(x, BS_CLZ|BS_SHORT) | 171 | #define count_leading_zeros(x) bs_generic(x, BS_CLZ|BS_SHORT) |
170 | 172 | ||
171 | void basterdised_rice_decompress(alac_file *alac, | 173 | #define RICE_THRESHOLD 8 // maximum number of bits for a rice prefix. |
172 | int32_t *output_buffer, | ||
173 | int output_size, | ||
174 | int readsamplesize, /* arg_10 */ | ||
175 | int rice_initialhistory, /* arg424->b */ | ||
176 | int rice_kmodifier, /* arg424->d */ | ||
177 | int rice_historymult, /* arg424->c */ | ||
178 | int rice_kmodifier_mask /* arg424->e */ | ||
179 | ) ICODE_ATTR_ALAC; | ||
180 | void basterdised_rice_decompress(alac_file *alac, | ||
181 | int32_t *output_buffer, | ||
182 | int output_size, | ||
183 | int readsamplesize, /* arg_10 */ | ||
184 | int rice_initialhistory, /* arg424->b */ | ||
185 | int rice_kmodifier, /* arg424->d */ | ||
186 | int rice_historymult, /* arg424->c */ | ||
187 | int rice_kmodifier_mask /* arg424->e */ | ||
188 | ) | ||
189 | { | ||
190 | int output_count; | ||
191 | unsigned int history = rice_initialhistory; | ||
192 | int sign_modifier = 0; | ||
193 | 174 | ||
194 | for (output_count = 0; output_count < output_size; output_count++) | 175 | static inline int32_t entropy_decode_value(alac_file* alac, |
176 | int readsamplesize, | ||
177 | int k) ICODE_ATTR_ALAC; | ||
178 | static inline int32_t entropy_decode_value(alac_file* alac, | ||
179 | int readsamplesize, | ||
180 | int k) | ||
181 | { | ||
182 | int32_t x = 0; // decoded value | ||
183 | |||
184 | // read x, number of 1s before 0 represent the rice value. | ||
185 | while (x <= RICE_THRESHOLD && readbit(alac)) | ||
195 | { | 186 | { |
196 | int32_t x = 0; | 187 | x++; |
197 | int32_t x_modified; | 188 | } |
198 | int32_t final_val; | 189 | |
199 | 190 | if (x > RICE_THRESHOLD) | |
200 | /* read x - number of 1s before 0 represent the rice */ | 191 | { |
201 | while (x <= 8 && readbit(alac)) | 192 | // read the number from the bit stream (raw value) |
193 | int32_t value; | ||
194 | |||
195 | value = readbits(alac, readsamplesize); | ||
196 | |||
197 | /* mask value to readsamplesize size */ | ||
198 | if (readsamplesize != 32) | ||
199 | value &= (((uint32_t)0xffffffff) >> (32 - readsamplesize)); | ||
200 | |||
201 | x = value; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | if (k != 1) | ||
202 | { | 206 | { |
203 | x++; | 207 | int extrabits = readbits(alac, k); |
204 | } | 208 | |
205 | 209 | // x = x * (2^k - 1) | |
206 | 210 | x = (x << k) - x; | |
207 | if (x > 8) /* RICE THRESHOLD */ | 211 | |
208 | { /* use alternative encoding */ | 212 | if (extrabits > 1) |
209 | int32_t value; | 213 | x += extrabits - 1; |
210 | 214 | else | |
211 | value = readbits(alac, readsamplesize); | 215 | unreadbits(alac, 1); |
212 | |||
213 | /* mask value to readsamplesize size */ | ||
214 | if (readsamplesize != 32) | ||
215 | value &= (0xffffffff >> (32 - readsamplesize)); | ||
216 | |||
217 | x = value; | ||
218 | } | ||
219 | else | ||
220 | { /* standard rice encoding */ | ||
221 | int extrabits; | ||
222 | int k; /* size of extra bits */ | ||
223 | |||
224 | /* read k, that is bits as is */ | ||
225 | k = 31 - rice_kmodifier - count_leading_zeros((history >> 9) + 3); | ||
226 | |||
227 | if (k < 0) k += rice_kmodifier; | ||
228 | else k = rice_kmodifier; | ||
229 | |||
230 | if (k != 1) | ||
231 | { | ||
232 | extrabits = readbits(alac, k); | ||
233 | |||
234 | /* multiply x by 2^k - 1, as part of their strange algorithm */ | ||
235 | x = (x << k) - x; | ||
236 | |||
237 | if (extrabits > 1) | ||
238 | { | ||
239 | x += extrabits - 1; | ||
240 | } | ||
241 | else unreadbits(alac, 1); | ||
242 | } | ||
243 | } | 216 | } |
217 | } | ||
218 | |||
219 | return x; | ||
220 | } | ||
244 | 221 | ||
245 | x_modified = sign_modifier + x; | 222 | static void entropy_rice_decode(alac_file* alac, |
246 | final_val = (x_modified + 1) / 2; | 223 | int32_t* output_buffer, |
247 | if (x_modified & 1) final_val *= -1; | 224 | int output_size, |
248 | 225 | int readsamplesize, | |
249 | output_buffer[output_count] = final_val; | 226 | int rice_initialhistory, |
250 | 227 | int rice_kmodifier, | |
228 | int rice_historymult, | ||
229 | int rice_kmodifier_mask) ICODE_ATTR_ALAC; | ||
230 | static void entropy_rice_decode(alac_file* alac, | ||
231 | int32_t* output_buffer, | ||
232 | int output_size, | ||
233 | int readsamplesize, | ||
234 | int rice_initialhistory, | ||
235 | int rice_kmodifier, | ||
236 | int rice_historymult, | ||
237 | int rice_kmodifier_mask) | ||
238 | { | ||
239 | int output_count; | ||
240 | int history = rice_initialhistory; | ||
241 | int sign_modifier = 0; | ||
242 | |||
243 | for (output_count = 0; output_count < output_size; output_count++) | ||
244 | { | ||
245 | int32_t decoded_value; | ||
246 | int32_t final_value; | ||
247 | int32_t k; | ||
248 | |||
249 | k = 31 - rice_kmodifier - count_leading_zeros((history >> 9) + 3); | ||
250 | |||
251 | if (k < 0) k += rice_kmodifier; | ||
252 | else k = rice_kmodifier; | ||
253 | |||
254 | decoded_value = entropy_decode_value(alac, readsamplesize, k); | ||
255 | |||
256 | decoded_value += sign_modifier; | ||
257 | final_value = (decoded_value + 1) / 2; // inc by 1 and shift out sign bit | ||
258 | if (decoded_value & 1) // the sign is stored in the low bit | ||
259 | final_value *= -1; | ||
260 | |||
261 | output_buffer[output_count] = final_value; | ||
262 | |||
251 | sign_modifier = 0; | 263 | sign_modifier = 0; |
252 | 264 | ||
253 | /* now update the history */ | 265 | // update history |
254 | history += (x_modified * rice_historymult) | 266 | history += (decoded_value * rice_historymult) |
255 | - ((history * rice_historymult) >> 9); | 267 | - ((history * rice_historymult) >> 9); |
256 | 268 | ||
257 | if (x_modified > 0xffff) | 269 | if (decoded_value > 0xFFFF) |
258 | history = 0xffff; | 270 | history = 0xFFFF; |
259 | 271 | ||
260 | /* special case: there may be compressed blocks of 0 */ | 272 | // special case, for compressed blocks of 0 |
261 | if ((history < 128) && (output_count+1 < output_size)) | 273 | if ((history < 128) && (output_count + 1 < output_size)) |
262 | { | 274 | { |
263 | int block_size; | 275 | int32_t block_size; |
264 | 276 | ||
265 | sign_modifier = 1; | 277 | sign_modifier = 1; |
266 | 278 | ||
267 | x = 0; | 279 | k = count_leading_zeros(history) + ((history + 16) / 64) - 24; |
268 | while (x <= 8 && readbit(alac)) | 280 | |
269 | { | 281 | // note: block_size is always 16bit |
270 | x++; | 282 | block_size = entropy_decode_value(alac, 16, k) & rice_kmodifier_mask; |
271 | } | 283 | |
272 | 284 | // got block_size 0s | |
273 | if (x > 8) | ||
274 | { | ||
275 | block_size = readbits(alac, 16); | ||
276 | block_size &= 0xffff; | ||
277 | } | ||
278 | else | ||
279 | { | ||
280 | int k; | ||
281 | int extrabits; | ||
282 | |||
283 | k = count_leading_zeros(history) + ((history + 16) >> 6 /* / 64 */) - 24; | ||
284 | |||
285 | extrabits = readbits(alac, k); | ||
286 | |||
287 | block_size = (((1 << k) - 1) & rice_kmodifier_mask) * x | ||
288 | + extrabits - 1; | ||
289 | |||
290 | if (extrabits < 2) | ||
291 | { | ||
292 | x = 1 - extrabits; | ||
293 | block_size += x; | ||
294 | unreadbits(alac, 1); | ||
295 | } | ||
296 | } | ||
297 | |||
298 | if (block_size > 0) | 285 | if (block_size > 0) |
299 | { | 286 | { |
300 | memset(&output_buffer[output_count+1], 0, block_size * 4); | 287 | memset(&output_buffer[output_count + 1], 0, |
288 | block_size * sizeof(*output_buffer)); | ||
301 | output_count += block_size; | 289 | output_count += block_size; |
302 | |||
303 | } | 290 | } |
304 | 291 | ||
305 | if (block_size > 0xffff) | 292 | if (block_size > 0xFFFF) |
306 | sign_modifier = 0; | 293 | sign_modifier = 0; |
307 | 294 | ||
308 | history = 0; | 295 | history = 0; |
309 | } | 296 | } |
310 | } | 297 | } |
@@ -632,6 +619,72 @@ void deinterlace_16(int32_t* buffer0, | |||
632 | } | 619 | } |
633 | } | 620 | } |
634 | 621 | ||
622 | void deinterlace_24(int32_t *buffer0, int32_t *buffer1, | ||
623 | int uncompressed_bytes, | ||
624 | int32_t *uncompressed_bytes_buffer0, | ||
625 | int32_t *uncompressed_bytes_buffer1, | ||
626 | int numsamples, | ||
627 | uint8_t interlacing_shift, | ||
628 | uint8_t interlacing_leftweight) ICODE_ATTR_ALAC; | ||
629 | void deinterlace_24(int32_t *buffer0, int32_t *buffer1, | ||
630 | int uncompressed_bytes, | ||
631 | int32_t *uncompressed_bytes_buffer0, | ||
632 | int32_t *uncompressed_bytes_buffer1, | ||
633 | int numsamples, | ||
634 | uint8_t interlacing_shift, | ||
635 | uint8_t interlacing_leftweight) | ||
636 | { | ||
637 | int i; | ||
638 | if (numsamples <= 0) return; | ||
639 | |||
640 | /* weighted interlacing */ | ||
641 | if (interlacing_leftweight) | ||
642 | { | ||
643 | for (i = 0; i < numsamples; i++) | ||
644 | { | ||
645 | int32_t difference, midright; | ||
646 | |||
647 | midright = buffer0[i]; | ||
648 | difference = buffer1[i]; | ||
649 | |||
650 | buffer0[i] = ((midright - ((difference * interlacing_leftweight) | ||
651 | >> interlacing_shift)) + difference) << SCALE24; | ||
652 | buffer1[i] = (midright - ((difference * interlacing_leftweight) | ||
653 | >> interlacing_shift)) << SCALE24; | ||
654 | |||
655 | if (uncompressed_bytes) | ||
656 | { | ||
657 | uint32_t mask = ~(0xFFFFFFFF << (uncompressed_bytes * 8)); | ||
658 | buffer0[i] <<= (uncompressed_bytes * 8); | ||
659 | buffer1[i] <<= (uncompressed_bytes * 8); | ||
660 | |||
661 | buffer0[i] |= uncompressed_bytes_buffer0[i] & mask; | ||
662 | buffer1[i] |= uncompressed_bytes_buffer1[i] & mask; | ||
663 | } | ||
664 | |||
665 | } | ||
666 | |||
667 | return; | ||
668 | } | ||
669 | |||
670 | /* otherwise basic interlacing took place */ | ||
671 | for (i = 0; i < numsamples; i++) | ||
672 | { | ||
673 | if (uncompressed_bytes) | ||
674 | { | ||
675 | uint32_t mask = ~(0xFFFFFFFF << (uncompressed_bytes * 8)); | ||
676 | buffer0[i] <<= (uncompressed_bytes * 8); | ||
677 | buffer1[i] <<= (uncompressed_bytes * 8); | ||
678 | |||
679 | buffer0[i] |= uncompressed_bytes_buffer0[i] & mask; | ||
680 | buffer1[i] |= uncompressed_bytes_buffer1[i] & mask; | ||
681 | } | ||
682 | |||
683 | buffer0[i] = buffer0[i] << SCALE24; | ||
684 | buffer1[i] = buffer1[i] << SCALE24; | ||
685 | } | ||
686 | |||
687 | } | ||
635 | 688 | ||
636 | static inline int decode_frame_mono( | 689 | static inline int decode_frame_mono( |
637 | alac_file *alac, | 690 | alac_file *alac, |
@@ -641,9 +694,10 @@ static inline int decode_frame_mono( | |||
641 | int hassize; | 694 | int hassize; |
642 | int isnotcompressed; | 695 | int isnotcompressed; |
643 | int readsamplesize; | 696 | int readsamplesize; |
697 | int infosamplesize = alac->setinfo_sample_size; | ||
644 | int outputsamples = alac->setinfo_max_samples_per_frame; | 698 | int outputsamples = alac->setinfo_max_samples_per_frame; |
645 | 699 | ||
646 | int wasted_bytes; | 700 | int uncompressed_bytes; |
647 | int ricemodifier; | 701 | int ricemodifier; |
648 | 702 | ||
649 | 703 | ||
@@ -656,7 +710,8 @@ static inline int decode_frame_mono( | |||
656 | 710 | ||
657 | hassize = readbits(alac, 1); /* the output sample size is stored soon */ | 711 | hassize = readbits(alac, 1); /* the output sample size is stored soon */ |
658 | 712 | ||
659 | wasted_bytes = readbits(alac, 2); /* unknown ? */ | 713 | /* number of bytes in the (compressed) stream that are not compressed */ |
714 | uncompressed_bytes = readbits(alac, 2); | ||
660 | 715 | ||
661 | isnotcompressed = readbits(alac, 1); /* whether the frame is compressed */ | 716 | isnotcompressed = readbits(alac, 1); /* whether the frame is compressed */ |
662 | 717 | ||
@@ -667,7 +722,7 @@ static inline int decode_frame_mono( | |||
667 | outputsamples = readbits(alac, 32); | 722 | outputsamples = readbits(alac, 32); |
668 | } | 723 | } |
669 | 724 | ||
670 | readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8); | 725 | readsamplesize = infosamplesize - (uncompressed_bytes * 8); |
671 | 726 | ||
672 | if (!isnotcompressed) | 727 | if (!isnotcompressed) |
673 | { /* so it is compressed */ | 728 | { /* so it is compressed */ |
@@ -693,24 +748,26 @@ static inline int decode_frame_mono( | |||
693 | predictor_coef_table[i] = (int16_t)readbits(alac, 16); | 748 | predictor_coef_table[i] = (int16_t)readbits(alac, 16); |
694 | } | 749 | } |
695 | 750 | ||
696 | if (wasted_bytes) | 751 | if (uncompressed_bytes) |
697 | { | 752 | { |
698 | /* these bytes seem to have something to do with | 753 | int i; |
699 | * > 2 channel files. | 754 | for (i = 0; i < outputsamples; i++) |
700 | */ | 755 | { |
701 | //fprintf(stderr, "FIXME: unimplemented, unhandling of wasted_bytes\n"); | 756 | outputbuffer[0][i] = readbits(alac, uncompressed_bytes * 8); |
757 | outputbuffer[1][i] = outputbuffer[0][i]; | ||
758 | } | ||
702 | } | 759 | } |
703 | 760 | ||
704 | yield(); | 761 | yield(); |
705 | 762 | ||
706 | basterdised_rice_decompress(alac, | 763 | entropy_rice_decode(alac, |
707 | outputbuffer[0], | 764 | outputbuffer[0], |
708 | outputsamples, | 765 | outputsamples, |
709 | readsamplesize, | 766 | readsamplesize, |
710 | alac->setinfo_rice_initialhistory, | 767 | alac->setinfo_rice_initialhistory, |
711 | alac->setinfo_rice_kmodifier, | 768 | alac->setinfo_rice_kmodifier, |
712 | ricemodifier * alac->setinfo_rice_historymult / 4, | 769 | ricemodifier * alac->setinfo_rice_historymult / 4, |
713 | (1 << alac->setinfo_rice_kmodifier) - 1); | 770 | (1 << alac->setinfo_rice_kmodifier) - 1); |
714 | 771 | ||
715 | yield(); | 772 | yield(); |
716 | 773 | ||
@@ -738,14 +795,14 @@ static inline int decode_frame_mono( | |||
738 | } | 795 | } |
739 | else | 796 | else |
740 | { /* not compressed, easy case */ | 797 | { /* not compressed, easy case */ |
741 | if (readsamplesize <= 16) | 798 | if (infosamplesize <= 16) |
742 | { | 799 | { |
743 | int i; | 800 | int i; |
744 | for (i = 0; i < outputsamples; i++) | 801 | for (i = 0; i < outputsamples; i++) |
745 | { | 802 | { |
746 | int32_t audiobits = readbits(alac, readsamplesize); | 803 | int32_t audiobits = readbits(alac, infosamplesize); |
747 | 804 | ||
748 | audiobits = SIGN_EXTENDED32(audiobits, readsamplesize); | 805 | audiobits = SIGN_EXTENDED32(audiobits, infosamplesize); |
749 | 806 | ||
750 | outputbuffer[0][i] = audiobits; | 807 | outputbuffer[0][i] = audiobits; |
751 | } | 808 | } |
@@ -760,20 +817,19 @@ static inline int decode_frame_mono( | |||
760 | audiobits = readbits(alac, 16); | 817 | audiobits = readbits(alac, 16); |
761 | /* special case of sign extension.. | 818 | /* special case of sign extension.. |
762 | * as we'll be ORing the low 16bits into this */ | 819 | * as we'll be ORing the low 16bits into this */ |
763 | audiobits = audiobits << 16; | 820 | audiobits = audiobits << (infosamplesize - 16); |
764 | audiobits = audiobits >> (32 - readsamplesize); | 821 | audiobits |= readbits(alac, infosamplesize - 16); |
765 | 822 | audiobits = SIGNEXTEND24(audiobits); | |
766 | audiobits |= readbits(alac, readsamplesize - 16); | ||
767 | 823 | ||
768 | outputbuffer[0][i] = audiobits; | 824 | outputbuffer[0][i] = audiobits; |
769 | } | 825 | } |
770 | } | 826 | } |
771 | /* wasted_bytes = 0; // unused */ | 827 | uncompressed_bytes = 0; // always 0 for uncompressed |
772 | } | 828 | } |
773 | 829 | ||
774 | yield(); | 830 | yield(); |
775 | 831 | ||
776 | switch(alac->setinfo_sample_size) | 832 | switch(infosamplesize) |
777 | { | 833 | { |
778 | case 16: | 834 | case 16: |
779 | { | 835 | { |
@@ -786,10 +842,29 @@ static inline int decode_frame_mono( | |||
786 | } | 842 | } |
787 | break; | 843 | break; |
788 | } | 844 | } |
789 | case 20: | ||
790 | case 24: | 845 | case 24: |
846 | { | ||
847 | int i; | ||
848 | for (i = 0; i < outputsamples; i++) | ||
849 | { | ||
850 | int32_t sample = outputbuffer[0][i]; | ||
851 | |||
852 | if (uncompressed_bytes) | ||
853 | { | ||
854 | uint32_t mask; | ||
855 | sample = sample << (uncompressed_bytes * 8); | ||
856 | mask = ~(0xFFFFFFFF << (uncompressed_bytes * 8)); | ||
857 | sample |= outputbuffer[0][i] & mask; | ||
858 | } | ||
859 | |||
860 | outputbuffer[0][i] = sample << SCALE24; | ||
861 | outputbuffer[1][i] = outputbuffer[0][i]; | ||
862 | } | ||
863 | break; | ||
864 | } | ||
865 | case 20: | ||
791 | case 32: | 866 | case 32: |
792 | //fprintf(stderr, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); | 867 | //fprintf(stderr, "FIXME: unimplemented sample size %i\n", infosamplesize); |
793 | break; | 868 | break; |
794 | default: | 869 | default: |
795 | break; | 870 | break; |
@@ -806,8 +881,9 @@ static inline int decode_frame_stereo( | |||
806 | int hassize; | 881 | int hassize; |
807 | int isnotcompressed; | 882 | int isnotcompressed; |
808 | int readsamplesize; | 883 | int readsamplesize; |
884 | int infosamplesize = alac->setinfo_sample_size; | ||
809 | int outputsamples = alac->setinfo_max_samples_per_frame; | 885 | int outputsamples = alac->setinfo_max_samples_per_frame; |
810 | int wasted_bytes; | 886 | int uncompressed_bytes; |
811 | 887 | ||
812 | uint8_t interlacing_shift; | 888 | uint8_t interlacing_shift; |
813 | uint8_t interlacing_leftweight; | 889 | uint8_t interlacing_leftweight; |
@@ -821,7 +897,8 @@ static inline int decode_frame_stereo( | |||
821 | 897 | ||
822 | hassize = readbits(alac, 1); /* the output sample size is stored soon */ | 898 | hassize = readbits(alac, 1); /* the output sample size is stored soon */ |
823 | 899 | ||
824 | wasted_bytes = readbits(alac, 2); /* unknown ? */ | 900 | /* the number of bytes in the (compressed) stream that are not compressed */ |
901 | uncompressed_bytes = readbits(alac, 2); | ||
825 | 902 | ||
826 | isnotcompressed = readbits(alac, 1); /* whether the frame is compressed */ | 903 | isnotcompressed = readbits(alac, 1); /* whether the frame is compressed */ |
827 | 904 | ||
@@ -832,7 +909,7 @@ static inline int decode_frame_stereo( | |||
832 | outputsamples = readbits(alac, 32); | 909 | outputsamples = readbits(alac, 32); |
833 | } | 910 | } |
834 | 911 | ||
835 | readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + 1; | 912 | readsamplesize = infosamplesize - (uncompressed_bytes * 8) + 1; |
836 | 913 | ||
837 | yield(); | 914 | yield(); |
838 | if (!isnotcompressed) | 915 | if (!isnotcompressed) |
@@ -879,21 +956,26 @@ static inline int decode_frame_stereo( | |||
879 | } | 956 | } |
880 | 957 | ||
881 | /*********************/ | 958 | /*********************/ |
882 | if (wasted_bytes) | 959 | if (uncompressed_bytes) |
883 | { /* see mono case */ | 960 | { /* see mono case */ |
884 | //fprintf(stderr, "FIXME: unimplemented, unhandling of wasted_bytes\n"); | 961 | int i; |
962 | for (i = 0; i < outputsamples; i++) | ||
963 | { | ||
964 | outputbuffer[0][i] = readbits(alac, uncompressed_bytes * 8); | ||
965 | outputbuffer[1][i] = readbits(alac, uncompressed_bytes * 8); | ||
966 | } | ||
885 | } | 967 | } |
886 | 968 | ||
887 | yield(); | 969 | yield(); |
888 | /* channel 1 */ | 970 | /* channel 1 */ |
889 | basterdised_rice_decompress(alac, | 971 | entropy_rice_decode(alac, |
890 | outputbuffer[0], | 972 | outputbuffer[0], |
891 | outputsamples, | 973 | outputsamples, |
892 | readsamplesize, | 974 | readsamplesize, |
893 | alac->setinfo_rice_initialhistory, | 975 | alac->setinfo_rice_initialhistory, |
894 | alac->setinfo_rice_kmodifier, | 976 | alac->setinfo_rice_kmodifier, |
895 | ricemodifier_a * alac->setinfo_rice_historymult / 4, | 977 | ricemodifier_a * alac->setinfo_rice_historymult / 4, |
896 | (1 << alac->setinfo_rice_kmodifier) - 1); | 978 | (1 << alac->setinfo_rice_kmodifier) - 1); |
897 | 979 | ||
898 | yield(); | 980 | yield(); |
899 | if (prediction_type_a == 0) | 981 | if (prediction_type_a == 0) |
@@ -914,14 +996,14 @@ static inline int decode_frame_stereo( | |||
914 | yield(); | 996 | yield(); |
915 | 997 | ||
916 | /* channel 2 */ | 998 | /* channel 2 */ |
917 | basterdised_rice_decompress(alac, | 999 | entropy_rice_decode(alac, |
918 | outputbuffer[1], | 1000 | outputbuffer[1], |
919 | outputsamples, | 1001 | outputsamples, |
920 | readsamplesize, | 1002 | readsamplesize, |
921 | alac->setinfo_rice_initialhistory, | 1003 | alac->setinfo_rice_initialhistory, |
922 | alac->setinfo_rice_kmodifier, | 1004 | alac->setinfo_rice_kmodifier, |
923 | ricemodifier_b * alac->setinfo_rice_historymult / 4, | 1005 | ricemodifier_b * alac->setinfo_rice_historymult / 4, |
924 | (1 << alac->setinfo_rice_kmodifier) - 1); | 1006 | (1 << alac->setinfo_rice_kmodifier) - 1); |
925 | 1007 | ||
926 | yield(); | 1008 | yield(); |
927 | if (prediction_type_b == 0) | 1009 | if (prediction_type_b == 0) |
@@ -941,18 +1023,18 @@ static inline int decode_frame_stereo( | |||
941 | } | 1023 | } |
942 | else | 1024 | else |
943 | { /* not compressed, easy case */ | 1025 | { /* not compressed, easy case */ |
944 | if (alac->setinfo_sample_size <= 16) | 1026 | if (infosamplesize <= 16) |
945 | { | 1027 | { |
946 | int i; | 1028 | int i; |
947 | for (i = 0; i < outputsamples; i++) | 1029 | for (i = 0; i < outputsamples; i++) |
948 | { | 1030 | { |
949 | int32_t audiobits_a, audiobits_b; | 1031 | int32_t audiobits_a, audiobits_b; |
950 | 1032 | ||
951 | audiobits_a = readbits(alac, alac->setinfo_sample_size); | 1033 | audiobits_a = readbits(alac, infosamplesize); |
952 | audiobits_b = readbits(alac, alac->setinfo_sample_size); | 1034 | audiobits_b = readbits(alac, infosamplesize); |
953 | 1035 | ||
954 | audiobits_a = SIGN_EXTENDED32(audiobits_a, alac->setinfo_sample_size); | 1036 | audiobits_a = SIGN_EXTENDED32(audiobits_a, infosamplesize); |
955 | audiobits_b = SIGN_EXTENDED32(audiobits_b, alac->setinfo_sample_size); | 1037 | audiobits_b = SIGN_EXTENDED32(audiobits_b, infosamplesize); |
956 | 1038 | ||
957 | outputbuffer[0][i] = audiobits_a; | 1039 | outputbuffer[0][i] = audiobits_a; |
958 | outputbuffer[1][i] = audiobits_b; | 1040 | outputbuffer[1][i] = audiobits_b; |
@@ -966,27 +1048,27 @@ static inline int decode_frame_stereo( | |||
966 | int32_t audiobits_a, audiobits_b; | 1048 | int32_t audiobits_a, audiobits_b; |
967 | 1049 | ||
968 | audiobits_a = readbits(alac, 16); | 1050 | audiobits_a = readbits(alac, 16); |
969 | audiobits_a = audiobits_a << 16; | 1051 | audiobits_a = audiobits_a << (infosamplesize - 16); |
970 | audiobits_a = audiobits_a >> (32 - alac->setinfo_sample_size); | 1052 | audiobits_a |= readbits(alac, infosamplesize - 16); |
971 | audiobits_a |= readbits(alac, alac->setinfo_sample_size - 16); | 1053 | audiobits_a = SIGNEXTEND24(audiobits_a); |
972 | 1054 | ||
973 | audiobits_b = readbits(alac, 16); | 1055 | audiobits_b = readbits(alac, 16); |
974 | audiobits_b = audiobits_b << 16; | 1056 | audiobits_b = audiobits_b << (infosamplesize - 16); |
975 | audiobits_b = audiobits_b >> (32 - alac->setinfo_sample_size); | 1057 | audiobits_b |= readbits(alac, infosamplesize - 16); |
976 | audiobits_b |= readbits(alac, alac->setinfo_sample_size - 16); | 1058 | audiobits_b = SIGNEXTEND24(audiobits_b); |
977 | 1059 | ||
978 | outputbuffer[0][i] = audiobits_a; | 1060 | outputbuffer[0][i] = audiobits_a; |
979 | outputbuffer[1][i] = audiobits_b; | 1061 | outputbuffer[1][i] = audiobits_b; |
980 | } | 1062 | } |
981 | } | 1063 | } |
982 | /* wasted_bytes = 0; */ | 1064 | uncompressed_bytes = 0; // always 0 for uncompressed |
983 | interlacing_shift = 0; | 1065 | interlacing_shift = 0; |
984 | interlacing_leftweight = 0; | 1066 | interlacing_leftweight = 0; |
985 | } | 1067 | } |
986 | 1068 | ||
987 | yield(); | 1069 | yield(); |
988 | 1070 | ||
989 | switch(alac->setinfo_sample_size) | 1071 | switch(infosamplesize) |
990 | { | 1072 | { |
991 | case 16: | 1073 | case 16: |
992 | { | 1074 | { |
@@ -997,10 +1079,21 @@ static inline int decode_frame_stereo( | |||
997 | interlacing_leftweight); | 1079 | interlacing_leftweight); |
998 | break; | 1080 | break; |
999 | } | 1081 | } |
1000 | case 20: | ||
1001 | case 24: | 1082 | case 24: |
1083 | { | ||
1084 | deinterlace_24(outputbuffer[0], | ||
1085 | outputbuffer[1], | ||
1086 | uncompressed_bytes, | ||
1087 | outputbuffer[0], | ||
1088 | outputbuffer[1], | ||
1089 | outputsamples, | ||
1090 | interlacing_shift, | ||
1091 | interlacing_leftweight); | ||
1092 | break; | ||
1093 | } | ||
1094 | case 20: | ||
1002 | case 32: | 1095 | case 32: |
1003 | //fprintf(stderr, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); | 1096 | //fprintf(stderr, "FIXME: unimplemented sample size %i\n", infosamplesize); |
1004 | break; | 1097 | break; |
1005 | default: | 1098 | default: |
1006 | break; | 1099 | break; |