#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define CELT_ENCODER_C
#include "cpu_support.h"
#include "os_support.h"
#include "mdct.h"
#include <math.h>
#include "celt.h"
#include "pitch.h"
#include "bands.h"
#include "modes.h"
#include "entcode.h"
#include "quant_bands.h"
#include "rate.h"
#include "stack_alloc.h"
#include "mathops.h"
#include "float_cast.h"
#include <stdarg.h>
#include "celt_lpc.h"
#include "vq.h"
struct OpusCustomEncoder { … };
int celt_encoder_get_size(int channels)
{ … }
OPUS_CUSTOM_NOSTATIC int opus_custom_encoder_get_size(const CELTMode *mode, int channels)
{ … }
#ifdef CUSTOM_MODES
CELTEncoder *opus_custom_encoder_create(const CELTMode *mode, int channels, int *error)
{
int ret;
CELTEncoder *st = (CELTEncoder *)opus_alloc(opus_custom_encoder_get_size(mode, channels));
ret = opus_custom_encoder_init(st, mode, channels);
if (ret != OPUS_OK)
{
opus_custom_encoder_destroy(st);
st = NULL;
}
if (error)
*error = ret;
return st;
}
#endif
static int opus_custom_encoder_init_arch(CELTEncoder *st, const CELTMode *mode,
int channels, int arch)
{ … }
#ifdef CUSTOM_MODES
int opus_custom_encoder_init(CELTEncoder *st, const CELTMode *mode, int channels)
{
return opus_custom_encoder_init_arch(st, mode, channels, opus_select_arch());
}
#endif
int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels,
int arch)
{ … }
#ifdef CUSTOM_MODES
void opus_custom_encoder_destroy(CELTEncoder *st)
{
opus_free(st);
}
#endif
static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int C,
opus_val16 *tf_estimate, int *tf_chan, int allow_weak_transients,
int *weak_transient)
{ … }
static int patch_transient_decision(opus_val16 *newE, opus_val16 *oldE, int nbEBands,
int start, int end, int C)
{ … }
static void compute_mdcts(const CELTMode *mode, int shortBlocks, celt_sig * OPUS_RESTRICT in,
celt_sig * OPUS_RESTRICT out, int C, int CC, int LM, int upsample,
int arch)
{ … }
void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp,
int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip)
{ … }
static opus_val32 l1_metric(const celt_norm *tmp, int N, int LM, opus_val16 bias)
{ … }
static int tf_analysis(const CELTMode *m, int len, int isTransient,
int *tf_res, int lambda, celt_norm *X, int N0, int LM,
opus_val16 tf_estimate, int tf_chan, int *importance)
{ … }
static void tf_encode(int start, int end, int isTransient, int *tf_res, int LM, int tf_select, ec_enc *enc)
{ … }
static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
const opus_val16 *bandLogE, int end, int LM, int C, int N0,
AnalysisInfo *analysis, opus_val16 *stereo_saving, opus_val16 tf_estimate,
int intensity, opus_val16 surround_trim, opus_int32 equiv_rate, int arch)
{ … }
static int stereo_analysis(const CELTMode *m, const celt_norm *X,
int LM, int N0)
{ … }
#define MSWAP(a,b) …
static opus_val16 median_of_5(const opus_val16 *x)
{ … }
static opus_val16 median_of_3(const opus_val16 *x)
{ … }
static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2,
int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN,
int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM,
int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc,
AnalysisInfo *analysis, int *importance, int *spread_weight)
{ … }
static int run_prefilter(CELTEncoder *st, celt_sig *in, celt_sig *prefilter_mem, int CC, int N,
int prefilter_tapset, int *pitch, opus_val16 *gain, int *qgain, int enabled, int nbAvailableBytes, AnalysisInfo *analysis)
{ … }
static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 base_target,
int LM, opus_int32 bitrate, int lastCodedBands, int C, int intensity,
int constrained_vbr, opus_val16 stereo_saving, int tot_boost,
opus_val16 tf_estimate, int pitch_change, opus_val16 maxDepth,
int lfe, int has_surround_mask, opus_val16 surround_masking,
opus_val16 temporal_vbr)
{ … }
int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc)
{ … }
#ifdef CUSTOM_MODES
#ifdef FIXED_POINT
int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
{
return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
}
#ifndef DISABLE_FLOAT_API
int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
{
int j, ret, C, N;
VARDECL(opus_int16, in);
ALLOC_STACK;
if (pcm==NULL)
return OPUS_BAD_ARG;
C = st->channels;
N = frame_size;
ALLOC(in, C*N, opus_int16);
for (j=0;j<C*N;j++)
in[j] = FLOAT2INT16(pcm[j]);
ret=celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL);
#ifdef RESYNTH
for (j=0;j<C*N;j++)
((float*)pcm)[j]=in[j]*(1.f/32768.f);
#endif
RESTORE_STACK;
return ret;
}
#endif
#else
int opus_custom_encode(CELTEncoder * OPUS_RESTRICT st, const opus_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
{
int j, ret, C, N;
VARDECL(celt_sig, in);
ALLOC_STACK;
if (pcm==NULL)
return OPUS_BAD_ARG;
C=st->channels;
N=frame_size;
ALLOC(in, C*N, celt_sig);
for (j=0;j<C*N;j++) {
in[j] = SCALEOUT(pcm[j]);
}
ret = celt_encode_with_ec(st,in,frame_size,compressed,nbCompressedBytes, NULL);
#ifdef RESYNTH
for (j=0;j<C*N;j++)
((opus_int16*)pcm)[j] = FLOAT2INT16(in[j]);
#endif
RESTORE_STACK;
return ret;
}
int opus_custom_encode_float(CELTEncoder * OPUS_RESTRICT st, const float * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes)
{
return celt_encode_with_ec(st, pcm, frame_size, compressed, nbCompressedBytes, NULL);
}
#endif
#endif
int opus_custom_encoder_ctl(CELTEncoder * OPUS_RESTRICT st, int request, ...)
{ … }