Widget: spectrogram up to 24 kHz by default
2 changed files+5−4
README.mdmodified+1−1View file
@@ -77,7 +77,7 @@ Runs are cached on [artifact-cache](https://artifact-cache.tempory.net) (app `to
7777 <toy-instrument-sim name="crash" exaggeration="5" settings="https://magland.github.io/toy-instruments/#/bead-cymbal?…&preset=0&gpu=1"></toy-instrument-sim>
7878 ```
7979
80-- `settings` is a link from "Copy link to these settings" (or its `#/<instrument>?…` part). `exaggeration` magnifies the drawn motion (default 5; the reader can change it in the motion bar, from ×1 to ×100); it is not part of the cache key. `fmax` sets the top of the spectrogram's frequency axis (default 5000 Hz; the reader can change it). `name` names the downloaded `.wav`.
80+- `settings` is a link from "Copy link to these settings" (or its `#/<instrument>?…` part). `exaggeration` magnifies the drawn motion (default 5; the reader can change it in the motion bar, from ×1 to ×100); it is not part of the cache key. `fmax` sets the top of the spectrogram's frequency axis (default 24000 Hz, capped at half the sample rate; the reader can change it). `name` names the downloaded `.wav`.
8181 - The reader sees the model at rest (the 3D view without its tabs, view buttons or exaggeration input; drag to rotate), the spectrogram of the sound, and two buttons. The light entry is downloaded when the widget comes within 400 px of the viewport, for the spectrogram. "Play sound" plays it in an audio player; "Play motion (N MB)" downloads the frames and plays the replay in slow motion, with pause, a time slider, an exaggeration choice and a speed choice. Each row expands in place, so the other button does not move. On load the widget only sends HEAD requests (for the link's backend first, then the other); the frames are downloaded only for the motion.
8282 - If the cache has no result, or cannot be reached, the widget offers to run the simulation in the browser, with a rough time estimate, and then shows both players. With the cache passcode saved in that browser (under "Shared cache" in the widget), the run is stored under the same key.
8383 - "Open the full app" shows the whole instrument page (every parameter, the plots, Run and Load cached) over the host page, starting from the widget's settings; Close or Escape returns to the post, and reopening keeps its state. It is the bundle's own copy of the page (not the live app in a frame), so it computes the same cache keys as the widget. It has no back link or "Copy link", and leaves the address alone.
src/embed.tsmodified+4−3View file
@@ -21,7 +21,8 @@ import type { SimResult } from './sim/types';
2121 // - exaggeration: how much the motion is magnified in the replay (default 5); the reader
2222 // can change it in the motion bar. It only affects the drawing, so it is not part of the
2323 // cache key.
24-// - fmax: top of the spectrogram's frequency axis in Hz (default 5000); the reader can change it.
24+// - fmax: top of the spectrogram's frequency axis in Hz (default 24000, capped at half the
25+// sample rate); the reader can change it.
2526 // - name: file name of the downloaded .wav (default toy-instrument).
2627 //
2728 // The reader sees the 3D model, the spectrogram of the sound, and "Play sound" and "Play
@@ -316,12 +317,12 @@ class ToyInstrumentSim extends HTMLElement {
316317 }
317318 }
318319
319- // the spectrogram, with a choice of its top frequency (attribute fmax, default 5000 Hz)
320+ // the spectrogram, with a choice of its top frequency (attribute fmax, default 24000 Hz)
320321 private mountSpectrogram() {
321322 this.spec = new Spectrogram(this.q('spec'));
322323 const sel = this.q<HTMLSelectElement>('fmax');
323324 const attr = Number(this.getAttribute('fmax'));
324- const fmax = attr > 0 ? attr : 5000;
325+ const fmax = attr > 0 ? attr : 24000;
325326 const choices = [...new Set([...FMAX_CHOICES, fmax])].sort((a, b) => a - b);
326327 sel.innerHTML = choices.map((v) => `<option value="${v}">${v}</option>`).join('');
327328 sel.value = String(fmax);