Skip to content

Commit dd9fb57

Browse files
committed
Tests: assert ReadWAV() length is accurate
Uses Python's scipy.io.wavfile as a source of truth. #33 #34
1 parent 08f4254 commit dd9fb57

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

dev/python/readwav.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
sample rate: 44100
3+
values: 166671
4+
value 12345: 4435
5+
"""
6+
from scipy.io import wavfile
7+
import pathlib
8+
PATH_HERE = pathlib.Path(__file__).parent
9+
PATH_DATA = PATH_HERE.joinpath("../../data")
10+
11+
if __name__ == "__main__":
12+
wavFilePath = PATH_DATA.joinpath("cant-do-that-44100.wav")
13+
samplerate, data = wavfile.read(wavFilePath)
14+
print(f"sample rate: {samplerate}")
15+
print(f"values: {len(data)}")
16+
print(f"value 12345: {data[12345]}")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Spectrogram.Tests
7+
{
8+
class AudioFileTests
9+
{
10+
/// <summary>
11+
/// Compare values read from the WAV reader against those read by Python's SciPy module (see script in /dev folder)
12+
/// </summary>
13+
[Test]
14+
public void Test_AudioFile_KnownValues()
15+
{
16+
(double[] audio, int sampleRate) = AudioFile.ReadWAV("../../../../../data/cant-do-that-44100.wav", multiplier: 32_000);
17+
18+
Assert.AreEqual(44100, sampleRate);
19+
Assert.AreEqual(166671, audio.Length);
20+
Assert.AreEqual(4435, audio[12345], 1000);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)