/* * Copyright (c) 2021-2022 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 "RNNoiseFeatureProcessor.hpp" #include #include /* Elements [0:512] from p232_113.wav cast as fp32. */ const std::vector testWav0 = std::vector{ -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, -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 }; /* Elements [512:1024] from p232_113.wav cast as fp32. */ const std::vector testWav1 = std::vector{ -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, -1511.0, -1479.0, -1641.0, -2133.0, -2027.0, -1997.0, -1868.0, -1778.0, -1920.0, -2122.0, -2293.0, -2552.0, -2771.0, -3030.0, -2462.0, -2665.0, -2866.0, -3601.0, -3459.0, -3388.0, -3216.0, -3834.0, -4424.0, -4587.0, -4396.0, -3942.0, -3761.0, -3631.0, -3528.0, -4064.0, -4095.0, -4370.0, -4297.0, -4932.0, -4613.0, -4339.0, -4483.0, -4407.0, -4203.0, -4240.0, -4196.0, -3745.0, -3501.0, -3514.0, -3461.0, -3578.0, -3588.0, -3747.0, -3706.0, -3171.0, -2746.0, -2936.0, -2737.0, -2976.0, -2324.0, -1975.0, -2117.0, -2743.0, -2242.0, -1549.0, -1485.0, -2059.0, -2376.0, -1977.0 }; /* Golden RNNoise pre-processing output for [0:512] p232_113.wav */ const std::vector RNNoisePreProcessGolden0 { 4.75129105, -0.87399225, 0.94622732, -0.04182188, 0.05464971, -0.52353621, -1.40791412, -0.05604708, -0.56039004, 0.48334449, 0.33882704, 0.29808432, 0.18402454, 0.05289553, -0.13116701, -0.47689547, 0.19254394, -0.01638567, 0.06637303, 0.07179865, 0.26687299, 0.11071566, 4.75129105, -0.87399225, 0.94622732, -0.04182188, 0.05464971, -0.52353621, 4.75129105, -0.87399225, 0.94622732, -0.04182188, 0.05464971, -0.52353621, -1.00467825, -1.2105895, -0.12928345, -0.18741458, -0.45585857, -0.4011966, -0.91, 1.35764497 }; /* Golden RNNoise pre-processing output for [512:1024] p232_113.wav */ const std::vector RNNoisePreProcessGolden1 { 11.26880569, -1.26922285, 2.28843852, 0.45148339, 0.53617535, -0.16797574, -0.90503742, 0.35760545, -0.50392295, 0.97835271, 0.60372606, 0.18782702, -0.15711423, -0.15144927, 0.00090368, -0.48593647, 0.32602252, 0.00773871, 0.08888109, 0.05869409, 0.00409013, -0.09099827, 6.51751463, -0.3952306, 1.34221119, 0.49330527, 0.48152563, 0.35556047, -2.98506748, 1.3527539, -0.55024345, 0.57694904, 0.3722262, 1.4026329, -0.70134894, -0.60284336, -0.12922247, 0.143284, 0.23019133, -0.33742403, -0.81, -0.64850574 }; const std::vector 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, 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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, 0, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -2, -2, -2, -2, -2, -2, -2, -2, -3, -2, -3, -3, -2, -3, -2, -2, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2, -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -2, -1, -2, -3, -2, -4, -3, -4, -5, -4, -6, -5, -5, -6, -5, -6, -6, -6, -7, -6, -7, -7, -7, -8, -7, -7, -8, -7, -8, -7, -7, -8, -6, -7, -6, -6, -7, -5, -6, -5, -4, -5, -3, -3, -3, -1, -2, 0, -1, -1, 1, 0, 1, 2, 1, 3, 1, 2, 2, 1, 2, 0, 0, 0, -2, -1, -3, -4, -4, -6, -6, -8, -9, -9, -12, -12, -12, -15, -14, -16, -16, -16, -18, -16, -18, -18, -17, -19, -17, -17, -18, -15, -17, -15, -14, -15, -12, -13, -11, -9, -10, -7, -8, -7, -5, -7, -4, -5, -6, -4, -8, -6, -7, -8, -6, -9, -7, -7, -9, -6, -10, -9, -8, -12, -9, -12, -13, -12, -17, -14, -17, -18, -15, -20, -17, -17, -20, -15, -20, -17, -16, -20, -15, -19, -17, -15, -20, -13, -16, -15, -9, -13, -5, -6, -6, 1, -5, 2, 1, -3, 6, -2, 1, 2, -5, 6, -2, 4, 15, 8, 27, 19, 21, 33, 14, 29, 11, 12, 40, -12, 53, 35 }; std::vector RNNoiseModelOutputGolden0{0.3046875, 0.17578125, 0.1484375, 0.12890625, 0.12109375, 0.15625, 0.17578125, 0.203125, 0.17578125, 0.16796875, 0.18359375, 0.22265625, 0.23046875, 0.2421875, 0.23046875, 0.23046875, 0.25, 0.2734375, 0.29296875, 0.3046875, 0.33984375, 0.35546875}; TEST_CASE("RNNoise preprocessing calculation test", "[RNNoise]") { SECTION("FP32") { arm::app::rnn::RNNoiseFeatureProcessor 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::RNNoiseFeatureProcessor rnnoiseProcessor; arm::app::rnn::FrameFeatures p; rnnoiseProcessor.PreprocessFrame(testWav0.data(), testWav0.size(), p); std::vector denoised(testWav0.size()); rnnoiseProcessor.PostProcessFrame(RNNoiseModelOutputGolden0, p, denoised); std::vector denoisedRoundedInt; denoisedRoundedInt.reserve(denoised.size()); for(auto i:denoised){ denoisedRoundedInt.push_back(static_cast(static_cast(std::roundf(i)))); } REQUIRE_THAT( denoisedRoundedInt, Catch::Approx( RNNoisePostProcessDenoiseGolden0 ).margin(1)); }