{
avctx->channels = 1;
avctx->channel_layout = AV_CH_LAYOUT_MONO;
- avctx->sample_rate = 8000;
+ if (!avctx->sample_rate)
+ avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
switch (avctx->codec_id) {
break;
case AV_CODEC_ID_GSM_MS:
avctx->frame_size = 2 * GSM_FRAME_SIZE;
- avctx->block_align = GSM_MS_BLOCK_SIZE;
+ if (!avctx->block_align)
+ avctx->block_align = GSM_MS_BLOCK_SIZE;
+ else
+ if (avctx->block_align < MSN_MIN_BLOCK_SIZE ||
+ avctx->block_align > GSM_MS_BLOCK_SIZE ||
+ (avctx->block_align - MSN_MIN_BLOCK_SIZE) % 3) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid block alignment %d\n",
+ avctx->block_align);
+ return AVERROR_INVALIDDATA;
+ }
}
return 0;
init_get_bits(&gb, buf, buf_size * 8);
if (get_bits(&gb, 4) != 0xd)
av_log(avctx, AV_LOG_WARNING, "Missing GSM magic!\n");
- res = gsm_decode_block(avctx, samples, &gb);
+ res = gsm_decode_block(avctx, samples, &gb, GSM_13000);
if (res < 0)
return res;
break;
case AV_CODEC_ID_GSM_MS:
- res = ff_msgsm_decode_block(avctx, samples, buf);
+ res = ff_msgsm_decode_block(avctx, samples, buf,
+ (GSM_MS_BLOCK_SIZE - avctx->block_align) / 3);
if (res < 0)
return res;
}
{-26879, -19199, -11520, -3840, 3840, 11520, 19199, 26879},
{-28671, -20479, -12288, -4096, 4096, 12288, 20479, 28671}
};
+
+static const int apcm_bits[11][13] = {
+ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
+ { 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1 },
+ { 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1 },
+ { 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1 },
+ { 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1 },
+ { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
+ { 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
+ { 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
+ { 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
+ { 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
+ { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
+};
+
+const int* const ff_gsm_apcm_bits[][4] = {
+ { apcm_bits[10], apcm_bits[10], apcm_bits[10], apcm_bits[10] }, // 13000
+ { apcm_bits[10], apcm_bits[10], apcm_bits[10], apcm_bits[ 6] }, // 12400
+ { apcm_bits[10], apcm_bits[10], apcm_bits[ 7], apcm_bits[ 5] }, // 11800
+ { apcm_bits[10], apcm_bits[ 8], apcm_bits[ 5], apcm_bits[ 5] }, // 11200
+ { apcm_bits[ 9], apcm_bits[ 5], apcm_bits[ 5], apcm_bits[ 5] }, // 10600
+ { apcm_bits[ 5], apcm_bits[ 5], apcm_bits[ 5], apcm_bits[ 1] }, // 10000
+ { apcm_bits[ 5], apcm_bits[ 5], apcm_bits[ 2], apcm_bits[ 0] }, // 9400
+ { apcm_bits[ 5], apcm_bits[ 3], apcm_bits[ 0], apcm_bits[ 0] }, // 8800
+ { apcm_bits[ 4], apcm_bits[ 0], apcm_bits[ 0], apcm_bits[ 0] }, // 8200
+};
#include "gsm.h"
#include "gsmdec_data.h"
-static void apcm_dequant_add(GetBitContext *gb, int16_t *dst)
+static const int requant_tab[4][8] = {
+ { 0 },
+ { 0, 7 },
+ { 0, 2, 5, 7 },
+ { 0, 1, 2, 3, 4, 5, 6, 7 }
+};
+
+static void apcm_dequant_add(GetBitContext *gb, int16_t *dst, const int *frame_bits)
{
- int i;
+ int i, val;
int maxidx = get_bits(gb, 6);
const int16_t *tab = ff_gsm_dequant_tab[maxidx];
- for (i = 0; i < 13; i++)
- dst[3*i] += tab[get_bits(gb, 3)];
+ for (i = 0; i < 13; i++) {
+ val = get_bits(gb, frame_bits[i]);
+ dst[3*i] += tab[requant_tab[frame_bits[i]][val]];
+ }
}
static inline int gsm_mult(int a, int b)
}
static int gsm_decode_block(AVCodecContext *avctx, int16_t *samples,
- GetBitContext *gb)
+ GetBitContext *gb, int mode)
{
GSMContext *ctx = avctx->priv_data;
int i;
int offset = get_bits(gb, 2);
lag = av_clip(lag, 40, 120);
long_term_synth(ref_dst, lag, gain_idx);
- apcm_dequant_add(gb, ref_dst + offset);
+ apcm_dequant_add(gb, ref_dst + offset, ff_gsm_apcm_bits[mode][i]);
ref_dst += 40;
}
memcpy(ctx->ref_buf, ctx->ref_buf + 160, 120 * sizeof(*ctx->ref_buf));