Mercurial > games > semicongine
annotate tests/test_audio.nim @ 1352:3bd16ad0e1b9
add: todo comment
author | sam <sam@basx.dev> |
---|---|
date | Thu, 12 Sep 2024 17:30:23 +0700 |
parents | df3c075e5dea |
children |
rev | line source |
---|---|
1225 | 1 import std/os |
2 import std/sequtils | |
3 import std/times | |
4 | |
1267 | 5 import ../semicongine |
1225 | 6 |
7 proc test1() = | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
8 mixer[].addSound("test1", sineSoundData(1000, 2, 44100)) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
9 mixer[].addSound("test2", sineSoundData(500, 2, 44100)) |
1225 | 10 |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
11 let s1 = mixer[].play("test1", loop = true) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
12 let s2 = mixer[].play("test2", loop = true) |
1225 | 13 |
14 let t0 = now() | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
15 mixer[].setLevel(0.5) |
1225 | 16 while true: |
17 let runtime = (now() - t0).inMilliseconds() | |
18 if runtime > 1500: | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
19 mixer[].setLevel(0.2) |
1225 | 20 if runtime > 3000: |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
21 mixer[].stop(s2) |
1225 | 22 if runtime > 6000: |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
23 mixer[].stop("") |
1225 | 24 if runtime > 8000: |
25 break | |
26 | |
27 proc test2() = | |
28 let | |
29 # notes | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
30 c = sineSoundData(261.6256, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
31 d = sineSoundData(293.6648, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
32 e = sineSoundData(329.6276, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
33 f = sineSoundData(349.2282, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
34 g = sineSoundData(391.9954, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
35 a = sineSoundData(440.0000, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
36 b = sineSoundData(493.8833, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
37 bb = sineSoundData(466.1638, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
38 c2 = sineSoundData(523.2511, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
39 d2 = sineSoundData(587.3295, 0.5, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
40 bbShort = sineSoundData(466.1638, 0.25, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
41 c2Short = sineSoundData(523.2511, 0.25, 44100) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
42 d2Short = sineSoundData(587.3295, 0.25, 44100) |
1225 | 43 |
44 # song | |
45 frerejaquesData = concat( | |
1332 | 46 f, g, a, f, f, g, a, f, a, bb, c2, c2, a, bb, c2, c2, c2Short, d2Short, c2Short, |
47 bbShort, a, f, c2Short, d2Short, c2Short, bbShort, a, f, f, c, f, f, f, c, f, f, | |
1225 | 48 ) |
49 | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
50 mixer[].addSound("frerejaques", frerejaquesData) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
51 discard mixer[].play("frerejaques") |
1225 | 52 |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
53 while mixer[].isPlaying(): |
1225 | 54 sleep(1) |
55 | |
56 proc test3() = | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
57 mixer[].addSound("toccata et fugue", loadAudio("toccata_et_fugue.ogg")) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
58 mixer[].addSound("ping", sineSoundData(500, 0.05, 44100)) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
59 mixer[].addTrack("effects") |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
60 discard mixer[].play("toccata et fugue") |
1225 | 61 |
62 when isMainModule: | |
63 test1() | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
64 mixer[].stop() |
1225 | 65 test2() |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
66 mixer[].stop() |
1225 | 67 test3() |
68 | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
69 while mixer[].isPlaying(): |
1225 | 70 # on windows we re-open stdin and this will not work |
71 when defined(linux): | |
1332 | 72 discard |
73 mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) | |
1225 | 74 echo "Press q and enter to exit" |
75 if stdin.readLine() == "q": | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
76 mixer[].stop() |
1225 | 77 elif defined(windows): |
1332 | 78 sleep(1000) |