annotate semiconginev2/audio/generators.nim @ 1247:c15770761865

add: gltf loading test, gltf loading for materials
author sam <sam@basx.dev>
date Wed, 24 Jul 2024 23:26:34 +0700
parents 27cd1c21290e
children
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 proc sinewave(f: float): proc(x: float): float =
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
2 proc ret(x: float): float =
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
3 sin(x * 2 * Pi * f)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
4 result = ret
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
5
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
6 proc SineSoundData*(f: float, len: float, rate: int, amplitude = 0.5'f32): SoundData =
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
7 let dt = 1'f / float(rate)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
8 var sine = sinewave(f)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
9 for i in 0 ..< int(float(rate) * len):
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
10 let t = dt * float(i)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
11 let value = int16(sine(t) * float(high(int16)) * amplitude)
27cd1c21290e did: refactor resources
sam <sam@basx.dev>
parents:
diff changeset
12 result.add [value, value]