67 p->refl_coef =
av_calloc(p->order,
sizeof(*p->refl_coef));
68 p->target_refl_coef =
av_calloc(p->order,
sizeof(*p->target_refl_coef));
69 p->lpc_coef =
av_calloc(p->order,
sizeof(*p->lpc_coef));
71 sizeof(*p->filter_out));
73 if (!p->refl_coef || !p->target_refl_coef || !p->lpc_coef ||
74 !p->filter_out || !p->excitation) {
90 for (m = 0; m < order; m++) {
92 for (
i = 0;
i < m;
i++)
93 next[
i] = cur[
i] + refl[m] * cur[m -
i - 1];
97 memcpy(lpc, cur,
sizeof(*lpc) * order);
107 int *got_frame_ptr,
AVPacket *avpkt)
110 int buf_size = avpkt->
size;
117 int dbov = -avpkt->
data[0];
118 p->target_energy = 1081109975 *
ff_exp10(dbov / 10.0) * 0.75;
119 memset(p->target_refl_coef, 0, p->order *
sizeof(*p->target_refl_coef));
120 for (
i = 0;
i <
FFMIN(avpkt->
size - 1, p->order);
i++) {
121 p->target_refl_coef[
i] = (avpkt->
data[1 +
i] - 127) / 128.0;
131 p->energy = p->energy / 2 + p->target_energy / 2;
132 for (
i = 0;
i < p->order;
i++)
133 p->refl_coef[
i] = 0.6 *p->refl_coef[
i] + 0.4 * p->target_refl_coef[
i];
135 p->energy = p->target_energy;
136 memcpy(p->refl_coef, p->target_refl_coef, p->order *
sizeof(*p->refl_coef));
141 for (
i = 0;
i < p->order;
i++)
142 e *= 1.0 - p->refl_coef[
i]*p->refl_coef[
i];
144 scaling = sqrt(e * p->energy / 1081109975);
147 p->excitation[
i] = scaling *
r;
155 buf_out = (int16_t *)
frame->data[0];
158 memcpy(p->filter_out, p->filter_out + avctx->
frame_size,
159 p->order *
sizeof(*p->filter_out));
167 .p.name =
"comfortnoise",
const FFCodec ff_comfortnoise_decoder
Libavcodec external API header.
#define i(width, name, range_min, range_max)
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float *in, int buffer_length, int filter_length)
LP synthesis filter.
static av_cold void cng_decode_flush(AVCodecContext *avctx)
static av_cold int cng_decode_close(AVCodecContext *avctx)
static av_cold int cng_decode_init(AVCodecContext *avctx)
static void make_lpc_coefs(float *lpc, const float *refl, int order)
static int cng_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal and external API header
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
@ AV_CODEC_ID_COMFORT_NOISE
#define AV_CHANNEL_LAYOUT_MONO
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ AV_SAMPLE_FMT_S16
signed 16 bits
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
common internal api header.
#define FFSWAP(type, a, b)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
An AVChannelLayout holds information about the channel layout of audio data.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
int frame_size
Number of samples per channel in an audio frame.
struct AVCodecInternal * internal
Private context used for internal data.
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
This structure describes decoded (raw) audio or video data.
Context structure for the Lagged Fibonacci PRNG.
This structure stores compressed data.