-
Notifications
You must be signed in to change notification settings - Fork 1
/
test1.nim
34 lines (30 loc) · 904 Bytes
/
test1.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import unittest
import parasound/miniaudio
import os
import json
from common import nil
test "can write wav file":
const
middleC = staticRead("middle_c.json")
sampleRate = 44100
let arr = parseJson(middleC)
var data = newSeq[cshort]()
for n in arr:
data.add(n.getInt.cshort)
common.writeFile("middle_c.wav", data, data.len.uint32, sampleRate)
doAssert fileExists("middle_c.wav")
sleep(1000)
test "can write wav to memory and play it":
const
middleC = staticRead("middle_c.json")
sampleRate = 44100
let arr = parseJson(middleC)
var data = newSeq[cshort]()
for n in arr:
data.add(n.getInt.cshort)
let wav = common.writeMemory(data, data.len.uint32, sampleRate)
check common.play(wav, 1000)
test "can play wav file":
check common.play("tests/xylophone-sweep.wav", 2000)
test "can play mp3 file":
check common.play("tests/xylophone-sweep.mp3", 2000)