Browse code

Make Smacker audio decoder output audio in original bit depth

Patch by Daniel Verkamp
($firstname) at (three-letter file extension for drivers in Win 3.1) dot (nu)

Thread: [PATCH] Smacker: Output audio in original bit depth

Originally committed as revision 18111 to svn://svn.ffmpeg.org/ffmpeg/trunk

Daniel Verkamp authored on 2009/03/22 00:52:14
Showing 2 changed files
... ...
@@ -558,7 +558,6 @@ static av_cold int decode_end(AVCodecContext *avctx)
558 558
 
559 559
 static av_cold int smka_decode_init(AVCodecContext *avctx)
560 560
 {
561
-    avctx->sample_fmt = SAMPLE_FMT_S16;
562 561
     avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
563 562
     return 0;
564 563
 }
... ...
@@ -572,6 +571,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
572 572
     HuffContext h[4];
573 573
     VLC vlc[4];
574 574
     int16_t *samples = data;
575
+    int8_t *samples8 = data;
575 576
     int val;
576 577
     int i, res;
577 578
     int unp_size;
... ...
@@ -589,7 +589,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
589 589
     }
590 590
     stereo = get_bits1(&gb);
591 591
     bits = get_bits1(&gb);
592
-    if (unp_size & 0xC0000000 || (unp_size << !bits) > *data_size) {
592
+    if (unp_size & 0xC0000000 || unp_size > *data_size) {
593 593
         av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
594 594
         return -1;
595 595
     }
... ...
@@ -655,7 +655,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
655 655
         for(i = stereo; i >= 0; i--)
656 656
             pred[i] = get_bits(&gb, 8);
657 657
         for(i = 0; i < stereo; i++)
658
-            *samples++ = (pred[i] - 0x80) << 8;
658
+            *samples8++ = pred[i];
659 659
         for(i = 0; i < unp_size; i++) {
660 660
             if(i & stereo){
661 661
                 if(vlc[1].table)
... ...
@@ -663,17 +663,16 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
663 663
                 else
664 664
                     res = 0;
665 665
                 pred[1] += (int8_t)h[1].values[res];
666
-                *samples++ = (pred[1] - 0x80) << 8;
666
+                *samples8++ = pred[1];
667 667
             } else {
668 668
                 if(vlc[0].table)
669 669
                     res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
670 670
                 else
671 671
                     res = 0;
672 672
                 pred[0] += (int8_t)h[0].values[res];
673
-                *samples++ = (pred[0] - 0x80) << 8;
673
+                *samples8++ = pred[0];
674 674
             }
675 675
         }
676
-        unp_size *= 2;
677 676
     }
678 677
 
679 678
     for(i = 0; i < 4; i++) {
... ...
@@ -183,6 +183,7 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap)
183 183
             ast[i]->codec->bits_per_coded_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8;
184 184
             if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8)
185 185
                 ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
186
+            ast[i]->codec->sample_fmt = ast[i]->codec->bits_per_coded_sample == 8 ? SAMPLE_FMT_U8 : SAMPLE_FMT_S16;
186 187
             av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
187 188
                     * ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8);
188 189
         }