AUDIO: Switch to BitStreamMemoryStream in the QDM2 decoder

This commit is contained in:
Bastien Bouclet 2017-11-08 20:56:06 +01:00
parent bf3c98815f
commit 1757f7dc5d

View File

@ -213,9 +213,9 @@ private:
void fill_coding_method_array(sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp,
sb_int8_array coding_method, int nb_channels,
int c, int superblocktype_2_3, int cm_table_select);
void synthfilt_build_sb_samples(Common::BitStream32LELSB *gb, int length, int sb_min, int sb_max);
void init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStream32LELSB *gb, int length);
void init_tone_level_dequantization(Common::BitStream32LELSB *gb, int length);
void synthfilt_build_sb_samples(Common::BitStreamMemory32LELSB *gb, int length, int sb_min, int sb_max);
void init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStreamMemory32LELSB *gb, int length);
void init_tone_level_dequantization(Common::BitStreamMemory32LELSB *gb, int length);
void process_subpacket_9(QDM2SubPNode *node);
void process_subpacket_10(QDM2SubPNode *node, int length);
void process_subpacket_11(QDM2SubPNode *node, int length);
@ -224,7 +224,7 @@ private:
void qdm2_decode_super_block(void);
void qdm2_fft_init_coefficient(int sub_packet, int offset, int duration,
int channel, int exp, int phase);
void qdm2_fft_decode_tones(int duration, Common::BitStream32LELSB *gb, int b);
void qdm2_fft_decode_tones(int duration, Common::BitStreamMemory32LELSB *gb, int b);
void qdm2_decode_fft_packets(void);
void qdm2_fft_generate_tone(FFTTone *tone);
void qdm2_fft_tone_synthesizer(uint8 sub_packet);
@ -672,7 +672,7 @@ void ff_mpa_synth_filter(int16 *synth_buf_ptr, int *synth_buf_offset,
* read the longest vlc code
* = (max_vlc_length + bits - 1) / bits
*/
static int getVlc2(Common::BitStream32LELSB *s, int16 (*table)[2], int bits, int maxDepth) {
static int getVlc2(Common::BitStreamMemory32LELSB *s, int16 (*table)[2], int bits, int maxDepth) {
int index = s->peekBits(bits);
int code = table[index][0];
int n = table[index][1];
@ -1221,7 +1221,7 @@ QDM2Stream::~QDM2Stream() {
delete[] _compressedData;
}
static int qdm2_get_vlc(Common::BitStream32LELSB *gb, VLC *vlc, int flag, int depth) {
static int qdm2_get_vlc(Common::BitStreamMemory32LELSB *gb, VLC *vlc, int flag, int depth) {
int value = getVlc2(gb, vlc->table, vlc->bits, depth);
// stage-2, 3 bits exponent escape sequence
@ -1240,7 +1240,7 @@ static int qdm2_get_vlc(Common::BitStream32LELSB *gb, VLC *vlc, int flag, int de
return value;
}
static int qdm2_get_se_vlc(VLC *vlc, Common::BitStream32LELSB *gb, int depth)
static int qdm2_get_se_vlc(VLC *vlc, Common::BitStreamMemory32LELSB *gb, int depth)
{
int value = qdm2_get_vlc(gb, vlc, 0, depth);
@ -1605,7 +1605,7 @@ void QDM2Stream::fill_coding_method_array(sb_int8_array tone_level_idx, sb_int8_
* @param sb_min lower subband processed (sb_min included)
* @param sb_max higher subband processed (sb_max excluded)
*/
void QDM2Stream::synthfilt_build_sb_samples(Common::BitStream32LELSB *gb, int length, int sb_min, int sb_max) {
void QDM2Stream::synthfilt_build_sb_samples(Common::BitStreamMemory32LELSB *gb, int length, int sb_min, int sb_max) {
int sb, j, k, n, ch, run, channels;
int joined_stereo, zero_encoding, chs;
int type34_first;
@ -1785,7 +1785,7 @@ void QDM2Stream::synthfilt_build_sb_samples(Common::BitStream32LELSB *gb, int le
* @param gb bitreader context
* @param length packet length in bits
*/
void QDM2Stream::init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStream32LELSB *gb, int length) {
void QDM2Stream::init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::BitStreamMemory32LELSB *gb, int length) {
int i, k, run, level, diff;
if ((length - gb->pos()) < 16)
@ -1819,7 +1819,7 @@ void QDM2Stream::init_quantized_coeffs_elem0(int8 *quantized_coeffs, Common::Bit
* @param gb bitreader context
* @param length packet length in bits
*/
void QDM2Stream::init_tone_level_dequantization(Common::BitStream32LELSB *gb, int length) {
void QDM2Stream::init_tone_level_dequantization(Common::BitStreamMemory32LELSB *gb, int length) {
int sb, j, k, n, ch;
for (ch = 0; ch < _channels; ch++) {
@ -1885,8 +1885,8 @@ void QDM2Stream::init_tone_level_dequantization(Common::BitStream32LELSB *gb, in
void QDM2Stream::process_subpacket_9(QDM2SubPNode *node) {
int i, j, k, n, ch, run, level, diff;
Common::MemoryReadStream d(node->packet->data, node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStream32LELSB gb(&d);
Common::BitStreamMemoryStream d(node->packet->data, node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStreamMemory32LELSB gb(&d);
n = coeff_per_sb_for_avg[_coeffPerSbSelect][QDM2_SB_USED(_subSampling) - 1] + 1; // same as averagesomething function
@ -1919,8 +1919,8 @@ void QDM2Stream::process_subpacket_9(QDM2SubPNode *node) {
* @param length packet length in bits
*/
void QDM2Stream::process_subpacket_10(QDM2SubPNode *node, int length) {
Common::MemoryReadStream d(((node == NULL) ? _emptyBuffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE));
Common::BitStream32LELSB gb(&d);
Common::BitStreamMemoryStream d(((node == NULL) ? _emptyBuffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE));
Common::BitStreamMemory32LELSB gb(&d);
if (length != 0) {
init_tone_level_dequantization(&gb, length);
@ -1937,8 +1937,8 @@ void QDM2Stream::process_subpacket_10(QDM2SubPNode *node, int length) {
* @param length packet length in bit
*/
void QDM2Stream::process_subpacket_11(QDM2SubPNode *node, int length) {
Common::MemoryReadStream d(((node == NULL) ? _emptyBuffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE));
Common::BitStream32LELSB gb(&d);
Common::BitStreamMemoryStream d(((node == NULL) ? _emptyBuffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE));
Common::BitStreamMemory32LELSB gb(&d);
if (length >= 32) {
int c = gb.getBits(13);
@ -1958,8 +1958,8 @@ void QDM2Stream::process_subpacket_11(QDM2SubPNode *node, int length) {
* @param length packet length in bits
*/
void QDM2Stream::process_subpacket_12(QDM2SubPNode *node, int length) {
Common::MemoryReadStream d(((node == NULL) ? _emptyBuffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE));
Common::BitStream32LELSB gb(&d);
Common::BitStreamMemoryStream d(((node == NULL) ? _emptyBuffer : node->packet->data), ((node == NULL) ? 0 : node->packet->size + FF_INPUT_BUFFER_PADDING_SIZE));
Common::BitStreamMemory32LELSB gb(&d);
synthfilt_build_sb_samples(&gb, length, 8, QDM2_SB_USED(_subSampling));
}
@ -2013,8 +2013,8 @@ void QDM2Stream::qdm2_decode_super_block(void) {
average_quantized_coeffs(); // average elements in quantized_coeffs[max_ch][10][8]
Common::MemoryReadStream packetStream(_compressedData, _packetSize + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStream32LELSB packetBitStream(packetStream);
Common::BitStreamMemoryStream packetStream(_compressedData, _packetSize + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStreamMemory32LELSB packetBitStream(packetStream);
//qdm2_decode_sub_packet_header
header.type = packetBitStream.getBits(8);
@ -2045,8 +2045,8 @@ void QDM2Stream::qdm2_decode_super_block(void) {
_superblocktype_2_3 = (header.type == 2 || header.type == 3);
packet_bytes = (_packetSize - packetBitStream.pos() / 8);
Common::MemoryReadStream headerStream(header.data, header.size + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStream32LELSB headerBitStream(headerStream);
Common::BitStreamMemoryStream headerStream(header.data, header.size + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStreamMemory32LELSB headerBitStream(headerStream);
if (header.type == 2 || header.type == 4 || header.type == 5) {
int csum = 257 * headerBitStream.getBits(8) + 2 * headerBitStream.getBits(8);
@ -2169,7 +2169,7 @@ void QDM2Stream::qdm2_fft_init_coefficient(int sub_packet, int offset, int durat
_fftCoefsIndex++;
}
void QDM2Stream::qdm2_fft_decode_tones(int duration, Common::BitStream32LELSB *gb, int b) {
void QDM2Stream::qdm2_fft_decode_tones(int duration, Common::BitStreamMemory32LELSB *gb, int b) {
int channel, stereo, phase, exp;
int local_int_4, local_int_8, stereo_phase, local_int_10;
int local_int_14, stereo_exp, local_int_20, local_int_28;
@ -2278,8 +2278,8 @@ void QDM2Stream::qdm2_decode_fft_packets(void) {
return;
// decode FFT tones
Common::MemoryReadStream d(packet->data, packet->size + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStream32LELSB gb(&d);
Common::BitStreamMemoryStream d(packet->data, packet->size + FF_INPUT_BUFFER_PADDING_SIZE);
Common::BitStreamMemory32LELSB gb(&d);
if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])
unknown_flag = 1;