From 9e402ff91fb6a2a737042c71fb684e9dc3677180 Mon Sep 17 00:00:00 2001 From: Alex Evgrashin Date: Fri, 2 Feb 2024 12:59:44 +0100 Subject: [PATCH] Fixed out of bounds exception during resampling (#74) * Fixed out of bounds resample * Update test.yml * Update test.yml * Update test.yml --- .github/workflows/test.yml | 4 +++- Packages/com.whisper.unity/Runtime/Utils/AudioUtils.cs | 4 ++-- Packages/com.whisper.unity/Tests/Runtime/AudioUtilsTests.cs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78dc1bd..9b51129 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,9 @@ on: branches: - master env: - UNITY_LICENSE: "\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \nm0Db8UK+ktnOLJBtHybkfetpcKo=o/pUbSQAukz7+ZYAWhnA0AJbIlyyCPL7bKVEM2lVqbrXt7cyey+umkCXamuOgsWPVUKBMkXtMH8L\n5etLmD0getWIhTGhzOnDCk+gtIPfL4jMo9tkEuOCROQAXCci23VFscKcrkB+3X6h4wEOtA2APhOY\nB+wvC794o8/82ffjP79aVAi57rp3Wmzx+9pe9yMwoJuljAy2sc2tIMgdQGWVmOGBpQm3JqsidyzI\nJWG2kjnc7pDXK9pwYzXoKiqUqqrut90d+kQqRyv7MSZXR50HFqD/LI69h68b7P8Bjo3bPXOhNXGR\n9YCoemH6EkfCJxp2gIjzjWW+l2Hj2EsFQi8YXw==" + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} jobs: testAllModes: diff --git a/Packages/com.whisper.unity/Runtime/Utils/AudioUtils.cs b/Packages/com.whisper.unity/Runtime/Utils/AudioUtils.cs index 0871042..a84da39 100644 --- a/Packages/com.whisper.unity/Runtime/Utils/AudioUtils.cs +++ b/Packages/com.whisper.unity/Runtime/Utils/AudioUtils.cs @@ -56,8 +56,8 @@ public static float[] ChangeSampleRate(float[] src, int srcSampleRate, int dstSa var low = Mathf.FloorToInt(index); var dif = index - low; - if (low + 1 == srcLen) - dst[i] = src[low]; + if (low + 1 >= srcLen) + dst[i] = src[srcLen - 1]; else dst[i] = Mathf.Lerp(src[low], src[low + 1], dif); } diff --git a/Packages/com.whisper.unity/Tests/Runtime/AudioUtilsTests.cs b/Packages/com.whisper.unity/Tests/Runtime/AudioUtilsTests.cs index 77281cc..5851bbe 100644 --- a/Packages/com.whisper.unity/Tests/Runtime/AudioUtilsTests.cs +++ b/Packages/com.whisper.unity/Tests/Runtime/AudioUtilsTests.cs @@ -30,8 +30,8 @@ public void ConvertToMonoTest() [Test] public void ChangeSampleRateTest() { - // create mono audio of 5 sec length - const int time = 5; + // create mono audio of 10 sec length + const int time = 10 * 60; const int srcRate = 16000; var src = new float[srcRate * time];