/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
Written by Jean-Marc Valin and Koen Vos */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdarg.h>
#include "celt.h"
#include "entenc.h"
#include "modes.h"
#include "API.h"
#include "stack_alloc.h"
#include "float_cast.h"
#include "opus.h"
#include "arch.h"
#include "pitch.h"
#include "opus_private.h"
#include "os_support.h"
#include "cpu_support.h"
#include "analysis.h"
#include "mathops.h"
#include "tuning_parameters.h"
#ifdef FIXED_POINT
#include "fixed/structs_FIX.h"
#else
#include "float/structs_FLP.h"
#endif
#define MAX_ENCODER_BUFFER 480
typedef struct {
opus_val32 XX, XY, YY;
opus_val16 smoothed_width;
opus_val16 max_follower;
} StereoWidthState;
struct OpusEncoder {
int celt_enc_offset;
int silk_enc_offset;
silk_EncControlStruct silk_mode;
int application;
int channels;
int delay_compensation;
int force_channels;
int signal_type;
int user_bandwidth;
int max_bandwidth;
int user_forced_mode;
int voice_ratio;
opus_int32 Fs;
int use_vbr;
int vbr_constraint;
int variable_duration;
opus_int32 bitrate_bps;
opus_int32 user_bitrate_bps;
int lsb_depth;
int encoder_buffer;
int lfe;
int arch;
#ifndef DISABLE_FLOAT_API
TonalityAnalysisState analysis;
#endif
#define OPUS_ENCODER_RESET_START stream_channels
int stream_channels;
opus_int16 hybrid_stereo_width_Q14;
opus_int32 variable_HP_smth2_Q15;
opus_val16 prev_HB_gain;
opus_val32 hp_mem[4];
int mode;
int prev_mode;
int prev_channels;
int prev_framesize;
int bandwidth;
int silk_bw_switch;
/* Sampling rate (at the API level) */
int first;
opus_val16 * energy_masking;
StereoWidthState width_mem;
opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2];
#ifndef DISABLE_FLOAT_API
int detected_bandwidth;
#endif
opus_uint32 rangeFinal;
};
/* Transition tables for the voice and music. First column is the
middle (memoriless) threshold. The second column is the hysteresis
(difference with the middle) */
static const opus_int32 mono_voice_bandwidth_thresholds[8] = {
11000, 1000, /* NB<->MB */
14000, 1000, /* MB<->WB */
17000, 1000, /* WB<->SWB */
21000, 2000, /* SWB<->FB */
};
static const opus_int32 mono_music_bandwidth_thresholds[8] = {
12000, 1000, /* NB<->MB */
15000, 1000, /* MB<->WB */
18000, 2000, /* WB<->SWB */
22000, 2000, /* SWB<->FB */
};
static const opus_int32 stereo_voice_bandwidth_thresholds[8] = {
11000, 1000, /* NB<->MB */
14000, 1000, /* MB<->WB */
21000, 2000, /* WB<->SWB */
28000, 2000, /* SWB<->FB */
};
static const opus_int32 stereo_music_bandwidth_thresholds[8] = {
12000, 1000, /* NB<->MB */
18000, 2000, /* MB<->WB */
21000, 2000, /* WB<->SWB */
30000, 2000, /* SWB<->FB */
};
/* Threshold bit-rates for switching between mono and stereo */
static const opus_int32 stereo_voice_threshold = 30000;
static const opus_int32 stereo_music_threshold = 30000;
/* Threshold bit-rate for switching between SILK/hybrid and CELT-only */
static const opus_int32 mode_thresholds[2][2] = {
/* voice */ /* music */
{ 64000, 16000}, /* mono */
{ 36000, 16000}, /* stereo */
};
int opus_encoder_get_size(int channels)
{
int silkEncSizeBytes, celtEncSizeBytes;
int ret;
if (channels<1 || channels > 2)
return 0;
ret = silk_Get_Encoder_Size( &silkEncSizeBytes );
if (ret)
return 0;
silkEncSizeBytes = align(silkEncSizeBytes);
celtEncSizeBytes = celt_encoder_get_size(channels);
return align(sizeof(OpusEncoder))+silkEncSizeBytes+celtEncSizeBytes;
}
int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int application)
{
void *silk_enc;
CELTEncoder *celt_enc;
int err;
int ret, silkEncSizeBytes;
if((Fs!=48000&&Fs!=24000&&Fs!=16000&&Fs!=12000&&Fs!=8000)||(channels!=1&&channels!=2)||
(application != OPUS_APPLICATION_VOIP && application != OPUS_APPLICATION_AUDIO
&& application != OPUS_APPLICATION_RESTRICTED_LOWDELAY))
return OPUS_BAD_ARG;
OPUS_CLEAR((char*)st, opus_encoder_get_size(channels));
/* Create SILK encoder */
ret = silk_Get_Encoder_Size( &silkEncSizeBytes );
if (ret)
return OPUS_BAD_ARG;
silkEncSizeBytes = align(silkEncSizeBytes);
st->silk_enc_offset = align(sizeof(OpusEncoder));
st->celt_enc_offset = st->silk_enc_offset+silkEncSizeBytes;
silk_enc = (char*)st+st->silk_enc_offset;
celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
st->stream_channels = st->channels = channels;
st->Fs = Fs;
st->arch = opus_select_arch();
ret = silk_InitEncoder( silk_enc, st->arch, &st->silk_mode );
if(ret)return OPUS_INTERNAL_ERROR;
/* default SILK parameters */
st->silk_mode.nChannelsAPI = channels;
st->silk_mode.nChannelsInternal = channels;
st->silk_mode.API_sampleRate = st->Fs;
st->silk_mode.maxInternalSampleRate = 16000;
st->silk_mode.minInternalSampleRate = 8000;
st->silk_mode.desiredInternalSampleRate = 16000;
st->silk_mode.payloadSize_ms = 20;
st->silk_mode.bitRate = 25000;
st->silk_mode.packetLossPercentage = 0;
st->silk_mode.complexity = 9;
st->silk_mode.useInBandFEC = 0;
st->silk_mode.useDTX = 0;
st->silk_mode.useCBR = 0;
st->silk_mode.reducedDependency = 0;
/* Create CELT encoder */
/* Initialize CELT encoder */
err = celt_encoder_init(celt_enc, Fs, channels, st->arch);
if(err!=OPUS_OK)return OPUS_INTERNAL_ERROR;
celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0));
celt_encoder_ctl(celt_enc, OPUS_SET_COMPLEXITY(st->silk_mode.complexity));
st->use_vbr = 1;
/* Makes constrained VBR the default (safer for real-time use) */
st->vbr_constraint = 1;
st->user_bitrate_bps = OPUS_AUTO;
st->bitrate_bps = 3000+Fs*channels;
st->application = application;
st->signal_type = OPUS_AUTO;
st->user_bandwidth = OPUS_AUTO;
st->max_bandwidth = OPUS_BANDWIDTH_FULLBAND;
st->force_channels = OPUS_AUTO;
st->user_forced_mode = OPUS_AUTO;
st->voice_ratio = -1;
st
没有合适的资源?快使用搜索试试~ 我知道了~
音频编码之opus(最新)
需积分: 50 41 下载量 121 浏览量
2019-03-06
17:54:48
上传
评论 3
收藏 956KB GZ 举报
温馨提示
共370个文件
c:198个
h:99个
m4:9个
opus是一个高保真的适合在网络中传输的开源的语音编码格式,相对于其他编码格式来讲,保真性更好
资源推荐
资源详情
资源评论
收起资源包目录
音频编码之opus(最新) (370个子文件)
configure.ac 31KB
Makefile.am 10KB
Makefile.am 1KB
AUTHORS 239B
genversion.bat 926B
opus_encoder.c 84KB
celt_encoder.c 75KB
test_opus_api.c 69KB
NSQ_del_dec_sse.c 45KB
bands.c 43KB
NSQ_del_dec.c 38KB
opus_multistream_encoder.c 38KB
celt_decoder.c 37KB
pitch_analysis_core_FIX.c 35KB
opus_demo.c 34KB
NSQ_sse.c 33KB
enc_API.c 30KB
pitch_analysis_core_FLP.c 29KB
opus_decoder.c 28KB
cwrs.c 28KB
analysis.c 25KB
noise_shape_analysis_FIX.c 24KB
NSQ.c 22KB
burg_modified_FIX_sse.c 21KB
rate.c 21KB
test_opus_encode.c 21KB
encode_frame_FIX.c 21KB
control_codec.c 20KB
PLC.c 20KB
dec_API.c 19KB
encode_frame_FLP.c 19KB
quant_bands.c 18KB
noise_shape_analysis_FLP.c 17KB
burg_modified_FIX.c 16KB
kiss_fft.c 16KB
test_opus_decode.c 15KB
VAD.c 15KB
pitch.c 14KB
opus_multistream_decoder.c 14KB
modes.c 14KB
find_LTP_FIX.c 13KB
stereo_LR_to_MS.c 12KB
decode_core.c 12KB
NLSF_del_dec_quant.c 12KB
test_unit_entropy.c 12KB
solve_LS_FIX.c 12KB
prefilter_FIX.c 11KB
VAD_sse.c 11KB
vq.c 11KB
tables_pulses_per_block.c 11KB
opus_compare.c 11KB
tables_NLSF_CB_WB.c 11KB
resampler_private_down_FIR.c 11KB
mdct.c 11KB
A2NLSF.c 11KB
x86_silk_map.c 10KB
LPC_analysis_filter_FLP.c 10KB
solve_LS_FLP.c 10KB
wrappers_FLP.c 10KB
resampler.c 10KB
opus.c 10KB
repacketizer.c 10KB
CNG.c 9KB
entenc.c 9KB
encode_indices.c 9KB
celt_neon_intr.c 9KB
prefilter_FLP.c 9KB
encode_pulses.c 9KB
corrMatrix_FIX.c 9KB
tables_NLSF_CB_NB_MB.c 8KB
celt_lpc.c 8KB
celt.c 8KB
celt_ne10_mdct.c 8KB
entdec.c 8KB
burg_modified_FLP.c 8KB
NLSF2A.c 8KB
find_pred_coefs_FIX.c 8KB
shell_coder.c 8KB
test_unit_mathops.c 7KB
tables_LTP.c 7KB
find_pitch_lags_FIX.c 7KB
find_LPC_FIX.c 7KB
decode_indices.c 7KB
prefilter_FIX_sse.c 7KB
quant_LTP_gains.c 7KB
gain_quant.c 7KB
debug.c 7KB
mathops.c 7KB
repacketizer_demo.c 6KB
process_gains_FIX.c 6KB
VQ_WMat_EC_sse.c 6KB
NLSF_encode.c 6KB
LP_variable_cutoff.c 6KB
find_pitch_lags_FLP.c 6KB
pitch_sse4_1.c 6KB
NLSF_stabilize.c 6KB
LPC_inv_pred_gain.c 6KB
sort.c 6KB
opus_custom_demo.c 6KB
test_unit_mdct.c 6KB
共 370 条
- 1
- 2
- 3
- 4
资源评论
论持久战-YJL
- 粉丝: 4
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功