Revision b7c24ff6 libavcodec/cook.c

View differences:

libavcodec/cook.c
985 985
    init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8);
986 986
    decode_gain_info(&q->gb, &q->gain_current);
987 987
    memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));  //This copy does not seem to be used. FIXME
988
    //fprintf(stdout,"cu bits ds = %d\n",get_bits_count(&q->gb));
988

  
989 989
    if(q->nb_channels==2 && q->joint_stereo==1){
990 990
        joint_decode(q, q->decode_buf_ptr[0], q->decode_buf_ptr[2]);
991 991

  
......
1025 1025
        memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1026 1026

  
1027 1027
    } else if (q->nb_channels==2 && q->joint_stereo==0) {
1028
        for (i=0 ; i<q->nb_channels ; i++){
1028
            /* channel 0 */
1029 1029
            mono_decode(q, q->decode_buf_ptr[0]);
1030 1030

  
1031
            av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are not supported at the moment, do not report as a bug!\n");
1032 1031
            tmp_ptr = q->decode_buf_ptr[0];
1033 1032
            q->decode_buf_ptr[0] = q->decode_buf_ptr[1];
1034 1033
            q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
......
1050 1049
                value = lrintf(q->mono_mdct_output[j]);
1051 1050
                if(value < -32768) value = -32768;
1052 1051
                else if(value > 32767) value = 32767;
1053
                outbuffer[2*j+i] = value;
1052
                outbuffer[2*j+1] = value;
1054 1053
            }
1054

  
1055
            /* channel 1 */
1056
            //av_log(NULL,AV_LOG_ERROR,"bits = %d\n",get_bits_count(&q->gb));
1057
            init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8+q->bits_per_subpacket);
1058
            decode_gain_info(&q->gb, &q->gain_current);
1059
            //memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));
1060
            mono_decode(q, q->decode_buf_ptr[0]);
1061
            tmp_ptr = q->decode_buf_ptr[0];
1062
            q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
1063
            q->decode_buf_ptr[2] = q->decode_buf_ptr[3];
1064
            q->decode_buf_ptr[3] = tmp_ptr;
1065

  
1066
            q->gain_now_ptr = &q->gain_now;
1067
            q->gain_previous_ptr = &q->gain_previous;
1068

  
1069
            cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
1070
            gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr, q->gain_previous_ptr, q->previous_buffer_ptr[0]);
1071

  
1072
            /* Swap out the previous buffer. */
1073
            tmp_ptr = q->previous_buffer_ptr[0];
1074
            q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
1075
            q->previous_buffer_ptr[1] = tmp_ptr;
1076

  
1077
            for (j=0 ; j<q->samples_per_frame ; j++){
1078
                value = lrintf(q->mono_mdct_output[j]);
1079
                if(value < -32768) value = -32768;
1080
                else if(value > 32767) value = 32767;
1081
                outbuffer[2*j] = value;
1082
            }
1083

  
1084

  
1085
            /* Swap out the previous buffer. */
1055 1086
            memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
1056 1087
            memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1057
        }
1088

  
1058 1089
    } else {
1059 1090
        mono_decode(q, q->decode_buf_ptr[0]);
1060 1091

  
......
1082 1113
        memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
1083 1114
        memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1084 1115
    }
1085
    /* FIXME: Shouldn't the total number of bytes be returned? */
1086
    return /*q->nb_channels*/ q->samples_per_frame * sizeof(int16_t);
1116
    return q->samples_per_frame * sizeof(int16_t);
1087 1117
}
1088 1118

  
1089 1119

  
......
1096 1126
static int cook_decode_frame(AVCodecContext *avctx,
1097 1127
            void *data, int *data_size,
1098 1128
            uint8_t *buf, int buf_size) {
1099
    /* This stuff is quite messy, the Cook packets are sent unordered
1100
     * and need to be ordered before they are sent to the rest of the
1101
     * decoder. The order can be found in the q->frame_reorder_index.
1102
     * Currently decoding of the last packets is not handled at
1103
     * all. FIXME */
1104

  
1105 1129
    COOKContext *q = avctx->priv_data;
1106 1130

  
1107 1131
    if (buf_size < avctx->block_align)
......
1201 1225
        case MONO_COOK2:
1202 1226
            if (q->nb_channels != 1) {
1203 1227
                q->joint_stereo = 0;
1204
                av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are not supported at the moment!\n");
1205
                return -1;
1228
                av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are decoded with wrong gain at the moment!\n");
1229
                q->bits_per_subpacket = q->bits_per_subpacket/2;
1230

  
1206 1231
            }
1207 1232
            av_log(NULL,AV_LOG_DEBUG,"MONO_COOK2\n");
1208 1233
            break;

Also available in: Unified diff