Skip to content

Instantly share code, notes, and snippets.

@shirok
Created November 6, 2021 10:32
Show Gist options
  • Save shirok/7008dbe09942a35df7a75dadd3c05a61 to your computer and use it in GitHub Desktop.
Save shirok/7008dbe09942a35df7a75dadd3c05a61 to your computer and use it in GitHub Desktop.
diff --git a/sanmai.scm b/sanmai.scm
index 5fcc936..773fbaf 100644
--- a/sanmai.scm
+++ b/sanmai.scm
@@ -58,7 +58,7 @@
(de FRAME-RATE 44100)
(de FADE-MS 3)
-(de FRAME/MS (/ FRAME-RATE 1000))
+(de FRAME/MS (/. FRAME-RATE 1000))
(de (ms-to-frames ms)
(* ms FRAME/MS))
@@ -70,7 +70,7 @@
(de WAVE-TABLE-SIZE 11025)
-(de TIMER-RESOLUTION 96)
+(de TIMER-RESOLUTION 96.0)
@@ -101,7 +101,7 @@
;; 60 = sec/min
;; step = frame/beat
;; = rate * 60 / bpm
- (/ RATE*60 bpm))
+ (/. RATE*60 bpm))
@@ -519,7 +519,7 @@
;; ===== Wavetable =====
;; =====================
-(de wave-table-delta (/ 1 WAVE-TABLE-SIZE))
+(de wave-table-delta (/. 1 WAVE-TABLE-SIZE))
(de (create-wave-table f)
(vector-tabulate WAVE-TABLE-SIZE f))
@@ -527,10 +527,10 @@
(de sine-table
(create-wave-table
(lambda (i)
- (sin (* 2.0 math:pi (/ i WAVE-TABLE-SIZE))))))
+ (sin (* 2.0 math:pi (/. i WAVE-TABLE-SIZE))))))
(de sq-table
- (let* ([half (/ WAVE-TABLE-SIZE 2)])
+ (let* ([half (/. WAVE-TABLE-SIZE 2)])
(create-wave-table
(lambda (i)
(if (> i half) 1.0 -1.0)))))
@@ -553,7 +553,7 @@
(de env-table-ed
;; early down
;; m = 1.0 + (log(1) - log(minimum)) / WAVE-TABLE-SIZE
- (let* ([m (expt env-table-minimum (/ 1 WAVE-TABLE-SIZE))]
+ (let* ([m (expt env-table-minimum (/. 1 WAVE-TABLE-SIZE))]
[v 1.0])
(create-wave-table
(lambda (i)
@@ -718,12 +718,10 @@
;; ----- table utils -----
(dm dig-table ([tbl <hash-table>] key)
- (hash-table-ref
- tbl key
- (lambda ()
- (let* ([new (make-hash-table (hash-table-comparator tbl))])
- (set! (ref tbl key) new)
- new))))
+ (or (hash-table-get tbl key #f)
+ (let* ([new (make-hash-table (hash-table-comparator tbl))])
+ (set! (ref tbl key) new)
+ new)))
@@ -775,14 +773,10 @@
(state-of env)
(let* ([current (state-of env)]
[trans (transition-table-of env)]
- [nexts (hash-table-ref
- trans current
- (lambda ()
- (error `(unknown-state, env ,current))))])
- (hash-table-ref
- nexts event
- (lambda ()
- (error `(unknown-transition for ,env from ,current with ,event)))))))
+ [nexts (or (hash-table-get trans current #f)
+ (error `(unknown-state, env ,current)))])
+ (or (hash-table-ref nexts event #f)
+ (error `(unknown-transition for ,env from ,current with ,event))))))
(dm next-state! ([env <env>])
(let* ([next (next-state env (next-event-of env))])
@@ -851,7 +845,7 @@
(set! (atk-amp-of env) (amp-of env)) ;; start from current amp
(set! (atk-dur-of env) atk-dur)
(set! (atk-idx-of env) 0)
- (set! (atk-dlt-of env) (/ WAVE-TABLE-SIZE (max atk-dur 1)))
+ (set! (atk-dlt-of env) (/. WAVE-TABLE-SIZE (max atk-dur 1)))
(set! (atk-dif-of env) (vel-of env)))
;; decay & sustain
(let* ([dcy-dur (ms-to-frames (dcy-len-of env))]
@@ -861,7 +855,7 @@
(set! (sus-amp-of env) sus-vol)
(set! (dcy-dif-of env) (- vel sus-vol))
(set! (dcy-idx-of env) 0)
- (set! (dcy-dlt-of env) (/ WAVE-TABLE-SIZE (max dcy-dur 1))))
+ (set! (dcy-dlt-of env) (/. WAVE-TABLE-SIZE (max dcy-dur 1))))
(set! (next-event-of env) :next))
([:attack]
(let* ([diff (* (atk-dif-of env)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment