Go to the documentation of this file.
38 #define ROUND_MULL(a,b,s) (((MUL64(a, b) >> ((s) - 1)) + 1) >> 1)
76 for (pass = 0; pass < 20; pass++) {
78 for (
i = 0;
i < order+1;
i++) {
79 int low =
i != 0 ? nlsf[
i-1] : 0;
80 int high =
i != order ? nlsf[
i] : 32768;
83 if (
diff < min_diff) {
97 nlsf[0] = min_delta[0];
98 }
else if (k == order) {
100 nlsf[order-1] = 32768 - min_delta[order];
103 int min_center = 0, max_center = 32768, center_val;
106 for (
i = 0;
i < k;
i++)
107 min_center += min_delta[
i];
108 min_center += min_delta[k] >> 1;
111 for (
i = order;
i > k;
i--)
112 max_center -= min_delta[
i];
113 max_center -= min_delta[k] >> 1;
116 center_val = nlsf[k - 1] + nlsf[k];
117 center_val = (center_val >> 1) + (center_val & 1);
118 center_val =
FFMIN(max_center,
FFMAX(min_center, center_val));
120 nlsf[k - 1] = center_val - (min_delta[k] >> 1);
121 nlsf[k] = nlsf[k - 1] + min_delta[k];
128 for (
i = 1;
i < order;
i++) {
130 for (j =
i - 1; j >= 0 && nlsf[j] >
value; j--)
131 nlsf[j + 1] = nlsf[j];
136 if (nlsf[0] < min_delta[0])
137 nlsf[0] = min_delta[0];
138 for (
i = 1;
i < order;
i++)
139 nlsf[
i] =
FFMAX(nlsf[
i],
FFMIN(nlsf[
i - 1] + min_delta[
i], 32767));
142 if (nlsf[order-1] > 32768 - min_delta[order])
143 nlsf[order-1] = 32768 - min_delta[order];
144 for (
i = order-2;
i >= 0;
i--)
145 if (nlsf[
i] > nlsf[
i + 1] - min_delta[
i+1])
146 nlsf[
i] = nlsf[
i + 1] - min_delta[
i+1];
153 int k, j, DC_resp = 0;
155 int totalinvgain = 1 << 30;
156 int32_t *row = lpc32[0], *prevrow;
159 for (k = 0; k < order; k++) {
161 row[k] = lpc[k] * 4096;
168 for (k = order - 1; 1; k--) {
175 if (
FFABS(row[k]) > 16773022)
178 rc = -(row[k] * 128);
179 gaindiv = (1 << 30) -
MULH(rc, rc);
181 totalinvgain =
MULH(totalinvgain, gaindiv) << 2;
183 return (totalinvgain >= 107374);
187 gain = ((1 << 29) - 1) / (gaindiv >> (fbits + 1 - 16));
188 error = (1 << 29) -
MULL(gaindiv << (15 + 16 - fbits), gain, 16);
189 gain = ((gain << 16) + (
error * gain >> 13));
195 for (j = 0; j < k; j++) {
201 if (tmp < INT32_MIN || tmp > INT32_MAX)
217 for (
i = 1;
i < half_order;
i++) {
219 for (j =
i; j > 1; j--)
220 pol[j] += pol[j - 2] -
ROUND_MULL(lsp[2 *
i], pol[j - 1], 16);
222 pol[1] -= lsp[2 *
i];
226 static void silk_lsf2lpc(
const int16_t nlsf[16],
float lpcf[16],
int order)
235 for (k = 0; k < order; k++) {
236 int index = nlsf[k] >> 8;
237 int offset = nlsf[k] & 255;
243 lsp[k2] = (lsp[k2] + 4) >> 3;
250 for (k = 0; k < order>>1; k++) {
252 int32_t q_tmp = q[k + 1] - q[k];
253 lpc32[k] = -q_tmp - p_tmp;
254 lpc32[order-k-1] = q_tmp - p_tmp;
258 for (
i = 0;
i < 10;
i++) {
260 unsigned int maxabs = 0;
261 for (j = 0, k = 0; j < order; j++) {
262 unsigned int x =
FFABS(lpc32[k]);
269 maxabs = (maxabs + 16) >> 5;
271 if (maxabs > 32767) {
273 unsigned int chirp, chirp_base;
274 maxabs =
FFMIN(maxabs, 163838);
275 chirp_base = chirp = 65470 - ((maxabs - 32767) << 14) / ((maxabs * (k+1)) >> 2);
277 for (k = 0; k < order; k++) {
279 chirp = (chirp_base * chirp + 32768) >> 16;
286 for (k = 0; k < order; k++) {
287 int x = (lpc32[k] + 16) >> 5;
289 lpc32[k] = lpc[k] << 5;
292 for (k = 0; k < order; k++)
293 lpc[k] = (lpc32[k] + 16) >> 5;
299 unsigned int chirp, chirp_base;
300 chirp_base = chirp = 65536 - (1 <<
i);
302 for (k = 0; k < order; k++) {
304 lpc[k] = (lpc32[k] + 16) >> 5;
305 chirp = (chirp_base * chirp + 32768) >> 16;
309 for (
i = 0;
i < order;
i++)
310 lpcf[
i] = lpc[
i] / 4096.0
f;
315 float lpc_leadin[16],
float lpc[16],
316 int *lpc_order,
int *has_lpc_leadin,
int voiced)
320 int8_t lsf_i1, lsf_i2[16];
324 *lpc_order = order =
s->wb ? 16 : 10;
328 for (
i = 0;
i < order;
i++) {
334 else if (lsf_i2[
i] == 4)
339 for (
i = order - 1;
i >= 0;
i--) {
340 int qstep =
s->wb ? 9830 : 11796;
342 lsf_res[
i] = lsf_i2[
i] * 1024;
343 if (lsf_i2[
i] < 0) lsf_res[
i] += 102;
344 else if (lsf_i2[
i] > 0) lsf_res[
i] -= 102;
345 lsf_res[
i] = (lsf_res[
i] * qstep) >> 16;
350 lsf_res[
i] += (lsf_res[
i+1] *
weight) >> 8;
355 for (
i = 0;
i < order;
i++) {
376 if (
s->subframes == 4) {
381 int16_t nlsf_leadin[16];
382 for (
i = 0;
i < order;
i++)
383 nlsf_leadin[
i] =
frame->nlsf[
i] +
387 memcpy(lpc_leadin,
frame->lpc, 16 *
sizeof(
float));
390 s->nlsf_interp_factor =
offset;
394 s->nlsf_interp_factor = 4;
398 memcpy(
frame->nlsf, nlsf, order *
sizeof(nlsf[0]));
399 memcpy(
frame->lpc, lpc, order *
sizeof(lpc[0]));
408 child[1] = total - child[0];
417 int qoffset_high,
int active,
int voiced)
423 uint8_t pulsecount[20];
424 uint8_t lsbcount[20] = {0};
432 for (
i = 0;
i < shellblocks;
i++) {
434 if (pulsecount[
i] == 17) {
435 while (pulsecount[
i] == 17 && ++lsbcount[
i] != 10)
437 if (lsbcount[
i] == 10)
443 for (
i = 0;
i < shellblocks;
i++) {
444 if (pulsecount[
i] != 0) {
446 int32_t * location = excitation + 16*
i;
448 branch[0][0] = pulsecount[
i];
451 for (
a = 0;
a < 1;
a++) {
453 for (
b = 0;
b < 2;
b++) {
455 for (
c = 0;
c < 2;
c++) {
457 for (d = 0; d < 2; d++) {
465 memset(excitation + 16*
i, 0, 16*
sizeof(
int32_t));
469 for (
i = 0;
i < shellblocks << 4;
i++) {
471 for (
bit = 0; bit < lsbcount[i >> 4];
bit++)
472 excitation[
i] = (excitation[
i] << 1) |
477 for (
i = 0;
i < shellblocks << 4;
i++) {
478 if (excitation[
i] != 0) {
480 voiced][qoffset_high][
FFMIN(pulsecount[
i >> 4], 6)]);
487 for (
i = 0;
i < shellblocks << 4;
i++) {
488 int value = excitation[
i];
490 if (
value < 0) excitation[
i] += 20;
491 else if (
value > 0) excitation[
i] -= 20;
494 seed = 196314165 *
seed + 907633515;
495 if (
seed & 0x80000000)
499 excitationf[
i] = excitation[
i] / 8388608.0f;
504 #define SILK_MAX_LAG (288 + LTP_ORDER / 2)
510 int frame_num,
int channel,
int coded_channels,
511 int active,
int active1,
int redundant)
533 if (coded_channels == 2 &&
channel == 0) {
534 int n, wi[2], ws[2],
w[2];
541 for (
i = 0;
i < 2;
i++)
546 s->stereo_weights[0] = (
w[0] -
w[1]) / 8192.0;
547 s->stereo_weights[1] =
w[1] / 8192.0;
559 qoffset_high =
type & 1;
564 for (
i = 0;
i <
s->subframes;
i++) {
566 int ipart, fpart, lingain;
568 if (
i == 0 && (frame_num == 0 || !
frame->coded)) {
574 log_gain =
FFMAX(log_gain,
frame->log_gain - 16);
579 frame->log_gain + delta_gain - 4), 6);
582 frame->log_gain = log_gain;
585 log_gain = (log_gain * 0x1D1C71 >> 16) + 2090;
586 ipart = log_gain >> 7;
587 fpart = log_gain & 127;
588 lingain = (1 << ipart) + ((-174 * fpart * (128-fpart) >>16) + fpart) * ((1<<ipart) >> 7);
589 sf[
i].gain = lingain / 65536.0f;
597 int lag_absolute = (!frame_num || !
frame->prev_voiced);
612 int highbits, lowbits;
613 static const uint16_t *
const model[] = {
623 frame->primarylag = primarylag;
625 if (
s->subframes == 2)
638 for (
i = 0;
i <
s->subframes;
i++)
645 for (
i = 0;
i <
s->subframes;
i++) {
647 static const uint16_t *
const filter_sel[] = {
651 static const int8_t (*
const filter_taps[])[5] = {
655 for (j = 0; j < 5; j++)
656 sf[
i].ltptaps[j] = filter_taps[ltpfilter][
index][j] / 128.0
f;
661 if (voiced && frame_num == 0)
664 else ltpscale = 15565.0f/16384.0f;
672 if (
s->output_channels ==
channel || redundant)
676 for (
i = 0;
i <
s->subframes;
i++) {
677 const float * lpc_coeff = (
i < 2 && has_lpc_leadin) ? lpc_leadin : lpc_body;
688 if (i < 2 || s->nlsf_interp_factor == 4) {
689 out_end = -
i *
s->sflength;
692 out_end = -(
i - 2) *
s->sflength;
698 for (j = - sf[
i].pitchlag -
LTP_ORDER/2; j < out_end; j++) {
700 for (k = 0; k < order; k++)
701 sum -= lpc_coeff[k] *
dst[j - k - 1];
706 float rescale = sf[
i-1].gain / sf[
i].gain;
707 for (j = out_end; j < 0; j++)
712 for (j = 0; j <
s->sflength; j++) {
715 sum += sf[
i].ltptaps[k] * resptr[j - sf[
i].pitchlag +
LTP_ORDER/2 - k];
721 for (j = 0; j <
s->sflength; j++) {
722 sum = resptr[j] * sf[
i].gain;
723 for (k = 1; k <= order; k++)
724 sum += lpc_coeff[k - 1] * lpc[j - k];
731 frame->prev_voiced = voiced;
742 float w0_prev =
s->prev_stereo_weights[0];
743 float w1_prev =
s->prev_stereo_weights[1];
744 float w0 =
s->stereo_weights[0];
745 float w1 =
s->stereo_weights[1];
749 for (
i = 0;
i < n1;
i++) {
750 float interp0 = w0_prev +
i * (w0 - w0_prev) / n1;
751 float interp1 = w1_prev +
i * (w1 - w1_prev) / n1;
752 float p0 = 0.25 * (mid[
i - 2] + 2 * mid[
i - 1] + mid[
i]);
754 l[
i] =
av_clipf((1 + interp1) * mid[
i - 1] + side[
i - 1] + interp0 * p0, -1.0, 1.0);
755 r[
i] =
av_clipf((1 - interp1) * mid[
i - 1] - side[
i - 1] - interp0 * p0, -1.0, 1.0);
758 for (;
i <
s->flength;
i++) {
759 float p0 = 0.25 * (mid[
i - 2] + 2 * mid[
i - 1] + mid[
i]);
761 l[
i] =
av_clipf((1 + w1) * mid[
i - 1] + side[
i - 1] + w0 * p0, -1.0, 1.0);
762 r[
i] =
av_clipf((1 - w1) * mid[
i - 1] - side[
i - 1] - w0 * p0, -1.0, 1.0);
765 memcpy(
s->prev_stereo_weights,
s->stereo_weights,
sizeof(
s->stereo_weights));
773 memset(
frame->output, 0,
sizeof(
frame->output));
774 memset(
frame->lpc_history, 0,
sizeof(
frame->lpc_history));
781 frame->primarylag = 0;
782 frame->prev_voiced = 0;
792 int active[2][6], redundancy[2];
796 coded_channels > 2 || duration_ms > 60) {
798 "to the SILK decoder.\n");
802 nb_frames = 1 + (duration_ms > 20) + (duration_ms > 40);
803 s->subframes = duration_ms / nb_frames / 5;
804 s->sflength = 20 * (bandwidth + 2);
805 s->flength =
s->sflength *
s->subframes;
806 s->bandwidth = bandwidth;
810 if (coded_channels >
s->prev_coded_channels)
812 s->prev_coded_channels = coded_channels;
815 for (
i = 0;
i < coded_channels;
i++) {
816 for (j = 0; j < nb_frames; j++)
823 for (
i = 0;
i < coded_channels;
i++)
824 if (redundancy[
i] && duration_ms > 20) {
830 for (
i = 0;
i < nb_frames;
i++) {
831 for (j = 0; j < coded_channels; j++)
832 if (redundancy[j] & (1 <<
i)) {
833 int active1 = (j == 0 && !(redundancy[1] & (1 <<
i))) ? 0 : 1;
840 for (
i = 0;
i < nb_frames;
i++) {
841 for (j = 0; j < coded_channels && !
s->midonly; j++) {
842 int active1 = coded_channels > 1 ? active[1][
i] : 0;
847 if (
s->midonly &&
s->frame[1].coded)
850 if (coded_channels == 1 ||
s->output_channels == 1) {
851 for (j = 0; j <
s->output_channels; j++) {
854 s->flength *
sizeof(
float));
863 return nb_frames *
s->flength;
876 memset(
s->prev_stereo_weights, 0,
sizeof(
s->prev_stereo_weights));
883 if (output_channels != 1 && output_channels != 2) {
894 s->output_channels = output_channels;
static void error(const char *err)
const uint8_t ff_silk_lsf_codebook_wb[32][16]
const uint16_t ff_silk_model_gain_highbits[3][9]
float lpc_history[2 *SILK_HISTORY]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
const int16_t ff_silk_cosine[]
@ OPUS_BANDWIDTH_NARROWBAND
const uint16_t ff_silk_model_stereo_s1[]
float prev_stereo_weights[2]
const uint16_t ff_silk_model_gain_lowbits[]
static void silk_stabilize_lsf(int16_t nlsf[16], int order, const uint16_t min_delta[17])
#define ROUND_MULL(a, b, s)
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
static int silk_is_lpc_stable(const int16_t lpc[16], int order)
const uint8_t ff_silk_lsf_weight_sel_nbmb[32][9]
static void silk_count_children(OpusRangeCoder *rc, int model, int32_t total, int32_t child[2])
const uint16_t ff_silk_model_pitch_delta[]
float output[2 *SILK_HISTORY]
const int8_t ff_silk_pitch_offset_mbwb20ms[34][4]
static void silk_lsf2lpc(const int16_t nlsf[16], float lpcf[16], int order)
const uint8_t ff_silk_lsf_weight_sel_wb[32][15]
#define ff_silk_model_pitch_lowbits_nb
#define bit(string, value)
const uint16_t ff_silk_lsf_min_spacing_wb[]
enum OpusBandwidth bandwidth
const uint16_t ff_silk_model_lsf_s2_ext[]
const h264_weight_func weight
void ff_silk_free(SilkContext **ps)
const uint16_t ff_silk_model_excitation_sign[3][2][7][3]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
#define ff_silk_model_pitch_lowbits_wb
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint16_t ff_silk_model_pitch_contour_mbwb20ms[]
const uint16_t ff_silk_model_lsf_interpolation_offset[]
const uint8_t ff_silk_lsf_codebook_nbmb[32][10]
const uint8_t ff_silk_lsf_s2_model_sel_wb[32][16]
const uint8_t ff_silk_lsf_s2_model_sel_nbmb[32][10]
static const int offsets[]
const uint8_t ff_silk_lsf_pred_weights_wb[2][15]
const uint16_t ff_silk_model_lcg_seed[]
const int8_t ff_silk_pitch_offset_nb10ms[3][2]
const uint16_t ff_silk_model_excitation_lsb[]
const uint8_t ff_silk_lsf_ordering_nbmb[]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
@ OPUS_BANDWIDTH_WIDEBAND
const int8_t ff_silk_pitch_offset_nb20ms[11][4]
const uint16_t ff_silk_model_ltp_filter0_sel[]
const int16_t ff_silk_stereo_weights[]
const uint16_t ff_silk_model_lbrr_flags_40[]
const uint16_t ff_silk_model_lsf_s1[2][2][33]
#define LTP_ORDER
Order of the LTP filter.
const uint16_t ff_silk_model_pitch_highbits[]
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
const uint16_t ff_silk_model_mid_only[]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int ff_silk_init(void *logctx, SilkContext **ps, int output_channels)
void ff_silk_flush(SilkContext *s)
const uint8_t ff_silk_shell_blocks[3][2]
const uint16_t ff_silk_model_gain_delta[]
static void rescale(GDVContext *gdv, uint8_t *dst, int w, int h, int scale_v, int scale_h)
static void silk_unmix_ms(SilkContext *s, float *l, float *r)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
const uint8_t ff_silk_lsf_ordering_wb[]
const uint16_t ff_silk_model_pulse_location[4][168]
const uint16_t ff_silk_model_lsf_weight_wb[32][16]
#define SILK_MAX_LAG
Maximum residual history according to 4.2.7.6.1.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static void silk_flush_frame(SilkFrame *frame)
const int8_t ff_silk_ltp_filter2_taps[32][5]
uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf)
const uint16_t ff_silk_model_pitch_contour_nb10ms[]
const uint16_t ff_silk_model_pitch_contour_nb20ms[]
const uint16_t ff_silk_model_ltp_filter1_sel[]
const uint16_t ff_silk_model_lsf_weight_nbmb[32][10]
static void silk_decode_excitation(SilkContext *s, OpusRangeCoder *rc, float *excitationf, int qoffset_high, int active, int voiced)
const int8_t ff_silk_ltp_filter1_taps[16][5]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
const uint16_t ff_silk_model_lbrr_flags_60[]
const uint16_t ff_silk_model_exc_rate[2][10]
const uint16_t ff_silk_model_frame_type_inactive[]
const uint16_t ff_silk_lsf_min_spacing_nbmb[]
const int8_t ff_silk_pitch_offset_mbwb10ms[12][2]
const uint16_t ff_silk_model_ltp_filter2_sel[]
const uint16_t ff_silk_model_pitch_lowbits_mb[]
const uint16_t ff_silk_model_stereo_s2[]
const uint16_t ff_silk_pitch_scale[]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
const uint16_t ff_silk_pitch_max_lag[]
static void silk_decode_frame(SilkContext *s, OpusRangeCoder *rc, int frame_num, int channel, int coded_channels, int active, int active1, int redundant)
const uint8_t ff_silk_lsf_pred_weights_nbmb[2][9]
const uint16_t ff_silk_model_ltp_filter[]
int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc, float *output[2], enum OpusBandwidth bandwidth, int coded_channels, int duration_ms)
Decode the LP layer of one Opus frame (which may correspond to several SILK frames).
const int ff_silk_stereo_interp_len[3]
const int8_t ff_silk_ltp_filter0_taps[8][5]
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
const uint16_t ff_silk_model_frame_type_active[]
const uint16_t ff_silk_model_ltp_scale_index[]
const uint16_t ff_silk_model_lsf_s2[32][10]
static void scale(int *out, const int *in, const int w, const int h, const int shift)
const uint16_t ff_silk_pitch_min_lag[]
static void silk_lsp2poly(const int32_t lsp[], int32_t pol[], int half_order)
const uint16_t ff_silk_model_pulse_count[11][19]
const uint8_t ff_silk_quant_offset[2][2]
static void silk_decode_lpc(SilkContext *s, SilkFrame *frame, OpusRangeCoder *rc, float lpc_leadin[16], float lpc[16], int *lpc_order, int *has_lpc_leadin, int voiced)
const uint16_t ff_silk_ltp_scale_factor[]
static const unsigned codebook[256][2]
const uint16_t ff_silk_model_pitch_contour_mbwb10ms[]
const uint16_t ff_silk_model_stereo_s3[]