Mercurial > games > semicongine
annotate tests/test_audio.nim @ 632:42ad7e6208e9
add: audio subsystem, windows backend still missing
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 01 May 2023 23:55:07 +0700 |
parents | a68941309f22 |
children | 36e10cc04a33 |
rev | line source |
---|---|
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
1 import std/os |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/sequtils |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/times |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 import semicongine |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
7 |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 proc test1() = |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
9 mixer[].addSound("test1", newSound(sineSoundData(1000, 2))) |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
10 mixer[].addSound("test2", newSound(sineSoundData(500, 2))) |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
13 let s1 = mixer[].play("test1", loop=true) |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
14 let s2 = mixer[].play("test2", loop=true) |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 let t0 = now() |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 while true: |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 let runtime = (now() - t0).inMilliseconds() |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 if runtime > 1500: |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
20 mixer[].setLevel(0.1) |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 if runtime > 3000: |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
22 mixer[].stop(s2) |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 if runtime > 6000: |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
24 mixer[].stop("") |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 if runtime > 8000: |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 break |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 proc test2() = |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 let |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 # notes |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 c = sineSoundData(261.6256, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 d = sineSoundData(293.6648, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 e = sineSoundData(329.6276, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 f = sineSoundData(349.2282, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 g = sineSoundData(391.9954, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
36 a = sineSoundData(440.0000, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 b = sineSoundData(493.8833, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 bb = sineSoundData(466.1638, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 c2 = sineSoundData(523.2511, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
40 d2 = sineSoundData(587.3295, 0.5) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
41 bbShort = sineSoundData(466.1638, 0.25) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
42 c2Short = sineSoundData(523.2511, 0.25) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
43 d2Short = sineSoundData(587.3295, 0.25) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
44 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 # song |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 frerejaquesData = concat( |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
47 f, g, a, f, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
48 f, g, a, f, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
49 a, bb, c2, c2, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
50 a, bb, c2, c2, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
51 c2Short, d2Short, c2Short, bbShort, a, f, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 c2Short, d2Short, c2Short, bbShort, a, f, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
53 f, c, f, f, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
54 f, c, f, f, |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
55 ) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
57 mixer[].addSound("frerejaques", newSound(frerejaquesData)) |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
58 discard mixer[].play("frerejaques") |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
59 |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
60 while mixer[].isPlaying(): |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
61 sleep(1) |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
63 proc test3() = |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 var song: SoundData |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
65 var f = open("tests/audiotest.PCM.s16le.48000.2") |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 var readLen = 999 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 while readLen > 0: |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
68 var sample: Sample |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
69 readLen = f.readBuffer(addr sample, sizeof(Sample)) |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
70 song.add sample |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
71 |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
72 mixer[].addSound("pianosong", newSound(song)) |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
73 mixer[].addSound("ping", newSound(sineSoundData(500, 0.05))) |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
74 mixer[].addTrack("effects") |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
75 discard mixer[].play("pianosong") |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 let t0 = now() |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
78 while mixer[].isPlaying(): |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
79 discard mixer[].play("ping", track="effects", stopOtherSounds=true, level=0.5) |
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
80 var input = stdin.readLine() |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 |
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 when isMainModule: |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
83 startMixerThread() |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
84 test1() |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
85 mixer[].stop() |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
86 test2() |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
87 mixer[].stop() |
630
a68941309f22
add: audio test, be aware that the file tests/audiotest.PCM.s16le.48000.2 needs to be manually generated and placed in order for the test to play it successfully
Sam <sam@basx.dev>
parents:
diff
changeset
|
88 test3() |
632
42ad7e6208e9
add: audio subsystem, windows backend still missing
Sam <sam@basx.dev>
parents:
630
diff
changeset
|
89 mixer[].stop() |