tetorica-fm2612 0.2.3 → 0.2.4

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/README.md CHANGED
@@ -232,10 +232,10 @@ FM/PSG/PCM mixing, stop/reset and close/restart. Playwright is a development
232
232
  dependency; it is not required by users of the sound-chip runtime.
233
233
 
234
234
  The build is staged in `dist/fm2612/`; packing produces
235
- `tetorica-fm2612-0.2.3.tgz`. To install a local build in another project:
235
+ `tetorica-fm2612-0.2.4.tgz`. To install a local build in another project:
236
236
 
237
237
  ```sh
238
- npm install /absolute/path/to/tetorica-fm2612-0.2.3.tgz
238
+ npm install /absolute/path/to/tetorica-fm2612-0.2.4.tgz
239
239
  ```
240
240
 
241
241
  The existing `tetorica-vgm` CLI package is built separately. This first package
@@ -251,6 +251,11 @@ and generator. External instrument/sample ROMs are not included.
251
251
 
252
252
  ## Release notes
253
253
 
254
+ `0.2.4` removes the ymfm YM2612 DAC ladder's idle offset from AudioWorklet
255
+ output and keeps output silent until FM/PSG initialization completes. This
256
+ reduces clicks when browser audio starts or disconnects. Raw chip PCM remains
257
+ unchanged.
258
+
254
259
  `0.2.3` adds common `encodeWav()` for mono/stereo PCM16 WAV bytes and fixes
255
260
  default browser/Worker `createSoundChip()` loading by reading WASM internally.
256
261
  Node and browsers use the same chip creation and WAV encoding API; output
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tetorica-fm2612",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Tetorica sound chip WASM cores, Synth helpers and browser audio runtime",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
package/ym2612-worklet.js CHANGED
@@ -32,9 +32,12 @@ class YM2612Processor extends AudioWorkletProcessor {
32
32
 
33
33
  this.ym2612 = null;
34
34
  this.psg = null;
35
+ this.initializing = false;
35
36
  this.resampleRemainder = 0;
36
37
  this.lastLeft = 0;
37
38
  this.lastRight = 0;
39
+ this.idleLeft = 0;
40
+ this.idleRight = 0;
38
41
  this.pendingCommands = [];
39
42
  this.scheduledCommands = [];
40
43
  this.scheduledHead = 0;
@@ -73,6 +76,7 @@ class YM2612Processor extends AudioWorkletProcessor {
73
76
  }
74
77
 
75
78
  async init(wasmBinary, psgWasmBinary) {
79
+ this.initializing = true;
76
80
  try {
77
81
  this.ym2612 = await createYm2612(
78
82
  ym2612ModuleFactory,
@@ -115,11 +119,20 @@ class YM2612Processor extends AudioWorkletProcessor {
115
119
  this.ym2612.reserveStereoFrames(capacity);
116
120
  this.psg?.reserveStereoFrames(capacity);
117
121
 
122
+ // ymfm models the YM2612 DAC ladder's nonzero idle level. Keep that
123
+ // behavior in the raw chip API, but center browser output on silence:
124
+ // connecting/disconnecting a constant DC level otherwise makes a click.
125
+ const idle = this.ym2612.generateStereoView(1);
126
+ this.idleLeft = idle.left[0];
127
+ this.idleRight = idle.right[0];
128
+ this.ym2612.reset();
129
+
118
130
  for (const command of this.pendingCommands) {
119
131
  this.applyCommand(command);
120
132
  }
121
133
 
122
134
  this.pendingCommands.length = 0;
135
+ this.initializing = false;
123
136
 
124
137
  this.port.postMessage({
125
138
  type: "ready",
@@ -250,7 +263,7 @@ class YM2612Processor extends AudioWorkletProcessor {
250
263
  const leftOut = output[0];
251
264
  const rightOut = output[1];
252
265
 
253
- if (!this.ym2612) {
266
+ if (!this.ym2612 || this.initializing) {
254
267
  leftOut.fill(0);
255
268
  rightOut.fill(0);
256
269
  return true;
@@ -364,8 +377,10 @@ class YM2612Processor extends AudioWorkletProcessor {
364
377
  if (count > 0) {
365
378
  let left = 0, right = 0;
366
379
  for (let j = 0; j < count; j++, sourceOffset++) {
367
- left += psg ? clampSample(pcm.left[sourceOffset] * YM_GAIN + psg.left[sourceOffset] * PSG_GAIN) : pcm.left[sourceOffset];
368
- right += psg ? clampSample(pcm.right[sourceOffset] * YM_GAIN + psg.right[sourceOffset] * PSG_GAIN) : pcm.right[sourceOffset];
380
+ const fmLeft = pcm.left[sourceOffset] - this.idleLeft;
381
+ const fmRight = pcm.right[sourceOffset] - this.idleRight;
382
+ left += psg ? clampSample(fmLeft * YM_GAIN + psg.left[sourceOffset] * PSG_GAIN) : fmLeft;
383
+ right += psg ? clampSample(fmRight * YM_GAIN + psg.right[sourceOffset] * PSG_GAIN) : fmRight;
369
384
  }
370
385
  this.lastLeft = left / count;
371
386
  this.lastRight = right / count;