Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b88df34
lab: add deterministic WASM DSP per-block host profiler with source-h…
Testing7B Nov 17, 2026
a93de55
lab: report output limiting honestly rather than unreachable post-cla…
Testing7B Nov 17, 2026
ca857ae
lab: add measured-cycle budget profiler bridge for strict pi32v2 traces
Testing7B Nov 18, 2026
a6775c6
test: validate host profile provenance and dual-core cycle-budget math
Testing7B Nov 18, 2026
1bd07f5
ci: exercise source-locked BluesBox host DSP benchmark and cycle trac…
Testing7B Nov 18, 2026
291c262
docs: retain exact baseline provenance, emulator limitations and gain…
Testing7B Nov 18, 2026
4f876cb
lab: handle long cycle traces without JS argument-list overflow
Testing7B Nov 18, 2026
1706d48
lab: implement standalone offline browser dashboard for per-slot host…
Testing7B Nov 18, 2026
4a56140
docs: record successful GitHub Actions host execution and browser pro…
Testing7B Nov 18, 2026
8cf5b9a
lab: add unclamped C DSP gain/headroom sweeps across 52 preset paths
Testing7B Nov 18, 2026
8d53b8e
ci: compile exact C engine and collect unclamped pre-output gain sweep
Testing7B Nov 18, 2026
6926d32
docs: record CI-verified native C raw headroom measurements and host …
Testing7B Nov 18, 2026
a778193
lab: add zero-logarithm UI-rate gain-reduction meter core with OFF fa…
Testing7B Nov 18, 2026
7e76bde
test: verify gain reduction meter off skips all conversions and avoid…
Testing7B Nov 18, 2026
013c5bf
ci: verify portable GR meter with zero log10f and fast OFF path
Testing7B Nov 18, 2026
3863043
docs: distinguish implemented GR meter core from pending device UI/se…
Testing7B Nov 18, 2026
bd3f417
docs: distinguish implemented GR meter component from pending firmwar…
Testing7B Nov 18, 2026
5f80232
docs: record portable tested GR meter core and missing latest-firmwar…
Testing7B Nov 18, 2026
bfe06d3
docs: user design brief and implementation/status handoff for DSPL OP…
Testing7B Nov 18, 2026
381ad8f
docs: add iPhone-readable TXT copy of FX container handoff
Testing7B Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/virtual-lab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Virtual Lab Stage A host tests
on:
push:
branches:
- lab/virtual-lab-stage-a-20261118
pull_request:
paths:
- 'tools/lab/**'
- 'tests/virtual-lab.test.mjs'
- 'tests/lab/**'
- 'engine/px_gr_meter.h'
- '.github/workflows/virtual-lab.yml'
jobs:
host-profile:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Check compiler for simulated pedal
run: cc --version
- name: Run source-locked WASM DSP and cycle-budget tests
run: node --test tests/virtual-lab.test.mjs
- name: Profile 52 factory presets (synthetic quiet, nominal, hard)
run: node tools/lab/dsp-profile.mjs --preset all --seconds 0.1 --warmup 0 --out build/lab/dsp-profile.json
- name: Compile real C DSP engine and profile raw pre-limiter output
run: |
mkdir -p build/lab
cc -std=c11 -O2 -fno-builtin -ffp-contract=off -Iengine tests/lab/raw-output.c engine/px_dsp.c firmware/px_math.c -lm -o build/lab/raw-output
build/lab/raw-output 25 > build/lab/raw-output.csv
head -n 5 build/lab/raw-output.csv
- name: Verify UI-rate gain reduction conversion and OFF fast path
run: |
cc -std=c11 -O2 -Wall -Wextra -Iengine tests/lab/gr-meter.c -o build/lab/gr-meter
build/lab/gr-meter
if grep -E '\\blog10f[[:space:]]*\\(' engine/px_gr_meter.h; then echo 'Unexpected log10f in GR meter'; exit 1; fi
- name: Retain test evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: bluesbox-host-profile
path: |
build/lab/dsp-profile.json
build/lab/raw-output.csv
if-no-files-found: warn

Large diffs are not rendered by default.

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions docs/VIRTUAL-LAB-STAGE-A-B.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# BluesBox Virtual Lab — Stage A / Stage B experimental handoff

