comparison tests/test_audio.nim @ 889:a2736295c3f6

add: proper sound test, from public domain
author Sam <sam@basx.dev>
date Sun, 04 Feb 2024 22:07:54 +0700
parents 252cbc10b25f
children 1ba0e5dfbf68
comparison
equal deleted inserted replaced
888:cbbb9abe256e 889:a2736295c3f6
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()
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("pianosong", loadAudio("test.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("pianosong") 68 discard mixer[].play("toccata et fugue")
69 69
70 while mixer[].isPlaying():
71 discard mixer[].play("ping", track="effects", stopOtherSounds=true, level=0.5)
72 discard stdin.readLine()
73 70
74 when isMainModule: 71 when isMainModule:
75 startMixerThread() 72 startMixerThread()
76 test1() 73 test1()
77 mixer[].stop() 74 mixer[].stop()
78 test2() 75 test2()
79 mixer[].stop() 76 mixer[].stop()
80 # test3() 77 test3()
81 # mixer[].stop() 78
79 while mixer[].isPlaying():
80 discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5)
81 echo "Press q and enter to exit"
82 if stdin.readLine() == "q":
83 mixer[].stop()