summaryrefslogtreecommitdiffstats
path: root/media/libopus/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /media/libopus/src
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-upstream/125.0.1.tar.xz
firefox-upstream/125.0.1.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'media/libopus/src')
-rw-r--r--media/libopus/src/analysis.c6
-rw-r--r--media/libopus/src/extensions.c315
-rw-r--r--media/libopus/src/mapping_matrix.c561
-rw-r--r--media/libopus/src/mapping_matrix.h12
-rw-r--r--media/libopus/src/mlp.c42
-rw-r--r--media/libopus/src/mlp.h20
-rw-r--r--media/libopus/src/mlp_data.c6
-rw-r--r--media/libopus/src/opus.c10
-rw-r--r--media/libopus/src/opus_decoder.c495
-rw-r--r--media/libopus/src/opus_encoder.c651
-rw-r--r--media/libopus/src/opus_multistream_decoder.c4
-rw-r--r--media/libopus/src/opus_multistream_encoder.c2
-rw-r--r--media/libopus/src/opus_private.h28
-rw-r--r--media/libopus/src/opus_projection_encoder.c42
-rw-r--r--media/libopus/src/repacketizer.c144
-rw-r--r--media/libopus/src/tansig_table.h45
16 files changed, 2087 insertions, 296 deletions
diff --git a/media/libopus/src/analysis.c b/media/libopus/src/analysis.c
index 058328f0fd..1f58013812 100644
--- a/media/libopus/src/analysis.c
+++ b/media/libopus/src/analysis.c
@@ -929,9 +929,9 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt
features[23] = info->tonality_slope + 0.069216f;
features[24] = tonal->lowECount - 0.067930f;
- compute_dense(&layer0, layer_out, features);
- compute_gru(&layer1, tonal->rnn_state, layer_out);
- compute_dense(&layer2, frame_probs, tonal->rnn_state);
+ analysis_compute_dense(&layer0, layer_out, features);
+ analysis_compute_gru(&layer1, tonal->rnn_state, layer_out);
+ analysis_compute_dense(&layer2, frame_probs, tonal->rnn_state);
/* Probability of speech or music vs noise */
info->activity_probability = frame_probs[1];
diff --git a/media/libopus/src/extensions.c b/media/libopus/src/extensions.c
new file mode 100644
index 0000000000..bb6c0b0268
--- /dev/null
+++ b/media/libopus/src/extensions.c
@@ -0,0 +1,315 @@
+/* Copyright (c) 2022 Amazon */
+/*
+ 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 "opus_types.h"
+#include "opus_defines.h"
+#include "arch.h"
+#include "os_support.h"
+#include "opus_private.h"
+
+
+/* Given an extension payload, advance data to the next extension and return the
+ length of the remaining extensions. */
+opus_int32 skip_extension(const unsigned char **data, opus_int32 len, opus_int32 *header_size)
+{
+ int id, L;
+ if (len==0)
+ return 0;
+ id = **data>>1;
+ L = **data&1;
+ if (id == 0 && L == 1)
+ {
+ *header_size = 1;
+ if (len < 1)
+ return -1;
+ (*data)++;
+ len--;
+ return len;
+ } else if (id > 0 && id < 32)
+ {
+ if (len < 1+L)
+ return -1;
+ *data += 1+L;
+ len -= 1+L;
+ *header_size = 1;
+ return len;
+ } else {
+ if (L==0)
+ {
+ *data += len;
+ *header_size = 1;
+ return 0;
+ } else {
+ opus_int32 bytes=0;
+ *header_size = 1;
+ do {
+ (*data)++;
+ len--;
+ if (len == 0)
+ return -1;
+ bytes += **data;
+ (*header_size)++;
+ } while (**data == 255);
+ (*data)++;
+ len--;
+ if (bytes <= len)
+ {
+ len -= bytes;
+ *data += bytes;
+ } else {
+ return -1;
+ }
+ return len;
+ }
+ }
+}
+
+/* Count the number of extensions, excluding real padding and separators. */
+opus_int32 opus_packet_extensions_count(const unsigned char *data, opus_int32 len)
+{
+ opus_int32 curr_len;
+ opus_int32 count=0;
+ const unsigned char *curr_data = data;
+
+ celt_assert(len >= 0);
+ celt_assert(data != NULL || len == 0);
+
+ curr_len = len;
+ while (curr_len > 0)
+ {
+ int id;
+ opus_int32 header_size;
+ id = *curr_data>>1;
+ curr_len = skip_extension(&curr_data, curr_len, &header_size);
+ if (curr_len < 0)
+ return OPUS_INVALID_PACKET;
+ if (id > 1)
+ count++;
+ }
+ return count;
+}
+
+/* Extract extensions from Opus padding (excluding real padding and separators) */
+opus_int32 opus_packet_extensions_parse(const unsigned char *data, opus_int32 len, opus_extension_data *extensions, opus_int32 *nb_extensions)
+{
+ const unsigned char *curr_data;
+ opus_int32 curr_len;
+ int curr_frame=0;
+ opus_int32 count=0;
+
+ celt_assert(len >= 0);
+ celt_assert(data != NULL || len == 0);
+ celt_assert(nb_extensions != NULL);
+ celt_assert(extensions != NULL || *nb_extensions == 0);
+
+ curr_data = data;
+ curr_len = len;
+ while (curr_len > 0)
+ {
+ int id;
+ opus_int32 header_size;
+ opus_extension_data curr_ext;
+ id = *curr_data>>1;
+ if (id > 1)
+ {
+ curr_ext.id = id;
+ curr_ext.frame = curr_frame;
+ curr_ext.data = curr_data;
+ } else if (id == 1)
+ {
+ int L = *curr_data&1;
+ if (L==0)
+ curr_frame++;
+ else {
+ if (curr_len >= 2)
+ curr_frame += curr_data[1];
+ /* Else we're at the end and it doesn't matter. */
+ }
+ if (curr_frame >= 48)
+ {
+ *nb_extensions = count;
+ return OPUS_INVALID_PACKET;
+ }
+ }
+ curr_len = skip_extension(&curr_data, curr_len, &header_size);
+ /* printf("curr_len = %d, header_size = %d\n", curr_len, header_size); */
+ if (curr_len < 0)
+ {
+ *nb_extensions = count;
+ return OPUS_INVALID_PACKET;
+ }
+ celt_assert(curr_data - data == len - curr_len);
+ if (id > 1)
+ {
+ if (count == *nb_extensions)
+ {
+ return OPUS_BUFFER_TOO_SMALL;
+ }
+ curr_ext.len = curr_data - curr_ext.data - header_size;
+ curr_ext.data += header_size;
+ extensions[count++] = curr_ext;
+ }
+ }
+ celt_assert(curr_len == 0);
+ *nb_extensions = count;
+ return OPUS_OK;
+}
+
+opus_int32 opus_packet_extensions_generate(unsigned char *data, opus_int32 len, const opus_extension_data *extensions, opus_int32 nb_extensions, int pad)
+{
+ int max_frame=0;
+ opus_int32 i;
+ int frame;
+ int curr_frame = 0;
+ opus_int32 pos = 0;
+ opus_int32 written = 0;
+
+ celt_assert(len >= 0);
+
+ for (i=0;i<nb_extensions;i++)
+ {
+ max_frame = IMAX(max_frame, extensions[i].frame);
+ if (extensions[i].id < 2 || extensions[i].id > 127)
+ return OPUS_BAD_ARG;
+ }
+ if (max_frame >= 48) return OPUS_BAD_ARG;
+ for (frame=0;frame<=max_frame;frame++)
+ {
+ for (i=0;i<nb_extensions;i++)
+ {
+ if (extensions[i].frame == frame)
+ {
+ /* Insert separator when needed. */
+ if (frame != curr_frame) {
+ int diff = frame - curr_frame;
+ if (len-pos < 2)
+ return OPUS_BUFFER_TOO_SMALL;
+ if (diff == 1) {
+ if (data) data[pos] = 0x02;
+ pos++;
+ } else {
+ if (data) data[pos] = 0x03;
+ pos++;
+ if (data) data[pos] = diff;
+ pos++;
+ }
+ curr_frame = frame;
+ }
+ if (extensions[i].id < 32)
+ {
+ if (extensions[i].len < 0 || extensions[i].len > 1)
+ return OPUS_BAD_ARG;
+ if (len-pos < extensions[i].len+1)
+ return OPUS_BUFFER_TOO_SMALL;
+ if (data) data[pos] = (extensions[i].id<<1) + extensions[i].len;
+ pos++;
+ if (extensions[i].len > 0) {
+ if (data) data[pos] = extensions[i].data[0];
+ pos++;
+ }
+ } else {
+ int last;
+ opus_int32 length_bytes;
+ if (extensions[i].len < 0)
+ return OPUS_BAD_ARG;
+ last = (written == nb_extensions - 1);
+ length_bytes = 1 + extensions[i].len/255;
+ if (last)
+ length_bytes = 0;
+ if (len-pos < 1 + length_bytes + extensions[i].len)
+ return OPUS_BUFFER_TOO_SMALL;
+ if (data) data[pos] = (extensions[i].id<<1) + !last;
+ pos++;
+ if (!last)
+ {
+ opus_int32 j;
+ for (j=0;j<extensions[i].len/255;j++) {
+ if (data) data[pos] = 255;
+ pos++;
+ }
+ if (data) data[pos] = extensions[i].len % 255;
+ pos++;
+ }
+ if (data) OPUS_COPY(&data[pos], extensions[i].data, extensions[i].len);
+ pos += extensions[i].len;
+ }
+ written++;
+ }
+ }
+ }
+ /* If we need to pad, just prepend 0x01 bytes. Even better would be to fill the
+ end with zeros, but that requires checking that turning the last extesion into
+ an L=1 case still fits. */
+ if (pad && pos < len)
+ {
+ opus_int32 padding = len - pos;
+ if (data) {
+ OPUS_MOVE(data+padding, data, pos);
+ for (i=0;i<padding;i++)
+ data[i] = 0x01;
+ }
+ pos += padding;
+ }
+ return pos;
+}
+
+#if 0
+#include <stdio.h>
+int main()
+{
+ opus_extension_data ext[] = {{2, 0, (const unsigned char *)"a", 1},
+ {32, 10, (const unsigned char *)"DRED", 4},
+ {33, 1, (const unsigned char *)"NOT DRED", 8},
+ {3, 4, (const unsigned char *)NULL, 0}
+ };
+ opus_extension_data ext2[10];
+ int i, len;
+ int nb_ext = 10;
+ unsigned char packet[10000];
+ len = opus_packet_extensions_generate(packet, 32, ext, 4, 1);
+ for (i=0;i<len;i++)
+ {
+ printf("%#04x ", packet[i]);
+ if (i%16 == 15)
+ printf("\n");
+ }
+ printf("\n");
+ printf("count = %d\n", opus_packet_extensions_count(packet, len));
+ opus_packet_extensions_parse(packet, len, ext2, &nb_ext);
+ for (i=0;i<nb_ext;i++)
+ {
+ int j;
+ printf("%d %d {", ext2[i].id, ext2[i].frame);
+ for (j=0;j<ext2[i].len;j++) printf("%#04x ", ext2[i].data[j]);
+ printf("} %d\n", ext2[i].len);
+ }
+}
+#endif
diff --git a/media/libopus/src/mapping_matrix.c b/media/libopus/src/mapping_matrix.c
index 31298af057..3f78ab5990 100644
--- a/media/libopus/src/mapping_matrix.c
+++ b/media/libopus/src/mapping_matrix.c
@@ -302,6 +302,287 @@ const opus_int16 mapping_matrix_toa_mixing_data[324] = {
0, 0, 0, 32767
};
+const MappingMatrix mapping_matrix_fourthoa_mixing = { 27, 27, 0 };
+const opus_int16 mapping_matrix_fourthoa_mixing_data[729] = {
+ 9243, 0, 16010, 0, 0, 0, 20669, 0,
+ 0, 0, 0, 0, 24456, 0, 0, 0,
+ 0, 0, 0, 0, 27731, 0, 0, 0,
+ 0, 0, 0, 9243, 0, 10884, 11741, 0,
+ 0, 3995, 17849, 9626, 0, 0, 0, -5727,
+ 14399, 17315, 7625, 0, 0, 0, 0, -11747,
+ 2574, 18637, 15552, 5930, 0, 0, 9243, -14302,
+ -2682, -6677, 13337, 5357, -9464, 2501, -11170, 4770,
+ -5911, 11501, 5858, 5369, 4951, 17901, -19071, -2397,
+ -9281, -9198, 7576, -4294, 7773, -8997, -3399, 0,
+ 0, 9243, 9940, 11991, -3705, -5144, 16647, 7057,
+ -6206, -5941, -2698, -10194, 16781, -1788, -6256, -11772,
+ 4935, 3912, -6062, -13039, 9446, -9758, -3521, -15058,
+ 11089, 565, 0, 0, 9243, -15376, 3720, 2461,
+ -5285, -7989, -8660, 1278, -16087, 15811, -3249, 10500,
+ -7757, -1680, -9890, -8153, 10884, 11022, 2847, 12828,
+ 5137, -2053, 8666, -5684, 14776, 0, 0, 9243,
+ -10577, 10304, -6186, 9139, -15222, 2507, -8902, -5140,
+ -145, 15562, -10596, -7311, -6197, -8753, 8667, -6014,
+ -281, 15033, 938, -11859, 548, -8456, 16735, -3654,
+ 0, 0, 9243, 8974, 4839, -12343, -15472, 6066,
+ -7501, -8343, 5015, 15920, -12374, -4559, -9400, 6271,
+ 4011, 5191, -9932, 14438, 4828, -8768, 1909, 12059,
+ -1565, 4707, -13711, 0, 0, 9243, 15799, 2085,
+ -1534, -3386, 4602, -9808, -447, -17267, -18054, -1167,
+ -13525, -4644, 1313, -5951, 5397, 7485, -7056, 2584,
+ -8120, 8669, 788, 13177, 2109, 18349, 0, 0,
+ 9243, 12371, -10036, 1597, 2760, -17341, 1848, -2239,
+ -10509, -8474, -4577, 11164, 7935, 1441, 17430, -3436,
+ -3713, 15936, 4184, 2647, -11730, 341, -15934, 6462,
+ 6581, 0, 0, 9243, -8963, 2184, 13084, -16381,
+ -2734, -9757, 3991, 6345, -18297, -5912, 7604, -4849,
+ -11100, 2290, -4304, -13305, -7488, 12338, 4805, 8505,
+ -7014, -4779, -1761, -14597, 0, 0, 9243, 1301,
+ -15498, 3799, 690, -2816, 18718, -8223, 889, 255,
+ -1768, 4485, -19951, 13097, -2278, 167, 78, -740,
+ 3324, -6139, 19488, -17925, 4283, -486, 20, 0,
+ 0, 9243, -13470, -6719, 5452, -10257, 12641, -4873,
+ -5116, -10595, 5856, 11389, 1502, 10876, -608, 11765,
+ -13218, 13911, -7373, -2070, -13679, -4154, 5536, -2138,
+ 16643, 451, 0, 0, 9243, 2455, -3679, -15387,
+ -5277, -1261, -8697, 7906, 16112, 8147, 3208, -1690,
+ 7687, 10593, -9796, -15852, -10884, -5616, 2881, 2032,
+ 5246, -12735, -8796, 10928, 14833, 0, 0, 9243,
+ -6849, 2775, -14202, 13586, -2655, -9402, -5505, 10809,
+ -18013, 6231, 5444, -6041, 11288, 4958, -4078, 18799,
+ -9368, -9291, 4535, 7383, 9405, -7391, -2121, -4336,
+ 0, 0, 9243, 6423, -9040, 11548, 10359, -8109,
+ -450, -14580, 6431, 10857, -15475, 3569, 9707, 6416,
+ -9607, 521, 8528, -18391, 11049, 3815, -10423, 6860,
+ 6860, -883, -4221, 0, 0, 9243, 11932, -5968,
+ -8850, -14749, -9946, -6026, 7377, -4472, 5206, 14547,
+ -3406, 10508, 2526, 4411, 14543, 8444, -5822, 347,
+ 12347, -1709, -9158, 105, -16265, -12642, 0, 0,
+ 9243, 13044, -150, 9282, 16910, -274, -10332, -194,
+ -5864, 5428, -420, -12196, 344, -8679, 145, -18554,
+ -12695, -152, -14635, 503, 10389, 358, 5076, 522,
+ -16100, 0, 0, 9243, -8374, -13590, -1221, 1428,
+ 15896, 12005, 2318, -4793, 2590, -3209, -20390, -6256,
+ -2974, 10766, 1202, -876, -6597, 5004, 19896, -1541,
+ 2902, -16788, -3062, 1340, 0, 0, 9243, 9879,
+ 10267, 7300, 10073, 14167, 2416, 10469, -3094, 2899,
+ 17092, 9762, -7400, 7214, -5250, -8238, -3989, 5578,
+ 16392, -1050, -11848, -776, -5034, -15850, -5882, 0,
+ 0, 9243, -4974, -9068, 12221, -8490, 6299, -388,
+ -15478, 8702, -9920, 12723, -2810, 9668, 6905, -13040,
+ 4325, -9456, 16856, -9159, -2909, -10476, 7149, 9387,
+ -7350, 233, 0, 0, 9243, 3627, -13823, -7218,
+ -3656, -7002, 12776, 13935, 2719, 2446, 8352, 9252,
+ -7676, -18413, -6212, -429, -1272, -6335, -13356, -9510,
+ 295, 18926, 9934, 1112, -382, 0, 0, 9243,
+ -6383, -9343, -11326, 10097, 8329, 223, 14780, 6114,
+ -10348, -15590, -4195, 9257, -7445, -9439, -323, 7902,
+ 18117, 12101, -3142, -10944, -5577, 7327, 566, -4133,
+ 0, 0, 9243, 2626, 865, 15769, 5783, 317,
+ -10244, 1905, 16884, 9144, 826, -2420, -1972, -14536,
+ 2413, 16939, 12500, 1482, -4906, -578, 10096, -3476,
+ -14323, 2745, 16105, 0, 0, 9243, -8975, 12086,
+ 5450, -6832, -15149, 7333, 9200, -3550, -362, -13645,
+ -15525, -1391, 9428, -7091, -5442, 3105, -820, -17685,
+ -9175, -9462, 5572, -9191, -12325, -2180, 0, 0,
+ 9243, -114, 11576, -11058, 177, -185, 5875, -17880,
+ 8539, -198, 339, -173, -3411, -16698, 16336, -6369,
+ 193, -430, 408, -75, -10806, -7225, 19670, -13817,
+ 4665, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 32767, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 32767
+};
+
+const MappingMatrix mapping_matrix_fifthoa_mixing = { 38, 38, 0 };
+const opus_int16 mapping_matrix_fifthoa_mixing_data[1444] = {
+ 9243, 0, 16010, 0, 0, 0, 20669, 0,
+ 0, 0, 0, 0, 24456, 0, 0, 0,
+ 0, 0, 0, 0, 27731, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 30657, 0,
+ 0, 0, 0, 0, 0, 0, 9243, 0,
+ -7023, 14387, 0, 0, -4369, -14112, 14455, 0,
+ 0, 0, 10931, -510, -16777, 14031, 0, 0,
+ 0, 0, -5118, 14286, 4343, -18465, 13374, 0,
+ 0, 0, 0, 0, -6494, -12221, 11761, 8513,
+ -19458, 12605, 0, 0, 9243, -14128, 5093, 5547,
+ -10946, -10050, -7197, 3945, -11790, 7142, -9213, 6529,
+ -9701, -2563, -9923, -14846, 16521, 6816, 2764, 14103,
+ 1118, -5537, 2977, -14168, 1228, 4866, 17430, -528,
+ 10639, 2641, 10437, -1037, 11460, 1098, 1296, 15737,
+ 0, 0, 9243, 1128, -14775, 6062, 955, -2329,
+ 16069, -12511, 2477, 579, -2333, 3440, -14197, 18478,
+ -6050, 940, 303, -1604, 4106, -4223, 9829, -22688,
+ 10647, -2604, 334, 145, -927, 3203, -6017, 4507,
+ -3812, 24212, -15600, 5198, -1023, 110, 0, 0,
+ 9243, 1158, 12997, 9277, 1501, 2103, 10097, 16840,
+ 5916, 1402, 3225, 2488, 2929, 19916, 12706, 3585,
+ 1137, 3415, 4698, 2078, -5442, 16634, 18511, 8731,
+ 2095, 850, 3061, 5733, 5225, 960, -11728, 7689,
+ 20588, 14659, 5642, 1187, 0, 0, 9243, -4663,
+ -3081, -15003, 9771, 2007, -9185, 6457, 14199, -14357,
+ -4976, 3554, 6625, 11434, -7231, -11297, 17760, 8291,
+ -6267, -3368, 6712, -10837, -9107, 6524, 6793, -19531,
+ -11338, 7934, 7335, -2205, -9215, -7094, 10659, 6243,
+ -4337, -1250, 0, 0, 9243, -13515, 7679, -3831,
+ 7232, -14496, -3201, -4109, -11731, 8828, 9178, -1901,
+ -10848, -539, -14888, 9626, -10860, 12703, 3824, 12334,
+ -7104, 3496, -6203, 13852, 5461, -2109, -17277, 7837,
+ -4714, 13901, 4097, 3940, 7647, 8546, 8688, -10986,
+ 0, 0, 9243, 8113, -9860, 9657, 10943, -11174,
+ 1426, -13300, 1915, 8178, -17833, 6805, 8309, 8100,
+ -3121, -4742, 2683, -15111, 15688, 2358, -11590, 2807,
+ 2746, 8762, -7430, -2251, -5481, 16370, -4081, -9694,
+ 5872, -11539, -714, -9492, 15177, -6126, 0, 0,
+ 9243, 9933, -9215, -8528, -11831, -12785, -62, 10976,
+ -1811, 5593, 18018, 6100, 9455, -5237, 2758, 8971,
+ 2743, -9659, -13517, 5330, -10737, -4576, -2069, -15491,
+ -8749, -7226, -5237, 9191, -181, -12277, 2815, 10540,
+ -27, 14741, 16703, 3103, 0, 0, 9243, -10067,
+ -8881, -8723, 12265, 12487, -793, 10821, -1762, -6021,
+ -18002, -5072, 9912, -4395, 2587, 9368, -2767, 10021,
+ 12259, -6468, -10113, -5605, -1761, -15590, -9430, 7800,
+ 5092, -8835, 2293, 12314, 1222, 10671, -329, 13745,
+ 17349, 3563, 0, 0, 9243, -6485, 12991, -6743,
+ 6108, -11768, 10080, -12236, 238, -2883, 13115, -13907,
+ 2900, -14460, 511, 2564, 186, -7019, 19094, -11597,
+ -5472, -12058, 744, 6243, -2384, 930, 501, -11778,
+ 21214, -5330, -11746, -5542, 827, 10475, -6418, 1132,
+ 0, 0, 9243, 3862, 5238, -14627, -7891, 2826,
+ -7015, -10701, 13900, 11410, -6831, -1679, -9861, 6359,
+ 12032, -11660, -14041, 11199, 1713, -3895, 657, 14749,
+ -3017, -11445, 8380, 15575, -15236, -346, 7690, -923,
+ 10317, 3498, -13545, 354, 9093, -4476, 0, 0,
+ 9243, -8417, 13183, 3418, -4018, -15498, 10685, 6294,
+ -4132, 1419, -8755, -18818, 3926, 7642, -9001, -3235,
+ 2125, 3506, -13037, -16570, -4337, 6729, -13404, -7991,
+ 59, 443, 5804, 6005, -15011, -9060, -11044, 3679,
+ -15434, -13685, 161, 1185, 0, 0, 9243, -5288,
+ 6773, -13508, 9977, -5002, -4784, -12780, 10790, -12942,
+ 11168, 519, -10890, 1326, 12078, -6274, 13780, -16427,
+ 2186, 5352, -4328, 13671, 2364, -7963, 1080, -12568,
+ 19336, -6557, -8574, 4084, 7277, 10433, -9273, -3178,
+ 1516, 3817, 0, 0, 9243, 9660, 7817, 10093,
+ 13619, 10548, -2942, 11021, 597, 9663, 17594, 1736,
+ -10794, 1814, 771, -8469, 1041, 14155, 7891, -8597,
+ -7498, -8982, 346, -12407, -11848, -6809, 1686, 9181,
+ -8306, -10247, 3538, -10706, -364, -8047, -19188, -8493,
+ 0, 0, 9243, -7163, -1020, 14282, -14289, 1021,
+ -10208, -2036, 10660, -18919, 2410, 6564, 2323, -13088,
+ -1798, 3365, -19498, 3619, 12022, -1858, 9978, 3705,
+ -8969, -643, -5794, -15523, 4123, 15113, -3949, -6265,
+ -3596, 12490, 2946, -2688, 1225, -14570, 0, 0,
+ 9243, -12187, 772, -10354, 17623, -1314, -10262, -1117,
+ -2885, -9937, 2249, 11267, -1763, 9572, -368, 16506,
+ -6510, -1438, -15014, 2402, 10157, 2041, 2458, 2389,
+ -19346, 19860, -1041, 8067, -3704, -10931, 2743, -9286,
+ 606, -13399, -3095, 7924, 0, 0, 9243, 15545,
+ -2367, -3011, -6538, -5139, -9657, 995, -16242, -15706,
+ 2557, -12952, 5226, 2508, 6353, 10156, 13593, 6966,
+ 4795, 8960, 8183, -1735, 11914, -4504, 14149, 11727,
+ -6665, 10460, -3962, 10145, -7648, -1965, -9845, -6764,
+ -6938, -16633, 0, 0, 9243, 3098, 12983, -8841,
+ -3826, 5618, 10053, -16031, 4787, 3283, -8209, 6632,
+ 2856, -18922, 10272, -2055, -2344, 7987, -11939, 5516,
+ -5520, -15739, 14940, -5001, 530, 1465, -6306, 13388,
+ -13243, 2513, -11772, -7170, 16572, -8384, 1426, 168,
+ 0, 0, 9243, -15767, -2008, -1916, 4220, 4422,
+ -9846, 537, -17105, 17650, -1400, 13589, 4481, 1651,
+ 5677, 6701, -9241, -6642, -3252, -7827, 8792, -951,
+ 13182, -2522, 17586, -17005, 3845, -12562, 2213, -11472,
+ -6688, -1394, -8970, -4769, -7316, -11753, 0, 0,
+ 9243, -13344, -3829, 7975, -14863, 7136, -8561, -4265,
+ -7992, -801, 9405, 8912, 7937, -5326, 5057, -17681,
+ 15207, 575, 7717, -11360, 4847, 6789, 4150, 12686,
+ -10050, 16730, -12063, 322, -12920, -3313, -10267, 1980,
+ -6948, 7112, 7972, 8042, 0, 0, 9243, 7791,
+ -1021, 13949, 15180, -1111, -10208, -1989, 9348, 19199,
+ -2561, -7140, 2323, -12782, -1577, 817, 18164, -3673,
+ -12771, 2022, 9978, 3620, -7865, -156, -9155, 11924,
+ -3842, -15336, 4196, 6814, -3596, 12199, 2583, -652,
+ 1936, -17637, 0, 0, 9243, -4810, -15144, -1958,
+ 1315, 10175, 17406, 4142, -1348, 263, -3292, -15632,
+ -17046, -6363, 3374, 605, -227, -748, 5997, 20334,
+ 14481, 8277, -6146, -1717, 5, 27, 712, 1542,
+ -9197, -23572, -10163, -9595, 9425, 3539, -17, -72,
+ 0, 0, 9243, -7366, 8261, 11568, -11901, -8499,
+ -2079, 13347, 5556, -12049, -16247, -2282, -10529, 3584,
+ 7585, -1577, -8464, -18652, -8902, 5913, -8688, -9287,
+ 4156, -2442, -7089, -2993, -14485, -13949, 5422, 8459,
+ 1638, -13285, -2531, -1826, -12132, -9456, 0, 0,
+ 9243, 11716, 698, -10889, -17818, 1143, -10275, -1062,
+ -1305, 12057, -2057, -10855, -1595, 10088, -150, 15043,
+ 2978, 1578, 15225, -2090, 10201, 1943, 1115, 1969,
+ -20211, -17636, 430, -9826, 3391, 10572, 2485, -9826,
+ 248, -12259, -2924, 12131, 0, 0, 9243, 4361,
+ -4594, -14703, -8956, -2798, -7781, 9434, 13769, 12936,
+ 6800, -2400, 9082, 8091, -10453, -11023, -15786, -11136,
+ 3285, 4153, 2658, -14002, -5051, 9489, 7000, 17206,
+ 15024, -2777, -8491, -42, -10626, 141, 13053, 2366,
+ -6662, -2231, 0, 0, 9243, -752, -11933, -10646,
+ 1119, 1254, 6890, 17745, 7875, -1203, -2207, -1251,
+ 2024, -17706, -15532, -5600, 1128, 2691, 2800, 683,
+ -9927, 9661, 19706, 12522, 3889, -978, -2789, -3992,
+ -2440, 206, 12695, 2921, -17173, -18575, -9616, -2657,
+ 0, 0, 9243, 4791, -15001, -2887, -1931, -10037,
+ 16885, 6048, -1020, 46, 4789, 15191, -15922, -9154,
+ 2530, 823, 252, -130, -8608, -19335, 12613, 11651,
+ -4549, -2314, -172, -101, -784, 265, 12975, 21741,
+ -7551, -13101, 6856, 4710, 535, -46, 0, 0,
+ 9243, -12153, -10395, 754, -1281, 17644, 2735, -1095,
+ -10274, 8359, 2200, -12593, 7083, 782, 17650, -1573,
+ 1685, -16282, -2164, -530, -11878, 32, -17359, 3065,
+ 6651, -5212, -3628, 19365, 965, 13180, 8243, -818,
+ 7746, -3645, -14323, 1670, 0, 0, 9243, -6961,
+ -11198, 9081, -8829, 10887, 4833, -14202, 2374, -6524,
+ 16339, -9417, 4737, 12284, -4394, -2691, -2683, 13690,
+ -18539, 2830, -11438, -3692, 4985, 5648, -4628, 514,
+ 6225, -18409, 12672, 5311, 11170, -6928, -3407, -7595,
+ 10737, -3977, 0, 0, 9243, 12099, -10405, 1294,
+ 2187, -17582, 2760, -1880, -10105, -8058, -3760, 12583,
+ 7058, 1346, 17376, -2667, -2829, 15710, 3705, 468,
+ -11880, 50, -17123, 5201, 6230, 4698, 6098, -18716,
+ -1665, -13088, 8285, -1400, 7696, -6196, -13429, 2770,
+ 0, 0, 9243, 8602, 13392, 1722, 2070, 16090,
+ 11359, 3222, -4960, -2638, 4581, 20106, 5099, 4026,
+ -10978, -1778, -1314, -6620, 6988, 18701, -2965, 3745,
+ -16745, -4461, 1300, 584, -3646, -11588, 8350, 11847,
+ -10050, 2372, -20010, -7809, 3608, 887, 0, 0,
+ 9243, 14252, -1958, 7026, 13986, -3899, -9870, -1922,
+ -10736, -3693, -4527, -12333, 4376, -6080, 3475, -18537,
+ -19222, 1355, -10843, 6913, 8869, 3408, 8323, 6804,
+ -5141, -13648, 7800, 2649, 7171, 10505, -6548, 5179,
+ -5505, 13299, 2086, 15579, 0, 0, 9243, 11323,
+ 9021, -6835, -10810, 14267, -489, -8613, -5689, 639,
+ -16117, 6224, -9731, -3757, -8482, 10882, 7873, 1080,
+ -11447, -6791, -10388, 4099, -6025, 18396, -5407, -7536,
+ 14714, 984, 1267, -13940, -1889, 8416, 666, 16762,
+ -10106, -3418, 0, 0, 9243, 871, 4833, 15238,
+ 1855, 588, -7508, 10287, 16162, 2857, 1481, -443,
+ -9392, -7758, 12910, 16506, 3837, 2588, -581, -851,
+ 1928, -14879, -5066, 14950, 16498, 4773, 3842, -425,
+ -1785, -82, 10578, -1435, -15554, -2459, 16520, 16250,
+ 0, 0, 9243, 14762, 5967, 1673, 3450, 12303,
+ -6027, 1394, -15022, -14571, 3402, -4217, -10507, -478,
+ -14813, -5131, -6634, -16293, -82, -15276, -1705, -1731,
+ 358, -5738, 13681, 12503, -8200, -3023, -3290, -7384,
+ 9272, -837, 14328, -1064, 16913, 7915, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 32767, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 32767
+};
+
const MappingMatrix mapping_matrix_foa_demixing = { 6, 6, 0 };
const opus_int16 mapping_matrix_foa_demixing_data[36] = {
16384, 16384, 16384, 16384, 0, 0, 0, 23170,
@@ -376,3 +657,283 @@ const opus_int16 mapping_matrix_toa_demixing_data[324] = {
0, 0, 0, 32767
};
+const MappingMatrix mapping_matrix_fourthoa_demixing = { 27, 27, 0 };
+const opus_int16 mapping_matrix_fourthoa_demixing_data[729] = {
+ 4870, 4484, 4870, 4347, 4440, 4726, 4683, 4821,
+ 4883, 4842, 4603, 4484, 4683, 4698, 4234, 4368,
+ 4603, 4783, 4783, 4820, 4821, 4347, 4820, 4440,
+ 4698, 0, 0, 101, 84, -7818, 4640, -7178,
+ -5492, 4629, 8384, 6547, -4966, 617, -6345, 1061,
+ -3241, 2939, 5549, 6390, -4434, 4994, -2610, 1993,
+ -2873, 1547, -4356, -164, 0, 0, 8797, 5074,
+ -1553, 5383, 1906, 5297, 2722, 1158, -5226, 1311,
+ -7760, -3327, -1940, 1586, -4093, -2951, -214, -6873,
+ 5450, -4875, -7193, -4438, 558, 5593, 5607, 0,
+ 0, -26, 5761, -3723, -1460, 1195, -3065, -6357,
+ -1175, 608, 6965, 2310, 2759, -8023, -7138, 5162,
+ -3624, 5006, -809, 3592, 6209, -4159, -4968, 8150,
+ 2513, -5702, 0, 0, 301, 109, 7161, -2462,
+ -2443, 5044, -7125, -2256, 1967, -9107, 259, -4928,
+ -2592, 6514, 4111, -7236, 8695, 635, 5009, -4025,
+ -1937, 4794, 3420, -3507, -400, 0, 0, -134,
+ 85, 2771, 7842, -3649, -8225, 2866, 2586, -9200,
+ -1945, -1563, 6155, -720, -1061, -3494, -4513, -487,
+ 8389, 7317, 3348, -3721, 3806, 371, -6896, 70,
+ 0, 0, 10919, 2072, -4867, 3472, -4429, 1721,
+ -4066, -5193, 1032, -5253, 9501, -2017, -3971, -5261,
+ -306, -2737, -5137, 5713, 1237, -8, 6387, 364,
+ -5423, 3364, 2888, 0, 0, -48, 8946, 1048,
+ -2691, 602, -4332, -4302, -514, -1730, 2459, -4328,
+ -2156, 3335, -2748, -6029, 4023, 155, 897, 5268,
+ -8380, 7625, 7395, 508, 3945, -8951, 0, 0,
+ 39, 4151, -5965, -3398, -7006, -3534, 2697, -8989,
+ -5237, 2913, 46, -5540, 8196, 5766, 2711, -2520,
+ -3043, -2146, -948, 4965, 1806, 2472, 8988, -1266,
+ 4840, 0, 0, -407, -189, 2179, -1627, 6516,
+ 259, 7196, -9449, -4905, -9766, 561, 4021, 3371,
+ -8650, 5032, 3329, 2534, 641, 2224, -5747, 1047,
+ -4074, 5252, -24, 674, 0, 0, 664, 237,
+ -2837, -4072, -1205, 8252, -5875, -1670, -2743, -3984,
+ 381, 5059, 1765, 2666, -8295, 7403, 1154, -2086,
+ 7622, 7105, 3677, -6943, 1050, -6632, -694, 0,
+ 0, 382, -133, 5699, 7650, 5154, -5713, -1645,
+ -6902, 6181, 4450, 1151, 410, -993, 3829, 2444,
+ -2405, -6618, -9514, 5366, -1896, 5844, -2886, -1524,
+ -7321, -1007, 0, 0, 12767, -2530, 3183, -1409,
+ -4015, -2894, -5155, -1710, 3841, -2107, -10274, 5119,
+ 3979, -4010, 5550, 4822, -746, -2507, -3080, 4289,
+ -3675, 4333, -1416, -1230, -1122, 0, 0, 17,
+ 8048, 2398, -2167, -73, -3606, 3125, 398, 731,
+ -5973, 5705, -1032, 4679, 7305, 3134, 1301, -3858,
+ -89, 2938, 4359, -9155, -4805, -8407, 3673, -8645,
+ 0, 0, 187, 7355, 3145, -6719, -4432, -5939,
+ 2541, -2810, 9723, 778, -1105, 5687, -4174, 2534,
+ -4461, 1017, -244, 5481, -1655, -6765, -3350, -4894,
+ 1592, -2318, 8827, 0, 0, 196, 3588, 9631,
+ 3063, -4564, 6043, 2683, 2595, -2488, -2186, 173,
+ -6059, -8270, -2386, 409, 7441, -8608, 376, -4364,
+ 2321, -280, 97, 8331, -3022, -4721, 0, 0,
+ 117, -748, -10833, 1533, 4200, -2875, -997, -109,
+ -3661, -6119, 4454, 8808, -9189, 8294, 1521, 7265,
+ -2348, -5094, -948, -5400, -3193, 8914, 5763, 1716,
+ -1070, 0, 0, 2497, 399, -5201, -2038, 7843,
+ -376, 7567, -5073, 7616, -5537, 2086, -3453, -5544,
+ -56, -11648, -1314, 3546, -3432, -117, 8694, -4245,
+ 9621, 3098, -2582, -2351, 0, 0, 4386, -3104,
+ -3132, -10512, 566, 5217, 5128, 4967, 1348, 7035,
+ -1470, 91, -125, -3548, 8244, -3029, -10033, 2186,
+ 9745, -6440, -2074, 3638, -1477, -7045, -562, 0,
+ 0, 2154, 8116, -6102, 6570, 12998, -712, -4126,
+ -4996, 30, 1571, -6393, -12794, 425, 5036, 1190,
+ 5763, 5653, 12933, -6671, 5197, -2964, -3316, -6354,
+ -10554, -2652, 0, 0, 12618, -3737, 93, -5901,
+ 4262, -3364, 4444, 3103, -2767, 3403, 4925, -2584,
+ -989, 4977, -3714, -1965, 3076, 326, -2946, -2568,
+ 1026, -2980, 3362, -6132, -5966, 0, 0, 6001,
+ 48, -1979, -7275, 3476, -2096, 10591, 3793, 2629,
+ -447, -14747, -3689, -5525, 8358, 6883, -9703, -4556,
+ 7471, 2965, 4056, 13221, -7327, -3073, -2353, -6720,
+ 0, 0, 621, 11034, -44, -2828, 5978, -1850,
+ -1772, 3894, -7471, -1397, 945, -2028, -2928, -2240,
+ 3172, 2222, 4544, -4243, -5645, 3745, 2573, 3511,
+ -8206, -7286, 5700, 0, 0, 321, 10818, -4982,
+ 7813, -749, 9907, 1360, -1443, 568, -1103, 2305,
+ 6045, 2270, -1063, -1920, -3073, 5893, -3476, -11346,
+ -1657, -588, 2957, -2287, -8527, -8041, 0, 0,
+ 119, -268, 2372, -3040, 4979, -3789, -5630, 10619,
+ 5900, -5109, -4585, -3862, 10467, -3527, -385, -10034,
+ -9991, 4860, 984, 2362, 2311, -6804, 6324, 433,
+ 5291, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 32767, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 32767
+};
+
+const MappingMatrix mapping_matrix_fifthoa_demixing = { 38, 38, 0 };
+const opus_int16 mapping_matrix_fifthoa_demixing_data[1444] = {
+ 3188, 3247, 3268, 3368, 3368, 3138, 3268, 3099,
+ 3211, 3368, 3099, 3247, 3211, 3368, 3368, 3368,
+ 3149, 3268, 3247, 3211, 3099, 3188, 3138, 3149,
+ 3099, 3188, 3368, 3149, 3188, 3247, 3268, 3138,
+ 3211, 3368, 3138, 3149, 0, 0, 118, -47,
+ -5011, 282, 333, -1497, -4584, 2908, 3388, -3647,
+ -2493, 1139, -2882, -1719, 3604, -2543, -4328, 5443,
+ 1286, -5498, -4583, 2510, -1743, -2556, 4168, 1446,
+ -290, 1812, -4074, -2377, 4152, 2847, 4991, 3980,
+ 393, 5072, 0, 0, 5489, -2235, 1507, -5326,
+ 4609, -1096, 2926, -3427, -3301, -3078, 4226, 1730,
+ 4627, 2561, 2966, -592, 143, -677, 4617, -755,
+ -956, -433, -5138, 3037, 157, -1394, -4498, -4984,
+ -3661, -4112, -3756, 4628, -570, 3356, 1605, 1803,
+ 0, 0, -162, 5162, 2132, 2392, 3556, -5141,
+ -1536, 2975, -3001, -3350, -2231, -5230, 1294, -4965,
+ 3494, 5230, -3292, -1359, -2945, -773, 2670, 4867,
+ -660, 3720, -3415, -5112, -3700, -1211, 407, 3013,
+ 763, 591, 2481, -2657, 5210, 784, 0, 0,
+ -156, 338, -4246, 510, 462, 3296, 2846, 3333,
+ -4292, 4574, 1940, -2986, -1275, 3701, 5022, -5250,
+ 5780, -2676, -1180, 1516, -4852, 4877, 342, -3923,
+ -5703, -2920, 379, -657, -361, -3346, 1044, 795,
+ 5257, -4004, 698, 1115, 0, 0, 47, -140,
+ -3292, -1097, 652, 855, -5260, -3691, -4470, 4521,
+ -3863, 1093, -5552, -2016, 3831, 334, -456, -1532,
+ 2068, 1788, 2054, -295, 3668, -2820, 328, -994,
+ 295, -3301, 5770, 4282, -6353, 5632, -1371, 5005,
+ 238, 4041, 0, 0, 6764, -1659, -2730, 5726,
+ 3715, -3216, -933, 531, -52, -345, 3022, -2818,
+ 4005, -1617, -1189, -3748, -3403, -3592, 4040, -3553,
+ -2806, -3444, 6023, -711, -3298, -2503, 2548, 5564,
+ 940, 1848, 1207, 4010, -3488, -358, -2511, -1966,
+ 0, 0, -64, -5039, 1403, -4455, 6240, 2189,
+ -1716, -4348, 4183, 3951, -4042, -3606, 2399, -4563,
+ 4050, -612, -395, 348, -5791, 391, -1440, -735,
+ 1398, 4359, -518, 2969, 6556, 1951, -518, -4993,
+ -925, 998, -569, -2934, 3460, 420, 0, 0,
+ 16, 5482, -4122, 770, 2082, 5020, -3961, 485,
+ -584, -793, 3, 5222, -1416, 3673, 78, 3549,
+ -937, -5723, 1673, -6162, -2540, 3082, -355, 1838,
+ -615, 4601, 2832, -359, -3346, 668, -3393, -1583,
+ -3774, -2206, 5754, -4961, 0, 0, -328, 299,
+ 2470, 317, 525, -4494, 2805, 2617, 2383, -2363,
+ -1037, 4085, 895, -4622, 3218, -6607, -3381, -5933,
+ 1397, 6394, -446, 5694, 14, -4510, 4329, 3690,
+ -334, 0, 2932, -2478, -2944, -577, -599, -230,
+ 1553, -4736, 0, 0, -324, 142, -3252, -867,
+ 1111, -1882, 3378, -6055, 6502, -6840, 4280, -2694,
+ -2876, 4190, 6454, 655, 1061, 626, -2669, -798,
+ 3192, -985, -898, -5482, -548, 2315, -558, 1302,
+ 900, 5747, -1325, 1599, -1384, -5749, 624, 1110,
+ 0, 0, 321, 312, 2188, 1322, 237, 708,
+ -304, 2463, 1500, -1094, -5112, -1010, -6799, 646,
+ 992, 1969, 3423, -3996, 2628, 4451, 3432, -2833,
+ -6101, -330, -3768, -3, -707, 5961, -4037, -3736,
+ 4080, 7254, -4113, 2151, 54, -2150, 0, 0,
+ 7735, 4064, -3884, -5240, 577, 2229, -3947, 2914,
+ 3555, 4011, 774, -3519, 1985, -3701, -3824, 330,
+ -905, 2085, 1155, 2176, 3006, 340, -5533, -3264,
+ -902, 3114, 344, -5060, 1524, 1805, 1926, 2350,
+ 1905, -3203, -2762, -4162, 0, 0, 193, -151,
+ -1434, 6289, 7354, 4234, 169, 2868, -1977, -1375,
+ -4987, 2345, 2742, 599, 939, -4837, 2688, 991,
+ -6907, 716, -1542, -4346, -1833, 1493, 3134, 2903,
+ -7019, -2835, 93, 4395, 621, 870, -2357, -975,
+ -2933, -127, 0, 0, -616, -5968, -3479, -1651,
+ 4932, -2445, -5512, -1451, 691, 739, 479, 4227,
+ -2886, 3853, 8, -501, 188, 1990, 3842, 2270,
+ 1662, -174, 1290, 2456, 67, -3267, -5535, 483,
+ 5721, -1642, 6501, -3432, 1184, -3246, 4101, -4880,
+ 0, 0, -465, 5264, -4812, 682, 1683, -4539,
+ 2916, -1985, 2899, 3324, 1060, -4398, -745, -2137,
+ -3827, 1044, 6225, 3609, -532, 1980, -6001, 564,
+ -209, -1299, 5336, -3605, -1484, 37, 19, -1295,
+ -665, -385, -6773, 3651, 6153, -1291, 0, 0,
+ 193, -415, 5166, -110, 626, 6743, -2860, 1425,
+ 1101, -1341, 80, -4533, 249, 4231, -119, -6009,
+ -2970, 5170, -822, -2610, 4527, 5948, 182, -2589,
+ 837, -5471, 371, -43, 373, -665, -1233, -626,
+ -7353, 2606, 1339, -1398, 0, 0, -533, 147,
+ 2075, -672, 1043, 3503, 4402, -4971, -3287, 3731,
+ -2606, 3817, 1972, -5603, 5114, 1185, -1318, 1906,
+ 3018, -1999, 343, -1943, 207, -6744, 913, -4060,
+ 645, -349, -5667, 4766, 5575, -1733, 1116, 160,
+ 1534, -5690, 0, 0, -137, -36, 1556, 1325,
+ 1553, -2230, 1188, 5296, -5104, 4673, 6295, 498,
+ -4723, 933, 2994, 4067, -4700, 1758, -4116, -1252,
+ 2444, -4092, 1653, -2802, 5069, 1133, 790, -2355,
+ -934, -6304, 1642, 2045, -4259, -3873, -213, 215,
+ 0, 0, -364, 423, 4888, -1316, 118, -950,
+ 4027, 114, 2961, -3136, -3012, -883, -6192, 1340,
+ -3210, -1193, 1376, 3128, 1596, -2994, -3194, 533,
+ 8502, 2487, -1485, 1032, 301, -8007, -577, 887,
+ 297, 7778, 3121, -1901, -94, -6401, 0, 0,
+ 9260, -1845, 668, 2787, -2255, 2699, -2512, -3737,
+ -3675, -3601, -1803, 210, -1701, -1442, -2700, 3457,
+ 2868, 2079, -2113, 3178, 1277, 3578, 5240, -2482,
+ 3324, 1020, -4027, 3835, -3758, -3633, -3170, -1310,
+ 2509, -3110, 713, 174, 0, 0, -399, 4969,
+ -2321, -7744, 6494, -3776, 1478, 758, -1794, -2233,
+ -4059, 4932, 2770, 4761, -3475, 1243, 829, -651,
+ -5358, -436, 2381, 1360, 2561, -3118, 858, -4366,
+ 3933, 3646, -43, -1310, -16, 924, 1197, 1415,
+ -5036, -376, 0, 0, 100, 1410, 1290, 3199,
+ 7091, -3638, -2641, 1118, 45, -441, 794, -974,
+ -5033, 889, 438, -3102, 895, 3555, 4672, 4795,
+ 1129, -2408, -2153, 1742, 159, -2040, 7578, -2006,
+ -5737, 1986, -5568, -6413, 2428, -1387, -2441, 667,
+ 0, 0, -37, -6031, -4434, -904, 3290, 1806,
+ 4736, 2516, -5905, -5927, 1754, -4300, -2468, -2203,
+ -4836, -672, 1444, -1591, -1631, -1789, 4311, -153,
+ -688, -1222, 1058, 3139, 4659, -353, 1543, 1838,
+ 2180, -1448, 2432, 6277, 5304, -1692, 0, 0,
+ -280, 4506, 807, -477, 823, 3550, 1427, -1856,
+ -3003, -3501, -1203, 2679, 933, 778, -4954, -1977,
+ -7458, 4687, 435, 7045, -4053, -3130, 257, -3917,
+ -6165, 1889, 927, 235, 1889, -1097, 1985, 630,
+ -2172, -2130, 7080, 4810, 0, 0, -300, 496,
+ 2808, 279, 667, -7179, -2661, -526, -2832, 1751,
+ 2849, 4829, -906, -4151, -1124, -3062, 8166, 5361,
+ -1656, -6017, 3265, 2551, -864, -432, -6966, 6295,
+ -168, 901, 442, -582, 269, 236, -3574, 799,
+ 472, 565, 0, 0, 805, -2466, 6208, -4592,
+ -170, -6701, -5610, 3678, -4242, 4561, -724, -5534,
+ 2415, 7354, 2761, 2699, -349, 3822, -2372, 1756,
+ -5523, -3445, -588, -5749, -3986, 9804, -3871, 5375,
+ -2308, 5504, -2766, -1651, 1472, 6832, 2705, -5104,
+ 0, 0, -700, -1179, 4402, 400, 1383, 939,
+ -1342, 6013, 2577, -3472, 472, 2883, 1450, -3917,
+ 2849, 5084, 4990, 5392, 342, -4925, -3329, -5372,
+ -2674, -6035, -5072, -836, 179, 2506, 7987, -3647,
+ -8202, -1437, 1891, 2400, 1607, -3611, 0, 0,
+ -4706, -4003, 9928, -379, 5557, 3738, -8789, 685,
+ 1937, -5157, 13388, 7995, -4119, -9909, -5079, 4804,
+ 5586, 774, -5430, 299, -9943, 3264, -3690, -3901,
+ -1133, -6199, 3182, 1544, 5467, 3686, -2639, 4068,
+ 1163, -185, -1299, -506, 0, 0, 843, 1005,
+ -1059, 467, -1279, -2259, 6057, -1694, -5885, 5342,
+ -5160, -3748, -1382, 4420, -697, -2000, -3808, 3100,
+ 2685, -4073, 531, 318, -7822, 2414, 2901, 3399,
+ -1340, 8449, 3685, 463, -3341, 2423, 2304, -2723,
+ 84, -2622, 0, 0, 12088, -265, 2562, -435,
+ -4348, -2426, 3538, 1552, 1279, 883, -4166, 2634,
+ -6130, 2994, 3729, -1570, -601, -1753, -5124, -2788,
+ -2096, -1920, -2649, 2793, -1079, -1952, 2983, -1530,
+ 2499, 1769, 1492, -6757, -2108, 2841, 1466, 2597,
+ 0, 0, -3830, -4093, 2448, 12720, 7737, -665,
+ -832, -9257, 2971, -2400, 791, 1873, 1072, -587,
+ -7440, 8055, 1531, -4736, 616, -1782, -2982, 9663,
+ -5057, -5926, 1610, -4489, 7033, -8658, 6010, -5673,
+ 5648, 812, -271, -1802, -4500, 4392, 0, 0,
+ -888, -327, 3373, -1084, 7959, 2430, 1898, -2360,
+ -1820, -1377, -1090, -4436, -3422, -1106, -3230, 3876,
+ -41, -5128, 6375, -1848, -3824, 5844, 617, -1957,
+ 4232, 1345, -1439, -83, 3046, -214, 5458, -5566,
+ -4387, -3738, -5740, 8657, 0, 0, 6978, 6239,
+ -3686, -981, -2854, 78, 5859, -357, 4618, 7391,
+ -138, 971, -5799, 2135, 4478, -7004, -5949, 1668,
+ -6933, -1163, 7010, -5624, 2990, 6192, -8075, 3567,
+ -8308, 2236, -5098, -2120, -4355, -4238, 4955, 10230,
+ 692, -5606, 0, 0, -1348, -7069, -12, -4927,
+ 1211, 651, 1360, 7744, 3404, 5069, -2438, -105,
+ 2332, 1494, -4686, 1336, -3628, -881, 2474, 1736,
+ -26, -257, 2135, -4452, 446, -641, -4704, 2605,
+ -6436, 6662, -4939, 990, -1100, -3782, 5028, 4753,
+ 0, 0, -2875, 6410, 3518, 3950, 1271, 869,
+ -2842, -5837, 1532, -2899, 1140, -597, 1712, -1988,
+ -4819, -4783, 4773, -8796, 2240, -4596, 3565, -4853,
+ -556, -3974, 7366, -4370, 3113, -3548, 3552, -5450,
+ 3869, 2514, 6736, -4570, 6074, 3151, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 32767, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 32767
+};
diff --git a/media/libopus/src/mapping_matrix.h b/media/libopus/src/mapping_matrix.h
index 98bc82df3e..53646cb19f 100644
--- a/media/libopus/src/mapping_matrix.h
+++ b/media/libopus/src/mapping_matrix.h
@@ -117,6 +117,12 @@ extern const opus_int16 mapping_matrix_soa_mixing_data[121];
extern const MappingMatrix mapping_matrix_toa_mixing;
extern const opus_int16 mapping_matrix_toa_mixing_data[324];
+extern const MappingMatrix mapping_matrix_fourthoa_mixing;
+extern const opus_int16 mapping_matrix_fourthoa_mixing_data[729];
+
+extern const MappingMatrix mapping_matrix_fifthoa_mixing;
+extern const opus_int16 mapping_matrix_fifthoa_mixing_data[1444];
+
extern const MappingMatrix mapping_matrix_foa_demixing;
extern const opus_int16 mapping_matrix_foa_demixing_data[36];
@@ -126,6 +132,12 @@ extern const opus_int16 mapping_matrix_soa_demixing_data[121];
extern const MappingMatrix mapping_matrix_toa_demixing;
extern const opus_int16 mapping_matrix_toa_demixing_data[324];
+extern const MappingMatrix mapping_matrix_fourthoa_demixing;
+extern const opus_int16 mapping_matrix_fourthoa_demixing_data[729];
+
+extern const MappingMatrix mapping_matrix_fifthoa_demixing;
+extern const opus_int16 mapping_matrix_fifthoa_demixing_data[1444];
+
#ifdef __cplusplus
}
#endif
diff --git a/media/libopus/src/mlp.c b/media/libopus/src/mlp.c
index 964c6a98f6..e658ccde0d 100644
--- a/media/libopus/src/mlp.c
+++ b/media/libopus/src/mlp.c
@@ -33,35 +33,23 @@
#include "opus_types.h"
#include "opus_defines.h"
#include "arch.h"
-#include "tansig_table.h"
#include "mlp.h"
+#define fmadd(a, b, c) ((a)*(b)+(c))
static OPUS_INLINE float tansig_approx(float x)
{
- int i;
- float y, dy;
- float sign=1;
- /* Tests are reversed to catch NaNs */
- if (!(x<8))
- return 1;
- if (!(x>-8))
- return -1;
-#ifndef FIXED_POINT
- /* Another check in case of -ffast-math */
- if (celt_isnan(x))
- return 0;
-#endif
- if (x<0)
- {
- x=-x;
- sign=-1;
- }
- i = (int)floor(.5f+25*x);
- x -= .04f*i;
- y = tansig_table[i];
- dy = 1-y*y;
- y = y + x*dy*(1 - y*x);
- return sign*y;
+ const float N0 = 952.52801514f;
+ const float N1 = 96.39235687f;
+ const float N2 = 0.60863042f;
+ const float D0 = 952.72399902f;
+ const float D1 = 413.36801147f;
+ const float D2 = 11.88600922f;
+ float X2, num, den;
+ X2 = x*x;
+ num = fmadd(fmadd(N2, X2, N1), X2, N0);
+ den = fmadd(fmadd(D2, X2, D1), X2, D0);
+ num = num*x/den;
+ return MAX32(-1.f, MIN32(1.f, num));
}
static OPUS_INLINE float sigmoid_approx(float x)
@@ -79,7 +67,7 @@ static void gemm_accum(float *out, const opus_int8 *weights, int rows, int cols,
}
}
-void compute_dense(const DenseLayer *layer, float *output, const float *input)
+void analysis_compute_dense(const AnalysisDenseLayer *layer, float *output, const float *input)
{
int i;
int N, M;
@@ -101,7 +89,7 @@ void compute_dense(const DenseLayer *layer, float *output, const float *input)
}
}
-void compute_gru(const GRULayer *gru, float *state, const float *input)
+void analysis_compute_gru(const AnalysisGRULayer *gru, float *state, const float *input)
{
int i;
int N, M;
diff --git a/media/libopus/src/mlp.h b/media/libopus/src/mlp.h
index d7670550fd..e6b1a8f76c 100644
--- a/media/libopus/src/mlp.h
+++ b/media/libopus/src/mlp.h
@@ -24,8 +24,8 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef _MLP_H_
-#define _MLP_H_
+#ifndef MLP_H_
+#define MLP_H_
#include "opus_types.h"
@@ -39,7 +39,7 @@ typedef struct {
int nb_inputs;
int nb_neurons;
int sigmoid;
-} DenseLayer;
+} AnalysisDenseLayer;
typedef struct {
const opus_int8 *bias;
@@ -47,14 +47,14 @@ typedef struct {
const opus_int8 *recurrent_weights;
int nb_inputs;
int nb_neurons;
-} GRULayer;
+} AnalysisGRULayer;
-extern const DenseLayer layer0;
-extern const GRULayer layer1;
-extern const DenseLayer layer2;
+extern const AnalysisDenseLayer layer0;
+extern const AnalysisGRULayer layer1;
+extern const AnalysisDenseLayer layer2;
-void compute_dense(const DenseLayer *layer, float *output, const float *input);
+void analysis_compute_dense(const AnalysisDenseLayer *layer, float *output, const float *input);
-void compute_gru(const GRULayer *gru, float *state, const float *input);
+void analysis_compute_gru(const AnalysisGRULayer *gru, float *state, const float *input);
-#endif /* _MLP_H_ */
+#endif /* MLP_H_ */
diff --git a/media/libopus/src/mlp_data.c b/media/libopus/src/mlp_data.c
index ae4178df76..65f7448ea0 100644
--- a/media/libopus/src/mlp_data.c
+++ b/media/libopus/src/mlp_data.c
@@ -651,20 +651,20 @@ static const opus_int8 layer2_bias[2] = {
14, 117
};
-const DenseLayer layer0 = {
+const AnalysisDenseLayer layer0 = {
layer0_bias,
layer0_weights,
25, 32, 0
};
-const GRULayer layer1 = {
+const AnalysisGRULayer layer1 = {
layer1_bias,
layer1_weights,
layer1_recur_weights,
32, 24
};
-const DenseLayer layer2 = {
+const AnalysisDenseLayer layer2 = {
layer2_bias,
layer2_weights,
24, 2, 1
diff --git a/media/libopus/src/opus.c b/media/libopus/src/opus.c
index 538b5ea74e..816a4dd5fa 100644
--- a/media/libopus/src/opus.c
+++ b/media/libopus/src/opus.c
@@ -194,7 +194,8 @@ int opus_packet_get_samples_per_frame(const unsigned char *data,
int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
int self_delimited, unsigned char *out_toc,
const unsigned char *frames[48], opus_int16 size[48],
- int *payload_offset, opus_int32 *packet_offset)
+ int *payload_offset, opus_int32 *packet_offset,
+ const unsigned char **padding, opus_int32 *padding_len)
{
int i, bytes;
int count;
@@ -337,6 +338,11 @@ int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
data += size[i];
}
+ if (padding != NULL)
+ {
+ *padding = data;
+ *padding_len = pad;
+ }
if (packet_offset)
*packet_offset = pad+(opus_int32)(data-data0);
@@ -351,6 +357,6 @@ int opus_packet_parse(const unsigned char *data, opus_int32 len,
opus_int16 size[48], int *payload_offset)
{
return opus_packet_parse_impl(data, len, 0, out_toc,
- frames, size, payload_offset, NULL);
+ frames, size, payload_offset, NULL, NULL, NULL);
}
diff --git a/media/libopus/src/opus_decoder.c b/media/libopus/src/opus_decoder.c
index 6520e748ea..b57c809434 100644
--- a/media/libopus/src/opus_decoder.c
+++ b/media/libopus/src/opus_decoder.c
@@ -52,6 +52,15 @@
#include "mathops.h"
#include "cpu_support.h"
+#ifdef ENABLE_DEEP_PLC
+#include "dred_rdovae_dec_data.h"
+#include "dred_rdovae_dec.h"
+#endif
+
+#ifdef ENABLE_OSCE
+#include "osce.h"
+#endif
+
struct OpusDecoder {
int celt_dec_offset;
int silk_dec_offset;
@@ -59,7 +68,11 @@ struct OpusDecoder {
opus_int32 Fs; /** Sampling rate (at the API level) */
silk_DecControlStruct DecControl;
int decode_gain;
+ int complexity;
int arch;
+#ifdef ENABLE_DEEP_PLC
+ LPCNetPLCState lpcnet;
+#endif
/* Everything beyond this point gets cleared on a reset */
#define OPUS_DECODER_RESET_START stream_channels
@@ -135,6 +148,7 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels)
silk_dec = (char*)st+st->silk_dec_offset;
celt_dec = (CELTDecoder*)((char*)st+st->celt_dec_offset);
st->stream_channels = st->channels = channels;
+ st->complexity = 0;
st->Fs = Fs;
st->DecControl.API_sampleRate = st->Fs;
@@ -152,6 +166,9 @@ int opus_decoder_init(OpusDecoder *st, opus_int32 Fs, int channels)
st->prev_mode = 0;
st->frame_size = Fs/400;
+#ifdef ENABLE_DEEP_PLC
+ lpcnet_plc_init( &st->lpcnet);
+#endif
st->arch = opus_select_arch();
return OPUS_OK;
}
@@ -370,7 +387,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
pcm_ptr = pcm_silk;
if (st->prev_mode==MODE_CELT_ONLY)
- silk_InitDecoder( silk_dec );
+ silk_ResetDecoder( silk_dec );
/* The SILK PLC cannot produce frames of less than 10 ms */
st->DecControl.payloadSize_ms = IMAX(10, 1000 * audiosize / st->Fs);
@@ -394,14 +411,28 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
st->DecControl.internalSampleRate = 16000;
}
}
+ st->DecControl.enable_deep_plc = st->complexity >= 5;
+#ifdef ENABLE_OSCE
+ st->DecControl.osce_method = OSCE_METHOD_NONE;
+#ifndef DISABLE_LACE
+ if (st->complexity >= 6) {st->DecControl.osce_method = OSCE_METHOD_LACE;}
+#endif
+#ifndef DISABLE_NOLACE
+ if (st->complexity >= 7) {st->DecControl.osce_method = OSCE_METHOD_NOLACE;}
+#endif
+#endif
- lost_flag = data == NULL ? 1 : 2 * decode_fec;
+ lost_flag = data == NULL ? 1 : 2 * !!decode_fec;
decoded_samples = 0;
do {
/* Call SILK decoder */
int first_frame = decoded_samples == 0;
silk_ret = silk_Decode( silk_dec, &st->DecControl,
- lost_flag, first_frame, &dec, pcm_ptr, &silk_frame_size, st->arch );
+ lost_flag, first_frame, &dec, pcm_ptr, &silk_frame_size,
+#ifdef ENABLE_DEEP_PLC
+ &st->lpcnet,
+#endif
+ st->arch );
if( silk_ret ) {
if (lost_flag) {
/* PLC failure should not be fatal */
@@ -521,8 +552,12 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
if (mode != st->prev_mode && st->prev_mode > 0 && !st->prev_redundancy)
MUST_SUCCEED(celt_decoder_ctl(celt_dec, OPUS_RESET_STATE));
/* Decode CELT */
- celt_ret = celt_decode_with_ec(celt_dec, decode_fec ? NULL : data,
- len, pcm, celt_frame_size, &dec, celt_accum);
+ celt_ret = celt_decode_with_ec_dred(celt_dec, decode_fec ? NULL : data,
+ len, pcm, celt_frame_size, &dec, celt_accum
+#ifdef ENABLE_DEEP_PLC
+ , &st->lpcnet
+#endif
+ );
} else {
unsigned char silence[2] = {0xFF, 0xFF};
if (!celt_accum)
@@ -634,7 +669,7 @@ static int opus_decode_frame(OpusDecoder *st, const unsigned char *data,
int opus_decode_native(OpusDecoder *st, const unsigned char *data,
opus_int32 len, opus_val16 *pcm, int frame_size, int decode_fec,
- int self_delimited, opus_int32 *packet_offset, int soft_clip)
+ int self_delimited, opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset)
{
int i, nb_samples;
int count, offset;
@@ -648,6 +683,35 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
/* For FEC/PLC, frame_size has to be to have a multiple of 2.5 ms */
if ((decode_fec || len==0 || data==NULL) && frame_size%(st->Fs/400)!=0)
return OPUS_BAD_ARG;
+#ifdef ENABLE_DRED
+ if (dred != NULL && dred->process_stage == 2) {
+ int F10;
+ int features_per_frame;
+ int needed_feature_frames;
+ int init_frames;
+ lpcnet_plc_fec_clear(&st->lpcnet);
+ F10 = st->Fs/100;
+ /* if blend==0, the last PLC call was "update" and we need to feed two extra 10-ms frames. */
+ init_frames = (st->lpcnet.blend == 0) ? 2 : 0;
+ features_per_frame = IMAX(1, frame_size/F10);
+ needed_feature_frames = init_frames + features_per_frame;
+ lpcnet_plc_fec_clear(&st->lpcnet);
+ for (i=0;i<needed_feature_frames;i++) {
+ int feature_offset;
+ /* We floor instead of rounding because 5-ms overlap compensates for the missing 0.5 rounding offset. */
+ feature_offset = init_frames - i - 2 + (int)floor(((float)dred_offset + dred->dred_offset*F10/4)/F10);
+ if (feature_offset <= 4*dred->nb_latents-1 && feature_offset >= 0) {
+ lpcnet_plc_fec_add(&st->lpcnet, dred->fec_features+feature_offset*DRED_NUM_FEATURES);
+ } else {
+ if (feature_offset >= 0) lpcnet_plc_fec_add(&st->lpcnet, NULL);
+ }
+
+ }
+ }
+#else
+ (void)dred;
+ (void)dred_offset;
+#endif
if (len==0 || data==NULL)
{
int pcm_count=0;
@@ -672,7 +736,7 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
packet_stream_channels = opus_packet_get_nb_channels(data);
count = opus_packet_parse_impl(data, len, self_delimited, &toc, NULL,
- size, &offset, packet_offset);
+ size, &offset, packet_offset, NULL, NULL);
if (count<0)
return count;
@@ -684,12 +748,12 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data,
int ret;
/* If no FEC can be present, run the PLC (recursive call) */
if (frame_size < packet_frame_size || packet_mode == MODE_CELT_ONLY || st->mode == MODE_CELT_ONLY)
- return opus_decode_native(st, NULL, 0, pcm, frame_size, 0, 0, NULL, soft_clip);
+ return opus_decode_native(st, NULL, 0, pcm, frame_size, 0, 0, NULL, soft_clip, NULL, 0);
/* Otherwise, run the PLC on everything except the size for which we might have FEC */
duration_copy = st->last_packet_duration;
if (frame_size-packet_frame_size!=0)
{
- ret = opus_decode_native(st, NULL, 0, pcm, frame_size-packet_frame_size, 0, 0, NULL, soft_clip);
+ ret = opus_decode_native(st, NULL, 0, pcm, frame_size-packet_frame_size, 0, 0, NULL, soft_clip, NULL, 0);
if (ret<0)
{
st->last_packet_duration = duration_copy;
@@ -753,7 +817,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
{
if(frame_size<=0)
return OPUS_BAD_ARG;
- return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0);
+ return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0, NULL, 0);
}
#ifndef DISABLE_FLOAT_API
@@ -781,7 +845,7 @@ int opus_decode_float(OpusDecoder *st, const unsigned char *data,
celt_assert(st->channels == 1 || st->channels == 2);
ALLOC(out, frame_size*st->channels, opus_int16);
- ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 0);
+ ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 0, NULL, 0);
if (ret > 0)
{
for (i=0;i<ret*st->channels;i++)
@@ -819,7 +883,7 @@ int opus_decode(OpusDecoder *st, const unsigned char *data,
celt_assert(st->channels == 1 || st->channels == 2);
ALLOC(out, frame_size*st->channels, float);
- ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1);
+ ret = opus_decode_native(st, data, len, out, frame_size, decode_fec, 0, NULL, 1, NULL, 0);
if (ret > 0)
{
for (i=0;i<ret*st->channels;i++)
@@ -834,7 +898,7 @@ int opus_decode_float(OpusDecoder *st, const unsigned char *data,
{
if(frame_size<=0)
return OPUS_BAD_ARG;
- return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0);
+ return opus_decode_native(st, data, len, pcm, frame_size, decode_fec, 0, NULL, 0, NULL, 0);
}
#endif
@@ -864,6 +928,27 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...)
*value = st->bandwidth;
}
break;
+ case OPUS_SET_COMPLEXITY_REQUEST:
+ {
+ opus_int32 value = va_arg(ap, opus_int32);
+ if(value<0 || value>10)
+ {
+ goto bad_arg;
+ }
+ st->complexity = value;
+ celt_decoder_ctl(celt_dec, OPUS_SET_COMPLEXITY(value));
+ }
+ break;
+ case OPUS_GET_COMPLEXITY_REQUEST:
+ {
+ opus_int32 *value = va_arg(ap, opus_int32*);
+ if (!value)
+ {
+ goto bad_arg;
+ }
+ *value = st->complexity;
+ }
+ break;
case OPUS_GET_FINAL_RANGE_REQUEST:
{
opus_uint32 *value = va_arg(ap, opus_uint32*);
@@ -881,9 +966,12 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...)
((char*)&st->OPUS_DECODER_RESET_START - (char*)st));
celt_decoder_ctl(celt_dec, OPUS_RESET_STATE);
- silk_InitDecoder( silk_dec );
+ silk_ResetDecoder( silk_dec );
st->stream_channels = st->channels;
st->frame_size = st->Fs/400;
+#ifdef ENABLE_DEEP_PLC
+ lpcnet_plc_reset( &st->lpcnet );
+#endif
}
break;
case OPUS_GET_SAMPLE_RATE_REQUEST:
@@ -959,6 +1047,20 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...)
ret = celt_decoder_ctl(celt_dec, OPUS_GET_PHASE_INVERSION_DISABLED(value));
}
break;
+#ifdef USE_WEIGHTS_FILE
+ case OPUS_SET_DNN_BLOB_REQUEST:
+ {
+ const unsigned char *data = va_arg(ap, const unsigned char *);
+ opus_int32 len = va_arg(ap, opus_int32);
+ if(len<0 || data == NULL)
+ {
+ goto bad_arg;
+ }
+ ret = lpcnet_plc_load_model(&st->lpcnet, data, len);
+ ret = silk_LoadOSCEModels(silk_dec, data, len) || ret;
+ }
+ break;
+#endif
default:
/*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/
ret = OPUS_UNIMPLEMENTED;
@@ -1034,8 +1136,373 @@ int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len,
return samples;
}
+int opus_packet_has_lbrr(const unsigned char packet[], opus_int32 len)
+{
+ int ret;
+ const unsigned char *frames[48];
+ opus_int16 size[48];
+ int packet_mode, packet_frame_size, packet_stream_channels;
+ int nb_frames=1;
+ int lbrr;
+
+ packet_mode = opus_packet_get_mode(packet);
+ if (packet_mode == MODE_CELT_ONLY)
+ return 0;
+ packet_frame_size = opus_packet_get_samples_per_frame(packet, 48000);
+ if (packet_frame_size > 960)
+ nb_frames = packet_frame_size/960;
+ packet_stream_channels = opus_packet_get_nb_channels(packet);
+ ret = opus_packet_parse(packet, len, NULL, frames, size, NULL);
+ if (ret <= 0)
+ return ret;
+ lbrr = (frames[0][0] >> (7-nb_frames)) & 0x1;
+ if (packet_stream_channels == 2)
+ lbrr = lbrr || ((frames[0][0] >> (6-2*nb_frames)) & 0x1);
+ return lbrr;
+}
+
int opus_decoder_get_nb_samples(const OpusDecoder *dec,
const unsigned char packet[], opus_int32 len)
{
return opus_packet_get_nb_samples(packet, len, dec->Fs);
}
+
+struct OpusDREDDecoder {
+#ifdef ENABLE_DRED
+ RDOVAEDec model;
+#endif
+ int loaded;
+ int arch;
+ opus_uint32 magic;
+};
+
+#if defined(ENABLE_DRED) && (defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS))
+static void validate_dred_decoder(OpusDREDDecoder *st)
+{
+ celt_assert(st->magic == 0xD8EDDEC0);
+#ifdef OPUS_ARCHMASK
+ celt_assert(st->arch >= 0);
+ celt_assert(st->arch <= OPUS_ARCHMASK);
+#endif
+}
+#define VALIDATE_DRED_DECODER(st) validate_dred_decoder(st)
+#else
+#define VALIDATE_DRED_DECODER(st)
+#endif
+
+
+int opus_dred_decoder_get_size(void)
+{
+ return sizeof(OpusDREDDecoder);
+}
+
+#ifdef ENABLE_DRED
+int dred_decoder_load_model(OpusDREDDecoder *dec, const unsigned char *data, int len)
+{
+ WeightArray *list;
+ int ret;
+ parse_weights(&list, data, len);
+ ret = init_rdovaedec(&dec->model, list);
+ opus_free(list);
+ if (ret == 0) dec->loaded = 1;
+ return (ret == 0) ? OPUS_OK : OPUS_BAD_ARG;
+}
+#endif
+
+int opus_dred_decoder_init(OpusDREDDecoder *dec)
+{
+ int ret = 0;
+ dec->loaded = 0;
+#if defined(ENABLE_DRED) && !defined(USE_WEIGHTS_FILE)
+ ret = init_rdovaedec(&dec->model, rdovaedec_arrays);
+ if (ret == 0) dec->loaded = 1;
+#endif
+ dec->arch = opus_select_arch();
+ /* To make sure nobody forgets to init, use a magic number. */
+ dec->magic = 0xD8EDDEC0;
+ return (ret == 0) ? OPUS_OK : OPUS_UNIMPLEMENTED;
+}
+
+OpusDREDDecoder *opus_dred_decoder_create(int *error)
+{
+ int ret;
+ OpusDREDDecoder *dec;
+ dec = (OpusDREDDecoder *)opus_alloc(opus_dred_decoder_get_size());
+ if (dec == NULL)
+ {
+ if (error)
+ *error = OPUS_ALLOC_FAIL;
+ return NULL;
+ }
+ ret = opus_dred_decoder_init(dec);
+ if (error)
+ *error = ret;
+ if (ret != OPUS_OK)
+ {
+ opus_free(dec);
+ dec = NULL;
+ }
+ return dec;
+}
+
+void opus_dred_decoder_destroy(OpusDREDDecoder *dec)
+{
+ if (dec) dec->magic = 0xDE57801D;
+ opus_free(dec);
+}
+
+int opus_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request, ...)
+{
+#ifdef ENABLE_DRED
+ int ret = OPUS_OK;
+ va_list ap;
+
+ va_start(ap, request);
+ (void)dred_dec;
+ switch (request)
+ {
+# ifdef USE_WEIGHTS_FILE
+ case OPUS_SET_DNN_BLOB_REQUEST:
+ {
+ const unsigned char *data = va_arg(ap, const unsigned char *);
+ opus_int32 len = va_arg(ap, opus_int32);
+ if(len<0 || data == NULL)
+ {
+ goto bad_arg;
+ }
+ return dred_decoder_load_model(dred_dec, data, len);
+ }
+ break;
+# endif
+ default:
+ /*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/
+ ret = OPUS_UNIMPLEMENTED;
+ break;
+ }
+ va_end(ap);
+ return ret;
+# ifdef USE_WEIGHTS_FILE
+bad_arg:
+ va_end(ap);
+ return OPUS_BAD_ARG;
+# endif
+#else
+ (void)dred_dec;
+ (void)request;
+ return OPUS_UNIMPLEMENTED;
+#endif
+}
+
+#ifdef ENABLE_DRED
+static int dred_find_payload(const unsigned char *data, opus_int32 len, const unsigned char **payload, int *dred_frame_offset)
+{
+ const unsigned char *data0;
+ int len0;
+ int frame = 0;
+ int ret;
+ const unsigned char *frames[48];
+ opus_int16 size[48];
+ int frame_size;
+
+ *payload = NULL;
+ /* Get the padding section of the packet. */
+ ret = opus_packet_parse_impl(data, len, 0, NULL, frames, size, NULL, NULL, &data0, &len0);
+ if (ret < 0)
+ return ret;
+ frame_size = opus_packet_get_samples_per_frame(data, 48000);
+ data = data0;
+ len = len0;
+ /* Scan extensions in order until we find the earliest frame with DRED data. */
+ while (len > 0)
+ {
+ opus_int32 header_size;
+ int id, L;
+ len0 = len;
+ data0 = data;
+ id = *data0 >> 1;
+ L = *data0 & 0x1;
+ len = skip_extension(&data, len, &header_size);
+ if (len < 0)
+ break;
+ if (id == 1)
+ {
+ if (L==0)
+ {
+ frame++;
+ } else {
+ frame += data0[1];
+ }
+ } else if (id == DRED_EXTENSION_ID)
+ {
+ const unsigned char *curr_payload;
+ opus_int32 curr_payload_len;
+ curr_payload = data0+header_size;
+ curr_payload_len = (data-data0)-header_size;
+ /* DRED position in the packet, in units of 2.5 ms like for the signaled DRED offset. */
+ *dred_frame_offset = frame*frame_size/120;
+#ifdef DRED_EXPERIMENTAL_VERSION
+ /* Check that temporary extension type and version match.
+ This check will be removed once extension is finalized. */
+ if (curr_payload_len > DRED_EXPERIMENTAL_BYTES && curr_payload[0] == 'D' && curr_payload[1] == DRED_EXPERIMENTAL_VERSION) {
+ *payload = curr_payload+2;
+ return curr_payload_len-2;
+ }
+#else
+ if (curr_payload_len > 0) {
+ *payload = curr_payload;
+ return curr_payload_len;
+ }
+#endif
+ }
+ }
+ return 0;
+}
+#endif
+
+int opus_dred_get_size(void)
+{
+#ifdef ENABLE_DRED
+ return sizeof(OpusDRED);
+#else
+ return 0;
+#endif
+}
+
+OpusDRED *opus_dred_alloc(int *error)
+{
+#ifdef ENABLE_DRED
+ OpusDRED *dec;
+ dec = (OpusDRED *)opus_alloc(opus_dred_get_size());
+ if (dec == NULL)
+ {
+ if (error)
+ *error = OPUS_ALLOC_FAIL;
+ return NULL;
+ }
+ return dec;
+#else
+ if (error)
+ *error = OPUS_UNIMPLEMENTED;
+ return NULL;
+#endif
+}
+
+void opus_dred_free(OpusDRED *dec)
+{
+#ifdef ENABLE_DRED
+ opus_free(dec);
+#else
+ (void)dec;
+#endif
+}
+
+int opus_dred_parse(OpusDREDDecoder *dred_dec, OpusDRED *dred, const unsigned char *data, opus_int32 len, opus_int32 max_dred_samples, opus_int32 sampling_rate, int *dred_end, int defer_processing)
+{
+#ifdef ENABLE_DRED
+ const unsigned char *payload;
+ opus_int32 payload_len;
+ int dred_frame_offset=0;
+ VALIDATE_DRED_DECODER(dred_dec);
+ if (!dred_dec->loaded) return OPUS_UNIMPLEMENTED;
+ dred->process_stage = -1;
+ payload_len = dred_find_payload(data, len, &payload, &dred_frame_offset);
+ if (payload_len < 0)
+ return payload_len;
+ if (payload != NULL)
+ {
+ int offset;
+ int min_feature_frames;
+ offset = 100*max_dred_samples/sampling_rate;
+ min_feature_frames = IMIN(2 + offset, 2*DRED_NUM_REDUNDANCY_FRAMES);
+ dred_ec_decode(dred, payload, payload_len, min_feature_frames, dred_frame_offset);
+ if (!defer_processing)
+ opus_dred_process(dred_dec, dred, dred);
+ if (dred_end) *dred_end = IMAX(0, -dred->dred_offset*sampling_rate/400);
+ return IMAX(0, dred->nb_latents*sampling_rate/25 - dred->dred_offset* sampling_rate/400);
+ }
+ if (dred_end) *dred_end = 0;
+ return 0;
+#else
+ (void)dred_dec;
+ (void)dred;
+ (void)data;
+ (void)len;
+ (void)max_dred_samples;
+ (void)sampling_rate;
+ (void)defer_processing;
+ (void)dred_end;
+ return OPUS_UNIMPLEMENTED;
+#endif
+}
+
+int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src, OpusDRED *dst)
+{
+#ifdef ENABLE_DRED
+ if (dred_dec == NULL || src == NULL || dst == NULL || (src->process_stage != 1 && src->process_stage != 2))
+ return OPUS_BAD_ARG;
+ VALIDATE_DRED_DECODER(dred_dec);
+ if (!dred_dec->loaded) return OPUS_UNIMPLEMENTED;
+ if (src != dst)
+ OPUS_COPY(dst, src, 1);
+ if (dst->process_stage == 2)
+ return OPUS_OK;
+ DRED_rdovae_decode_all(&dred_dec->model, dst->fec_features, dst->state, dst->latents, dst->nb_latents, dred_dec->arch);
+ dst->process_stage = 2;
+ return OPUS_OK;
+#else
+ (void)dred_dec;
+ (void)src;
+ (void)dst;
+ return OPUS_UNIMPLEMENTED;
+#endif
+}
+
+int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size)
+{
+#ifdef ENABLE_DRED
+ VARDECL(float, out);
+ int ret, i;
+ ALLOC_STACK;
+
+ if(frame_size<=0)
+ {
+ RESTORE_STACK;
+ return OPUS_BAD_ARG;
+ }
+
+ celt_assert(st->channels == 1 || st->channels == 2);
+ ALLOC(out, frame_size*st->channels, float);
+
+ ret = opus_decode_native(st, NULL, 0, out, frame_size, 0, 0, NULL, 1, dred, dred_offset);
+ if (ret > 0)
+ {
+ for (i=0;i<ret*st->channels;i++)
+ pcm[i] = FLOAT2INT16(out[i]);
+ }
+ RESTORE_STACK;
+ return ret;
+#else
+ (void)st;
+ (void)dred;
+ (void)dred_offset;
+ (void)pcm;
+ (void)frame_size;
+ return OPUS_UNIMPLEMENTED;
+#endif
+}
+
+int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size)
+{
+#ifdef ENABLE_DRED
+ if(frame_size<=0)
+ return OPUS_BAD_ARG;
+ return opus_decode_native(st, NULL, 0, pcm, frame_size, 0, 0, NULL, 0, dred, dred_offset);
+#else
+ (void)st;
+ (void)dred;
+ (void)dred_offset;
+ (void)pcm;
+ (void)frame_size;
+ return OPUS_UNIMPLEMENTED;
+#endif
+}
diff --git a/media/libopus/src/opus_encoder.c b/media/libopus/src/opus_encoder.c
index 8c8db5a546..d18d582f03 100644
--- a/media/libopus/src/opus_encoder.c
+++ b/media/libopus/src/opus_encoder.c
@@ -45,11 +45,19 @@
#include "analysis.h"
#include "mathops.h"
#include "tuning_parameters.h"
+
+#ifdef ENABLE_DRED
+#include "dred_coding.h"
+#endif
+
#ifdef FIXED_POINT
#include "fixed/structs_FIX.h"
#else
#include "float/structs_FLP.h"
#endif
+#ifdef ENABLE_OSCE_TRAINING_DATA
+#include <stdio.h>
+#endif
#define MAX_ENCODER_BUFFER 480
@@ -67,6 +75,9 @@ struct OpusEncoder {
int celt_enc_offset;
int silk_enc_offset;
silk_EncControlStruct silk_mode;
+#ifdef ENABLE_DRED
+ DREDEnc dred_encoder;
+#endif
int application;
int channels;
int delay_compensation;
@@ -116,6 +127,14 @@ struct OpusEncoder {
int nb_no_activity_ms_Q1;
opus_val32 peak_signal_energy;
#endif
+#ifdef ENABLE_DRED
+ int dred_duration;
+ int dred_q0;
+ int dred_dQ;
+ int dred_qmax;
+ int dred_target_chunks;
+ unsigned char activity_mem[DRED_MAX_FRAMES*4]; /* 2.5ms resolution*/
+#endif
int nonfinal_frame; /* current frame is not the final in a packet */
opus_uint32 rangeFinal;
};
@@ -224,6 +243,7 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat
st->silk_mode.packetLossPercentage = 0;
st->silk_mode.complexity = 9;
st->silk_mode.useInBandFEC = 0;
+ st->silk_mode.useDRED = 0;
st->silk_mode.useDTX = 0;
st->silk_mode.useCBR = 0;
st->silk_mode.reducedDependency = 0;
@@ -236,6 +256,11 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat
celt_encoder_ctl(celt_enc, CELT_SET_SIGNALLING(0));
celt_encoder_ctl(celt_enc, OPUS_SET_COMPLEXITY(st->silk_mode.complexity));
+#ifdef ENABLE_DRED
+ /* Initialize DRED Encoder */
+ dred_encoder_init( &st->dred_encoder, Fs, channels );
+#endif
+
st->use_vbr = 1;
/* Makes constrained VBR the default (safer for real-time use) */
st->vbr_constraint = 1;
@@ -544,6 +569,73 @@ OpusEncoder *opus_encoder_create(opus_int32 Fs, int channels, int application, i
return st;
}
+#ifdef ENABLE_DRED
+
+static const float dred_bits_table[16] = {73.2f, 68.1f, 62.5f, 57.0f, 51.5f, 45.7f, 39.9f, 32.4f, 26.4f, 20.4f, 16.3f, 13.f, 9.3f, 8.2f, 7.2f, 6.4f};
+static int estimate_dred_bitrate(int q0, int dQ, int qmax, int duration, opus_int32 target_bits, int *target_chunks) {
+ int dred_chunks;
+ int i;
+ float bits;
+ /* Signaling DRED costs 3 bytes. */
+ bits = 8*(3+DRED_EXPERIMENTAL_BYTES);
+ /* Approximation for the size of the IS. */
+ bits += 50.f+dred_bits_table[q0];
+ dred_chunks = IMIN((duration+5)/4, DRED_NUM_REDUNDANCY_FRAMES/2);
+ if (target_chunks != NULL) *target_chunks = 0;
+ for (i=0;i<dred_chunks;i++) {
+ int q = compute_quantizer(q0, dQ, qmax, i);
+ bits += dred_bits_table[q];
+ if (target_chunks != NULL && bits < target_bits) *target_chunks = i+1;
+ }
+ return (int)floor(.5f+bits);
+}
+
+static opus_int32 compute_dred_bitrate(OpusEncoder *st, opus_int32 bitrate_bps, int frame_size)
+{
+ float dred_frac;
+ int bitrate_offset;
+ opus_int32 dred_bitrate;
+ opus_int32 target_dred_bitrate;
+ int target_chunks;
+ opus_int32 max_dred_bits;
+ int q0, dQ, qmax;
+ if (st->silk_mode.useInBandFEC) {
+ dred_frac = MIN16(.7f, 3.f*st->silk_mode.packetLossPercentage/100.f);
+ bitrate_offset = 20000;
+ } else {
+ if (st->silk_mode.packetLossPercentage > 5) {
+ dred_frac = MIN16(.8f, .55f + st->silk_mode.packetLossPercentage/100.f);
+ } else {
+ dred_frac = 12*st->silk_mode.packetLossPercentage/100.f;
+ }
+ bitrate_offset = 12000;
+ }
+ /* Account for the fact that longer packets require less redundancy. */
+ dred_frac = dred_frac/(dred_frac + (1-dred_frac)*(frame_size*50.f)/st->Fs);
+ /* Approximate fit based on a few experiments. Could probably be improved. */
+ q0 = IMIN(15, IMAX(4, 51 - 3*EC_ILOG(IMAX(1, bitrate_bps-bitrate_offset))));
+ dQ = bitrate_bps-bitrate_offset > 36000 ? 3 : 5;
+ qmax = 15;
+ target_dred_bitrate = IMAX(0, (int)(dred_frac*(bitrate_bps-bitrate_offset)));
+ if (st->dred_duration > 0) {
+ opus_int32 target_bits = target_dred_bitrate*frame_size/st->Fs;
+ max_dred_bits = estimate_dred_bitrate(q0, dQ, qmax, st->dred_duration, target_bits, &target_chunks);
+ } else {
+ max_dred_bits = 0;
+ target_chunks=0;
+ }
+ dred_bitrate = IMIN(target_dred_bitrate, max_dred_bits*st->Fs/frame_size);
+ /* If we can't afford enough bits, don't bother with DRED at all. */
+ if (target_chunks < 2)
+ dred_bitrate = 0;
+ st->dred_q0 = q0;
+ st->dred_dQ = dQ;
+ st->dred_qmax = qmax;
+ st->dred_target_chunks = target_chunks;
+ return dred_bitrate;
+}
+#endif
+
static opus_int32 user_bitrate_to_bitrate(OpusEncoder *st, int frame_size, int max_data_bytes)
{
if(!frame_size)frame_size=st->Fs/400;
@@ -872,7 +964,7 @@ static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, in
/* Compute the right shift required in the MAC to avoid an overflow */
max_shift = celt_ilog2(len);
- shift = IMAX(0, (celt_ilog2(sample_max) << 1) + max_shift - 28);
+ shift = IMAX(0, (celt_ilog2(1+sample_max) << 1) + max_shift - 28);
/* Compute the energy */
for (i=0; i<len; i++)
@@ -922,105 +1014,6 @@ static int decide_dtx_mode(opus_int activity, /* indicates if this fr
#endif
-static opus_int32 encode_multiframe_packet(OpusEncoder *st,
- const opus_val16 *pcm,
- int nb_frames,
- int frame_size,
- unsigned char *data,
- opus_int32 out_data_bytes,
- int to_celt,
- int lsb_depth,
- int float_api)
-{
- int i;
- int ret = 0;
- VARDECL(unsigned char, tmp_data);
- int bak_mode, bak_bandwidth, bak_channels, bak_to_mono;
- VARDECL(OpusRepacketizer, rp);
- int max_header_bytes;
- opus_int32 bytes_per_frame;
- opus_int32 cbr_bytes;
- opus_int32 repacketize_len;
- int tmp_len;
- ALLOC_STACK;
-
- /* Worst cases:
- * 2 frames: Code 2 with different compressed sizes
- * >2 frames: Code 3 VBR */
- max_header_bytes = nb_frames == 2 ? 3 : (2+(nb_frames-1)*2);
-
- if (st->use_vbr || st->user_bitrate_bps==OPUS_BITRATE_MAX)
- repacketize_len = out_data_bytes;
- else {
- cbr_bytes = 3*st->bitrate_bps/(3*8*st->Fs/(frame_size*nb_frames));
- repacketize_len = IMIN(cbr_bytes, out_data_bytes);
- }
- bytes_per_frame = IMIN(1276, 1+(repacketize_len-max_header_bytes)/nb_frames);
-
- ALLOC(tmp_data, nb_frames*bytes_per_frame, unsigned char);
- ALLOC(rp, 1, OpusRepacketizer);
- opus_repacketizer_init(rp);
-
- bak_mode = st->user_forced_mode;
- bak_bandwidth = st->user_bandwidth;
- bak_channels = st->force_channels;
-
- st->user_forced_mode = st->mode;
- st->user_bandwidth = st->bandwidth;
- st->force_channels = st->stream_channels;
-
- bak_to_mono = st->silk_mode.toMono;
- if (bak_to_mono)
- st->force_channels = 1;
- else
- st->prev_channels = st->stream_channels;
-
- for (i=0;i<nb_frames;i++)
- {
- st->silk_mode.toMono = 0;
- st->nonfinal_frame = i<(nb_frames-1);
-
- /* When switching from SILK/Hybrid to CELT, only ask for a switch at the last frame */
- if (to_celt && i==nb_frames-1)
- st->user_forced_mode = MODE_CELT_ONLY;
-
- tmp_len = opus_encode_native(st, pcm+i*(st->channels*frame_size), frame_size,
- tmp_data+i*bytes_per_frame, bytes_per_frame, lsb_depth, NULL, 0, 0, 0, 0,
- NULL, float_api);
-
- if (tmp_len<0)
- {
- RESTORE_STACK;
- return OPUS_INTERNAL_ERROR;
- }
-
- ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len);
-
- if (ret<0)
- {
- RESTORE_STACK;
- return OPUS_INTERNAL_ERROR;
- }
- }
-
- ret = opus_repacketizer_out_range_impl(rp, 0, nb_frames, data, repacketize_len, 0, !st->use_vbr);
-
- if (ret<0)
- {
- RESTORE_STACK;
- return OPUS_INTERNAL_ERROR;
- }
-
- /* Discard configs that were forced locally for the purpose of repacketization */
- st->user_forced_mode = bak_mode;
- st->user_bandwidth = bak_bandwidth;
- st->force_channels = bak_channels;
- st->silk_mode.toMono = bak_to_mono;
-
- RESTORE_STACK;
- return ret;
-}
-
static int compute_redundancy_bytes(opus_int32 max_data_bytes, opus_int32 bitrate_bps, int frame_rate, int channels)
{
int redundancy_bytes_cap;
@@ -1049,6 +1042,18 @@ static int compute_redundancy_bytes(opus_int32 max_data_bytes, opus_int32 bitrat
return redundancy_bytes;
}
+static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
+ unsigned char *data, opus_int32 max_data_bytes,
+ int float_api, int first_frame,
+#ifdef ENABLE_DRED
+ opus_int32 dred_bitrate_bps,
+#endif
+#ifndef DISABLE_FLOAT_API
+ AnalysisInfo *analysis_info, int is_silence,
+#endif
+ int redundancy, int celt_to_silk, int prefill,
+ opus_int32 equiv_rate, int to_celt);
+
opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2,
@@ -1058,28 +1063,17 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
CELTEncoder *celt_enc;
int i;
int ret=0;
- opus_int32 nBytes;
- ec_enc enc;
- int bytes_target;
int prefill=0;
- int start_band = 0;
int redundancy = 0;
- int redundancy_bytes = 0; /* Number of bytes to use for redundancy frame */
int celt_to_silk = 0;
- VARDECL(opus_val16, pcm_buf);
- int nb_compr_bytes;
int to_celt = 0;
- opus_uint32 redundant_rng = 0;
- int cutoff_Hz, hp_freq_smth1;
int voice_est; /* Probability of voice in Q7 */
opus_int32 equiv_rate;
- int delay_compensation;
int frame_rate;
opus_int32 max_rate; /* Max bitrate we're allowed to use */
int curr_bandwidth;
- opus_val16 HB_gain;
opus_int32 max_data_bytes; /* Max number of bytes we're allowed to use */
- int total_buffer;
+ opus_int32 cbr_bytes=-1;
opus_val16 stereo_width;
const CELTMode *celt_mode;
#ifndef DISABLE_FLOAT_API
@@ -1088,10 +1082,9 @@ 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);
-
+#ifdef ENABLE_DRED
+ opus_int32 dred_bitrate_bps;
+#endif
ALLOC_STACK;
max_data_bytes = IMIN(1276, out_data_bytes);
@@ -1112,10 +1105,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
silk_enc = (char*)st+st->silk_enc_offset;
celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
- if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
- delay_compensation = 0;
- else
- delay_compensation = st->delay_compensation;
lsb_depth = IMIN(lsb_depth, st->lsb_depth);
@@ -1157,20 +1146,6 @@ 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)
{
@@ -1207,21 +1182,24 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
stereo_width = compute_stereo_width(pcm, frame_size, st->Fs, &st->width_mem);
else
stereo_width = 0;
- total_buffer = delay_compensation;
st->bitrate_bps = user_bitrate_to_bitrate(st, frame_size, max_data_bytes);
frame_rate = st->Fs/frame_size;
if (!st->use_vbr)
{
- int cbrBytes;
/* Multiply by 12 to make sure the division is exact. */
int frame_rate12 = 12*st->Fs/frame_size;
/* We need to make sure that "int" values always fit in 16 bits. */
- cbrBytes = IMIN( (12*st->bitrate_bps/8 + frame_rate12/2)/frame_rate12, max_data_bytes);
- st->bitrate_bps = cbrBytes*(opus_int32)frame_rate12*8/12;
+ cbr_bytes = IMIN( (12*st->bitrate_bps/8 + frame_rate12/2)/frame_rate12, max_data_bytes);
+ st->bitrate_bps = cbr_bytes*(opus_int32)frame_rate12*8/12;
/* Make sure we provide at least one byte to avoid failing. */
- max_data_bytes = IMAX(1, cbrBytes);
+ max_data_bytes = IMAX(1, cbr_bytes);
}
+#ifdef ENABLE_DRED
+ /* Allocate some of the bits to DRED if needed. */
+ dred_bitrate_bps = compute_dred_bitrate(st, st->bitrate_bps, frame_size);
+ st->bitrate_bps -= dred_bitrate_bps;
+#endif
if (max_data_bytes<3 || st->bitrate_bps < 3*frame_rate*8
|| (frame_rate<50 && (max_data_bytes*frame_rate<300 || st->bitrate_bps < 2400)))
{
@@ -1575,6 +1553,15 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
{
int enc_frame_size;
int nb_frames;
+ VARDECL(unsigned char, tmp_data);
+ VARDECL(OpusRepacketizer, rp);
+ int max_header_bytes;
+ opus_int32 repacketize_len;
+ opus_int32 max_len_sum;
+ opus_int32 tot_size=0;
+ unsigned char *curr_data;
+ int tmp_len;
+ int dtx_count = 0;
if (st->mode == MODE_SILK_ONLY)
{
@@ -1593,17 +1580,186 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
#ifndef DISABLE_FLOAT_API
if (analysis_read_pos_bak!= -1)
{
+ /* Reset analysis position to the beginning of the first frame so we
+ can use it one frame at a time. */
st->analysis.read_pos = analysis_read_pos_bak;
st->analysis.read_subframe = analysis_read_subframe_bak;
}
#endif
- ret = encode_multiframe_packet(st, pcm, nb_frames, enc_frame_size, data,
- out_data_bytes, to_celt, lsb_depth, float_api);
+ /* Worst cases:
+ * 2 frames: Code 2 with different compressed sizes
+ * >2 frames: Code 3 VBR */
+ max_header_bytes = nb_frames == 2 ? 3 : (2+(nb_frames-1)*2);
+
+ if (st->use_vbr || st->user_bitrate_bps==OPUS_BITRATE_MAX)
+ repacketize_len = out_data_bytes;
+ else {
+ celt_assert(cbr_bytes>=0);
+ repacketize_len = IMIN(cbr_bytes, out_data_bytes);
+ }
+ max_len_sum = nb_frames + repacketize_len - max_header_bytes;
+
+ ALLOC(tmp_data, max_len_sum, unsigned char);
+ curr_data = tmp_data;
+ ALLOC(rp, 1, OpusRepacketizer);
+ opus_repacketizer_init(rp);
+
+ int bak_to_mono = st->silk_mode.toMono;
+ if (bak_to_mono)
+ st->force_channels = 1;
+ else
+ st->prev_channels = st->stream_channels;
+
+ for (i=0;i<nb_frames;i++)
+ {
+ int first_frame;
+ int frame_to_celt;
+ int frame_redundancy;
+ opus_int32 curr_max;
+ /* Attempt DRED encoding until we have a non-DTX frame. In case of DTX refresh,
+ that allows for DRED not to be in the first frame. */
+ first_frame = (i == 0) || (i == dtx_count);
+ st->silk_mode.toMono = 0;
+ st->nonfinal_frame = i<(nb_frames-1);
+
+ /* When switching from SILK/Hybrid to CELT, only ask for a switch at the last frame */
+ frame_to_celt = to_celt && i==nb_frames-1;
+ frame_redundancy = redundancy && (frame_to_celt || (!to_celt && i==0));
+
+ curr_max = IMIN(3*st->bitrate_bps/(3*8*st->Fs/enc_frame_size), max_len_sum/nb_frames);
+#ifdef ENABLE_DRED
+ curr_max = IMIN(curr_max, (max_len_sum-3*dred_bitrate_bps/(3*8*st->Fs/frame_size))/nb_frames);
+ if (first_frame) curr_max += 3*dred_bitrate_bps/(3*8*st->Fs/frame_size);
+#endif
+ curr_max = IMIN(max_len_sum-tot_size, curr_max);
+#ifndef DISABLE_FLOAT_API
+ if (analysis_read_pos_bak != -1) {
+ is_silence = is_digital_silence(pcm, frame_size, st->channels, lsb_depth);
+ /* Get analysis for current frame. */
+ tonality_get_info(&st->analysis, &analysis_info, enc_frame_size);
+ }
+#endif
+
+ tmp_len = opus_encode_frame_native(st, pcm+i*(st->channels*enc_frame_size), enc_frame_size, curr_data, curr_max, float_api, first_frame,
+#ifdef ENABLE_DRED
+ dred_bitrate_bps,
+#endif
+#ifndef DISABLE_FLOAT_API
+ &analysis_info,
+ is_silence,
+#endif
+ frame_redundancy, celt_to_silk, prefill,
+ equiv_rate, frame_to_celt
+ );
+ if (tmp_len<0)
+ {
+ RESTORE_STACK;
+ return OPUS_INTERNAL_ERROR;
+ } else if (tmp_len==1) {
+ dtx_count++;
+ }
+ ret = opus_repacketizer_cat(rp, curr_data, tmp_len);
+
+ if (ret<0)
+ {
+ RESTORE_STACK;
+ return OPUS_INTERNAL_ERROR;
+ }
+ tot_size += tmp_len;
+ curr_data += tmp_len;
+ }
+ ret = opus_repacketizer_out_range_impl(rp, 0, nb_frames, data, repacketize_len, 0, !st->use_vbr && (dtx_count != nb_frames), NULL, 0);
+ if (ret<0)
+ {
+ ret = OPUS_INTERNAL_ERROR;
+ }
+ st->silk_mode.toMono = bak_to_mono;
RESTORE_STACK;
return ret;
+ } else {
+ ret = opus_encode_frame_native(st, pcm, frame_size, data, max_data_bytes, float_api, 1,
+#ifdef ENABLE_DRED
+ dred_bitrate_bps,
+#endif
+#ifndef DISABLE_FLOAT_API
+ &analysis_info,
+ is_silence,
+#endif
+ redundancy, celt_to_silk, prefill,
+ equiv_rate, to_celt
+ );
+ RESTORE_STACK;
+ return ret;
}
+}
+
+static opus_int32 opus_encode_frame_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
+ unsigned char *data, opus_int32 max_data_bytes,
+ int float_api, int first_frame,
+#ifdef ENABLE_DRED
+ opus_int32 dred_bitrate_bps,
+#endif
+#ifndef DISABLE_FLOAT_API
+ AnalysisInfo *analysis_info, int is_silence,
+#endif
+ int redundancy, int celt_to_silk, int prefill,
+ opus_int32 equiv_rate, int to_celt)
+{
+ void *silk_enc;
+ CELTEncoder *celt_enc;
+ const CELTMode *celt_mode;
+ int i;
+ int ret=0;
+ opus_int32 nBytes;
+ ec_enc enc;
+ int bytes_target;
+ int start_band = 0;
+ int redundancy_bytes = 0; /* Number of bytes to use for redundancy frame */
+ int nb_compr_bytes;
+ opus_uint32 redundant_rng = 0;
+ int cutoff_Hz;
+ int hp_freq_smth1;
+ opus_val16 HB_gain;
+ int apply_padding;
+ int frame_rate;
+ int curr_bandwidth;
+ int delay_compensation;
+ int total_buffer;
+ opus_int activity = VAD_NO_DECISION;
+ VARDECL(opus_val16, pcm_buf);
+ VARDECL(opus_val16, tmp_prefill);
+ SAVE_STACK;
+
+ st->rangeFinal = 0;
+ silk_enc = (char*)st+st->silk_enc_offset;
+ celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
+ celt_encoder_ctl(celt_enc, CELT_GET_MODE(&celt_mode));
+ curr_bandwidth = st->bandwidth;
+ if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
+ delay_compensation = 0;
+ else
+ delay_compensation = st->delay_compensation;
+ total_buffer = delay_compensation;
+
+ frame_rate = st->Fs/frame_size;
+
+#ifndef DISABLE_FLOAT_API
+ 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);
+ }
+ }
+#endif
/* For the first frame at a new SILK bandwidth */
if (st->silk_bw_switch)
@@ -1611,7 +1767,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
redundancy = 1;
celt_to_silk = 1;
st->silk_bw_switch = 0;
- /* Do a prefill without reseting the sampling rate control. */
+ /* Do a prefill without resetting the sampling rate control. */
prefill=2;
}
@@ -1651,6 +1807,25 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
if (st->application == OPUS_APPLICATION_VOIP)
{
hp_cutoff(pcm, cutoff_Hz, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs, st->arch);
+
+#ifdef ENABLE_OSCE_TRAINING_DATA
+ /* write out high pass filtered clean signal*/
+ static FILE *fout =NULL;
+ if (fout == NULL)
+ {
+ fout = fopen("clean_hp.s16", "wb");
+ }
+
+ {
+ int idx;
+ opus_int16 tmp;
+ for (idx = 0; idx < frame_size; idx++)
+ {
+ tmp = (opus_int16) (32768 * pcm_buf[total_buffer + idx] + 0.5f);
+ fwrite(&tmp, sizeof(tmp), 1, fout);
+ }
+ }
+#endif
} else {
dc_reject(pcm, 3, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs);
}
@@ -1667,8 +1842,24 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->hp_mem[0] = st->hp_mem[1] = st->hp_mem[2] = st->hp_mem[3] = 0;
}
}
+#else
+ (void)float_api;
#endif
+#ifdef ENABLE_DRED
+ if ( st->dred_duration > 0 && st->dred_encoder.loaded ) {
+ int frame_size_400Hz;
+ /* DRED Encoder */
+ dred_compute_latents( &st->dred_encoder, &pcm_buf[total_buffer*st->channels], frame_size, total_buffer, st->arch );
+ frame_size_400Hz = frame_size*400/st->Fs;
+ OPUS_MOVE(&st->activity_mem[frame_size_400Hz], st->activity_mem, 4*DRED_MAX_FRAMES-frame_size_400Hz);
+ for (i=0;i<frame_size_400Hz;i++)
+ st->activity_mem[i] = activity;
+ } else {
+ st->dred_encoder.latents_buffer_fill = 0;
+ OPUS_CLEAR(st->activity_mem, DRED_MAX_FRAMES);
+ }
+#endif
/* SILK processing */
HB_gain = Q15ONE;
@@ -1763,7 +1954,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->silk_mode.maxInternalSampleRate = 16000;
if (st->mode == MODE_SILK_ONLY)
{
- opus_int32 effective_max_rate = max_rate;
+ opus_int32 effective_max_rate = frame_rate*max_data_bytes*8;
if (frame_rate > 50)
effective_max_rate = effective_max_rate*2/3;
if (effective_max_rate < 8000)
@@ -1793,9 +1984,19 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
}
if (st->silk_mode.useCBR)
{
+ /* When we're in CBR mode, but we have non-SILK data to encode, switch SILK to VBR with cap to
+ save on complexity. Any variations will be absorbed by CELT and/or DRED and we can still
+ produce a constant bitrate without wasting bits. */
+#ifdef ENABLE_DRED
+ if (st->mode == MODE_HYBRID || dred_bitrate_bps > 0)
+#else
if (st->mode == MODE_HYBRID)
+#endif
{
- st->silk_mode.maxBits = IMIN(st->silk_mode.maxBits, st->silk_mode.bitRate * frame_size / st->Fs);
+ /* Allow SILK to steal up to 25% of the remaining bits */
+ opus_int16 other_bits = IMAX(0, st->silk_mode.maxBits - st->silk_mode.bitRate * frame_size / st->Fs);
+ st->silk_mode.maxBits = IMAX(0, st->silk_mode.maxBits - other_bits*3/4);
+ st->silk_mode.useCBR = 0;
}
} else {
/* Constrained VBR. */
@@ -1908,26 +2109,10 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
if (st->mode != MODE_SILK_ONLY)
{
opus_val32 celt_pred=2;
- celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0));
/* We may still decide to disable prediction later */
if (st->silk_mode.reducedDependency)
celt_pred = 0;
celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(celt_pred));
-
- if (st->mode == MODE_HYBRID)
- {
- if( st->use_vbr ) {
- celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps-st->silk_mode.bitRate));
- celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(0));
- }
- } else {
- if (st->use_vbr)
- {
- celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1));
- celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(st->vbr_constraint));
- celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps));
- }
- }
}
ALLOC(tmp_prefill, st->channels*st->Fs/400, opus_val16);
@@ -2021,13 +2206,27 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
ec_enc_done(&enc);
nb_compr_bytes = ret;
} else {
- nb_compr_bytes = (max_data_bytes-1)-redundancy_bytes;
- ec_enc_shrink(&enc, nb_compr_bytes);
+ nb_compr_bytes = (max_data_bytes-1)-redundancy_bytes;
+#ifdef ENABLE_DRED
+ if (st->dred_duration > 0)
+ {
+ int max_celt_bytes;
+ opus_int32 dred_bytes = dred_bitrate_bps/(frame_rate*8);
+ /* Allow CELT to steal up to 25% of the remaining bits. */
+ max_celt_bytes = nb_compr_bytes - dred_bytes*3/4;
+ /* But try to give CELT at least 5 bytes to prevent a mismatch with
+ the redundancy signaling. */
+ max_celt_bytes = IMAX((ec_tell(&enc)+7)/8 + 5, max_celt_bytes);
+ /* Subject to the original max. */
+ nb_compr_bytes = IMIN(nb_compr_bytes, max_celt_bytes);
+ }
+#endif
+ ec_enc_shrink(&enc, nb_compr_bytes);
}
#ifndef DISABLE_FLOAT_API
if (redundancy || st->mode != MODE_SILK_ONLY)
- celt_encoder_ctl(celt_enc, CELT_SET_ANALYSIS(&analysis_info));
+ celt_encoder_ctl(celt_enc, CELT_SET_ANALYSIS(analysis_info));
#endif
if (st->mode == MODE_HYBRID) {
SILKInfo info;
@@ -2057,6 +2256,34 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
if (st->mode != MODE_SILK_ONLY)
{
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(st->use_vbr));
+ if (st->mode == MODE_HYBRID)
+ {
+ if( st->use_vbr ) {
+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps-st->silk_mode.bitRate));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(0));
+ }
+ } else {
+ if (st->use_vbr)
+ {
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(st->vbr_constraint));
+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps));
+ }
+ }
+#ifdef ENABLE_DRED
+ /* When Using DRED CBR, we can actually make the CELT part VBR and have DRED pick up the slack. */
+ if (!st->use_vbr && st->dred_duration > 0)
+ {
+ opus_int32 celt_bitrate = st->bitrate_bps;
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1));
+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(0));
+ if (st->mode == MODE_HYBRID) {
+ celt_bitrate -= st->silk_mode.bitRate;
+ }
+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(celt_bitrate));
+ }
+#endif
if (st->mode != st->prev_mode && st->prev_mode > 0)
{
unsigned char dummy[2];
@@ -2069,10 +2296,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
/* If false, we already busted the budget and we'll end up with a "PLC frame" */
if (ec_tell(&enc) <= 8*nb_compr_bytes)
{
- /* Set the bitrate again if it was overridden in the redundancy code above*/
- if (redundancy && celt_to_silk && st->mode==MODE_HYBRID && st->use_vbr)
- celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps-st->silk_mode.bitRate));
- celt_encoder_ctl(celt_enc, OPUS_SET_VBR(st->use_vbr));
ret = celt_encode_with_ec(celt_enc, pcm_buf, frame_size, NULL, nb_compr_bytes, &enc);
if (ret < 0)
{
@@ -2080,10 +2303,10 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
return OPUS_INTERNAL_ERROR;
}
/* Put CELT->SILK redundancy data in the right place. */
- if (redundancy && celt_to_silk && st->mode==MODE_HYBRID && st->use_vbr)
+ if (redundancy && celt_to_silk && st->mode==MODE_HYBRID && nb_compr_bytes != ret)
{
OPUS_MOVE(data+ret, data+nb_compr_bytes, redundancy_bytes);
- nb_compr_bytes = nb_compr_bytes+redundancy_bytes;
+ nb_compr_bytes = ret+redundancy_bytes;
}
}
}
@@ -2140,7 +2363,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
/* DTX decision */
#ifndef DISABLE_FLOAT_API
- if (st->use_dtx && (analysis_info.valid || is_silence))
+ if (st->use_dtx && (analysis_info->valid || is_silence))
{
if (decide_dtx_mode(activity, &st->nb_no_activity_ms_Q1, 2*1000*frame_size/st->Fs))
{
@@ -2178,7 +2401,51 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
}
/* Count ToC and redundancy */
ret += 1+redundancy_bytes;
- if (!st->use_vbr)
+ apply_padding = !st->use_vbr;
+#ifdef ENABLE_DRED
+ if (st->dred_duration > 0 && st->dred_encoder.loaded && first_frame) {
+ opus_extension_data extension;
+ unsigned char buf[DRED_MAX_DATA_SIZE];
+ int dred_chunks;
+ int dred_bytes_left;
+ dred_chunks = IMIN((st->dred_duration+5)/4, DRED_NUM_REDUNDANCY_FRAMES/2);
+ if (st->use_vbr) dred_chunks = IMIN(dred_chunks, st->dred_target_chunks);
+ /* Remaining space for DRED, accounting for cost the 3 extra bytes for code 3, padding length, and extension number. */
+ dred_bytes_left = IMIN(DRED_MAX_DATA_SIZE, max_data_bytes-ret-3);
+ /* Account for the extra bytes required to signal large padding length. */
+ dred_bytes_left -= (dred_bytes_left+1+DRED_EXPERIMENTAL_BYTES)/255;
+ /* Check whether we actually have something to encode. */
+ if (dred_chunks >= 1 && dred_bytes_left >= DRED_MIN_BYTES+DRED_EXPERIMENTAL_BYTES) {
+ int dred_bytes;
+#ifdef DRED_EXPERIMENTAL_VERSION
+ /* Add temporary extension type and version.
+ These bytes will be removed once extension is finalized. */
+ buf[0] = 'D';
+ buf[1] = DRED_EXPERIMENTAL_VERSION;
+#endif
+ dred_bytes = dred_encode_silk_frame(&st->dred_encoder, buf+DRED_EXPERIMENTAL_BYTES, dred_chunks, dred_bytes_left-DRED_EXPERIMENTAL_BYTES,
+ st->dred_q0, st->dred_dQ, st->dred_qmax, st->activity_mem, st->arch);
+ if (dred_bytes > 0) {
+ dred_bytes += DRED_EXPERIMENTAL_BYTES;
+ celt_assert(dred_bytes <= dred_bytes_left);
+ extension.id = DRED_EXTENSION_ID;
+ extension.frame = 0;
+ extension.data = buf;
+ extension.len = dred_bytes;
+ ret = opus_packet_pad_impl(data, ret, max_data_bytes, !st->use_vbr, &extension, 1);
+ if (ret < 0)
+ {
+ RESTORE_STACK;
+ return OPUS_INTERNAL_ERROR;
+ }
+ apply_padding = 0;
+ }
+ }
+ }
+#else
+ (void)first_frame; /* Avoids a warning about first_frame being unused. */
+#endif
+ if (apply_padding)
{
if (opus_packet_pad(data, ret, max_data_bytes) != OPUS_OK)
{
@@ -2677,6 +2944,29 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
celt_encoder_ctl(celt_enc, OPUS_GET_PHASE_INVERSION_DISABLED(value));
}
break;
+#ifdef ENABLE_DRED
+ case OPUS_SET_DRED_DURATION_REQUEST:
+ {
+ opus_int32 value = va_arg(ap, opus_int32);
+ if(value<0 || value>DRED_MAX_FRAMES)
+ {
+ goto bad_arg;
+ }
+ st->dred_duration = value;
+ st->silk_mode.useDRED = !!value;
+ }
+ break;
+ case OPUS_GET_DRED_DURATION_REQUEST:
+ {
+ opus_int32 *value = va_arg(ap, opus_int32*);
+ if (!value)
+ {
+ goto bad_arg;
+ }
+ *value = st->dred_duration;
+ }
+ break;
+#endif
case OPUS_RESET_STATE:
{
void *silk_enc;
@@ -2692,6 +2982,10 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
celt_encoder_ctl(celt_enc, OPUS_RESET_STATE);
silk_InitEncoder( silk_enc, st->arch, &dummy );
+#ifdef ENABLE_DRED
+ /* Initialize DRED Encoder */
+ dred_encoder_reset( &st->dred_encoder );
+#endif
st->stream_channels = st->channels;
st->hybrid_stereo_width_Q14 = 1 << 14;
st->prev_HB_gain = Q15ONE;
@@ -2752,6 +3046,21 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
}
}
break;
+#ifdef USE_WEIGHTS_FILE
+ case OPUS_SET_DNN_BLOB_REQUEST:
+ {
+ const unsigned char *data = va_arg(ap, const unsigned char *);
+ opus_int32 len = va_arg(ap, opus_int32);
+ if(len<0 || data == NULL)
+ {
+ goto bad_arg;
+ }
+#ifdef ENABLE_DRED
+ ret = dred_encoder_load_model(&st->dred_encoder, data, len);
+#endif
+ }
+ break;
+#endif
case CELT_GET_MODE_REQUEST:
{
const CELTMode ** value = va_arg(ap, const CELTMode**);
diff --git a/media/libopus/src/opus_multistream_decoder.c b/media/libopus/src/opus_multistream_decoder.c
index a2837c3549..4ae877a759 100644
--- a/media/libopus/src/opus_multistream_decoder.c
+++ b/media/libopus/src/opus_multistream_decoder.c
@@ -162,7 +162,7 @@ static int opus_multistream_packet_validate(const unsigned char *data,
if (len<=0)
return OPUS_INVALID_PACKET;
count = opus_packet_parse_impl(data, len, s!=nb_streams-1, &toc, NULL,
- size, NULL, &packet_offset);
+ size, NULL, &packet_offset, NULL, NULL);
if (count<0)
return count;
tmp_samples = opus_packet_get_nb_samples(data, packet_offset, Fs);
@@ -250,7 +250,7 @@ int opus_multistream_decode_native(
return OPUS_INTERNAL_ERROR;
}
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);
+ ret = opus_decode_native(dec, data, len, buf, frame_size, decode_fec, s!=st->layout.nb_streams-1, &packet_offset, soft_clip, NULL, 0);
if (!do_plc)
{
data += packet_offset;
diff --git a/media/libopus/src/opus_multistream_encoder.c b/media/libopus/src/opus_multistream_encoder.c
index 213e3eb2c2..1725ade75a 100644
--- a/media/libopus/src/opus_multistream_encoder.c
+++ b/media/libopus/src/opus_multistream_encoder.c
@@ -1003,7 +1003,7 @@ int opus_multistream_encode_native
return OPUS_INTERNAL_ERROR;
}
len = opus_repacketizer_out_range_impl(&rp, 0, opus_repacketizer_get_nb_frames(&rp),
- data, max_data_bytes-tot_size, s != st->layout.nb_streams-1, !vbr && s == st->layout.nb_streams-1);
+ data, max_data_bytes-tot_size, s != st->layout.nb_streams-1, !vbr && s == st->layout.nb_streams-1, NULL, 0);
data += len;
tot_size += len;
}
diff --git a/media/libopus/src/opus_private.h b/media/libopus/src/opus_private.h
index 5e2463f546..364c21cebc 100644
--- a/media/libopus/src/opus_private.h
+++ b/media/libopus/src/opus_private.h
@@ -42,8 +42,17 @@ struct OpusRepacketizer {
const unsigned char *frames[48];
opus_int16 len[48];
int framesize;
+ const unsigned char *paddings[48];
+ opus_int32 padding_len[48];
};
+typedef struct {
+ int id;
+ int frame;
+ const unsigned char *data;
+ opus_int32 len;
+} opus_extension_data;
+
typedef struct ChannelLayout {
int nb_channels;
int nb_streams;
@@ -148,7 +157,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
- opus_int32 *packet_offset, int soft_clip);
+ opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset);
/* Make sure everything is properly aligned. */
static OPUS_INLINE int align(int i)
@@ -162,13 +171,18 @@ static OPUS_INLINE int align(int i)
return ((i + alignment - 1) / alignment) * alignment;
}
+/* More than that is ridiculous for now (3 * max frames per packet)*/
+opus_int32 skip_extension(const unsigned char **data, opus_int32 len, opus_int32 *header_size);
+
int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
int self_delimited, unsigned char *out_toc,
const unsigned char *frames[48], opus_int16 size[48],
- int *payload_offset, opus_int32 *packet_offset);
+ int *payload_offset, opus_int32 *packet_offset,
+ const unsigned char **padding, opus_int32 *padding_len);
opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
- unsigned char *data, opus_int32 maxlen, int self_delimited, int pad);
+ unsigned char *data, opus_int32 maxlen, int self_delimited, int pad,
+ const opus_extension_data *extensions, int nb_extensions);
int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len);
@@ -198,4 +212,12 @@ int opus_multistream_decode_native(
void *user_data
);
+opus_int32 opus_packet_extensions_parse(const unsigned char *data, opus_int32 len, opus_extension_data *extensions, opus_int32 *nb_extensions);
+
+opus_int32 opus_packet_extensions_generate(unsigned char *data, opus_int32 len, const opus_extension_data *extensions, int nb_extensions, int pad);
+
+opus_int32 opus_packet_extensions_count(const unsigned char *data, opus_int32 len);
+
+opus_int32 opus_packet_pad_impl(unsigned char *data, opus_int32 len, opus_int32 new_len, int pad, const opus_extension_data *extensions, int nb_extensions);
+
#endif /* OPUS_PRIVATE_H */
diff --git a/media/libopus/src/opus_projection_encoder.c b/media/libopus/src/opus_projection_encoder.c
index 06fb2d2526..92813ad01f 100644
--- a/media/libopus/src/opus_projection_encoder.c
+++ b/media/libopus/src/opus_projection_encoder.c
@@ -177,6 +177,20 @@ opus_int32 opus_projection_ambisonics_encoder_get_size(int channels,
demixing_matrix_rows = mapping_matrix_toa_demixing.rows;
demixing_matrix_cols = mapping_matrix_toa_demixing.cols;
}
+ else if (order_plus_one == 5)
+ {
+ mixing_matrix_rows = mapping_matrix_fourthoa_mixing.rows;
+ mixing_matrix_cols = mapping_matrix_fourthoa_mixing.cols;
+ demixing_matrix_rows = mapping_matrix_fourthoa_demixing.rows;
+ demixing_matrix_cols = mapping_matrix_fourthoa_demixing.cols;
+ }
+ else if (order_plus_one == 6)
+ {
+ mixing_matrix_rows = mapping_matrix_fifthoa_mixing.rows;
+ mixing_matrix_cols = mapping_matrix_fifthoa_mixing.cols;
+ demixing_matrix_rows = mapping_matrix_fifthoa_demixing.rows;
+ demixing_matrix_cols = mapping_matrix_fifthoa_demixing.cols;
+ }
else
return 0;
@@ -245,6 +259,20 @@ int opus_projection_ambisonics_encoder_init(OpusProjectionEncoder *st, opus_int3
mapping_matrix_toa_mixing_data,
sizeof(mapping_matrix_toa_mixing_data));
}
+ else if (order_plus_one == 5)
+ {
+ mapping_matrix_init(mixing_matrix, mapping_matrix_fourthoa_mixing.rows,
+ mapping_matrix_fourthoa_mixing.cols, mapping_matrix_fourthoa_mixing.gain,
+ mapping_matrix_fourthoa_mixing_data,
+ sizeof(mapping_matrix_fourthoa_mixing_data));
+ }
+ else if (order_plus_one == 6)
+ {
+ mapping_matrix_init(mixing_matrix, mapping_matrix_fifthoa_mixing.rows,
+ mapping_matrix_fifthoa_mixing.cols, mapping_matrix_fifthoa_mixing.gain,
+ mapping_matrix_fifthoa_mixing_data,
+ sizeof(mapping_matrix_fifthoa_mixing_data));
+ }
else
return OPUS_BAD_ARG;
@@ -276,6 +304,20 @@ int opus_projection_ambisonics_encoder_init(OpusProjectionEncoder *st, opus_int3
mapping_matrix_toa_demixing_data,
sizeof(mapping_matrix_toa_demixing_data));
}
+ else if (order_plus_one == 5)
+ {
+ mapping_matrix_init(demixing_matrix, mapping_matrix_fourthoa_demixing.rows,
+ mapping_matrix_fourthoa_demixing.cols, mapping_matrix_fourthoa_demixing.gain,
+ mapping_matrix_fourthoa_demixing_data,
+ sizeof(mapping_matrix_fourthoa_demixing_data));
+ }
+ else if (order_plus_one == 6)
+ {
+ mapping_matrix_init(demixing_matrix, mapping_matrix_fifthoa_demixing.rows,
+ mapping_matrix_fifthoa_demixing.cols, mapping_matrix_fifthoa_demixing.gain,
+ mapping_matrix_fifthoa_demixing_data,
+ sizeof(mapping_matrix_fifthoa_demixing_data));
+ }
else
return OPUS_BAD_ARG;
diff --git a/media/libopus/src/repacketizer.c b/media/libopus/src/repacketizer.c
index bda44a148a..6a7a8b3d8e 100644
--- a/media/libopus/src/repacketizer.c
+++ b/media/libopus/src/repacketizer.c
@@ -32,6 +32,7 @@
#include "opus.h"
#include "opus_private.h"
#include "os_support.h"
+#include "stack_alloc.h"
int opus_repacketizer_get_size(void)
@@ -82,10 +83,19 @@ static int opus_repacketizer_cat_impl(OpusRepacketizer *rp, const unsigned char
return OPUS_INVALID_PACKET;
}
- ret=opus_packet_parse_impl(data, len, self_delimited, &tmp_toc, &rp->frames[rp->nb_frames], &rp->len[rp->nb_frames], NULL, NULL);
+ ret=opus_packet_parse_impl(data, len, self_delimited, &tmp_toc, &rp->frames[rp->nb_frames], &rp->len[rp->nb_frames],
+ NULL, NULL, &rp->paddings[rp->nb_frames], &rp->padding_len[rp->nb_frames]);
if(ret<1)return ret;
- rp->nb_frames += curr_nb_frames;
+ /* set padding length to zero for all but the first frame */
+ while (curr_nb_frames > 1)
+ {
+ rp->nb_frames++;
+ rp->padding_len[rp->nb_frames] = 0;
+ rp->paddings[rp->nb_frames] = NULL;
+ curr_nb_frames--;
+ }
+ rp->nb_frames++;
return OPUS_OK;
}
@@ -100,17 +110,23 @@ int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp)
}
opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
- unsigned char *data, opus_int32 maxlen, int self_delimited, int pad)
+ unsigned char *data, opus_int32 maxlen, int self_delimited, int pad, const opus_extension_data *extensions, int nb_extensions)
{
int i, count;
opus_int32 tot_size;
opus_int16 *len;
const unsigned char **frames;
unsigned char * ptr;
+ int ones_begin=0, ones_end=0;
+ int ext_begin=0, ext_len=0;
+ int ext_count, total_ext_count;
+ VARDECL(opus_extension_data, all_extensions);
+ SAVE_STACK;
if (begin<0 || begin>=end || end>rp->nb_frames)
{
/*fprintf(stderr, "%d %d %d\n", begin, end, rp->nb_frames);*/
+ RESTORE_STACK;
return OPUS_BAD_ARG;
}
count = end-begin;
@@ -122,13 +138,50 @@ opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int
else
tot_size = 0;
+ /* figure out total number of extensions */
+ total_ext_count = nb_extensions;
+ for (i=begin;i<end;i++)
+ {
+ int n = opus_packet_extensions_count(rp->paddings[i], rp->padding_len[i]);
+ if (n > 0) total_ext_count += n;
+ }
+ ALLOC(all_extensions, total_ext_count ? total_ext_count : ALLOC_NONE, opus_extension_data);
+ /* copy over any extensions that were passed in */
+ for (ext_count=0;ext_count<nb_extensions;ext_count++)
+ {
+ all_extensions[ext_count] = extensions[ext_count];
+ }
+
+ /* incorporate any extensions from the repacketizer padding */
+ for (i=begin;i<end;i++)
+ {
+ int frame_ext_count, j;
+ frame_ext_count = total_ext_count - ext_count;
+ int ret = opus_packet_extensions_parse(rp->paddings[i], rp->padding_len[i],
+ &all_extensions[ext_count], &frame_ext_count);
+ if (ret<0)
+ {
+ RESTORE_STACK;
+ return OPUS_INTERNAL_ERROR;
+ }
+ /* renumber the extension frame numbers */
+ for (j=0;j<frame_ext_count;j++)
+ {
+ all_extensions[ext_count+j].frame += i-begin;
+ }
+ ext_count += frame_ext_count;
+ }
+
ptr = data;
if (count==1)
{
/* Code 0 */
tot_size += len[0]+1;
if (tot_size > maxlen)
+ {
+ RESTORE_STACK;
return OPUS_BUFFER_TOO_SMALL;
+ }
*ptr++ = rp->toc&0xFC;
} else if (count==2)
{
@@ -137,18 +190,24 @@ opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int
/* Code 1 */
tot_size += 2*len[0]+1;
if (tot_size > maxlen)
+ {
+ RESTORE_STACK;
return OPUS_BUFFER_TOO_SMALL;
+ }
*ptr++ = (rp->toc&0xFC) | 0x1;
} else {
/* Code 2 */
tot_size += len[0]+len[1]+2+(len[0]>=252);
if (tot_size > maxlen)
+ {
+ RESTORE_STACK;
return OPUS_BUFFER_TOO_SMALL;
+ }
*ptr++ = (rp->toc&0xFC) | 0x2;
ptr += encode_size(len[0], ptr);
}
}
- if (count > 2 || (pad && tot_size < maxlen))
+ if (count > 2 || (pad && tot_size < maxlen) || ext_count > 0)
{
/* Code 3 */
int vbr;
@@ -177,22 +236,45 @@ opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int
tot_size += len[count-1];
if (tot_size > maxlen)
+ {
+ RESTORE_STACK;
return OPUS_BUFFER_TOO_SMALL;
+ }
*ptr++ = (rp->toc&0xFC) | 0x3;
*ptr++ = count | 0x80;
} else {
tot_size += count*len[0]+2;
if (tot_size > maxlen)
+ {
+ RESTORE_STACK;
return OPUS_BUFFER_TOO_SMALL;
+ }
*ptr++ = (rp->toc&0xFC) | 0x3;
*ptr++ = count;
}
pad_amount = pad ? (maxlen-tot_size) : 0;
+ if (ext_count>0)
+ {
+ /* figure out how much space we need for the extensions */
+ ext_len = opus_packet_extensions_generate(NULL, maxlen-tot_size, all_extensions, ext_count, 0);
+ if (ext_len < 0) return ext_len;
+ if (!pad)
+ pad_amount = ext_len + ext_len/254 + 1;
+ }
if (pad_amount != 0)
{
int nb_255s;
data[1] |= 0x40;
nb_255s = (pad_amount-1)/255;
+ if (tot_size + ext_len + nb_255s + 1 > maxlen)
+ {
+ RESTORE_STACK;
+ return OPUS_BUFFER_TOO_SMALL;
+ }
+ ext_begin = tot_size+pad_amount-ext_len;
+ /* Prepend 0x01 padding */
+ ones_begin = tot_size+nb_255s+1;
+ ones_end = tot_size+pad_amount-ext_len;
for (i=0;i<nb_255s;i++)
*ptr++ = 255;
*ptr++ = pad_amount-255*nb_255s-1;
@@ -218,42 +300,62 @@ opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int
OPUS_MOVE(ptr, frames[i], len[i]);
ptr += len[i];
}
- if (pad)
+ if (ext_len > 0) {
+ int ret = opus_packet_extensions_generate(&data[ext_begin], ext_len, all_extensions, ext_count, 0);
+ celt_assert(ret == ext_len);
+ }
+ for (i=ones_begin;i<ones_end;i++)
+ data[i] = 0x01;
+ if (pad && ext_count==0)
{
/* Fill padding with zeros. */
while (ptr<data+maxlen)
*ptr++=0;
}
+ RESTORE_STACK;
return tot_size;
}
opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen)
{
- return opus_repacketizer_out_range_impl(rp, begin, end, data, maxlen, 0, 0);
+ return opus_repacketizer_out_range_impl(rp, begin, end, data, maxlen, 0, 0, NULL, 0);
}
opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen)
{
- return opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, maxlen, 0, 0);
+ return opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, maxlen, 0, 0, NULL, 0);
}
-int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len)
+opus_int32 opus_packet_pad_impl(unsigned char *data, opus_int32 len, opus_int32 new_len, int pad, const opus_extension_data *extensions, int nb_extensions)
{
OpusRepacketizer rp;
opus_int32 ret;
+ VARDECL(unsigned char, copy);
+ SAVE_STACK;
if (len < 1)
return OPUS_BAD_ARG;
if (len==new_len)
return OPUS_OK;
else if (len > new_len)
return OPUS_BAD_ARG;
+ ALLOC(copy, len, unsigned char);
opus_repacketizer_init(&rp);
/* Moving payload to the end of the packet so we can do in-place padding */
- OPUS_MOVE(data+new_len-len, data, len);
- ret = opus_repacketizer_cat(&rp, data+new_len-len, len);
+ OPUS_COPY(copy, data, len);
+ ret = opus_repacketizer_cat(&rp, copy, len);
if (ret != OPUS_OK)
return ret;
- ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, new_len, 0, 1);
+ ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, new_len, 0, pad, extensions, nb_extensions);
+ RESTORE_STACK;
+ return ret;
+}
+
+int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len)
+{
+ opus_int32 ret;
+ ALLOC_STACK;
+ ret = opus_packet_pad_impl(data, len, new_len, 1, NULL, 0);
+ RESTORE_STACK;
if (ret > 0)
return OPUS_OK;
else
@@ -264,13 +366,19 @@ opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len)
{
OpusRepacketizer rp;
opus_int32 ret;
+ int i;
if (len < 1)
return OPUS_BAD_ARG;
opus_repacketizer_init(&rp);
ret = opus_repacketizer_cat(&rp, data, len);
if (ret < 0)
return ret;
- ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, len, 0, 0);
+ /* Discard all padding and extensions. */
+ for (i=0;i<rp.nb_frames;i++) {
+ rp.padding_len[i] = 0;
+ rp.paddings[i] = NULL;
+ }
+ ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, data, len, 0, 0, NULL, 0);
celt_assert(ret > 0 && ret <= len);
return ret;
}
@@ -297,7 +405,7 @@ int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32
if (len<=0)
return OPUS_INVALID_PACKET;
count = opus_packet_parse_impl(data, len, 1, &toc, NULL,
- size, NULL, &packet_offset);
+ size, NULL, &packet_offset, NULL, NULL);
if (count<0)
return count;
data += packet_offset;
@@ -324,18 +432,24 @@ opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, in
for (s=0;s<nb_streams;s++)
{
opus_int32 ret;
+ int i;
int self_delimited = s!=nb_streams-1;
if (len<=0)
return OPUS_INVALID_PACKET;
opus_repacketizer_init(&rp);
ret = opus_packet_parse_impl(data, len, self_delimited, &toc, NULL,
- size, NULL, &packet_offset);
+ size, NULL, &packet_offset, NULL, NULL);
if (ret<0)
return ret;
ret = opus_repacketizer_cat_impl(&rp, data, packet_offset, self_delimited);
if (ret < 0)
return ret;
- ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, dst, len, self_delimited, 0);
+ /* Discard all padding and extensions. */
+ for (i=0;i<rp.nb_frames;i++) {
+ rp.padding_len[i] = 0;
+ rp.paddings[i] = NULL;
+ }
+ ret = opus_repacketizer_out_range_impl(&rp, 0, rp.nb_frames, dst, len, self_delimited, 0, NULL, 0);
if (ret < 0)
return ret;
else
diff --git a/media/libopus/src/tansig_table.h b/media/libopus/src/tansig_table.h
deleted file mode 100644
index c76f844a72..0000000000
--- a/media/libopus/src/tansig_table.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* This file is auto-generated by gen_tables */
-
-static const float tansig_table[201] = {
-0.000000f, 0.039979f, 0.079830f, 0.119427f, 0.158649f,
-0.197375f, 0.235496f, 0.272905f, 0.309507f, 0.345214f,
-0.379949f, 0.413644f, 0.446244f, 0.477700f, 0.507977f,
-0.537050f, 0.564900f, 0.591519f, 0.616909f, 0.641077f,
-0.664037f, 0.685809f, 0.706419f, 0.725897f, 0.744277f,
-0.761594f, 0.777888f, 0.793199f, 0.807569f, 0.821040f,
-0.833655f, 0.845456f, 0.856485f, 0.866784f, 0.876393f,
-0.885352f, 0.893698f, 0.901468f, 0.908698f, 0.915420f,
-0.921669f, 0.927473f, 0.932862f, 0.937863f, 0.942503f,
-0.946806f, 0.950795f, 0.954492f, 0.957917f, 0.961090f,
-0.964028f, 0.966747f, 0.969265f, 0.971594f, 0.973749f,
-0.975743f, 0.977587f, 0.979293f, 0.980869f, 0.982327f,
-0.983675f, 0.984921f, 0.986072f, 0.987136f, 0.988119f,
-0.989027f, 0.989867f, 0.990642f, 0.991359f, 0.992020f,
-0.992631f, 0.993196f, 0.993718f, 0.994199f, 0.994644f,
-0.995055f, 0.995434f, 0.995784f, 0.996108f, 0.996407f,
-0.996682f, 0.996937f, 0.997172f, 0.997389f, 0.997590f,
-0.997775f, 0.997946f, 0.998104f, 0.998249f, 0.998384f,
-0.998508f, 0.998623f, 0.998728f, 0.998826f, 0.998916f,
-0.999000f, 0.999076f, 0.999147f, 0.999213f, 0.999273f,
-0.999329f, 0.999381f, 0.999428f, 0.999472f, 0.999513f,
-0.999550f, 0.999585f, 0.999617f, 0.999646f, 0.999673f,
-0.999699f, 0.999722f, 0.999743f, 0.999763f, 0.999781f,
-0.999798f, 0.999813f, 0.999828f, 0.999841f, 0.999853f,
-0.999865f, 0.999875f, 0.999885f, 0.999893f, 0.999902f,
-0.999909f, 0.999916f, 0.999923f, 0.999929f, 0.999934f,
-0.999939f, 0.999944f, 0.999948f, 0.999952f, 0.999956f,
-0.999959f, 0.999962f, 0.999965f, 0.999968f, 0.999970f,
-0.999973f, 0.999975f, 0.999977f, 0.999978f, 0.999980f,
-0.999982f, 0.999983f, 0.999984f, 0.999986f, 0.999987f,
-0.999988f, 0.999989f, 0.999990f, 0.999990f, 0.999991f,
-0.999992f, 0.999992f, 0.999993f, 0.999994f, 0.999994f,
-0.999994f, 0.999995f, 0.999995f, 0.999996f, 0.999996f,
-0.999996f, 0.999997f, 0.999997f, 0.999997f, 0.999997f,
-0.999997f, 0.999998f, 0.999998f, 0.999998f, 0.999998f,
-0.999998f, 0.999998f, 0.999999f, 0.999999f, 0.999999f,
-0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f,
-0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f,
-1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
-1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
-1.000000f,
-};