# Rebuild or replace the MP3 encoder

The separately distributed encoder is available at:

`/vendor/lamejs/1.2.7/index.js`

It is the unmodified ESM `dist/lamejs.js` from `@breezystack/lamejs` version
1.2.7. The browser worker loads that URL with a native dynamic import; the
encoder is not compiled into the application worker. Replacing the encoder
does not require rebuilding the application or the worker.

## Obtain and build matching source

Download `lamejs-1.2.7-source.tar.gz` from this directory. It corresponds to
upstream revision `1fb0ef5fa177413107e2e107d054a9b994e3f79c` and has SHA-256:

`af8f08f0ff9a13777f2ffff737b48e40019b53a4b21db270dd62e829574e2b83`

The archive includes the encoder source, `package.json`, lockfile and Vite
build configuration (`pnpm-lock.yaml` uses lock format 6). Extract it into a
directory of your choice, change into its root, and use Node.js with pnpm 8 to
install the locked build dependencies and run the upstream build:

```sh
pnpm install --frozen-lockfile
pnpm run build
```

The ESM output is `dist/lamejs.js`. If changing the encoder, keep its LGPL
notices, record your modifications and make the corresponding modified source
available as required by its license. Dependency download availability and
Node.js compatibility may affect a future rebuild; a new build need not be
byte-identical to the originally published file.

## Interface-compatible replacement

The module must export the named `Mp3Encoder` constructor supporting:

```js
const encoder = new Mp3Encoder(channels, sampleRate, bitrateKbps);
const encoded = encoder.encodeBuffer(pcmInt16Array);
const finalBytes = encoder.flush();
```

This application supplies mono (`channels = 1`) signed 16-bit PCM, the decoded
sample rate, and a target bitrate of 96 kbps. `encodeBuffer` and `flush` return
byte arrays that are appended to the resulting MP3. Preserve this interface
when substituting a modified library.

On a deployment or local copy you control, replace the file served at
`/vendor/lamejs/1.2.7/index.js` with your compatible ESM file. Clear cached
copies, reload the page, and create or upload audio before applying an effect.
You can also use your browser's local response override feature for that exact
URL to test a modified module. Library source changes and replacement are not
restricted by a hash check in the application's import path. Same-origin
loading is used; no third-party CDN account is required.

The LGPL texts and this application's acknowledgement accompany the module
in this directory. These instructions concern the encoder replacement
mechanism and do not grant a new license to unrelated application source.
