comparison tests/test_audio.nim @ 1332:df3c075e5dea

did: formatting
author sam <sam@basx.dev>
date Thu, 22 Aug 2024 18:31:59 +0700
parents e0326aa067c8
children
comparison
equal deleted inserted replaced
1331:1abdd42f5cfe 1332:df3c075e5dea
2 import std/sequtils 2 import std/sequtils
3 import std/times 3 import std/times
4 4
5 import ../semicongine 5 import ../semicongine
6 6
7
8 proc test1() = 7 proc test1() =
9 mixer[].addSound("test1", sineSoundData(1000, 2, 44100)) 8 mixer[].addSound("test1", sineSoundData(1000, 2, 44100))
10 mixer[].addSound("test2", sineSoundData(500, 2, 44100)) 9 mixer[].addSound("test2", sineSoundData(500, 2, 44100))
11
12 10
13 let s1 = mixer[].play("test1", loop = true) 11 let s1 = mixer[].play("test1", loop = true)
14 let s2 = mixer[].play("test2", loop = true) 12 let s2 = mixer[].play("test2", loop = true)
15 13
16 let t0 = now() 14 let t0 = now()
43 c2Short = sineSoundData(523.2511, 0.25, 44100) 41 c2Short = sineSoundData(523.2511, 0.25, 44100)
44 d2Short = sineSoundData(587.3295, 0.25, 44100) 42 d2Short = sineSoundData(587.3295, 0.25, 44100)
45 43
46 # song 44 # song
47 frerejaquesData = concat( 45 frerejaquesData = concat(
48 f, g, a, f, 46 f, g, a, f, f, g, a, f, a, bb, c2, c2, a, bb, c2, c2, c2Short, d2Short, c2Short,
49 f, g, a, f, 47 bbShort, a, f, c2Short, d2Short, c2Short, bbShort, a, f, f, c, f, f, f, c, f, 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 ) 48 )
57 49
58 mixer[].addSound("frerejaques", frerejaquesData) 50 mixer[].addSound("frerejaques", frerejaquesData)
59 discard mixer[].play("frerejaques") 51 discard mixer[].play("frerejaques")
60 52
65 mixer[].addSound("toccata et fugue", loadAudio("toccata_et_fugue.ogg")) 57 mixer[].addSound("toccata et fugue", loadAudio("toccata_et_fugue.ogg"))
66 mixer[].addSound("ping", sineSoundData(500, 0.05, 44100)) 58 mixer[].addSound("ping", sineSoundData(500, 0.05, 44100))
67 mixer[].addTrack("effects") 59 mixer[].addTrack("effects")
68 discard mixer[].play("toccata et fugue") 60 discard mixer[].play("toccata et fugue")
69 61
70
71 when isMainModule: 62 when isMainModule:
72 test1() 63 test1()
73 mixer[].stop() 64 mixer[].stop()
74 test2() 65 test2()
75 mixer[].stop() 66 mixer[].stop()
76 test3() 67 test3()
77 68
78 while mixer[].isPlaying(): 69 while mixer[].isPlaying():
79 # on windows we re-open stdin and this will not work 70 # on windows we re-open stdin and this will not work
80 when defined(linux): 71 when defined(linux):
81 discard mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5) 72 discard
73 mixer[].play("ping", track = "effects", stopOtherSounds = true, level = 0.5)
82 echo "Press q and enter to exit" 74 echo "Press q and enter to exit"
83 if stdin.readLine() == "q": 75 if stdin.readLine() == "q":
84 mixer[].stop() 76 mixer[].stop()
85 elif defined(windows): 77 elif defined(windows):
86 sleep(1000) 78 sleep(1000)