* @author Ronald S. Bultje <rsbultje@gmail.com>
*/
+#define UNCHECKED_BITSTREAM_READER 1
+
#include <math.h>
+
+#include "dsputil.h"
#include "avcodec.h"
#include "get_bits.h"
#include "put_bits.h"
#include "wmavoice_data.h"
-#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_vectors.h"
#include "acelp_filters.h"
* @name Global values specified in the stream header / extradata or used all over.
* @{
*/
+ AVFrame frame;
GetBitContext gb; ///< packet bitreader. During decoder init,
///< it contains the extradata from the
///< demuxer. During decoding, it contains
* @{
*/
int spillover_nbits; ///< number of bits of the previous packet's
- ///< last superframe preceeding this
+ ///< last superframe preceding this
///< packet's first full superframe (useful
///< for re-synchronization also)
int has_residual_lsps; ///< if set, superframes contain one set of
0x0ffc, 0x0ffd, 0x0ffe, // 1111111111+00/01/10
0x3ffc, 0x3ffd, 0x3ffe, 0x3fff // 111111111111+xx
};
- int cntr[8], n, res;
+ int cntr[8] = { 0 }, n, res;
memset(vbm_tree, 0xff, sizeof(vbm_tree[0]) * 25);
- memset(cntr, 0, sizeof(cntr));
for (n = 0; n < 17; n++) {
res = get_bits(gb, 3);
if (cntr[res] > 3) // should be >= 3 + (res == 7))
ctx->sample_fmt = AV_SAMPLE_FMT_FLT;
+ avcodec_get_frame_defaults(&s->frame);
+ ctx->coded_frame = &s->frame;
+
return 0;
}
/* find best fitting point in history */
do {
- dot = ff_dot_productf(in, ptr, size);
+ dot = ff_scalarproduct_float_c(in, ptr, size);
if (dot > optimal_gain) {
optimal_gain = dot;
best_hist_ptr = ptr;
if (optimal_gain <= 0)
return -1;
- dot = ff_dot_productf(best_hist_ptr, best_hist_ptr, size);
+ dot = ff_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);
if (dot <= 0) // would be 1.0
return -1;
{
float rh0, rh1;
- rh0 = 1.0 + ff_dot_productf(lpcs, lpcs, n_lpcs);
- rh1 = lpcs[0] + ff_dot_productf(lpcs, &lpcs[1], n_lpcs - 1);
+ rh0 = 1.0 + ff_scalarproduct_float_c(lpcs, lpcs, n_lpcs);
+ rh1 = lpcs[0] + ff_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);
return rh1 / rh0;
}
-1.8 * tilt_factor(coeffs, remainder - 1),
coeffs, remainder);
}
- sq = (1.0 / 64.0) * sqrtf(1 / ff_dot_productf(coeffs, coeffs, remainder));
+ sq = (1.0 / 64.0) * sqrtf(1 / ff_scalarproduct_float_c(coeffs, coeffs, remainder));
for (n = 0; n < remainder; n++)
coeffs[n] *= sq;
}
/* Calculate gain for adaptive & fixed codebook signal.
* see ff_amr_set_fixed_gain(). */
idx = get_bits(gb, 7);
- fcb_gain = expf(ff_dot_productf(s->gain_pred_err, gain_coeff, 6) -
+ fcb_gain = expf(ff_scalarproduct_float_c(s->gain_pred_err, gain_coeff, 6) -
5.2409161640 + wmavoice_gain_codebook_fcb[idx]);
acb_gain = wmavoice_gain_codebook_acb[idx];
pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx],
int pitch[MAX_BLOCKS], last_block_pitch;
/* Parse frame type ("frame header"), see frame_descs */
- int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)],
- block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks;
+ int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)], block_nsamples;
if (bd_idx < 0) {
av_log(ctx, AV_LOG_ERROR,
return -1;
}
+ block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks;
+
/* Pitch calculation for ACB_TYPE_ASYMMETRIC ("pitch-per-frame") */
if (frame_descs[bd_idx].acb_type == ACB_TYPE_ASYMMETRIC) {
/* Pitch is provided per frame, which is interpreted as the pitch of
* (if less than 480), usually used to prevent blanks at track boundaries.
*
* @param ctx WMA Voice decoder context
- * @param samples pointer to output buffer for voice samples
- * @param data_size pointer containing the size of #samples on input, and the
- * amount of #samples filled on output
* @return 0 on success, <0 on error or 1 if there was not enough data to
* fully parse the superframe
*/
-static int synth_superframe(AVCodecContext *ctx,
- float *samples, int *data_size)
+static int synth_superframe(AVCodecContext *ctx, int *got_frame_ptr)
{
WMAVoiceContext *s = ctx->priv_data;
GetBitContext *gb = &s->gb, s_gb;
- int n, res, out_size, n_samples = 480;
+ int n, res, n_samples = 480;
double lsps[MAX_FRAMES][MAX_LSPS];
const double *mean_lsf = s->lsps == 16 ?
wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];
float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];
float synth[MAX_LSPS + MAX_SFRAMESIZE];
+ float *samples;
memcpy(synth, s->synth_history,
s->lsps * sizeof(*synth));
}
if ((res = check_bits_for_superframe(gb, s)) == 1) {
- *data_size = 0;
+ *got_frame_ptr = 0;
return 1;
}
stabilize_lsps(lsps[n], s->lsps);
}
- out_size = n_samples * av_get_bytes_per_sample(ctx->sample_fmt);
- if (*data_size < out_size) {
- av_log(ctx, AV_LOG_ERROR,
- "Output buffer too small (%d given - %d needed)\n",
- *data_size, out_size);
- return -1;
+ /* get output buffer */
+ s->frame.nb_samples = 480;
+ if ((res = ctx->get_buffer(ctx, &s->frame)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return res;
}
+ s->frame.nb_samples = n_samples;
+ samples = (float *)s->frame.data[0];
- /* Parse frames, optionally preceeded by per-frame (independent) LSPs. */
+ /* Parse frames, optionally preceded by per-frame (independent) LSPs. */
for (n = 0; n < 3; n++) {
if (!s->has_residual_lsps) {
int m;
lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],
&excitation[s->history_nsamples + n * MAX_FRAMESIZE],
&synth[s->lsps + n * MAX_FRAMESIZE]))) {
- *data_size = 0;
+ *got_frame_ptr = 0;
return res;
}
}
skip_bits(gb, 10 * (res + 1));
}
- /* Specify nr. of output samples */
- *data_size = out_size;
+ *got_frame_ptr = 1;
/* Update history */
memcpy(s->prev_lsps, lsps[2],
* For more information about frames, see #synth_superframe().
*/
static int wmavoice_decode_packet(AVCodecContext *ctx, void *data,
- int *data_size, AVPacket *avpkt)
+ int *got_frame_ptr, AVPacket *avpkt)
{
WMAVoiceContext *s = ctx->priv_data;
GetBitContext *gb = &s->gb;
* capping the packet size at ctx->block_align. */
for (size = avpkt->size; size > ctx->block_align; size -= ctx->block_align);
if (!size) {
- *data_size = 0;
+ *got_frame_ptr = 0;
return 0;
}
init_get_bits(&s->gb, avpkt->data, size << 3);
copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits);
flush_put_bits(&s->pb);
s->sframe_cache_size += s->spillover_nbits;
- if ((res = synth_superframe(ctx, data, data_size)) == 0 &&
- *data_size > 0) {
+ if ((res = synth_superframe(ctx, got_frame_ptr)) == 0 &&
+ *got_frame_ptr) {
cnt += s->spillover_nbits;
s->skip_bits_next = cnt & 7;
+ *(AVFrame *)data = s->frame;
return cnt >> 3;
} else
skip_bits_long (gb, s->spillover_nbits - cnt +
s->sframe_cache_size = 0;
s->skip_bits_next = 0;
pos = get_bits_left(gb);
- if ((res = synth_superframe(ctx, data, data_size)) < 0) {
+ if ((res = synth_superframe(ctx, got_frame_ptr)) < 0) {
return res;
- } else if (*data_size > 0) {
+ } else if (*got_frame_ptr) {
int cnt = get_bits_count(gb);
s->skip_bits_next = cnt & 7;
+ *(AVFrame *)data = s->frame;
return cnt >> 3;
} else if ((s->sframe_cache_size = pos) > 0) {
/* rewind bit reader to start of last (incomplete) superframe... */
AVCodec ff_wmavoice_decoder = {
.name = "wmavoice",
.type = AVMEDIA_TYPE_AUDIO,
- .id = CODEC_ID_WMAVOICE,
+ .id = AV_CODEC_ID_WMAVOICE,
.priv_data_size = sizeof(WMAVoiceContext),
.init = wmavoice_decode_init,
.close = wmavoice_decode_end,
.decode = wmavoice_decode_packet,
- .capabilities = CODEC_CAP_SUBFRAMES,
- .flush = wmavoice_flush,
- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"),
+ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,
+ .flush = wmavoice_flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"),
};