**Evidence scope:** This branch is based on the inspected public \`Testing7B/bluesbox\` repository,
\`experiment/blues-lab\`, which describes the V52/OpenPocket-era architecture. It is NOT an automatic
merge of the separately delivered BlackBox_978 / BluesBox V 04.2.2 source archive. That newer archive
must be reconciled and inspected locally before making firmware changes.

**Firmware release:** none. No flash image was changed. No device was flashed.

## Run the working-tree host workload profiler

On a Mac with Node 18+ and the exact source-locked WASM engine in this branch:

\`\`\`sh
node --test tests/virtual-lab.test.mjs
node tools/lab/dsp-profile.mjs --preset all --seconds 3 --warmup 0.25 --out build/lab/dsp-profile.json
node tools/lab/dsp-profile.mjs --preset 5 --scenarios quiet,nominal,hard --seconds 10 --out build/lab/slot05.json
\`\`\`

Use \`--input path/to/44k1-mono-16bit.wav\` to process an original DI file instead of synthetic tones.
The WAV path currently accepts 44.1 kHz mono or multichannel 16-bit PCM and reads channel 1. This is
a *model-processing profile*, not a measurement of the AC791N's CPU utilization.

The command refuses to use a compiled WebAssembly engine when its tracked source SHA-256 no longer
matches. Rebuild it with \`node tools/op.mjs wasm\` after editing DSP code; that requires the repository's
cross-compile environment. Never compare a stale binary with a revised source tree.

A profile reports per-preset/scenario block timings (p50, p95, p99, p99.9, maximum), finite output,
output sample peaks and any samples at the wrapper's full-scale output limit. The simulator itself
clamps its output; the counter cannot measure pre-clipping internal DSP headroom.
Do not call these times BlackBox CPU percent.

## Stage B cycle trace contract

Once the AC791N emulator can boot the actual BlackBox image, emit:

\`\`\`json
{
"schema": "bluesbox.target-cycle-trace.v1",
"source_kind": "fm1-emu strict-cycle estimate",
"model": "BlackBox_978",
"blocks": [
{"cpu0_cycles": 12000, "cpu1_cycles": 2400, "deadline_missed": false, "bypass": false}
]
}
\`\`\`

Then use measured device clock/sample rate/block size, not convenient guesses:

\`\`\`sh
node tools/lab/cycle-budget.mjs --trace trace.json --clock-hz 240000000 --rate 44100 --frames 64 --out build/lab/target-budget.json
\`\`\`

The clock/sample-rate/frame counts in this example are illustrative until verified against the
**exact** BlackBox build. CPU0/CPU1 utilization must be reported separately, not blindly added.

**Not implemented yet:** BlackBox-specific board MMIO and codec/DMA integration into fm1-emu;
booting an unchanged BlackBox_978 binary; strict-target cycle trace generation; runtime target
trace correlation with physical 976–978 telemetry. A native host CPU benchmark and a target
cycle-profile converter do not substitute for a whole-firmware emulator.

## GR meter / settings source integration

Requested behavior: on-device gain reduction in the area previously assigned to Bluetooth status,
a persisted Settings on/off switch, and no \`log10f\` conversion or meter refresh when OFF.

**Implemented portable component:** `engine/px_gr_meter.h` converts pre-makeup linear attenuation into integer 0–30 dB at UI rate without logarithms; when OFF, conversion is skipped. The C test verifies 0/6/20/30 dB and 10,000 disabled UI ticks. The component is not yet wired into BlackBox_978's compressor, PLAY display or persistent Settings. Those edits require inspecting the latest firmware source.

Do **not** patch the historical V52 \`firmware/ui.h\` or \`px_settings.h\` as if it were
BlackBox_978. The newer source added Ambience and DSPL LA-2A, and its actual UI storage/ABI
must be inspected before assigning a settings bit. Safe acceptance tests:

1. Disable meter, assert no meter-only conversion work is called during audio callback or UI tick.
2. Enable meter, measure attenuation **before makeup gain**; calculate dB on the UI side from
a small LUT or other inexpensive conversion (not \`log10f\`).
3. Toggle meter repeatedly and require byte-identical compressor audio at identical controls.
4. Check settings persistence, 52 preset storage, and exact 118-byte ABI compatibility.
5. Verify text fits the freed display region, does not mask CPU/bypass alarms, and has a
fallback for compressors without a valid GR signal.
6. Build and run on physical JieLi hardware before promoting.

This is an explicitly **blocked firmware UI edit**, not a fabricated completed revision.

## Next gates

- Reconcile BlackBox_978 source ZIP SHA-256 and exact source with this branch.
- Port the identical complete integrated DSP engine to WASM (all DSPL/OP/OLD models), update
the source lock and parity tests. Avoid substituting old V52 models for new models.
- Add source-level non-clamped peak instrumentation and per-block tracing.
- Port \`fm1-emu\` peripherals/USB/audio for BlackBox and run actual firmware.
- Compare emulated CPU cycles against known-good and failing physical presets.
- Implement GR UI and its global on/off setting on the **correct current firmware source**.

**Qualification:** source-authored and GitHub Actions host tests configured. A GitHub Actions
runner executed the source-locked WASM benchmark and compiled the raw C audio engine successfully against this historical repository
baseline (four tests passed and 156 slot/scenario records, zero non-finite paths, 37 paths
reaching post-limiter full scale). Raw C profile example: factory preset 01 hard fixture generated
peak 1.17835474 before limiter and 134 above-full-scale samples in 25 blocks; its quiet and nominal
fixtures reported no overrange. These are short V52-era synthetic fixtures, not evidence that
the BlackBox_978 integrated DSPL source or firmware was tested. These are V52-era fixtures, not evidence that
the BlackBox_978 integrated DSPL source or firmware was tested. No native JieLi build or actual
BlackBox firmware emulation was performed. This branch is LAB only, with zero hardware claims.
41 changes: 41 additions & 0 deletions engine/px_gr_meter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* SPDX-License-Identifier: GPL-3.0-only
* UI-rate gain reduction display helper for DSPL compressors.
* No log10f, powf, expf, or audio callback work. Must be called by UI tick only.
* Input: actual pre-makeup *linear gain ratio* from compressor, 1.0 means 0 dB GR.
* This is a reusable component; it is NOT wired to the current BlackBox firmware.
*/
#ifndef PX_GR_METER_H
#define PX_GR_METER_H
#include <stdint.h>
typedef struct {
uint8_t enabled; /* 0: no calculations and UI blank */
uint8_t db; /* integer GR 0..30 dB; 30 is >=30 dB */
uint32_t conversions; /* validation counter; can be omitted in firmware-specific implementation */
} px_gr_meter_t;

static inline void px_gr_meter_enable(px_gr_meter_t *m, int on)
{
m->enabled = on ? 1u : 0u;
if (!m->enabled) m->db = 0u;
}
static inline void px_gr_meter_ui_tick(px_gr_meter_t *m, float attenuation_linear)
{
if (!m->enabled) return; /* OFF: no conversion work */
++m->conversions;
/* Reject non-finite/nonphysical states without corrupting the display. */
if (!(attenuation_linear >= 0.0f)) { m->db = 0u; return; }
if (attenuation_linear >= 1.0f) { m->db = 0u; return; }
/* Rounded integer dB: thresholds halfway between whole dB values.
* 10^(-0.5/20) = 0.944060876; 10^(-1/20) = 0.891250938.
* 30 iterations at <=10 Hz UI tick, never per audio sample/block.
*/
float threshold = 0.944060876f;
const float ratio_per_db = 0.891250938f;
unsigned db = 0;
while (db < 30u && attenuation_linear < threshold) {
++db;
threshold *= ratio_per_db;
}
m->db = (uint8_t)db;
}
#endif
32 changes: 32 additions & 0 deletions tests/lab/gr-meter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Pure C verification of the UI-rate GR conversion. Does not validate DSP wiring.
*/
#include <stdio.h>
#include <stdint.h>
#include "px_gr_meter.h"

#define CHECK(c) do { if (!(c)) { fprintf(stderr,"GR meter test failed line %d: %s\n",__LINE__,#c); return 1; } } while (0)
int main(void)
{
px_gr_meter_t m = {0};
for (unsigned i=0;i<10000;i++) px_gr_meter_ui_tick(&m, 0.1f);
CHECK(m.enabled == 0u && m.conversions == 0u && m.db == 0u);
px_gr_meter_enable(&m,1);
px_gr_meter_ui_tick(&m,1.0f);
CHECK(m.db == 0u);
px_gr_meter_ui_tick(&m,0.5011872f);
CHECK(m.db == 6u);
px_gr_meter_ui_tick(&m,0.1f);
CHECK(m.db == 20u);
px_gr_meter_ui_tick(&m,0.001f);
CHECK(m.db == 30u);
px_gr_meter_ui_tick(&m,-1.0f);
CHECK(m.db == 0u);
const uint32_t before = m.conversions;
px_gr_meter_enable(&m,0);
CHECK(m.db == 0u);
for (unsigned i=0;i<10000;i++) px_gr_meter_ui_tick(&m,0.01f);
CHECK(m.conversions == before && m.db == 0u);
puts("GR UI-rate conversion: tested OFF fast-path, 0/6/20/30 dB thresholds and invalid input");
return 0;
}
103 changes: 103 additions & 0 deletions tests/lab/raw-output.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* SPDX-License-Identifier: GPL-3.0-only
* Stage A pre-limiter DSP profiler, using the firmware's own px_engine_process().
* Unlike the browser output, engine output here is NOT clipped to [-1, 1].
* Host timings are NOT measured AC791N cycles.
*
* Build (macOS/Linux):
* cc -std=c11 -O2 -fno-builtin -ffp-contract=off -Iengine \
* tests/lab/raw-output.c engine/px_dsp.c firmware/px_math.c -lm -o build/raw-output
* Run:
* ./build/raw-output 600 > build/raw-output.csv
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "px_dsp.h"

static px_engine E; /* a single engine; compiler and test harness use same source code */
static float in[64], out[64];
static double now_us(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) return -1.0;
return (double)ts.tv_sec * 1000000.0 + (double)ts.tv_nsec * 0.001;
}
static float signal_at(uint64_t n)
{
const double t = (double)n / 44100.0;
const double impact = (n % 22050u) < 180u ? 1.0 : 0.45;
return (float)(impact * (0.68 * sin(2.0 * 3.14159265358979323846 * 110.0 * t) +
0.24 * sin(2.0 * 3.14159265358979323846 * 659.0 * t) +
0.08 * sin(2.0 * 3.14159265358979323846 * 3101.0 * t)));
}
static int compare_double(const void *aa, const void *bb)
{
const double a = *(const double *)aa, b = *(const double *)bb;
return (a > b) - (a < b);
}
static double percentile(const double *samples, unsigned n, double fraction)
{
const double k = (n - 1u) * fraction;
const unsigned lo = (unsigned)k, hi = lo + (lo + 1u < n);
return samples[lo] + (samples[hi] - samples[lo]) * (k - (double)lo);
}
int main(int argc, char **argv)
{
unsigned blocks = 600;
if (argc > 1) {
char *end = NULL;
const unsigned long n = strtoul(argv[1], &end, 10);
if (!end || *end || n < 2u || n > 200000u) {
fprintf(stderr, "blocks must be an integer in [2, 200000]\n");
return 2;
}
blocks = (unsigned)n;
}
double *times = malloc(sizeof(double) * blocks);
if (!times) return 2;
printf("preset,scenario,blocks,preclip_peak,preclip_rms,above_fullscale_samples,nonfinite_samples,host_p99_us,host_p999_us,host_max_us\n");
for (int preset = 0; preset < 52; ++preset) {
for (int scenario = 0; scenario < 3; ++scenario) {
const float level = scenario == 0 ? 0.00015f : scenario == 1 ? 0.15f : 0.8f;
const char *name = scenario == 0 ? "quiet" : scenario == 1 ? "nominal" : "hard";
px_preset_t p;
px_preset_factory(&p, preset);
px_engine_init(&E, 44100.0f);
px_engine_set(&E, &p);
double sum = 0.0, peak = 0.0;
unsigned long long above = 0, nonfinite = 0;
for (unsigned b = 0; b < blocks + 12u; ++b) {
for (unsigned j = 0; j < 64; ++j) {
const uint64_t pos = ((uint64_t)b * 64u) + j;
in[j] = signal_at(pos) * level;
}
const double begin = now_us();
px_engine_process(&E, in, out, 64);
const double end = now_us();
if (begin < 0.0 || end < 0.0) return 3;
if (b < 12u) continue; /* transient warm-up, separate from timed/report windows */
times[b - 12u] = end - begin;
for (unsigned j = 0; j < 64; ++j) {
const double v = out[j], a = fabs(v);
if (!isfinite(v)) { nonfinite++; continue; }
if (a > peak) peak = a;
sum += v * v;
if (a > 1.0) above++;
}
}
qsort(times, blocks, sizeof(*times), compare_double);
printf("%d,%s,%u,%.9g,%.9g,%llu,%llu,%.4f,%.4f,%.4f\n",
preset + 1, name, blocks, peak,
sqrt(sum / (64.0 * (double)blocks)), above, nonfinite,
percentile(times, blocks, 0.99),
percentile(times, blocks, 0.999),
times[blocks - 1u]);
if (nonfinite) { free(times); return 1; }
}
}
free(times);
return 0;
}
44 changes: 44 additions & 0 deletions tests/virtual-lab.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-3.0-only
// Run: node --test tests/virtual-lab.test.mjs
import test from "node:test";
import assert from "node:assert/strict";
import { evaluateCycles } from "../tools/lab/cycle-budget.mjs";
import { profile } from "../tools/lab/dsp-profile.mjs";

const block = (cpu0_cycles, cpu1_cycles, deadline_missed = false, bypass = false) =>
({ cpu0_cycles, cpu1_cycles, deadline_missed, bypass });
test("target cycle conversion observes independent cores and deadline", () => {
const trace = {schema:"bluesbox.target-cycle-trace.v1", model:"synthetic only",
blocks:[block(240000,0), block(120000,360000,true,true), block(0,0)]};
const data = evaluateCycles(trace,{clockHz:240000000,sampleRate:48000,blockFrames:64});
assert.equal(data.cycles_available_per_core_per_block,320000);
assert.equal(data.cpu0.max_cycles,240000);
assert.equal(data.cpu1.max_cycles,360000);
assert.equal(data.core_cycle_budget_exceedance_blocks,1);
assert.equal(data.reported_deadline_misses,1);
assert.equal(data.reported_bypass_blocks,1);
});
test("cycle converter rejects missing data and invented defaults", () => {
const good = {schema:"bluesbox.target-cycle-trace.v1",blocks:[block(0,0)]};
assert.throws(()=>evaluateCycles(good,{clockHz:0,sampleRate:44100,blockFrames:64}));
assert.throws(()=>evaluateCycles({...good,blocks:[{cpu0_cycles:100}]},{clockHz:240000000,sampleRate:44100,blockFrames:64}));
assert.throws(()=>evaluateCycles({...good,schema:"bad"},{clockHz:240000000,sampleRate:44100,blockFrames:64}));
});
test("host benchmark uses actual simulator binary, source lock, and bounded fixtures", () => {
const x=profile({presets:[1],seconds:0.05,warmup:0,scenarios:["quiet","nominal"]});
assert.equal(x.schema,"bluesbox.host-dsp-profile.v1");
assert.equal(x.records.length,2);
assert.equal(x.records[0].target_ac791n_load_percent,null);
assert.equal(x.records[0].target_cpu_cycles,null);
assert.ok(x.engine_source_sha256.length===64);
assert.ok(x.engine_wasm_sha256.length===64);
for(const s of x.records){
assert.ok(s.host_wall_ms.max>=0);
assert.equal(s.nonfinite_samples,0);
assert.ok(s.frames>0);
}
});
test("out-of-range preset and invalid scenario are rejected",()=>{
assert.throws(()=>profile({presets:[53],seconds:.01,warmup:0,scenarios:["quiet"]}));
assert.throws(()=>profile({presets:[1],seconds:.01,warmup:0,scenarios:["unknown"]}));
});
Loading
Loading