summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sbc/sbc.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/sbc/sbc.c b/sbc/sbc.c
index d5ccf1fa..de88f82a 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -194,9 +194,13 @@ static void sbc_calculate_bits(const struct sbc_frame *frame, int (*bits)[8], ui
int ch, sb;
for (ch = 0; ch < frame->channels; ch++) {
+ max_bitneed = 0;
if (frame->allocation_method == SNR) {
- for (sb = 0; sb < frame->subbands; sb++)
+ for (sb = 0; sb < frame->subbands; sb++) {
bitneed[ch][sb] = frame->scale_factor[ch][sb];
+ if (bitneed[ch][sb] > max_bitneed)
+ max_bitneed = bitneed[ch][sb];
+ }
} else {
for (sb = 0; sb < frame->subbands; sb++) {
if (frame->scale_factor[ch][sb] == 0)
@@ -211,15 +215,11 @@ static void sbc_calculate_bits(const struct sbc_frame *frame, int (*bits)[8], ui
else
bitneed[ch][sb] = loudness;
}
+ if (bitneed[ch][sb] > max_bitneed)
+ max_bitneed = bitneed[ch][sb];
}
}
- max_bitneed = 0;
- for (sb = 0; sb < frame->subbands; sb++) {
- if (bitneed[ch][sb] > max_bitneed)
- max_bitneed = bitneed[ch][sb];
- }
-
bitcount = 0;
slicecount = 0;
bitslice = max_bitneed + 1;
@@ -250,8 +250,7 @@ static void sbc_calculate_bits(const struct sbc_frame *frame, int (*bits)[8], ui
}
}
- sb = 0;
- while (bitcount < frame->bitpool && sb < frame->subbands) {
+ for (sb = 0; bitcount < frame->bitpool && sb < frame->subbands; sb++) {
if ((bits[ch][sb] >= 2) && (bits[ch][sb] < 16)) {
bits[ch][sb]++;
bitcount++;
@@ -259,16 +258,13 @@ static void sbc_calculate_bits(const struct sbc_frame *frame, int (*bits)[8], ui
bits[ch][sb] = 2;
bitcount += 2;
}
- sb++;
}
- sb = 0;
- while (bitcount < frame->bitpool && sb < frame->subbands) {
+ for (sb = 0; bitcount < frame->bitpool && sb < frame->subbands; sb++) {
if (bits[ch][sb] < 16) {
bits[ch][sb]++;
bitcount++;
}
- sb++;
}
}