nish 0.46.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/AI.md +29 -18
- package/package.json +5 -5
- package/runtime/gfx/README.md +55 -0
- package/runtime/gfx/nish-gfx.c +1063 -0
- package/runtime/gfx/nish-gfx.h +221 -0
- package/runtime/gfx/nish-gfx.overrides.json +14 -0
- package/runtime/nish.d.ts +22 -5
- package/runtime/nish.h +1 -0
- package/runtime/nish.mjs +1 -0
- package/runtime/runtime-bytes.c +167 -7
- package/runtime/runtime-net.c +122 -52
- package/runtime/runtime-uring.c +150 -69
- package/runtime/sqlite/nish-sqlite.c +166 -39
- package/scripts/build.sh +88 -3
- package/std/README.md +2 -2
- package/std/base64.ts +28 -30
- package/std/compress/deflate.ts +1371 -704
- package/std/crypto/aes.ts +81 -45
- package/std/crypto/bcrypt-batch.ts +23 -4
- package/std/crypto/bcrypt.ts +36 -11
- package/std/crypto/chacha20poly1305.ts +93 -52
- package/std/crypto/x25519.ts +7 -4
- package/std/host/game.ts +52 -20
- package/std/host/ring.ts +115 -31
- package/std/host/text.ts +9 -3
- package/std/json.ts +83 -0
- package/std/math.ts +161 -131
- package/std/net/handler.ts +24 -6
- package/std/net/http-server.ts +358 -141
- package/std/net/http1-server.ts +44 -13
- package/std/net/prefork.ts +1 -2
- package/std/net/static.ts +7 -2
- package/std/random.ts +34 -51
- package/std/raster.ts +377 -113
- package/std/regex.ts +46 -15
- package/std/release.ts +19 -13
- package/std/sqlite.ts +380 -16
- package/std/synth.ts +20 -3
- package/std/temporal.ts +740 -363
- package/std/term-io.ts +81 -33
- package/std/term-pixels.ts +287 -112
- package/std/term-probe.ts +7 -3
- package/std/term-rate.ts +142 -66
- package/std/term.ts +782 -406
- package/std/testing.ts +14 -7
package/std/synth.ts
CHANGED
|
@@ -47,7 +47,15 @@ const SYNTH_SAMPLE_LIMIT: f64 = 2147483647.0
|
|
|
47
47
|
*/
|
|
48
48
|
export const synthSilence = (seconds: f64, sampleRate: i32): f64[] => {
|
|
49
49
|
const want: f64 = seconds * toF64(sampleRate)
|
|
50
|
-
|
|
50
|
+
let n: i32 = 1
|
|
51
|
+
if (want >= 1.0 && want < SYNTH_SAMPLE_LIMIT) {
|
|
52
|
+
const k: i32 = toI32(want)
|
|
53
|
+
// Never false: `want` is at least 1 here. The test is what proves the
|
|
54
|
+
// array length is not negative.
|
|
55
|
+
if (k >= 1) {
|
|
56
|
+
n = k
|
|
57
|
+
}
|
|
58
|
+
}
|
|
51
59
|
const out: f64[] = new Array<f64>(n)
|
|
52
60
|
out.fill(0.0)
|
|
53
61
|
return out
|
|
@@ -101,11 +109,19 @@ export const synthTone = (
|
|
|
101
109
|
}
|
|
102
110
|
const from: i32 = toI32(start * rate)
|
|
103
111
|
const n: i32 = toI32(length * rate)
|
|
112
|
+
// Never true: `start` is not negative here. The test is what proves `from + i`
|
|
113
|
+
// stays a sample index.
|
|
114
|
+
if (from < 0) {
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
const size: i32 = toI32(out.length)
|
|
104
118
|
const ratio: f64 = Math.log(f1 / f0)
|
|
105
119
|
let phase: f64 = 0.0
|
|
106
120
|
let noise: i32 = SYNTH_NOISE_SEED
|
|
107
121
|
let held: f64 = 0.0
|
|
108
|
-
|
|
122
|
+
// `at` is `from + i`, counted on its own so the test against `size` bounds it.
|
|
123
|
+
let at: i32 = from
|
|
124
|
+
for (let i: i32 = 0; i < n && at < size; i++) {
|
|
109
125
|
const t: f64 = toF64(i) / rate
|
|
110
126
|
const f: f64 = f0 * Math.exp((ratio * toF64(i)) / toF64(n))
|
|
111
127
|
const before: f64 = phase
|
|
@@ -128,7 +144,8 @@ export const synthTone = (
|
|
|
128
144
|
}
|
|
129
145
|
const attack: f64 = Math.min(t / 0.002, 1.0)
|
|
130
146
|
const release: f64 = Math.min((length - t) / 0.005, 1.0)
|
|
131
|
-
out[
|
|
147
|
+
out[at] = out[at] + v * volume * attack * release * Math.exp(-t * decay)
|
|
148
|
+
at = at + 1
|
|
132
149
|
}
|
|
133
150
|
}
|
|
134
151
|
|