diff options
author | Brad Midgley <bmidgley@xmission.com> | 2007-11-27 06:22:48 +0000 |
---|---|---|
committer | Brad Midgley <bmidgley@xmission.com> | 2007-11-27 06:22:48 +0000 |
commit | 4a2b8a2e67d13e8ed974e2e91e093383493883a7 (patch) | |
tree | 2ef0c3ec3c6cb2b0f8dafc2b910d213abb4bfa41 /sbc | |
parent | 6a2bcc32bffe68e452c2ce7e0bb328b1f7b7b9bb (diff) |
eliminate extra loop for bitneed compute
make a couple while loops easier to read as for loops
Diffstat (limited to 'sbc')
-rw-r--r-- | sbc/sbc.c | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -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++; } } |