00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <inttypes.h>
00023 #include <limits.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <math.h>
00027 #include <assert.h>
00028
00029 #include "avcodec.h"
00030 #include "libavutil/avutil.h"
00031 #include "bitstream.h"
00032
00033 #include "g729.h"
00034 #include "lsp.h"
00035 #include "celp_math.h"
00036 #include "acelp_filters.h"
00037 #include "acelp_pitch_delay.h"
00038 #include "acelp_vectors.h"
00039 #include "g729data.h"
00040
00045 #define LSFQ_MIN 40
00046
00051 #define LSFQ_MAX 25681
00052
00057 #define LSFQ_DIFF_MIN 321
00058
00063 #define SHARP_MIN 3277
00064
00072 #define SHARP_MAX 13017
00073
00074 typedef struct
00075 {
00076 int sample_rate;
00077 uint8_t packed_frame_size;
00078 uint8_t unpacked_frame_size;
00079 uint8_t fc_indexes_bits;
00080
00082 int mr_energy;
00083 } G729_format_description;
00084
00088 static inline uint16_t g729_random(uint16_t value)
00089 {
00090 return 31821 * value + 13849;
00091 }
00092
00096 static inline int g729_get_parity(uint8_t value)
00097 {
00098 return (0x6996966996696996ULL >> (value >> 2)) & 1;
00099 }
00100
00101 if(avctx->channels != 1)
00102 {
00103 av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels);
00104 return AVERROR_NOFMT;
00105 }
00106
00107 ff_acelp_weighted_vector_sum(
00108 fc + pitch_delay_int[i],
00109 fc + pitch_delay_int[i],
00110 fc,
00111 1 << 14,
00112 av_clip(ctx->gain_pitch, SHARP_MIN, SHARP_MAX),
00113 0,
00114 14,
00115 ctx->subframe_size - pitch_delay_int[i]);
00116
00117 if(ctx->frame_erasure)
00118 {
00119 ctx->gain_pitch = (29491 * ctx->gain_pitch) >> 15;
00120 ctx->gain_code = (2007 * ctx->gain_code) >> 11;
00121
00122 gain_corr_factor = 0;
00123 }
00124 else
00125 {
00126 ctx->gain_pitch = cb_gain_1st_8k[parm->gc_1st_index[i]][0] +
00127 cb_gain_2nd_8k[parm->gc_2nd_index[i]][0];
00128 gain_corr_factor = cb_gain_1st_8k[parm->gc_1st_index[i]][1] +
00129 cb_gain_2nd_8k[parm->gc_2nd_index[i]][1];
00130
00131 ff_acelp_weighted_vector_sum(
00132 ctx->exc + i * ctx->subframe_size,
00133 ctx->exc + i * ctx->subframe_size,
00134 fc,
00135 (!voicing && ctx->frame_erasure) ? 0 : ctx->gain_pitch,
00136 ( voicing && ctx->frame_erasure) ? 0 : ctx->gain_code,
00137 1<<13,
00138 14,
00139 ctx->subframe_size);
00140
00141 if (buf_size<packed_frame_size)
00142 {
00143 av_log(avctx, AV_LOG_ERROR, "Error processing packet: packet size too small\n");
00144 return AVERROR(EIO);
00145 }
00146 if (*data_size<unpacked_frame_size)
00147 {
00148 av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer too small\n");
00149 return AVERROR(EIO);
00150 }
00151
00152 AVCodec g729_decoder =
00153 {
00154 "g729",
00155 CODEC_TYPE_AUDIO,
00156 CODEC_ID_G729,
00157 sizeof(G729_Context),
00158 ff_g729_decoder_init,
00159 NULL,
00160 NULL,
00161 ff_g729_decode_frame,
00162 .long_name = NULL_IF_CONFIG_SMALL("G.729"),
00163 };