Mercurial > libavcodec.hg
comparison vorbis.c @ 2743:9f469a5d3a33 libavcodec
more trivial optimizations
author | michael |
---|---|
date | Mon, 30 May 2005 20:34:05 +0000 |
parents | d5ac91dafaa8 |
children | 12436597cc0c |
comparison
equal
deleted
inserted
replaced
2742:5bdc60634470 | 2743:9f469a5d3a33 |
---|---|
35 | 35 |
36 #ifndef V_DEBUG | 36 #ifndef V_DEBUG |
37 #define AV_DEBUG(...) | 37 #define AV_DEBUG(...) |
38 #endif | 38 #endif |
39 | 39 |
40 | 40 #undef NDEBUG |
41 #include <assert.h> | |
41 | 42 |
42 /* Helper functions */ | 43 /* Helper functions */ |
43 | 44 |
44 /** | 45 /** |
45 * reads 0-32 bits when using the ALT_BITSTREAM_READER_LE bitstream reader | 46 * reads 0-32 bits when using the ALT_BITSTREAM_READER_LE bitstream reader |
1097 uint_fast32_t temp=get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table, | 1098 uint_fast32_t temp=get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table, |
1098 V_NB_BITS, 3); | 1099 V_NB_BITS, 3); |
1099 | 1100 |
1100 AV_DEBUG("Classword: %d \n", temp); | 1101 AV_DEBUG("Classword: %d \n", temp); |
1101 | 1102 |
1103 assert(vr->classifications > 1 && vr->classifications<256 && temp<=65536); //needed for inverse[] | |
1102 for(i=0;i<c_p_c;++i) { | 1104 for(i=0;i<c_p_c;++i) { |
1103 uint_fast32_t temp2; | 1105 uint_fast32_t temp2; |
1104 | 1106 |
1105 temp2=temp/vr->classifications; | 1107 temp2=(((uint_fast64_t)temp) * inverse[vr->classifications])>>32; |
1106 classifs[j_times_ptns_to_read+partition_count+c_p_c-1-i]=temp-temp2*vr->classifications; | 1108 classifs[j_times_ptns_to_read+partition_count+c_p_c-1-i]=temp-temp2*vr->classifications; |
1107 temp=temp2; | 1109 temp=temp2; |
1108 } | 1110 } |
1109 } | 1111 } |
1110 j_times_ptns_to_read+=ptns_to_read; | 1112 j_times_ptns_to_read+=ptns_to_read; |
1118 uint_fast8_t vqclass=classifs[j_times_ptns_to_read+partition_count]; | 1120 uint_fast8_t vqclass=classifs[j_times_ptns_to_read+partition_count]; |
1119 int_fast16_t vqbook=vr->books[vqclass][pass]; | 1121 int_fast16_t vqbook=vr->books[vqclass][pass]; |
1120 | 1122 |
1121 if (vqbook>=0) { | 1123 if (vqbook>=0) { |
1122 uint_fast16_t coffs; | 1124 uint_fast16_t coffs; |
1125 uint_fast16_t step=vr->partition_size/vc->codebooks[vqbook].dimensions; | |
1126 vorbis_codebook codebook= vc->codebooks[vqbook]; | |
1123 | 1127 |
1124 if (vr->type==0) { | 1128 if (vr->type==0) { |
1125 uint_fast16_t step=vr->partition_size/vc->codebooks[vqbook].dimensions; | |
1126 | 1129 |
1127 voffs=voffset+j*vlen; | 1130 voffs=voffset+j*vlen; |
1128 for(k=0;k<step;++k) { | 1131 for(k=0;k<step;++k) { |
1129 coffs=get_vlc2(gb, vc->codebooks[vqbook].vlc.table, | 1132 coffs=get_vlc2(gb, codebook.vlc.table, V_NB_BITS, 3) * codebook.dimensions; |
1130 V_NB_BITS, 3) * vc->codebooks[vqbook].dimensions; | 1133 for(l=0;l<codebook.dimensions;++l) { |
1131 for(l=0;l<vc->codebooks[vqbook].dimensions;++l) { | 1134 vec[voffs+k+l*step]+=codebook.codevectors[coffs+l]; // FPMATH |
1132 vec[voffs+k+l*step]+=vc->codebooks[vqbook].codevectors[coffs+l]; // FPMATH | |
1133 } | 1135 } |
1134 } | 1136 } |
1135 } | 1137 } |
1136 else if (vr->type==1) { | 1138 else if (vr->type==1) { |
1137 voffs=voffset+j*vlen; | 1139 voffs=voffset+j*vlen; |
1138 for(k=0;k<vr->partition_size/vc->codebooks[vqbook].dimensions;++k) { | 1140 for(k=0;k<step;++k) { |
1139 coffs=get_vlc2(gb, vc->codebooks[vqbook].vlc.table, | 1141 coffs=get_vlc2(gb, codebook.vlc.table, V_NB_BITS, 3) * codebook.dimensions; |
1140 V_NB_BITS, 3) * vc->codebooks[vqbook].dimensions; | 1142 for(l=0;l<codebook.dimensions;++l, ++voffs) { |
1141 for(l=0;l<vc->codebooks[vqbook].dimensions;++l, ++voffs) { | 1143 vec[voffs]+=codebook.codevectors[coffs+l]; // FPMATH |
1142 vec[voffs]+=vc->codebooks[vqbook].codevectors[coffs+l]; // FPMATH | 1144 |
1143 | 1145 AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs); |
1144 AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], vc->codebooks[vqbook].codevectors[coffs+l], coffs); | |
1145 } | 1146 } |
1146 } | 1147 } |
1147 } | 1148 } |
1148 else if (vr->type==2 && ch==2) { // most frequent case optimized | 1149 else if (vr->type==2 && ch==2 && (voffset&1)==0 && (codebook.dimensions&1)==0) { // most frequent case optimized |
1149 voffs=voffset; | 1150 voffs=voffset>>1; |
1150 | 1151 |
1151 for(k=0;k<vr->partition_size/vc->codebooks[vqbook].dimensions;++k) { | 1152 for(k=0;k<step;++k) { |
1152 coffs=get_vlc2(gb, vc->codebooks[vqbook].vlc.table, | 1153 coffs=get_vlc2(gb, codebook.vlc.table, V_NB_BITS, 3) * codebook.dimensions; |
1153 V_NB_BITS, 3) * vc->codebooks[vqbook].dimensions; | 1154 for(l=0;l<codebook.dimensions;l+=2, voffs++) { |
1154 for(l=0;l<vc->codebooks[vqbook].dimensions;++l, ++voffs) { | 1155 vec[voffs ]+=codebook.codevectors[coffs+l ]; // FPMATH |
1155 vec[(voffs>>1)+((voffs&1) ? vlen : 0)]+=vc->codebooks[vqbook].codevectors[coffs+l]; // FPMATH | 1156 vec[voffs+vlen]+=codebook.codevectors[coffs+l+1]; // FPMATH |
1156 | 1157 |
1157 AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], vc->codebooks[vqbook].codevectors[coffs+l], coffs, l); | 1158 AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], codebook.codevectors[coffs+l], coffs, l); |
1158 } | 1159 } |
1159 } | 1160 } |
1160 | 1161 |
1161 } | 1162 } |
1162 else if (vr->type==2) { | 1163 else if (vr->type==2) { |
1163 voffs=voffset; | 1164 voffs=voffset; |
1164 | 1165 |
1165 for(k=0;k<vr->partition_size/vc->codebooks[vqbook].dimensions;++k) { | 1166 for(k=0;k<step;++k) { |
1166 coffs=get_vlc2(gb, vc->codebooks[vqbook].vlc.table, | 1167 coffs=get_vlc2(gb, codebook.vlc.table, V_NB_BITS, 3) * codebook.dimensions; |
1167 V_NB_BITS, 3) * vc->codebooks[vqbook].dimensions; | 1168 for(l=0;l<codebook.dimensions;++l, ++voffs) { |
1168 for(l=0;l<vc->codebooks[vqbook].dimensions;++l, ++voffs) { | 1169 vec[voffs/ch+(voffs%ch)*vlen]+=codebook.codevectors[coffs+l]; // FPMATH FIXME use if and counter instead of / and % |
1169 vec[voffs/ch+(voffs%ch)*vlen]+=vc->codebooks[vqbook].codevectors[coffs+l]; // FPMATH FIXME use if and counter instead of / and % | 1170 |
1170 | 1171 AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], codebook.codevectors[coffs+l], coffs, l); |
1171 AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset/ch+(voffs%ch)*vlen, vec[voffset/ch+(voffs%ch)*vlen], vc->codebooks[vqbook].codevectors[coffs+l], coffs, l); | |
1172 } | 1172 } |
1173 } | 1173 } |
1174 } else { | 1174 } else { |
1175 av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); | 1175 av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); |
1176 return 1; | 1176 return 1; |