content
notes
2022-08-13-algae-spotted-on-river-sava.md 2023-05-01-cachebusting-in-hugo.md 2023-05-05-run-9front-in-qemu.md 2023-05-06-git-push-multiple-origins.md 2023-05-07-mount-plan9-over-network.md 2023-05-08-write-iso-usb.md 2023-05-09-catv-weechat-config.md 2023-05-10-plan9-screenshot.md 2023-05-11-fix-plan9-bootloader.md 2023-05-12-install-plan9port-linux.md 2023-05-13-download-youtube-videos.md 2023-05-14-convert-mkv.md 2023-05-15-preview-troff-man-pages.md 2023-05-16-mass-set-permission.md 2023-05-22-non-blocking-shell-exec-csharp.md 2023-05-23-extend-lua-with-custom-c.md 2023-05-23-parse-rss-with-lua.md 2023-05-24-fresh-9front-desktop.md 2023-05-25-dcss-new-player-guide.md 2023-05-25-show-xterm-colors.md 2023-05-25-tmux-sane-defaults.md 2023-05-27-cronjobs-github-with-actions.md 2023-05-27-dcss-on-4k-displays.md 2023-05-27-drawing-pixels-in-plan9.md 2023-05-28-easy-time-took-in-bash.md 2023-05-29-grep-to-less-maintain-colors.md 2023-05-31-extending-dte-editor.md 2023-06-01-ewd-manuscripts-ebook.md 2023-06-04-bulk-make-thumbnails.md 2023-06-21-presentations-with-markdown.md 2023-06-24-making-cgit-look-nicer.md 2023-06-25-alacritty-open-links-with-modifier.md 2023-06-25-development-environments-with-nix.md 2023-06-29-10gui-10-finger-multitouch-user-interface.md 2023-06-29-60s-ibm-computers-commercial.md 2023-07-10-fix-screen-tearing-on-debian-12-xorg-and-i3.md 2023-07-10-online-radio-streaming-with-mpv-from-terminal.md 2023-07-14-set-color-temperature-of-displays-on-i3.md 2023-08-01-make-b-w-svg-charts-with-matplotlib.md 2023-09-18-aws-eb-pyyaml-fix.md 2023-09-25-compile-drawterm-on-fedora-38.md 2023-11-04-using-ffmpeg-to-combine-video-side-by-side.md 2023-11-05-add-lazy-loading-to-jekyll-posts.md 2023-11-07-personal-sane-vim-defaults.md 2024-02-15-extract-lines-from-file.md 2024-02-21-dcss-online-rc-defaults.md 2024-02-23-uninstall-ollama-from-a-linux-box.md 2024-06-17-calling-assembly-functions-from-c.md 2024-06-17-sending-signals-to-c-programs.md 2024-06-19-embedding-resources-into-binary-with-c.md 2024-06-22-write-and-read-structs-to-files-in-c.md 2024-09-19-use-option-key-as-meta-macos-alactritty.md 2025-02-26-male-and-female-body-proportion-reference-images.md 2025-03-17-vim-ale-linters.md 2025-04-11-lua-performance-in-different-environments.md 2025-06-30-xfce-alt-to-win.md 2025-07-19-minimal-desktop-with-cwm-and-conky.mdposts
2011-01-13-most-likely-to-succeed-in-year-of-2011.md 2012-03-09-led-technology-not-so-eco.md 2013-10-24-wireless-sensor-networks.md 2015-11-10-software-development-pitfalls.md 2017-03-07-golang-profiling-simplified.md 2017-04-17-what-i-ve-learned-developing-ad-server.md 2017-04-21-profiling-python-web-applications-with-visual-tools.md 2017-08-11-simple-iot-application.md 2018-01-16-using-digitalocean-spaces-object-storage-with-fuse.md 2019-01-03-encoding-binary-data-into-dna-sequence.md 2019-10-14-simplifying-and-reducing-clutter.md 2019-10-19-using-sentiment-analysis-for-clickbait-detection.md 2020-03-22-simple-sse-based-pubsub-server.md 2020-03-27-create-placeholder-images-with-sharp.md 2020-03-29-the-strange-case-of-elasticsearch-allocation-failure.md 2020-03-30-my-love-and-hate-relationship-with-nodejs.md 2020-05-05-remote-work.md 2020-08-15-systemd-disable-wake-onmouse.md 2020-09-06-esp-and-micropython.md 2020-09-08-bind-warning-on-login.md 2020-09-09-digitalocean-sync.md 2021-01-24-replacing-dropbox-with-s3.md 2021-01-25-goaccess.md 2021-06-26-simple-world-clock.md 2021-07-30-from-internet-consumer-to-full-hominum-again.md 2021-08-01-linux-cheatsheet.md 2021-12-03-debian-based-riced-up-distribution-for-developers.md 2021-12-25-running-golang-application-as-pid1.md 2021-12-30-wap-mobile-web-before-the-web.md 2022-06-30-trying-out-helix-editor.md 2022-07-05-what-would-dna-sound-if-synthesized.md 2022-10-06-state-of-web-technologies-in-year-2022.md 2022-10-16-that-sound-that-machine-makes-when-struggling.md 2023-01-26-trying-to-build-a-new-kind-of-terminal-emulator.md 2023-05-16-rekindling-my-love-for-programming.md 2023-05-23-i-was-wrong-about-git-workflows.md 2023-05-31-re-inventing-task-runner-that-i-actually-used-daily.md 2023-07-01-bringing-all-of-my-projects-together-under-one-umbrella.md 2023-07-08-who-knows-what-the-world-will-look-like-tomorrow.md 2023-11-05-elitist-attitudes-are-sapping-the-fun-from-programming.md 2024-02-11-k-mer.md 2024-02-28-converting-valgrind-callgrinds-to-svg-format.md 2024-03-10-the-abysmal-state-of-linux-in-the-year-2024.md 2024-03-10-using-custom-software-with-github-actions-to-deploy-a-site.md 2024-03-14-configuration-and-plugin-hell-and-why-i-dont-use-vim-and-tmux-anymore.md 2025-04-08-embedding-game-assets-within-your-binary.md 2026-01-09-vim.md 2026-01-14-change-default-applications-on-linux.md 2026-01-15-using-address-sanitizer-with-clang.mdstatic
assets
notes
10gui-10-finger-multitouch-user-interface.jpg 10gui-10-finger-multitouch-user-interface.mp4 60s-ibm-computers-commercial.jpg 60s-ibm-computers-commercial.mp4 9front-desktop.png asm64-handout.pdf cwm.png dcss-quickstart.pdf dcss.jpg dcss_manual.pdf embedding-assets.png embedding-binary-data.tar.xz embedding-window.png female-body-proportions.jpg grep-less.png male-body-proportions.jpg plan9-pixels.png plot.svg ps1-prompt.png trigraphs.gif xterm-palette.pngposts
algae-sava
dji-algae-0.jpg dji-algae-1.jpg dji-algae-2.jpg dji-algae-3.jpg dji-algae-4.jpg dji-algae-5.jpgdfd-rice
desktop.png install-00.png install-01.png install-02.png install-03.png install-04.png install-05.png installation.svg layout.png layout.svg script.pngdna-sequence
benchmarks.csv chart-size.py chart-size.svg chart-speed.py chart-speed.svg dna-basics.jpg quote.png sample-binary-file.png sample.pnggodot-dynamic-tile-loading
example1
index.apple-touch-icon.png index.audio.worklet.js index.html index.icon.png index.js index.pck index.png index.wasmiot-application
iot-app-output.png iot-rest-example.png iot-sqlite-db.png kcachegrind.png profiling-viewer.png simple-iot-application-overview.svg simple-iot-application.zip snakeviz.pngprojects
ClassicEnhanced-v1.0.0.tar.gz ClassicEnhanced-v1.0.1.tar.gz TurtleTweaks-v0.1.tar.gz TurtleTweaks-v0.2.tar.gz TurtleTweaks-v0.3.tar.gz TurtleTweaks-v0.4.tar.gz TurtleTweaks-v0.5.1.tar.gz TurtleTweaks-v0.5.tar.gz TurtleTweaks-v0.6.tar.gz TurtleTweaks-v0.7.tar.gz abtts-v0.1.tar.gz abtts-v0.2.tar.gz abtts-v0.3.tar.gz blpconvert-v1.0.tar.gz clutch-v1.0.tar.gz jbmafp-v0.1.tar.gz jbmafp-v0.2.tar.gz jbmafp-v0.3.tar.gz lazycommit-v1.0.tar.gz makext-v1.0.tar.gz mprogress-v1.0.tar.gz newsbarge-v0.1.tar.gz oberon-v1.0.tar.gz p9tree-v1.0.tar.gz pats-v1.0.tar.gz pats.fossil rssperado-v1.0.tar.gz sm-v1.0.tar.gz sparklines-v1.0.tar.gz ttdaw-v0.1.tar.gz xmagnify-v1.0.tar.gz xmagnify.fossiltemplates
.gitkeep 404.html base.html bookmarks.html feed.xml index.html note.html page-no-title.html page.html post.html robots.txt sitemap.xml
static/assets/posts/godot-dynamic-tile-loading/example1/index.audio.worklet.js
raw
1/*************************************************************************/
2/* audio.worklet.js */
3/*************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/*************************************************************************/
8/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
9/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/*************************************************************************/
30
31class RingBuffer {
32 constructor(p_buffer, p_state, p_threads) {
33 this.buffer = p_buffer;
34 this.avail = p_state;
35 this.threads = p_threads;
36 this.rpos = 0;
37 this.wpos = 0;
38 }
39
40 data_left() {
41 return this.threads ? Atomics.load(this.avail, 0) : this.avail;
42 }
43
44 space_left() {
45 return this.buffer.length - this.data_left();
46 }
47
48 read(output) {
49 const size = this.buffer.length;
50 let from = 0;
51 let to_write = output.length;
52 if (this.rpos + to_write > size) {
53 const high = size - this.rpos;
54 output.set(this.buffer.subarray(this.rpos, size));
55 from = high;
56 to_write -= high;
57 this.rpos = 0;
58 }
59 if (to_write) {
60 output.set(this.buffer.subarray(this.rpos, this.rpos + to_write), from);
61 }
62 this.rpos += to_write;
63 if (this.threads) {
64 Atomics.add(this.avail, 0, -output.length);
65 Atomics.notify(this.avail, 0);
66 } else {
67 this.avail -= output.length;
68 }
69 }
70
71 write(p_buffer) {
72 const to_write = p_buffer.length;
73 const mw = this.buffer.length - this.wpos;
74 if (mw >= to_write) {
75 this.buffer.set(p_buffer, this.wpos);
76 this.wpos += to_write;
77 if (mw === to_write) {
78 this.wpos = 0;
79 }
80 } else {
81 const high = p_buffer.subarray(0, mw);
82 const low = p_buffer.subarray(mw);
83 this.buffer.set(high, this.wpos);
84 this.buffer.set(low);
85 this.wpos = low.length;
86 }
87 if (this.threads) {
88 Atomics.add(this.avail, 0, to_write);
89 Atomics.notify(this.avail, 0);
90 } else {
91 this.avail += to_write;
92 }
93 }
94}
95
96class GodotProcessor extends AudioWorkletProcessor {
97 constructor() {
98 super();
99 this.threads = false;
100 this.running = true;
101 this.lock = null;
102 this.notifier = null;
103 this.output = null;
104 this.output_buffer = new Float32Array();
105 this.input = null;
106 this.input_buffer = new Float32Array();
107 this.port.onmessage = (event) => {
108 const cmd = event.data['cmd'];
109 const data = event.data['data'];
110 this.parse_message(cmd, data);
111 };
112 }
113
114 process_notify() {
115 if (this.notifier) {
116 Atomics.add(this.notifier, 0, 1);
117 Atomics.notify(this.notifier, 0);
118 }
119 }
120
121 parse_message(p_cmd, p_data) {
122 if (p_cmd === 'start' && p_data) {
123 const state = p_data[0];
124 let idx = 0;
125 this.threads = true;
126 this.lock = state.subarray(idx, ++idx);
127 this.notifier = state.subarray(idx, ++idx);
128 const avail_in = state.subarray(idx, ++idx);
129 const avail_out = state.subarray(idx, ++idx);
130 this.input = new RingBuffer(p_data[1], avail_in, true);
131 this.output = new RingBuffer(p_data[2], avail_out, true);
132 } else if (p_cmd === 'stop') {
133 this.running = false;
134 this.output = null;
135 this.input = null;
136 } else if (p_cmd === 'start_nothreads') {
137 this.output = new RingBuffer(p_data[0], p_data[0].length, false);
138 } else if (p_cmd === 'chunk') {
139 this.output.write(p_data);
140 }
141 }
142
143 static array_has_data(arr) {
144 return arr.length && arr[0].length && arr[0][0].length;
145 }
146
147 process(inputs, outputs, parameters) {
148 if (!this.running) {
149 return false; // Stop processing.
150 }
151 if (this.output === null) {
152 return true; // Not ready yet, keep processing.
153 }
154 const process_input = GodotProcessor.array_has_data(inputs);
155 if (process_input) {
156 const input = inputs[0];
157 const chunk = input[0].length * input.length;
158 if (this.input_buffer.length !== chunk) {
159 this.input_buffer = new Float32Array(chunk);
160 }
161 if (!this.threads) {
162 GodotProcessor.write_input(this.input_buffer, input);
163 this.port.postMessage({ 'cmd': 'input', 'data': this.input_buffer });
164 } else if (this.input.space_left() >= chunk) {
165 GodotProcessor.write_input(this.input_buffer, input);
166 this.input.write(this.input_buffer);
167 } else {
168 this.port.postMessage('Input buffer is full! Skipping input frame.');
169 }
170 }
171 const process_output = GodotProcessor.array_has_data(outputs);
172 if (process_output) {
173 const output = outputs[0];
174 const chunk = output[0].length * output.length;
175 if (this.output_buffer.length !== chunk) {
176 this.output_buffer = new Float32Array(chunk);
177 }
178 if (this.output.data_left() >= chunk) {
179 this.output.read(this.output_buffer);
180 GodotProcessor.write_output(output, this.output_buffer);
181 if (!this.threads) {
182 this.port.postMessage({ 'cmd': 'read', 'data': chunk });
183 }
184 } else {
185 this.port.postMessage('Output buffer has not enough frames! Skipping output frame.');
186 }
187 }
188 this.process_notify();
189 return true;
190 }
191
192 static write_output(dest, source) {
193 const channels = dest.length;
194 for (let ch = 0; ch < channels; ch++) {
195 for (let sample = 0; sample < dest[ch].length; sample++) {
196 dest[ch][sample] = source[sample * channels + ch];
197 }
198 }
199 }
200
201 static write_input(dest, source) {
202 const channels = source.length;
203 for (let ch = 0; ch < channels; ch++) {
204 for (let sample = 0; sample < source[ch].length; sample++) {
205 dest[sample * channels + ch] = source[ch][sample];
206 }
207 }
208 }
209}
210
211registerProcessor('godot-processor', GodotProcessor);