Mercurial > games > semicongine
comparison tests/test_audio.nim @ 176:36e10cc04a33
fix: bad audio buffer handling, reduce latency (unbearable on windows)
| author | Sam <sam@basx.dev> | 
|---|---|
| date | Tue, 02 May 2023 02:13:46 +0700 | 
| parents | ceba165f07d8 | 
| children | 88198b0afacc | 
   comparison
  equal
  deleted
  inserted
  replaced
| 175:ac75746f6b36 | 176:36e10cc04a33 | 
|---|---|
| 4 | 4 | 
| 5 import semicongine | 5 import semicongine | 
| 6 | 6 | 
| 7 | 7 | 
| 8 proc test1() = | 8 proc test1() = | 
| 9 mixer[].addSound("test1", newSound(sineSoundData(1000, 2))) | 9 mixer[].addSound("test1", newSound(sineSoundData(1000, 2, 44100))) | 
| 10 mixer[].addSound("test2", newSound(sineSoundData(500, 2))) | 10 mixer[].addSound("test2", newSound(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 | 
| 26 break | 26 break | 
| 27 | 27 | 
| 28 proc test2() = | 28 proc test2() = | 
| 29 let | 29 let | 
| 30 # notes | 30 # notes | 
| 31 c = sineSoundData(261.6256, 0.5) | 31 c = sineSoundData(261.6256, 0.5, 44100) | 
| 32 d = sineSoundData(293.6648, 0.5) | 32 d = sineSoundData(293.6648, 0.5, 44100) | 
| 33 e = sineSoundData(329.6276, 0.5) | 33 e = sineSoundData(329.6276, 0.5, 44100) | 
| 34 f = sineSoundData(349.2282, 0.5) | 34 f = sineSoundData(349.2282, 0.5, 44100) | 
| 35 g = sineSoundData(391.9954, 0.5) | 35 g = sineSoundData(391.9954, 0.5, 44100) | 
| 36 a = sineSoundData(440.0000, 0.5) | 36 a = sineSoundData(440.0000, 0.5, 44100) | 
| 37 b = sineSoundData(493.8833, 0.5) | 37 b = sineSoundData(493.8833, 0.5, 44100) | 
| 38 bb = sineSoundData(466.1638, 0.5) | 38 bb = sineSoundData(466.1638, 0.5, 44100) | 
| 39 c2 = sineSoundData(523.2511, 0.5) | 39 c2 = sineSoundData(523.2511, 0.5, 44100) | 
| 40 d2 = sineSoundData(587.3295, 0.5) | 40 d2 = sineSoundData(587.3295, 0.5, 44100) | 
| 41 bbShort = sineSoundData(466.1638, 0.25) | 41 bbShort = sineSoundData(466.1638, 0.25, 44100) | 
| 42 c2Short = sineSoundData(523.2511, 0.25) | 42 c2Short = sineSoundData(523.2511, 0.25, 44100) | 
| 43 d2Short = sineSoundData(587.3295, 0.25) | 43 d2Short = sineSoundData(587.3295, 0.25, 44100) | 
| 44 | 44 | 
| 45 # song | 45 # song | 
| 46 frerejaquesData = concat( | 46 frerejaquesData = concat( | 
| 47 f, g, a, f, | 47 f, g, a, f, | 
| 48 f, g, a, f, | 48 f, g, a, f, | 
| 68 var sample: Sample | 68 var sample: Sample | 
| 69 readLen = f.readBuffer(addr sample, sizeof(Sample)) | 69 readLen = f.readBuffer(addr sample, sizeof(Sample)) | 
| 70 song.add sample | 70 song.add sample | 
| 71 | 71 | 
| 72 mixer[].addSound("pianosong", newSound(song)) | 72 mixer[].addSound("pianosong", newSound(song)) | 
| 73 mixer[].addSound("ping", newSound(sineSoundData(500, 0.05))) | 73 mixer[].addSound("ping", newSound(sineSoundData(500, 0.05, 44100))) | 
| 74 mixer[].addTrack("effects") | 74 mixer[].addTrack("effects") | 
| 75 discard mixer[].play("pianosong") | 75 discard mixer[].play("pianosong") | 
| 76 | 76 | 
| 77 let t0 = now() | 77 let t0 = now() | 
| 78 while mixer[].isPlaying(): | 78 while mixer[].isPlaying(): | 
