#include "imcdata.h"
+#define IMC_BLOCK_SIZE 64
#define IMC_FRAME_ID 0x21
#define BANDS 32
#define COEFFS 256
} IMCContext;
-static int imc_decode_init(AVCodecContext * avctx)
+static av_cold int imc_decode_init(AVCodecContext * avctx)
{
int i, j;
IMCContext *q = avctx->priv_data;
q->old_floor[i] = 1.0;
/* Build mdct window, a simple sine window normalized with sqrt(2) */
+ ff_sine_window_init(q->mdct_sine_window, COEFFS);
for(i = 0; i < COEFFS; i++)
- q->mdct_sine_window[i] = sin((i + 0.5) / 512.0 * M_PI) * sqrt(2.0);
+ q->mdct_sine_window[i] *= sqrt(2.0);
for(i = 0; i < COEFFS/2; i++){
q->post_cos[i] = cos(i / 256.0 * M_PI);
q->post_sin[i] = sin(i / 256.0 * M_PI);
static int imc_decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
- uint8_t * buf, int buf_size)
+ const uint8_t * buf, int buf_size)
{
IMCContext *q = avctx->priv_data;
int flag;
int bits, summer;
int counter, bitscount;
- uint16_t *buf16 = (uint16_t *) buf;
+ uint16_t buf16[IMC_BLOCK_SIZE / 2];
- /* FIXME: input should not be modified */
- for(i = 0; i < FFMIN(buf_size, avctx->block_align) / 2; i++)
- buf16[i] = bswap_16(buf16[i]);
+ if (buf_size < IMC_BLOCK_SIZE) {
+ av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n");
+ return -1;
+ }
+ for(i = 0; i < IMC_BLOCK_SIZE / 2; i++)
+ buf16[i] = bswap_16(((const uint16_t*)buf)[i]);
- init_get_bits(&q->gb, buf, 512);
+ init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8);
/* Check the frame header */
imc_hdr = get_bits(&q->gb, 9);
*data_size = COEFFS * sizeof(int16_t);
- return avctx->block_align;
+ return IMC_BLOCK_SIZE;
}
-static int imc_decode_close(AVCodecContext * avctx)
+static av_cold int imc_decode_close(AVCodecContext * avctx)
{
IMCContext *q = avctx->priv_data;
.init = imc_decode_init,
.close = imc_decode_close,
.decode = imc_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("IMC (Intel Music Coder)"),
};