MLECO-2354 MLECO-2355 MLECO-2356: Moving noise reduction to public repository

* Use RNNoise model from PMZ
* Add Noise reduction use-case

Signed-off-by: Richard burton <richard.burton@arm.com>
Change-Id: Ia8cc7ef102e22a5ff8bfbd3833594a4905a66057
diff --git a/tests/use_case/noise_reduction/RNNoiseProcessingTests.cpp b/tests/use_case/noise_reduction/RNNoiseProcessingTests.cpp
new file mode 100644
index 0000000..24dd550
--- /dev/null
+++ b/tests/use_case/noise_reduction/RNNoiseProcessingTests.cpp
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2021 Arm Limited. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "RNNoiseProcess.hpp"
+#include <catch.hpp>
+#include <limits>
+
+
+/* Elements [0:480] from p232_113.wav cast as fp32. */
+const std::vector<float> testWav0 = std::vector<float>{
+    -1058.0, -768.0, -737.0, -1141.0, -1015.0, -315.0, -205.0, -105.0, -150.0, 277.0,
+    424.0, 523.0, 431.0, 256.0, 441.0, 830.0, 413.0, 421.0, 1002.0, 1186.0,
+    926.0, 841.0, 894.0, 1419.0, 1427.0, 1102.0, 587.0, 455.0, 962.0, 904.0,
+    504.0, -61.0, 242.0, 534.0, 407.0, -344.0, -973.0, -1178.0, -1056.0, -1454.0,
+    -1294.0, -1729.0, -2234.0, -2164.0, -2148.0, -1967.0, -2699.0, -2923.0, -2408.0, -2304.0,
+    -2567.0, -2894.0, -3104.0, -3045.0, -3210.0, -3774.0, -4159.0, -3902.0, -3525.0, -3652.0,
+    -3804.0, -3493.0, -3034.0, -2715.0, -2599.0, -2432.0, -2045.0, -1934.0, -1966.0, -2018.0,
+    -1757.0, -1296.0, -1336.0, -1124.0, -1282.0, -1001.0, -601.0, -706.0, -511.0, 278.0,
+    678.0, 1009.0, 1088.0, 1150.0, 1815.0, 2572.0, 2457.0, 2150.0, 2566.0, 2720.0,
+    3040.0, 3203.0, 3353.0, 3536.0, 3838.0, 3808.0, 3672.0, 3346.0, 3281.0, 3570.0,
+    3215.0, 2684.0, 3153.0, 3167.0, 3049.0, 2837.0, 2965.0, 3167.0, 3286.0, 2572.0,
+    1952.0, 1434.0, 1398.0, 505.0, -740.0, -898.0, -598.0, -1047.0, -1514.0, -1756.0,
+    -1457.0, -1518.0, -1497.0, -1605.0, -1364.0, -1332.0, -1306.0, -2361.0, -2809.0, -2185.0,
+    -1323.0, -1714.0, -2323.0, -1888.0, -1273.0, -1208.0, -1656.0, -1543.0, -736.0, -772.0,
+    -1113.0, -1001.0, -185.0, 468.0, 625.0, 609.0, 1080.0, 1654.0, 1678.0, 1462.0,
+    1468.0, 2065.0, 2266.0, 1779.0, 1513.0, 1646.0, 1721.0, 2019.0, 1212.0, 688.0,
+    1256.0, 1917.0, 2104.0, 1714.0, 1581.0, 2013.0, 1946.0, 2276.0, 2419.0, 2546.0,
+    2229.0, 1768.0, 1691.0, 1484.0, 914.0, 591.0, -279.0, 85.0, -190.0, -647.0,
+    -1120.0, -1636.0, -2057.0, -2177.0, -1650.0, -1826.0, -2206.0, -2568.0, -2374.0, -2227.0,
+    -2013.0, -1844.0, -2079.0, -1953.0, -1609.0, -1897.0, -2185.0, -2320.0, -2212.0, -2593.0,
+    -3077.0, -2840.0, -2081.0, -1642.0, -1793.0, -1437.0, -870.0, -451.0, -242.0, -267.0,
+    314.0, 641.0, 448.0, 721.0, 1087.0, 1720.0, 1831.0, 1381.0, 1254.0, 1873.0,
+    2504.0, 2496.0, 2265.0, 2396.0, 2703.0, 2933.0, 3100.0, 3423.0, 3464.0, 3846.0,
+    3890.0, 3959.0, 4047.0, 4058.0, 4327.0, 3907.0, 3505.0, 3837.0, 3471.0, 3490.0,
+    2991.0, 3129.0, 3082.0, 2950.0, 2329.0, 1964.0, 1523.0, 1179.0, 673.0, 439.0,
+    -130.0, -878.0, -1670.0, -1648.0, -1566.0, -1721.0, -2028.0, -2308.0, -1826.0, -2027.0,
+    -2221.0, -2025.0, -1858.0, -1966.0, -2384.0, -2221.0, -1936.0, -1747.0, -2159.0, -2265.0,
+    -2186.0, -1536.0, -1520.0, -1838.0, -1919.0, -1630.0, -1450.0, -1751.0, -2751.0, -3125.0,
+    -3258.0, -3049.0, -3199.0, -3272.0, -2498.0, -1884.0, -1660.0, -1894.0, -1208.0, -736.0,
+    -346.0, -337.0, -628.0, -274.0, 71.0, 245.0, 255.0, 132.0, 433.0, 229.0,
+    345.0, -85.0, 221.0, 278.0, 227.0, -107.0, -613.0, -215.0, -448.0, -306.0,
+    -845.0, -456.0, -390.0, -239.0, -895.0, -1151.0, -619.0, -554.0, -495.0, -1141.0,
+    -1079.0, -1342.0, -1252.0, -1668.0, -2177.0, -2478.0, -2116.0, -2163.0, -2343.0, -2380.0,
+    -2269.0, -1541.0, -1668.0, -2034.0, -2264.0, -2200.0, -2224.0, -2578.0, -2213.0, -2069.0,
+    -1774.0, -1437.0, -1845.0, -1812.0, -1654.0, -1492.0, -1914.0, -1944.0, -1870.0, -2477.0,
+    -2538.0, -2298.0, -2143.0, -2146.0, -2311.0, -1777.0, -1193.0, -1206.0, -1254.0, -743.0,
+    -84.0, -129.0, -469.0, -679.0, -114.0, 352.0, 239.0, 93.0, 381.0, 543.0,
+    283.0, 196.0, -460.0, -443.0, -307.0, -445.0, -979.0, -1095.0, -1050.0, -1172.0,
+    -967.0, -1246.0, -1217.0, -1830.0, -2167.0, -2712.0, -2778.0, -2980.0, -3055.0, -3839.0,
+    -4253.0, -4163.0, -4240.0, -4487.0, -4861.0, -5019.0, -4875.0, -4883.0, -5109.0, -5022.0,
+    -4438.0, -4639.0, -4509.0, -4761.0, -4472.0, -4841.0, -4910.0, -5264.0, -4743.0, -4802.0,
+    -4617.0, -4302.0, -4367.0, -3968.0, -3632.0, -3434.0, -4356.0, -4329.0, -3850.0, -3603.0,
+    -3654.0, -4229.0, -4262.0, -3681.0, -3026.0, -2570.0, -2486.0, -1859.0, -1264.0, -1145.0,
+    -1064.0, -1125.0, -855.0, -400.0, -469.0, -498.0, -691.0, -475.0, -528.0, -809.0,
+    -948.0, -1047.0, -1250.0, -1691.0, -2110.0, -2790.0, -2818.0, -2589.0, -2415.0, -2710.0,
+    -2744.0, -2767.0, -2506.0, -2285.0, -2361.0, -2103.0, -2336.0, -2341.0, -2687.0, -2667.0,
+    -2925.0, -2761.0, -2816.0, -2644.0, -2456.0, -2186.0, -2092.0, -2498.0, -2773.0, -2554.0,
+    -2218.0, -2626.0, -2996.0, -3119.0, -2574.0, -2582.0, -3009.0, -2876.0, -2747.0, -2999.0
+};
+
+/* Elements [480:960] from p232_113.wav cast as fp32. */
+const std::vector<float> testWav1 = std::vector<float>{
+    -2918.0, -2418.0, -2452.0, -2172.0, -2261.0, -2337.0, -2399.0, -2209.0, -2269.0, -2509.0,
+    -2721.0, -2884.0, -2891.0, -3440.0, -3757.0, -4338.0, -4304.0, -4587.0, -4714.0, -5686.0,
+    -5699.0, -5447.0, -5008.0, -5052.0, -5135.0, -4807.0, -4515.0, -3850.0, -3804.0, -3813.0,
+    -3451.0, -3527.0, -3764.0, -3627.0, -3527.0, -3737.0, -4043.0, -4394.0, -4672.0, -4561.0,
+    -4718.0, -4737.0, -5018.0, -5187.0, -5043.0, -4734.0, -4841.0, -5363.0, -5870.0, -5697.0,
+    -5731.0, -6081.0, -6557.0, -6306.0, -6422.0, -5990.0, -5738.0, -5559.0, -5880.0, -6093.0,
+    -6718.0, -6853.0, -6966.0, -6907.0, -6887.0, -7046.0, -6902.0, -6927.0, -6754.0, -6891.0,
+    -6630.0, -6381.0, -5877.0, -5858.0, -6237.0, -6129.0, -6248.0, -6297.0, -6717.0, -6731.0,
+    -5888.0, -5239.0, -5635.0, -5808.0, -5418.0, -4780.0, -4311.0, -4082.0, -4053.0, -3274.0,
+    -3214.0, -3194.0, -3206.0, -2407.0, -1824.0, -1753.0, -1908.0, -1865.0, -1535.0, -1246.0,
+    -1434.0, -1970.0, -1890.0, -1815.0, -1949.0, -2296.0, -2356.0, -1972.0, -2156.0, -2057.0,
+    -2189.0, -1861.0, -1640.0, -1456.0, -1641.0, -1786.0, -1781.0, -1880.0, -1918.0, -2251.0,
+    -2256.0, -2608.0, -3169.0, -2983.0, -2785.0, -2948.0, -3267.0, -3856.0, -3847.0, -3534.0,
+    -3799.0, -4028.0, -4438.0, -4509.0, -4343.0, -3913.0, -3752.0, -3709.0, -3302.0, -2612.0,
+    -2848.0, -3320.0, -3049.0, -2171.0, -2342.0, -2746.0, -2618.0, -2031.0, -1166.0, -1454.0,
+    -995.0, -156.0, 573.0, 1240.0, 506.0, 296.0, 524.0, 581.0, 212.0, -191.0,
+    169.0, -46.0, 17.0, 221.0, 586.0, 347.0, 40.0, 217.0, 951.0, 694.0,
+    191.0, -535.0, -260.0, 252.0, 187.0, -230.0, -541.0, -124.0, -59.0, -1152.0,
+    -1397.0, -1176.0, -1195.0, -2218.0, -2960.0, -2338.0, -1895.0, -2460.0, -3599.0, -3728.0,
+    -2896.0, -2672.0, -4025.0, -4322.0, -3625.0, -3066.0, -3599.0, -4989.0, -5005.0, -3988.0,
+    -3153.0, -3921.0, -4349.0, -4444.0, -3526.0, -2896.0, -3810.0, -4252.0, -3300.0, -2234.0,
+    -2044.0, -3229.0, -2959.0, -2542.0, -1821.0, -1561.0, -1853.0, -2112.0, -1361.0, -831.0,
+    -840.0, -999.0, -1021.0, -769.0, -388.0, -377.0, -513.0, -790.0, -938.0, -911.0,
+    -1654.0, -1809.0, -2326.0, -1879.0, -1956.0, -2241.0, -2307.0, -1900.0, -1620.0, -2265.0,
+    -2170.0, -1257.0, -681.0, -1552.0, -2405.0, -2443.0, -1941.0, -1774.0, -2245.0, -2652.0,
+    -2769.0, -2622.0, -2714.0, -3558.0, -4449.0, -4894.0, -4583.0, -5179.0, -6471.0, -6526.0,
+    -5918.0, -5153.0, -5770.0, -6250.0, -5532.0, -4751.0, -4810.0, -5519.0, -5661.0, -5028.0,
+    -4737.0, -5482.0, -5837.0, -5005.0, -4200.0, -4374.0, -4962.0, -5199.0, -4464.0, -4106.0,
+    -4783.0, -5151.0, -4588.0, -4137.0, -3936.0, -4954.0, -4582.0, -3855.0, -2912.0, -2867.0,
+    -2965.0, -2919.0, -2362.0, -1800.0, -2025.0, -1931.0, -1438.0, -979.0, -1124.0, -1124.0,
+    -1130.0, -781.0, -652.0, -814.0, -976.0, -1269.0, -1052.0, -551.0, -724.0, -947.0,
+    -934.0, -856.0, -705.0, -894.0, -916.0, -861.0, -487.0, -681.0, -493.0, -902.0,
+    -547.0, -466.0, -1013.0, -1466.0, -2178.0, -1907.0, -1618.0, -2169.0, -3226.0, -2973.0,
+    -2390.0, -2227.0, -3257.0, -4297.0, -4227.0, -3022.0, -3017.0, -4268.0, -4956.0, -4199.0,
+    -3099.0, -3627.0, -4820.0, -4666.0, -3475.0, -2648.0, -3613.0, -4521.0, -3942.0, -3083.0,
+    -2832.0, -3912.0, -4289.0, -3684.0, -2728.0, -2702.0, -3279.0, -2636.0, -2261.0, -2170.0,
+    -2346.0, -2500.0, -1894.0, -1745.0, -1849.0, -2078.0, -2170.0, -1608.0, -1027.0, -1350.0,
+    -1330.0, -1128.0, -478.0, -1113.0, -1584.0, -1656.0, -1636.0, -1678.0, -1726.0, -1554.0,
+    -1434.0, -1243.0, -748.0, -463.0, -277.0, 216.0, 517.0, 1063.0, 1101.0, 839.0,
+    724.0, 543.0, 713.0, 598.0, 806.0, 499.0, 612.0, 385.0, 830.0, 939.0,
+    602.0, 60.0, -378.0, -300.0, -308.0, -1079.0, -1461.0, -997.0, -855.0, -1087.0,
+    -1579.0, -1314.0, -742.0, -452.0, -327.0, 224.0, -46.0, -119.0, -339.0, -22.0,
+    172.0, -137.0, 196.0, -89.0, 34.0, -324.0, -281.0, -999.0, -1134.0, -516.0,
+    101.0, 321.0, -584.0, -231.0, 1254.0, 1744.0, 1175.0, 684.0, 842.0, 1439.0,
+    1507.0, 829.0, 296.0, 519.0, 716.0, 961.0, 175.0, -494.0, -501.0, -628.0,
+    -658.0, -700.0, -989.0, -1342.0, -1298.0, -1347.0, -1223.0, -1388.0, -1308.0, -1184.0,
+    -468.0, -2.0, -444.0, -388.0, -80.0, 361.0, 700.0, 120.0, 101.0, 464.0,
+    654.0, 40.0, -586.0, -607.0, -730.0, -705.0, -844.0, -692.0, -1032.0, -1216.0
+};
+
+/* Golden RNNoise pre-processing output for [0:480] p232_113.wav */
+const std::vector<float> RNNoisePreProcessGolden0 {
+    4.597353, -0.908727, 1.067204, -0.034760, -0.084974,
+    -0.361086, -1.494876, -0.173461, -0.671268, 0.245229,
+    0.371219, 0.159632, 0.230595, 0.245066, 0.148395,
+    -0.660396, -0.157954, 0.136425, 0.062801, -0.049542,
+    0.179730, 0.178653, 4.597353, -0.908727, 1.067204,
+    -0.034760, -0.084974, -0.361086, 4.597353, -0.908727,
+    1.067204, -0.034760, -0.084974, -0.361086, -1.437083,
+    -0.722769, -0.232802, -0.178104, -0.431379, -0.591088,
+    -0.930000, 1.257937
+};
+
+/* Golden RNNoise pre-processing output for [480:960] p232_113.wav */
+const std::vector<float> RNNoisePreProcessGolden1 {
+    11.031052, -1.249548, 2.498929, 0.492149, 0.364215,
+    0.138582, -0.846219, 0.279253, -0.526596, 0.610061,
+    0.820483, 0.293216, -0.047377, -0.178503, 0.229638,
+    -0.516174, 0.149612, 0.100330, 0.010542, 0.028561,
+    -0.037554, -0.094355, 6.433699, -0.340821, 1.431725,
+    0.526909, 0.449189, 0.499668, -2.761007, 1.476633,
+    -0.702682, 0.596430, 0.619138, 1.221840, -0.739308,
+    -0.490715, -0.085385, 0.035244, 0.104252, -0.192160,
+    -0.810000, -0.430191
+};
+
+
+const std::vector<float> RNNoisePostProcessDenoiseGolden0 {
+        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, 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,
+        -1, 0, 0, 0, 0, -1, 0, -1, 0, 0,
+        -1, 0, -1, -1, -1, -1, -1, -1, 0, -1,
+        -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
+        2, 2, 2, 2, 3, 3, 3, 3, 3, 4,
+        4, 4, 4, 4, 4, 4, 4, 5, 4, 5,
+        5, 5, 5, 5, 5, 4, 5, 4, 4, 4,
+        4, 4, 3, 4, 3, 3, 3, 2, 3, 2,
+        2, 2, 1, 1, 1, 1, 1, 0, 0, 0,
+        0, 0, 0, 0, 0, 0, 0, 0, 0, -1,
+        0, -1, 0, -1, -1, -1, -1, -1, -2, -1,
+        -1, -2, -1, -2, -1, -2, -2, -1, -2, -1,
+        -2, -1, -1, -1, 0, -1, 0, -1, 0, 0,
+        -1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+        0, 1, 0, 1, 0, 1, 1, 1, 2, 1,
+        2, 2, 2, 3, 2, 3, 2, 3, 3, 3,
+        4, 3, 4, 3, 3, 4, 3, 5, 4, 4,
+        4, 4, 5, 4, 5, 4, 4, 5, 4, 5,
+        4, 4, 4, 3, 4, 3, 4, 3, 2, 3,
+        1, 2, 0, 0, 0, 0, 0, -1, 0, -1,
+        -2, -1, -3, -1, -3, -2, -2, -3, -2, -3,
+        -2, -3, -3, -2, -4, -2, -3, -3, -3, -4,
+        -3, -4, -3, -4, -5, -4, -6, -4, -6, -6,
+        -5, -7, -5, -7, -6, -6, -7, -6, -8, -6,
+        -7, -7, -6, -8, -6, -8, -6, -7, -8, -6,
+        -9, -7, -8, -8, -7, -9, -7, -9, -8, -8,
+        -8, -6, -8, -5, -6, -5, -3, -3, 0, -1,
+        1, 2, 3, 7, 6, 10, 11, 13, 16, 15,
+        20, 19, 23, 24, 25, 28, 27, 31, 31, 32,
+        34, 32, 35, 33, 35, 35, 34, 36, 33, 35,
+        33, 32, 33, 30, 31, 28, 28, 27, 24, 25,
+        20, 21, 18, 16, 15, 11, 12, 8, 8, 7,
+        4, 6, 1, 3, 1, 0, 2, 0, 2, 0,
+        0, 1, 0, 3, 0, 3, 1, 1, 4, 0,
+        4, 1, 3, 3, 1, 4, 0, 3, 1, 0,
+        2, -1, 1, -1, -1, 0, -3, 0, -3, 0,
+        -1, -1, 2, 0, 5, 4, 7, 11, 11, 18,
+        15, 21, 23, 24, 31, 29, 38, 37, 42, 46,
+        45, 54, 51, 59, 60, 61, 68, 62, 70, 66,
+        68, 73, 69, 79, 73, 79, 76, 70, 75, 61,
+        71, 64, 74, 85, 70, 86, 51, 92, 73
+};
+
+
+std::vector<float> RNNoiseModelOutputGolden0{0.157920, 0.392021, 0.368438, 0.258663, 0.202650,
+                                             0.256764, 0.185472, 0.149062, 0.147317, 0.142133,
+                                             0.148236, 0.173523, 0.197672, 0.200920, 0.198408,
+                                             0.147500, 0.140215, 0.166651, 0.250242, 0.256278,
+                                             0.252104, 0.241938};
+
+TEST_CASE("RNNoise preprocessing calculation test",  "[RNNoise]")
+{
+    SECTION("FP32")
+    {
+        arm::app::rnn::RNNoiseProcess rnnoiseProcessor;
+        arm::app::rnn::FrameFeatures features;
+
+        rnnoiseProcessor.PreprocessFrame(testWav0.data(), testWav0.size(), features);
+        REQUIRE_THAT( features.m_featuresVec,
+            Catch::Approx( RNNoisePreProcessGolden0 ).margin(0.1));
+        rnnoiseProcessor.PreprocessFrame(testWav1.data(), testWav1.size(), features);
+        REQUIRE_THAT( features.m_featuresVec,
+            Catch::Approx( RNNoisePreProcessGolden1 ).margin(0.1));
+    }
+}
+
+
+TEST_CASE("RNNoise postprocessing test", "[RNNoise]")
+{
+    arm::app::rnn::RNNoiseProcess rnnoiseProcessor;
+    arm::app::rnn::FrameFeatures p;
+    rnnoiseProcessor.PreprocessFrame(testWav0.data(), testWav0.size(), p);
+    std::vector<float> denoised(testWav0.size());
+    rnnoiseProcessor.PostProcessFrame(RNNoiseModelOutputGolden0, p, denoised);
+
+    std::vector<float> denoisedRoundedInt;
+
+    denoisedRoundedInt.reserve(denoised.size());
+    for(auto i:denoised){
+        denoisedRoundedInt.push_back(static_cast<float>(static_cast<int>(std::roundf(i))));
+    }
+
+    REQUIRE_THAT( denoisedRoundedInt, Catch::Approx( RNNoisePostProcessDenoiseGolden0 ).margin(1));
+}
\ No newline at end of file