annotate semiconginev2/audio/generators.nim @ 1233:1cf698973dca
did: cleanup tests and old platform layer files
author |
sam <sam@basx.dev> |
date |
Fri, 19 Jul 2024 21:25:42 +0700 |
parents |
27cd1c21290e |
children |
|
rev |
line source |
1225
|
1 proc sinewave(f: float): proc(x: float): float =
|
|
2 proc ret(x: float): float =
|
|
3 sin(x * 2 * Pi * f)
|
|
4 result = ret
|
|
5
|
|
6 proc SineSoundData*(f: float, len: float, rate: int, amplitude = 0.5'f32): SoundData =
|
|
7 let dt = 1'f / float(rate)
|
|
8 var sine = sinewave(f)
|
|
9 for i in 0 ..< int(float(rate) * len):
|
|
10 let t = dt * float(i)
|
|
11 let value = int16(sine(t) * float(high(int16)) * amplitude)
|
|
12 result.add [value, value]
|