All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Go to the documentation of this file.
1 /*
2  * Real Audio 1.0 (14.4K)
3  * Copyright (c) 2003 The FFmpeg Project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
22 #ifndef AVCODEC_RA144_H
23 #define AVCODEC_RA144_H
25 #include <stdint.h>
26 #include "lpc.h"
27 #include "audio_frame_queue.h"
28 #include "audiodsp.h"
30 #define NBLOCKS 4 ///< number of subblocks within a block
31 #define BLOCKSIZE 40 ///< subblock size in 16-bit words
32 #define BUFFERSIZE 146 ///< the size of the adaptive codebook
33 #define FIXED_CB_SIZE 128 ///< size of fixed codebooks
34 #define FRAME_SIZE 20 ///< size of encoded frame
35 #define LPC_ORDER 10 ///< order of LPC filter
37 typedef struct RA144Context {
44  unsigned int old_energy; ///< previous frame energy
46  unsigned int lpc_tables[2][10];
48  /** LPC coefficients: lpc_coef[0] is the coefficients of the current frame
49  * and lpc_coef[1] of the previous one. */
50  unsigned int *lpc_coef[2];
52  unsigned int lpc_refl_rms[2];
56  /** The current subblock padded by the last 10 values of the previous one. */
57  int16_t curr_sblock[50];
59  /** Adaptive codebook, its size is two units bigger to avoid a
60  * buffer overflow. */
61  int16_t adapt_cb[146+2];
64 } RA144Context;
66 void ff_copy_and_dup(int16_t *target, const int16_t *source, int offset);
67 int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx);
68 void ff_eval_coefs(int *coefs, const int *refl);
69 void ff_int_to_int16(int16_t *out, const int *inp);
70 int ff_t_sqrt(unsigned int x);
71 unsigned int ff_rms(const int *data);
72 int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold,
73  int energy);
74 unsigned int ff_rescale_rms(unsigned int rms, unsigned int energy);
75 int ff_irms(AudioDSPContext *adsp, const int16_t *data/*align 16*/);
76 void ff_subblock_synthesis(RA144Context *ractx, const int16_t *lpc_coefs,
77  int cba_idx, int cb1_idx, int cb2_idx,
78  int gval, int gain);
80 extern const int16_t ff_gain_val_tab[256][3];
81 extern const uint8_t ff_gain_exp_tab[256];
82 extern const int8_t ff_cb1_vects[128][40];
83 extern const int8_t ff_cb2_vects[128][40];
84 extern const uint16_t ff_cb1_base[128];
85 extern const uint16_t ff_cb2_base[128];
86 extern const int16_t ff_energy_tab[32];
87 extern const int16_t * const ff_lpc_refl_cb[10];
89 #endif /* AVCODEC_RA144_H */
unsigned int lpc_tables[2][10]
Definition: ra144.h:46
unsigned int ff_rms(const int *data)
Definition: ra144.c:1636
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
Definition: lpc.h:51
const uint16_t ff_cb1_base[128]
Definition: ra144.c:1402
int16_t adapt_cb[146+2]
Adaptive codebook, its size is two units bigger to avoid a buffer overflow.
Definition: ra144.h:61
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:53
void ff_subblock_synthesis(RA144Context *ractx, const int16_t *lpc_coefs, int cba_idx, int cb1_idx, int cb2_idx, int gval, int gain)
Definition: ra144.c:1694
int ff_irms(AudioDSPContext *adsp, const int16_t *data)
inverse root mean square
Definition: ra144.c:1684
#define FFALIGN(x, a)
Definition: common.h:71
#define NBLOCKS
number of subblocks within a block
Definition: ra144.h:30
const int16_t ff_energy_tab[32]
Definition: ra144.c:1440
unsigned int lpc_refl_rms[2]
Definition: ra144.h:52
int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx)
Evaluate the reflection coefficients from the filter coefficients.
Definition: ra144.c:1545
AVCodecContext * avctx
Definition: ra144.h:38
void ff_int_to_int16(int16_t *out, const int *inp)
Definition: ra144.c:1613
int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy)
Definition: ra144.c:1657
unsigned int * lpc_coef[2]
LPC coefficients: lpc_coef[0] is the coefficients of the current frame and lpc_coef[1] of the previou...
Definition: ra144.h:50
const int8_t ff_cb2_vects[128][40]
Definition: ra144.c:758
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
AudioFrameQueue afq
Definition: ra144.h:41
unsigned int ff_rescale_rms(unsigned int rms, unsigned int energy)
Definition: ra144.c:1678
int last_frame
Definition: ra144.h:42
subblock size in 16-bit words
Definition: ra144.h:31
const int8_t ff_cb1_vects[128][40]
Definition: ra144.c:114
const int16_t ff_gain_val_tab[256][3]
Definition: ra144.c:28
main external API structure.
Definition: avcodec.h:1241
void ff_eval_coefs(int *coefs, const int *refl)
Evaluate the LPC filter coefficients from the reflection coefficients.
Definition: ra144.c:1593
void ff_copy_and_dup(int16_t *target, const int16_t *source, int offset)
Copy the last offset values of *source to *target.
Definition: ra144.c:1530
LPCContext lpc_ctx
Definition: ra144.h:40
const uint16_t ff_cb2_base[128]
Definition: ra144.c:1421
int16_t buffer_a[FFALIGN(BLOCKSIZE, 16)]
Definition: ra144.h:63
AudioDSPContext adsp
Definition: ra144.h:39
unsigned int old_energy
previous frame energy
Definition: ra144.h:44
int16_t curr_sblock[50]
The current subblock padded by the last 10 values of the previous one.
Definition: ra144.h:57
int ff_t_sqrt(unsigned int x)
Evaluate sqrt(x << 24).
Definition: ra144.c:1625
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int16_t curr_block[NBLOCKS *BLOCKSIZE]
Definition: ra144.h:54
const uint8_t ff_gain_exp_tab[256]
Definition: ra144.c:95
const int16_t *const ff_lpc_refl_cb[10]
Definition: ra144.c:1502