From 8e8cf7102b6d8ac2d6d30a0acd1de66dbfd87b68 Mon Sep 17 00:00:00 2001 From: Cardeal Russo Date: Wed, 16 Oct 2024 09:26:48 -0300 Subject: [PATCH] Create audio_bytebeats.nim --- examples/audio_bytebeats.nim | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/audio_bytebeats.nim diff --git a/examples/audio_bytebeats.nim b/examples/audio_bytebeats.nim new file mode 100644 index 0000000..83fd793 --- /dev/null +++ b/examples/audio_bytebeats.nim @@ -0,0 +1,51 @@ +import fenstim, fenstim_audio, math + +var + app = init(Fenster, "Bytebeats. Switch with Left Click.", 800, 600, 60) + app_audio = init(FensterAudio) + t, u, currentBeat = 0 + +let byteBeats = [ + proc(x: int): float32 = float32(((((x shr 10) and 42) * x) and 0xff)) / 256.0, + proc(x: int): float32 = float32((x * ((x shr 12 or x shr 8) and 63 and x shr 4)) and 0xff) / 256.0, + proc(x: int): float32 = float32(((not (x shr 2)) * ((127 and x * (7 and x shr 10)) < (245 and x * (2 + (5 and x shr 14)))).int) and 0xff) / 256.0, + proc(x: int): float32 = float32((((x shr 10 xor x shr 11) mod 5 * ((x shr 14 and 3 xor x shr 15 and 1) + 1) * x mod 99 + ((3 + (x shr 14 and 3) - (x shr 16 and 1)) div 3 * x mod 99 and 64))) and 0xff) / 256.0 +] + +let arts = [ + proc(x, y, t: int): uint32 = (x * y * t).uint32, + proc(x, y, t: int): uint32 = ((x xor y xor t) * 65793).uint32, + proc(x, y, t: int): uint32 = (((x * x + y * y + t) and 255) * 0x010101).uint32, + proc(x, y, t: int): uint32 = + ( + let freqX = 0.04 + app.mouse.pos.x / app.width * 0.1 + let freqY = 0.03 + app.mouse.pos.y / app.height * 0.1 + + let plasma = sin(x.float * freqX + 0.1 * t.float) + + sin(y.float * freqY) + + sin((x.float + y.float) * 0.02 + 0.1 * t.float) + + let color = uint32((plasma + 3) * 85) + + result = color shl 16 or (color shl 1) shl 8 or color shl 2 + ), +] + +proc generateAudio(n: int): seq[float32] = + result = newSeq[float32](n) + for i in 0.. 0: + app_audio.write(generateAudio(app_audio.available)) + + for i in 0..