Mercurial > games > semicongine
comparison old_tests/test_audio.nim @ 1203:6360c8d17ce0 compiletime-tests
did: preprations to add rendering tests
| author | sam <sam@basx.dev> |
|---|---|
| date | Mon, 15 Jul 2024 20:06:42 +0700 |
| parents | tests/test_audio.nim@114f395b9144 |
| children |
comparison
equal
deleted
inserted
replaced
| 1202:a8864fe6fe6e | 1203:6360c8d17ce0 |
|---|---|
| 1 import std/os | |
| 2 import std/sequtils | |
| 3 import std/times | |
| 4 | |
| 5 import semicongine | |
| 6 | |
| 7 | |
| 8 proc test1() = | |
| 9 mixer[].AddSound("test1", NewSound(SineSoundData(1000, 2, 44100))) | |
| 10 mixer[].AddSound("test2", NewSound(SineSoundData(500, 2, 44100))) | |
| 11 | |
| 12 | |
| 13 let s1 = mixer[].Play("test1", loop = true) | |
| 14 let s2 = mixer[].Play("test2", loop = true) | |
| 15 | |
| 16 let t0 = now() | |
| 17 mixer[].SetLevel(0.5) | |
| 18 while true: | |
| 19 let runtime = (now() - t0).inMilliseconds() | |
| 20 if runtime > 1500: | |
| 21 mixer[].SetLevel(0.2) | |
| 22 if runtime > 3000: | |
| 23 mixer[].Stop(s2) | |
| 24 if runtime > 6000: | |
| 25 mixer[].Stop("") | |
| 26 if runtime > 8000: | |
| 27 break | |
| 28 | |
| 29 proc test2() = | |
| 30 let | |
| 31 # notes | |
| 32 c = SineSoundData(261.6256, 0.5, 44100) | |
| 33 d = SineSoundData(293.6648, 0.5, 44100) | |
| 34 e = SineSoundData(329.6276, 0.5, 44100) | |
| 35 f = SineSoundData(349.2282, 0.5, 44100) | |
| 36 g = SineSoundData(391.9954, 0.5, 44100) | |
| 37 a = SineSoundData(440.0000, 0.5, 44100) | |
| 38 b = SineSoundData(493.8833, 0.5, 44100) | |
| 39 bb = SineSoundData(466.1638, 0.5, 44100) | |
| 40 c2 = SineSoundData(523.2511, 0.5, 44100) | |
| 41 d2 = SineSoundData(587.3295, 0.5, 44100) | |
| 42 bbShort = SineSoundData(466.1638, 0.25, 44100) | |
| 43 c2Short = SineSoundData(523.2511, 0.25, 44100) | |
| 44 d2Short = SineSoundData(587.3295, 0.25, 44100) | |
| 45 | |
| 46 # song | |
| 47 frerejaquesData = concat( | |
| 48 f, g, a, f, | |
| 49 f, g, a, f, | |
| 50 a, bb, c2, c2, | |
| 51 a, bb, c2, c2, | |
| 52 c2Short, d2Short, c2Short, bbShort, a, f, | |
| 53 c2Short, d2Short, c2Short, bbShort, a, f, | |
| 54 f, c, f, f, | |
| 55 f, c, f, f, | |
| 56 ) | |
| 57 | |
| 58 mixer[].AddSound("frerejaques", NewSound(frerejaquesData)) | |
| 59 discard mixer[].Play("frerejaques") | |
| 60 | |
| 61 while mixer[].IsPlaying(): | |
| 62 sleep(1) | |
| 63 | |
| 64 proc test3() = | |
| 65 mixer[].AddSound("toccata et fugue", LoadAudio("toccata_et_fugue.ogg")) | |
| 66 mixer[].AddSound("ping", NewSound(SineSoundData(500, 0.05, 44100))) | |
| 67 mixer[].AddTrack("effects") | |
| 68 discard mixer[].Play("toccata et fugue") | |
| 69 | |
| 70 | |
| 71 when isMainModule: | |
| 72 StartMixerThread() | |
| 73 test1() | |
| 74 mixer[].Stop() | |
| 75 test2() | |
| 76 mixer[].Stop() | |
| 77 test3() | |
| 78 | |
| 79 while mixer[].IsPlaying(): | |
| 80 discard mixer[].Play("ping", track = "effects", stopOtherSounds = true, level = 0.5) | |
| 81 # on windows we re-open stdin and this will not work | |
| 82 when defined(linux): | |
| 83 echo "Press q and enter to exit" | |
| 84 if stdin.readLine() == "q": | |
| 85 mixer[].Stop() | |
| 86 elif defined(windows): | |
| 87 sleep(5) | |
| 88 mixer[].Stop() |
