Skip to content

Instantly share code, notes, and snippets.

View fuxoft's full-sized avatar
🤡

Frantisek Fuka fuxoft

🤡
View GitHub Profile
@fuxoft
fuxoft / llamadeus.l
Created June 21, 2024 10:03
Terminates after 2 seconds, cannot be stopped using Ctrl+C
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
(scl 12)
(load "@lib/math.l")
(def '2pi (+ pi pi))
# Returns 0.01 for note 69.0, i.e. is hardcoded for 44.1 kHz sample rate
(de noteToStep (Note.)
~(assert (> Note. 0.1))
(*/ (pow 2.0 (*/ 1.0 Note. 12.0)) 0.0001858136117 1.0))
@fuxoft
fuxoft / multiinput.l
Created June 20, 2024 17:59
Multi Input in PicoLisp
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
# date.sh and date2.sh are shell scripts that endlessly generate a line of text every few seconds
(setq In1 (pipe (exec './date.sh)))
(setq In2 (pipe (exec './date2.sh)))
(task In1
(in @ (println 'task1 @ (line T))))
@fuxoft
fuxoft / counting.l
Created June 20, 2024 13:46
PicoLisp IPC counter
#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
(setq Uniq
(pipe
(prog
(zero X)
(loop
(pr (list "unique counter" (inc 'X))) ) ) ) )
(if (fork)
@fuxoft
fuxoft / plcoro.md
Created June 10, 2024 16:56
Self-destruction coroutines

I will try to explain in greater detail what I am trying to achieve and why I thought coroutines would be great for that. (This is a continuation of the previous thread called "Garbage collected coroutines?" which I am unable to reply to.)

I am experimenting with a way to generate musical waveforms using scripts. The script generates random melodies, renders them as tones, mixes those tones together and writes the resulting music to WAV file (or plays it directly using aplay on Linux).

So, the output of my script is a waveform consisting of 48000 samples per second.

Previously I've experimented with this in Lua a Janet where I was able to do the following:

There is an endless loop, let's call it "audio-out" that writes the resulting WAV file to disk (or plays it in semi-realtime).

@fuxoft
fuxoft / audiotest.janet
Created June 10, 2024 15:46
Audio generator using coroutines
# Sound device for Chromebook: hw:CARD=SoundCard,DEV=0
(def sample-rate 48000)
(defn is-generator? [x]
(and (dictionary? x) (x :is-generator)))
(defn- msg-format [args]
(string/join
(map
(fn [thing]

Keybase proof

I hereby claim:

  • I am fuxoft on github.
  • I am fuxoft (https://keybase.io/fuxoft) on keybase.
  • I have a public key whose fingerprint is 2AB6 F924 915E 497D D15D 74D5 DA10 6F1F 0BA0 6F67

To claim this, I am signing this object:

@fuxoft
fuxoft / gensym.janet
Last active September 22, 2023 21:32
gensym at line 30 generates non-unique values in Janet 1.31.0-c31314be
(defn generator
[]
(def factory @{})
(def generator-fun
(fn [output]
(ev/give output :stream-start)
(ev/give output 0)
(ev/give output :stream-end)))
(put factory :generate
(fn [self batch]
#!/usr/bin/env lua5.3
local ALLOWED = {}
for chr in string.gmatch("ABCDEFHIJKLMNOPRSTUVXYZ0123456789",".") do
ALLOWED[chr] = true
end
local SAMOHLASKY = {}
for chr in string.gmatch("AEIOUY",".") do
SAMOHLASKY[chr] = true
@fuxoft
fuxoft / Logitech keys.lua
Last active February 8, 2016 21:22
Logitech keys.lua
function OnEvent (event, arg)
if (event == "G_PRESSED" and arg == 5) then
for num = 0, 9999 do
PressAndReleaseKey ("e")
Sleep(1)
for chr in string.gmatch(string.format("%04d",num),".") do
PressAndReleaseKey(chr)
Sleep(1)
end
if IsModifierPressed("rshift") then
------------------------------------------------
-- Script by PaRaDoX. --
-- http://pokemon-project.com --
------------------------------------------------
local coords = {
ttilde={x=7,y=30},
t1={x=32,y=30},
t2={x=49,y=30},
t3={x=66,y=30},