comparison tests/test_audio.nim @ 1135:74957cbf589b

fix: update tests according to some API renaming
author sam <sam@basx.dev>
date Mon, 03 Jun 2024 16:05:17 +0700
parents 1ba0e5dfbf68
children a4aa9f374d44
comparison
equal deleted inserted replaced
1134:055eb17ce31e 1135:74957cbf589b
4 4
5 import semicongine 5 import semicongine
6 6
7 7
8 proc test1() = 8 proc test1() =
9 mixer[].addSound("test1", newSound(sineSoundData(1000, 2, 44100))) 9 mixer[].AddSound("test1", newSound(sineSoundData(1000, 2, 44100)))
10 mixer[].addSound("test2", newSound(sineSoundData(500, 2, 44100))) 10 mixer[].AddSound("test2", newSound(sineSoundData(500, 2, 44100)))
11 11
12 12
13 let s1 = mixer[].play("test1", loop = true) 13 let s1 = mixer[].Play("test1", loop = true)
14 let s2 = mixer[].play("test2", loop = true) 14 let s2 = mixer[].Play("test2", loop = true)
15 15
16 let t0 = now() 16 let t0 = now()
17 mixer[].setLevel(0.5) 17 mixer[].SetLevel(0.5)
18 while true: 18 while true:
19 let runtime = (now() - t0).inMilliseconds() 19 let runtime = (now() - t0).inMilliseconds()
20 if runtime > 1500: 20 if runtime > 1500:
21 mixer[].setLevel(0.2) 21 mixer[].SetLevel(0.2)
22 if runtime > 3000: 22 if runtime > 3000:
23 mixer[].stop(s2) 23 mixer[].Stop(s2)
24 if runtime > 6000: 24 if runtime > 6000:
25 mixer[].stop("") 25 mixer[].Stop("")
26 if runtime > 8000: 26 if runtime > 8000:
27 break 27 break
28 28
29 proc test2() = 29 proc test2() =
30 let 30 let
53 c2Short, d2Short, c2Short, bbShort, a, f, 53 c2Short, d2Short, c2Short, bbShort, a, f,
54 f, c, f, f, 54 f, c, f, f,
55 f, c, f, f, 55 f, c, f, f,
56 ) 56 )
57 57
58 mixer[].addSound("frerejaques", newSound(frerejaquesData)) 58 mixer[].AddSound("frerejaques", newSound(frerejaquesData))
59 discard mixer[].play("frerejaques") 59 discard mixer[].Play("frerejaques")
60 60
61 while mixer[].isPlaying(): 61 while mixer[].IsPlaying():
62 sleep(1) 62 sleep(1)
63 63
64 proc test3() = 64 proc test3() =
65 mixer[].addSound("toccata et fugue", loadAudio("toccata_et_fugue.ogg")) 65 mixer[].AddSound("toccata et fugue", loadAudio("toccata_et_fugue.ogg"))
66 mixer[].addSound("ping", newSound(sineSoundData(500, 0.05, 44100))) 66 mixer[].AddSound("ping", newSound(sineSoundData(500, 0.05, 44100)))
67 mixer[].addTrack("effects") 67 mixer[].AddTrack("effects")
68 discard mixer[].play("toccata et fugue") 68 discard mixer[].Play("toccata et fugue")
69 69
70 70
71 when isMainModule: 71 when isMainModule:
72 startMixerThread() 72 StartMixerThread()
73 test1() 73 test1()
74 mixer[].stop() 74 mixer[].Stop()
75 test2() 75 test2()
76 mixer[].stop() 76 mixer[].Stop()
77 test3() 77 test3()
78 78
79 while mixer[].isPlaying(): 79 while mixer[].IsPlaying():
80 discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) 80 discard mixer[].Play("ping", track = "effects", stopOtherSounds = true, level = 0.5)
81 # on windows we re-open stdin and this will not work 81 # on windows we re-open stdin and this will not work
82 when defined(linux): 82 when defined(linux):
83 echo "Press q and enter to exit" 83 echo "Press q and enter to exit"
84 if stdin.readLine() == "q": 84 if stdin.readLine() == "q":
85 mixer[].stop() 85 mixer[].Stop()
86 elif defined(windows): 86 elif defined(windows):
87 sleep(5) 87 sleep(5)
88 mixer[].stop() 88 mixer[].Stop()