annotate tests/test_audio.nim @ 1276:b5fb00760162

del: unused script
author sam <sam@basx.dev>
date Mon, 29 Jul 2024 12:22:58 +0700
parents 4cf9872f7bb6
children 3308b88e53a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1225
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
1 import std/os
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
2 import std/sequtils
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
3 import std/times
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
4
1267
4cf9872f7bb6 did: rename back to old name (no v2)
sam <sam@basx.dev>
parents: 1225
diff changeset
5 import ../semicongine
1225
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
6
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
7
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
8 proc test1() =
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
9 mixer[].AddSound("test1", SineSoundData(1000, 2, 44100))
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
10 mixer[].AddSound("test2", SineSoundData(500, 2, 44100))
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
11
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
12
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
13 let s1 = mixer[].Play("test1", loop = true)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
14 let s2 = mixer[].Play("test2", loop = true)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
15
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
16 let t0 = now()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
17 mixer[].SetLevel(0.5)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
18 while true:
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
19 let runtime = (now() - t0).inMilliseconds()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
20 if runtime > 1500:
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
21 mixer[].SetLevel(0.2)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
22 if runtime > 3000:
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
23 mixer[].Stop(s2)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
24 if runtime > 6000:
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
25 mixer[].Stop("")
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
26 if runtime > 8000:
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
27 break
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
28
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
29 proc test2() =
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
30 let
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
31 # notes
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
32 c = SineSoundData(261.6256, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
33 d = SineSoundData(293.6648, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
34 e = SineSoundData(329.6276, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
35 f = SineSoundData(349.2282, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
36 g = SineSoundData(391.9954, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
37 a = SineSoundData(440.0000, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
38 b = SineSoundData(493.8833, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
39 bb = SineSoundData(466.1638, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
40 c2 = SineSoundData(523.2511, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
41 d2 = SineSoundData(587.3295, 0.5, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
42 bbShort = SineSoundData(466.1638, 0.25, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
43 c2Short = SineSoundData(523.2511, 0.25, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
44 d2Short = SineSoundData(587.3295, 0.25, 44100)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
45
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
46 # song
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
47 frerejaquesData = concat(
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
48 f, g, a, f,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
49 f, g, a, f,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
50 a, bb, c2, c2,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
51 a, bb, c2, c2,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
52 c2Short, d2Short, c2Short, bbShort, a, f,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
53 c2Short, d2Short, c2Short, bbShort, a, f,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
54 f, c, f, f,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
55 f, c, f, f,
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
56 )
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
57
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
58 mixer[].AddSound("frerejaques", frerejaquesData)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
59 discard mixer[].Play("frerejaques")
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
60
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
61 while mixer[].IsPlaying():
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
62 sleep(1)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
63
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
64 proc test3() =
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
65 mixer[].AddSound("toccata et fugue", LoadAudio("toccata_et_fugue.ogg"))
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
66 mixer[].AddSound("ping", SineSoundData(500, 0.05, 44100))
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
67 mixer[].AddTrack("effects")
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
68 discard mixer[].Play("toccata et fugue")
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
69
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
70
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
71 when isMainModule:
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
72 test1()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
73 mixer[].Stop()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
74 test2()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
75 mixer[].Stop()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
76 test3()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
77
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
78 while mixer[].IsPlaying():
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
79 discard mixer[].Play("ping", track = "effects", stopOtherSounds = true, level = 0.5)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
80 # on windows we re-open stdin and this will not work
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
81 when defined(linux):
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
82 echo "Press q and enter to exit"
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
83 if stdin.readLine() == "q":
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
84 mixer[].Stop()
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
85 elif defined(windows):
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
86 sleep(5)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
87 mixer[].Stop()