Skip to content

Commit aad73bc

Browse files
committed
Test APM
1 parent cb23c17 commit aad73bc

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Tests/AudioProcessingModule.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using NUnit.Framework;
3+
using System.Runtime.InteropServices;
4+
5+
namespace LiveKit.Tests
6+
{
7+
public class AudioProcessingModuleTest
8+
{
9+
[Test]
10+
public void TestAudioProcessing()
11+
{
12+
var apm = new AudioProcessingModule(true, true, true, true);
13+
14+
apm.ProcessStream(CreateTestFrame());
15+
apm.ProcessReverseStream(CreateTestFrame());
16+
17+
Assert.Throws<Exception>(() => apm.ProcessStream(CreateInvalidFrame()));
18+
Assert.Throws<Exception>(() => apm.ProcessReverseStream(CreateInvalidFrame()));
19+
}
20+
21+
private AudioFrame CreateTestFrame()
22+
{
23+
const int SampleRate = 48000;
24+
const int NumChannels = 1;
25+
const int FramesPerChunk = SampleRate / 100;
26+
27+
var frame = new AudioFrame(SampleRate, NumChannels, FramesPerChunk);
28+
29+
var data = new short[frame.SamplesPerChannel * frame.NumChannels];
30+
for (int i = 0; i < data.Length; i++)
31+
{
32+
// Generate a 440Hz sine wave
33+
data[i] = (short)(short.MaxValue * Math.Sin(2 * Math.PI * 440 * i / frame.SampleRate));
34+
}
35+
Marshal.Copy(data, 0, frame.Data, data.Length);
36+
return frame;
37+
}
38+
39+
private AudioFrame CreateInvalidFrame()
40+
{
41+
return new AudioFrame(100, 1, 1);
42+
}
43+
}
44+
}

Tests/AudioProcessingModule.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)