chore: update

This commit is contained in:
skdhg committed 2023-08-09 23:22:32 +05:45
1 parent 345a8c44ca
commit 71b3dc90ee
136 files changed
+3928 -2157

No files matched your search

+2
View File
@@ -31,7 +31,9 @@
#define ANALYSIS_C
#ifdef MLP_TRAINING
#include <stdio.h>
#endif
#include "mathops.h"
#include "kiss_fft.h"
+45
View File
@@ -0,0 +1,45 @@
opus_sources = sources['OPUS_SOURCES']
opus_sources_float = sources['OPUS_SOURCES_FLOAT']
if not disable_float_api
opus_sources += opus_sources_float
endif
opus_lib_c_args = []
if host_machine.system() == 'windows'
opus_lib_c_args += ['-DDLL_EXPORT']
endif
opus_lib = library('opus',
opus_sources,
version: libversion,
darwin_versions: macosversion,
c_args: opus_lib_c_args,
include_directories: opus_includes,
link_with: [celt_lib, silk_lib],
dependencies: libm,
install: true)
opus_dep = declare_dependency(link_with: opus_lib,
include_directories: opus_public_includes)
# Extra uninstalled Opus programs
if not extra_programs.disabled()
foreach prog : ['opus_compare', 'opus_demo', 'repacketizer_demo']
executable(prog, '@[email protected]'.format(prog),
include_directories: opus_includes,
link_with: opus_lib,
dependencies: libm,
install: false)
endforeach
if opt_custom_modes
executable('opus_custom_demo', '../celt/opus_custom_demo.c',
include_directories: opus_includes,
link_with: opus_lib,
dependencies: libm,
install: false)
endif
endif
+12 -3
View File
@@ -278,7 +278,8 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
ec_dec_init(&dec,(unsigned char*)data,len);
} else {
audiosize = frame_size;
mode = st->prev_mode;
/* Run PLC using last used mode (CELT if we ended with CELT redundancy) */
mode = st->prev_redundancy ? MODE_CELT_ONLY : st->prev_mode;
bandwidth = 0;
if (mode == 0)
@@ -419,7 +420,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
start_band = 0;
if (!decode_fec && mode != MODE_CELT_ONLY && data != NULL
&& ec_tell(&dec)+17+20*(st->mode == MODE_HYBRID) <= 8*len)
&& ec_tell(&dec)+17+20*(mode == MODE_HYBRID) <= 8*len)
{
/* Check if we have a redundant 0-8 kHz band */
if (mode == MODE_HYBRID)
@@ -499,6 +500,11 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
/* 5 ms redundant frame for CELT->SILK*/
if (redundancy && celt_to_silk)
{
/* If the previous frame did not use CELT (the first redundancy frame in
a transition from SILK may have been lost) then the CELT decoder is
stale at this point and the redundancy audio is not useful, however
the final range is still needed (for testing), so the redundancy is
always decoded but the decoded audio may not be used */
MUST_SUCCEED(celt_decoder_ctl(celt_dec, CELT_SET_START_BAND(0)));
celt_decode_with_ec(celt_dec, data+len, redundancy_bytes,
redundant_audio, F5, NULL, 0);
@@ -561,7 +567,10 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
smooth_fade(pcm+st->channels*(frame_size-F2_5), redundant_audio+st->channels*F2_5,
pcm+st->channels*(frame_size-F2_5), F2_5, st->channels, window, st->Fs);
}
if (redundancy && celt_to_silk)
/* 5ms redundant frame for CELT->SILK; ignore if the previous frame did not
use CELT (the first redundancy frame in a transition from SILK may have
been lost) */
if (redundancy && celt_to_silk && (st->prev_mode != MODE_SILK_ONLY || st->prev_redundancy))
{
for (c=0;c<st->channels;c++)
{
+52 -55
View File
@@ -87,6 +87,7 @@ struct OpusEncoder {
int lfe;
int arch;
int use_dtx; /* general DTX for both SILK and CELT */
int fec_config;
#ifndef DISABLE_FLOAT_API
TonalityAnalysisState analysis;
#endif
@@ -112,7 +113,7 @@ struct OpusEncoder {
opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2];
#ifndef DISABLE_FLOAT_API
int detected_bandwidth;
int nb_no_activity_frames;
int nb_no_activity_ms_Q1;
opus_val32 peak_signal_energy;
#endif
int nonfinal_frame; /* current frame is not the final in a packet */
@@ -892,44 +893,29 @@ static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, in
#endif
/* Decides if DTX should be turned on (=1) or off (=0) */
static int decide_dtx_mode(float activity_probability, /* probability that current frame contains speech/music */
int *nb_no_activity_frames, /* number of consecutive frames with no activity */
opus_val32 peak_signal_energy, /* peak energy of desired signal detected so far */
const opus_val16 *pcm, /* input pcm signal */
int frame_size, /* frame size */
int channels,
int is_silence, /* only digital silence detected in this frame */
int arch
)
static int decide_dtx_mode(opus_int activity, /* indicates if this frame contains speech/music */
int *nb_no_activity_ms_Q1, /* number of consecutive milliseconds with no activity, in Q1 */
int frame_size_ms_Q1 /* number of miliseconds in this update, in Q1 */
)
{
opus_val32 noise_energy;
if (!is_silence)
if (!activity)
{
if (activity_probability < DTX_ACTIVITY_THRESHOLD) /* is noise */
/* The number of consecutive DTX frames should be within the allowed bounds.
Note that the allowed bound is defined in the SILK headers and assumes 20 ms
frames. As this function can be called with any frame length, a conversion to
milliseconds is done before the comparisons. */
(*nb_no_activity_ms_Q1) += frame_size_ms_Q1;
if (*nb_no_activity_ms_Q1 > NB_SPEECH_FRAMES_BEFORE_DTX*20*2)
{
noise_energy = compute_frame_energy(pcm, frame_size, channels, arch);
/* but is sufficiently quiet */
is_silence = peak_signal_energy >= (PSEUDO_SNR_THRESHOLD * noise_energy);
}
}
if (is_silence)
{
/* The number of consecutive DTX frames should be within the allowed bounds */
(*nb_no_activity_frames)++;
if (*nb_no_activity_frames > NB_SPEECH_FRAMES_BEFORE_DTX)
{
if (*nb_no_activity_frames <= (NB_SPEECH_FRAMES_BEFORE_DTX + MAX_CONSECUTIVE_DTX))
if (*nb_no_activity_ms_Q1 <= (NB_SPEECH_FRAMES_BEFORE_DTX + MAX_CONSECUTIVE_DTX)*20*2)
/* Valid frame for DTX! */
return 1;
else
(*nb_no_activity_frames) = NB_SPEECH_FRAMES_BEFORE_DTX;
(*nb_no_activity_ms_Q1) = NB_SPEECH_FRAMES_BEFORE_DTX*20*2;
}
} else
(*nb_no_activity_frames) = 0;
(*nb_no_activity_ms_Q1) = 0;
return 0;
}
@@ -1102,6 +1088,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
int analysis_read_subframe_bak=-1;
int is_silence = 0;
#endif
opus_int activity = VAD_NO_DECISION;
VARDECL(opus_val16, tmp_prefill);
ALLOC_STACK;
@@ -1169,6 +1157,20 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
if (!is_silence)
st->voice_ratio = -1;
if (is_silence)
{
activity = !is_silence;
} else if (analysis_info.valid)
{
activity = analysis_info.activity_probability >= DTX_ACTIVITY_THRESHOLD;
if (!activity)
{
/* Mark as active if this noise frame is sufficiently loud */
opus_val32 noise_energy = compute_frame_energy(pcm, frame_size, st->channels, st->arch);
activity = st->peak_signal_energy < (PSEUDO_SNR_THRESHOLD * noise_energy);
}
}
st->detected_bandwidth = 0;
if (analysis_info.valid)
{
@@ -1313,6 +1315,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->stream_channels = st->force_channels;
} else {
#ifdef FUZZING
(void)stereo_music_threshold;
(void)stereo_voice_threshold;
/* Random mono/stereo decision */
if (st->channels == 2 && (rand()&0x1F)==0)
st->stream_channels = 3-st->stream_channels;
@@ -1351,6 +1355,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
} else if (st->user_forced_mode == OPUS_AUTO)
{
#ifdef FUZZING
(void)stereo_width;
(void)mode_thresholds;
/* Random mode switching */
if ((rand()&0xF)==0)
{
@@ -1388,8 +1394,9 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->mode = (equiv_rate >= threshold) ? MODE_CELT_ONLY: MODE_SILK_ONLY;
/* When FEC is enabled and there's enough packet loss, use SILK */
if (st->silk_mode.useInBandFEC && st->silk_mode.packetLossPercentage > (128-voice_est)>>4)
/* When FEC is enabled and there's enough packet loss, use SILK.
Unless the FEC is set to 2, in which case we don't switch to SILK if we're confident we have music. */
if (st->silk_mode.useInBandFEC && st->silk_mode.packetLossPercentage > (128-voice_est)>>4 && (st->fec_config != 2 || voice_est > 25))
st->mode = MODE_SILK_ONLY;
/* When encoding voice and DTX is enabled but the generalized DTX cannot be used,
use SILK in order to make use of its DTX. */
@@ -1668,7 +1675,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
if (st->mode != MODE_CELT_ONLY)
{
opus_int32 total_bitRate, celt_rate;
opus_int activity;
#ifdef FIXED_POINT
const opus_int16 *pcm_silk;
#else
@@ -1676,14 +1682,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
ALLOC(pcm_silk, st->channels*frame_size, opus_int16);
#endif
activity = VAD_NO_DECISION;
#ifndef DISABLE_FLOAT_API
if( analysis_info.valid ) {
/* Inform SILK about the Opus VAD decision */
activity = ( analysis_info.activity_probability >= DTX_ACTIVITY_THRESHOLD );
}
#endif
/* Distribute bits between SILK and CELT */
total_bitRate = 8 * bytes_target * frame_rate;
if( st->mode == MODE_HYBRID ) {
@@ -2144,8 +2142,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
#ifndef DISABLE_FLOAT_API
if (st->use_dtx && (analysis_info.valid || is_silence))
{
if (decide_dtx_mode(analysis_info.activity_probability, &st->nb_no_activity_frames,
st->peak_signal_energy, pcm, frame_size, st->channels, is_silence, st->arch))
if (decide_dtx_mode(activity, &st->nb_no_activity_ms_Q1, 2*1000*frame_size/st->Fs))
{
st->rangeFinal = 0;
data[0] = gen_toc(st->mode, st->Fs/frame_size, curr_bandwidth, st->stream_channels);
@@ -2153,7 +2150,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
return 1;
}
} else {
st->nb_no_activity_frames = 0;
st->nb_no_activity_ms_Q1 = 0;
}
#endif
@@ -2448,11 +2445,12 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
case OPUS_SET_INBAND_FEC_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
if(value<0 || value>1)
if(value<0 || value>2)
{
goto bad_arg;
}
st->silk_mode.useInBandFEC = value;
st->fec_config = value;
st->silk_mode.useInBandFEC = (value != 0);
}
break;
case OPUS_GET_INBAND_FEC_REQUEST:
@@ -2462,7 +2460,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
{
goto bad_arg;
}
*value = st->silk_mode.useInBandFEC;
*value = st->fec_config;
}
break;
case OPUS_SET_PACKET_LOSS_PERC_REQUEST:
@@ -2736,17 +2734,17 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
}
if (st->silk_mode.useDTX && (st->prev_mode == MODE_SILK_ONLY || st->prev_mode == MODE_HYBRID)) {
/* DTX determined by Silk. */
int n;
void *silk_enc = (char*)st+st->silk_enc_offset;
*value = 1;
for (n=0;n<st->silk_mode.nChannelsInternal;n++) {
*value = *value && ((silk_encoder*)silk_enc)->state_Fxx[n].sCmn.noSpeechCounter >= NB_SPEECH_FRAMES_BEFORE_DTX;
silk_encoder *silk_enc = (silk_encoder*)(void *)((char*)st+st->silk_enc_offset);
*value = silk_enc->state_Fxx[0].sCmn.noSpeechCounter >= NB_SPEECH_FRAMES_BEFORE_DTX;
/* Stereo: check second channel unless only the middle channel was encoded. */
if(*value == 1 && st->silk_mode.nChannelsInternal == 2 && silk_enc->prev_decode_only_middle == 0) {
*value = silk_enc->state_Fxx[1].sCmn.noSpeechCounter >= NB_SPEECH_FRAMES_BEFORE_DTX;
}
}
#ifndef DISABLE_FLOAT_API
else if (st->use_dtx) {
/* DTX determined by Opus. */
*value = st->nb_no_activity_frames >= NB_SPEECH_FRAMES_BEFORE_DTX;
*value = st->nb_no_activity_ms_Q1 >= NB_SPEECH_FRAMES_BEFORE_DTX*20*2;
}
#endif
else {
@@ -2754,7 +2752,6 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
}
}
break;
case CELT_GET_MODE_REQUEST:
{
const CELTMode ** value = va_arg(ap, const CELTMode**);
+5 -2
View File
@@ -251,8 +251,11 @@ int opus_multistream_decode_native(
}
packet_offset = 0;
ret = opus_decode_native(dec, data, len, buf, frame_size, decode_fec, s!=st->layout.nb_streams-1, &packet_offset, soft_clip);
data += packet_offset;
len -= packet_offset;
if (!do_plc)
{
data += packet_offset;
len -= packet_offset;
}
if (ret <= 0)
{
RESTORE_STACK;
+5 -4
View File
@@ -443,7 +443,8 @@ static int opus_multistream_encoder_init_impl(
char *ptr;
if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
(streams<1) || (coupled_streams<0) || (streams>255-coupled_streams))
(streams<1) || (coupled_streams<0) || (streams>255-coupled_streams) ||
(streams+coupled_streams>channels))
return OPUS_BAD_ARG;
st->arch = opus_select_arch();
@@ -459,8 +460,7 @@ static int opus_multistream_encoder_init_impl(
st->layout.mapping[i] = mapping[i];
if (!validate_layout(&st->layout))
return OPUS_BAD_ARG;
if (mapping_type == MAPPING_TYPE_SURROUND &&
!validate_encoder_layout(&st->layout))
if (!validate_encoder_layout(&st->layout))
return OPUS_BAD_ARG;
if (mapping_type == MAPPING_TYPE_AMBISONICS &&
!validate_ambisonics(st->layout.nb_channels, NULL, NULL))
@@ -595,7 +595,8 @@ OpusMSEncoder *opus_multistream_encoder_create(
int ret;
OpusMSEncoder *st;
if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
(streams<1) || (coupled_streams<0) || (streams>255-coupled_streams))
(streams<1) || (coupled_streams<0) || (streams>255-coupled_streams) ||
(streams+coupled_streams>channels))
{
if (error)
*error = OPUS_BAD_ARG;
+37 -7
View File
@@ -119,7 +119,19 @@ int main(int argc, char *argv[])
for (i=0;i<nb_packets;i++)
{
unsigned char ch[4];
err = fread(ch, 1, 4, fin);
if (fread(ch, 1, 4, fin)!=4)
{
if (feof(fin))
{
eof = 1;
} else {
fprintf(stderr, "Error reading payload length.\n");
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
break;
}
len[i] = char_to_int(ch);
/*fprintf(stderr, "in len = %d\n", len[i]);*/
if (len[i]>1500 || len[i]<0)
@@ -135,13 +147,31 @@ int main(int argc, char *argv[])
}
break;
}
err = fread(ch, 1, 4, fin);
rng[i] = char_to_int(ch);
err = fread(packets[i], 1, len[i], fin);
if (feof(fin))
if (fread(ch, 1, 4, fin)!=4)
{
eof = 1;
break;
if (feof(fin))
{
eof = 1;
} else {
fprintf(stderr, "Error reading.\n");
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
break;
}
rng[i] = char_to_int(ch);
if (fread(packets[i], len[i], 1, fin)!=1) {
if (feof(fin))
{
eof = 1;
} else {
fprintf(stderr, "Error reading packet of %u bytes.\n", len[i]);
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
break;
}
err = opus_repacketizer_cat(rp, packets[i], len[i]);
if (err!=OPUS_OK)