Mercurial > games > semicongine
annotate tests/test_audio.nim @ 1295:76ca976804d0
fix: scale x to keep aspect ratio instead of y
author | sam <sam@basx.dev> |
---|---|
date | Mon, 05 Aug 2024 17:17:31 +0700 |
parents | 3308b88e53a6 |
children | e0326aa067c8 |
rev | line source |
---|---|
1225 | 1 import std/os |
2 import std/sequtils | |
3 import std/times | |
4 | |
1267 | 5 import ../semicongine |
1225 | 6 |
7 | |
8 proc test1() = | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
9 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
|
10 mixer[].addSound("test2", sineSoundData(500, 2, 44100)) |
1225 | 11 |
12 | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
13 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
|
14 let s2 = mixer[].play("test2", loop = true) |
1225 | 15 |
16 let t0 = now() | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
17 mixer[].setLevel(0.5) |
1225 | 18 while true: |
19 let runtime = (now() - t0).inMilliseconds() | |
20 if runtime > 1500: | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
21 mixer[].setLevel(0.2) |
1225 | 22 if runtime > 3000: |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
23 mixer[].stop(s2) |
1225 | 24 if runtime > 6000: |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
25 mixer[].stop("") |
1225 | 26 if runtime > 8000: |
27 break | |
28 | |
29 proc test2() = | |
30 let | |
31 # notes | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 d2Short = sineSoundData(587.3295, 0.25, 44100) |
1225 | 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 | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
58 mixer[].addSound("frerejaques", frerejaquesData) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
59 discard mixer[].play("frerejaques") |
1225 | 60 |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
61 while mixer[].isPlaying(): |
1225 | 62 sleep(1) |
63 | |
64 proc test3() = | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
65 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
|
66 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
|
67 mixer[].addTrack("effects") |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
68 discard mixer[].play("toccata et fugue") |
1225 | 69 |
70 | |
71 when isMainModule: | |
72 test1() | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
73 mixer[].stop() |
1225 | 74 test2() |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
75 mixer[].stop() |
1225 | 76 test3() |
77 | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
78 while mixer[].isPlaying(): |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
79 discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) |
1225 | 80 # on windows we re-open stdin and this will not work |
81 when defined(linux): | |
82 echo "Press q and enter to exit" | |
83 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
|
84 mixer[].stop() |
1225 | 85 elif defined(windows): |
86 sleep(5) | |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1267
diff
changeset
|
87 mixer[].stop() |