Skip to content

Commit

Permalink
Fixed out of bounds exception during resampling (Macoron#74)
Browse files Browse the repository at this point in the history
* Fixed out of bounds resample

* Update test.yml

* Update test.yml

* Update test.yml
  • Loading branch information
Macoron committed Feb 2, 2024
1 parent 0418999 commit cf5f1fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Runtime/Utils/AudioUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Runtime/AudioUtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit cf5f1fe

Please sign in to comment.