ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
167 lines
7.5 KiB
JavaScript
167 lines
7.5 KiB
JavaScript
class AegoOut extends AudioWorkletProcessor {
|
|
constructor(options) {
|
|
super();
|
|
const o = options.processorOptions;
|
|
this.ch = o.channels;
|
|
this.report = o.report;
|
|
this.shared = !!o.data;
|
|
if (this.shared) {
|
|
this.data = new Float32Array(o.data);
|
|
this.index = new Int32Array(o.index);
|
|
this.mask = this.data.length / this.ch - 1;
|
|
}
|
|
this.blocks = [];
|
|
this.block = null;
|
|
this.at = 0;
|
|
this.primed = false;
|
|
this.queued = 0;
|
|
this.refillAt = o.refillAt || 0;
|
|
this.refillArmed = false;
|
|
this.refillSequence = 0;
|
|
this.refillPending = 0;
|
|
this.consumed = 0;
|
|
this.underruns = 0;
|
|
this.sum = 0;
|
|
this.count = 0;
|
|
this.since = 0;
|
|
this.producer = null;
|
|
this.quiesced = false;
|
|
this.suppressed = 0;
|
|
const enqueue = data => {
|
|
if (!(data instanceof Float32Array) || data.length % this.ch !== 0) throw new Error('invalid audio PCM block');
|
|
this.queued += data.length / this.ch;
|
|
this.blocks.push(data);
|
|
};
|
|
this.port.onmessage = ({data}) => {
|
|
if (data && data.producerPort) {
|
|
if (this.producer) throw new Error('audio producer already attached');
|
|
if (data.quiet !== undefined && typeof data.quiet !== 'boolean') throw new Error('invalid initial audio state');
|
|
this.quiesced = data.quiet === true;
|
|
this.producer = data.producerPort;
|
|
this.producer.onmessage = ({data}) => {
|
|
if (data && Number.isSafeInteger(data.quiesce) && data.quiesce > 0) {
|
|
if (this.quiesced) throw new Error('audio output already quiesced');
|
|
// Producer messages are ordered on this port. Everything
|
|
// before this marker has arrived; discard only that PCM.
|
|
this.quiesced = true;
|
|
this.blocks.length = 0;
|
|
this.block = null;
|
|
this.at = this.queued = 0;
|
|
this.refillArmed = false;
|
|
this.refillPending = 0;
|
|
if (this.shared) Atomics.store(this.index, 0, Atomics.load(this.index, 1));
|
|
// Preserve the counters, including any real underruns
|
|
// since the last periodic page report.
|
|
this.port.postMessage({consumed:this.consumed, time:currentTime, underruns:this.underruns,
|
|
sum:this.sum, count:this.count, quiet:true, quietToken:data.quiesce, suppressed:this.suppressed});
|
|
this.producer.postMessage({quiesced:data.quiesce, consumed:this.consumed});
|
|
} else if (data && Number.isSafeInteger(data.resume) && data.resume > 0) {
|
|
if (!this.quiesced) throw new Error('audio output is not quiesced');
|
|
this.quiesced = false;
|
|
this.port.postMessage({consumed:this.consumed, time:currentTime, underruns:this.underruns,
|
|
sum:this.sum, count:this.count, quiet:false, suppressed:this.suppressed});
|
|
this.producer.postMessage({resumed:data.resume, consumed:this.consumed});
|
|
} else if (data && Number.isSafeInteger(data.refilled) && data.refilled > 0) {
|
|
if (data.refilled === this.refillPending) {
|
|
this.refillPending = 0;
|
|
this.refillArmed = true;
|
|
}
|
|
} else {
|
|
enqueue(data);
|
|
}
|
|
};
|
|
if (this.producer.start) this.producer.start();
|
|
if (this.quiesced) this.port.postMessage({consumed:this.consumed, time:currentTime, underruns:this.underruns,
|
|
sum:this.sum, count:this.count, quiet:true, quietToken:0, suppressed:this.suppressed});
|
|
this.producer.postMessage({ready:true, quiet:this.quiesced});
|
|
} else if (data && typeof data.refillAt === "number") {
|
|
this.refillAt = data.refillAt;
|
|
} else {
|
|
if (this.producer) throw new Error('audio PCM has multiple producers');
|
|
enqueue(data);
|
|
}
|
|
};
|
|
}
|
|
|
|
next() {
|
|
if (this.block && this.at < this.block.length) return true;
|
|
this.block = this.blocks.length ? this.blocks.shift() : null;
|
|
this.at = 0;
|
|
return this.block !== null;
|
|
}
|
|
|
|
process(inputs, outputs) {
|
|
const out = outputs[0];
|
|
const left = out[0];
|
|
const right = out.length > 1 ? out[1] : null;
|
|
const n = left.length;
|
|
if (this.quiesced) {
|
|
// An explicit silent lifecycle state is not an audible underrun.
|
|
// Keep all previous counters and do not consume newly primed PCM.
|
|
left.fill(0);
|
|
if (right) right.fill(0);
|
|
this.suppressed += n;
|
|
return true;
|
|
}
|
|
const ch = this.ch;
|
|
let got = 0;
|
|
let remaining = 0;
|
|
if (this.shared) {
|
|
const head = Atomics.load(this.index, 0);
|
|
const avail = (Atomics.load(this.index, 1) - head) | 0;
|
|
got = Math.min(n, avail);
|
|
for (let f = 0; f < got; f++) {
|
|
const k = ((head + f) & this.mask) * ch;
|
|
const l = this.data[k];
|
|
const r = ch > 1 ? this.data[k + 1] : l;
|
|
left[f] = l;
|
|
if (right) right[f] = r;
|
|
this.sum += l * l + r * r;
|
|
}
|
|
Atomics.store(this.index, 0, (head + got) | 0);
|
|
remaining = avail - got;
|
|
} else {
|
|
while (got < n && this.next()) {
|
|
const b = this.block;
|
|
while (got < n && this.at < b.length) {
|
|
const l = b[this.at];
|
|
const r = ch > 1 ? b[this.at + 1] : l;
|
|
left[got] = l;
|
|
if (right) right[got] = r;
|
|
this.sum += l * l + r * r;
|
|
this.at += ch;
|
|
got++;
|
|
}
|
|
}
|
|
}
|
|
if (!this.shared) remaining = this.queued -= got;
|
|
for (let f = got; f < n; f++) {
|
|
left[f] = 0;
|
|
if (right) right[f] = 0;
|
|
}
|
|
if (got > 0) this.primed = true;
|
|
if (got < n && this.primed) this.underruns++;
|
|
this.consumed += got;
|
|
this.count += got * 2;
|
|
this.since += n;
|
|
// Keep the regular reports. If the producer misses its usual frame,
|
|
// request the next fill before silence, only once per threshold crossing.
|
|
if (remaining > this.refillAt && !this.refillPending) this.refillArmed = true;
|
|
const need = this.refillAt > 0 && this.refillArmed && !this.refillPending && remaining <= this.refillAt;
|
|
if (need) this.refillArmed = false;
|
|
if (this.since >= this.report || need) {
|
|
this.since = 0;
|
|
const report = { consumed: this.consumed, time: currentTime + n / sampleRate, underruns: this.underruns, sum: this.sum, count: this.count };
|
|
if (need && this.producer) {
|
|
this.refillPending = ++this.refillSequence;
|
|
report.refill = this.refillPending;
|
|
}
|
|
this.port.postMessage(report);
|
|
if (this.producer) this.producer.postMessage(report);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
registerProcessor("aego-out", AegoOut);
|