Mercurial > games > semicongine
comparison tests/test_audio.nim @ 1282:3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
author | sam <sam@basx.dev> |
---|---|
date | Mon, 29 Jul 2024 16:05:09 +0700 |
parents | 4cf9872f7bb6 |
children | e0326aa067c8 |
comparison
equal
deleted
inserted
replaced
1281:c09cdff9a97e | 1282:3308b88e53a6 |
---|---|
4 | 4 |
5 import ../semicongine | 5 import ../semicongine |
6 | 6 |
7 | 7 |
8 proc test1() = | 8 proc test1() = |
9 mixer[].AddSound("test1", SineSoundData(1000, 2, 44100)) | 9 mixer[].addSound("test1", sineSoundData(1000, 2, 44100)) |
10 mixer[].AddSound("test2", SineSoundData(500, 2, 44100)) | 10 mixer[].addSound("test2", 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 |
31 # notes | 31 # notes |
32 c = SineSoundData(261.6256, 0.5, 44100) | 32 c = sineSoundData(261.6256, 0.5, 44100) |
33 d = SineSoundData(293.6648, 0.5, 44100) | 33 d = sineSoundData(293.6648, 0.5, 44100) |
34 e = SineSoundData(329.6276, 0.5, 44100) | 34 e = sineSoundData(329.6276, 0.5, 44100) |
35 f = SineSoundData(349.2282, 0.5, 44100) | 35 f = sineSoundData(349.2282, 0.5, 44100) |
36 g = SineSoundData(391.9954, 0.5, 44100) | 36 g = sineSoundData(391.9954, 0.5, 44100) |
37 a = SineSoundData(440.0000, 0.5, 44100) | 37 a = sineSoundData(440.0000, 0.5, 44100) |
38 b = SineSoundData(493.8833, 0.5, 44100) | 38 b = sineSoundData(493.8833, 0.5, 44100) |
39 bb = SineSoundData(466.1638, 0.5, 44100) | 39 bb = sineSoundData(466.1638, 0.5, 44100) |
40 c2 = SineSoundData(523.2511, 0.5, 44100) | 40 c2 = sineSoundData(523.2511, 0.5, 44100) |
41 d2 = SineSoundData(587.3295, 0.5, 44100) | 41 d2 = sineSoundData(587.3295, 0.5, 44100) |
42 bbShort = SineSoundData(466.1638, 0.25, 44100) | 42 bbShort = sineSoundData(466.1638, 0.25, 44100) |
43 c2Short = SineSoundData(523.2511, 0.25, 44100) | 43 c2Short = sineSoundData(523.2511, 0.25, 44100) |
44 d2Short = SineSoundData(587.3295, 0.25, 44100) | 44 d2Short = sineSoundData(587.3295, 0.25, 44100) |
45 | 45 |
46 # song | 46 # song |
47 frerejaquesData = concat( | 47 frerejaquesData = concat( |
48 f, g, a, f, | 48 f, g, a, f, |
49 f, g, a, f, | 49 f, g, a, f, |
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", frerejaquesData) | 58 mixer[].addSound("frerejaques", 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", SineSoundData(500, 0.05, 44100)) | 66 mixer[].addSound("ping", 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 test1() | 72 test1() |
73 mixer[].Stop() | 73 mixer[].stop() |
74 test2() | 74 test2() |
75 mixer[].Stop() | 75 mixer[].stop() |
76 test3() | 76 test3() |
77 | 77 |
78 while mixer[].IsPlaying(): | 78 while mixer[].isPlaying(): |
79 discard mixer[].Play("ping", track = "effects", stopOtherSounds = true, level = 0.5) | 79 discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) |
80 # on windows we re-open stdin and this will not work | 80 # on windows we re-open stdin and this will not work |
81 when defined(linux): | 81 when defined(linux): |
82 echo "Press q and enter to exit" | 82 echo "Press q and enter to exit" |
83 if stdin.readLine() == "q": | 83 if stdin.readLine() == "q": |
84 mixer[].Stop() | 84 mixer[].stop() |
85 elif defined(windows): | 85 elif defined(windows): |
86 sleep(5) | 86 sleep(5) |
87 mixer[].Stop() | 87 mixer[].stop() |