Skip to content

Commit

Permalink
Add cab sim example to gui; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
steeelydan committed Aug 27, 2024
2 parents 4bc928c + a11f9de commit bb57fc6
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 10 deletions.
4 changes: 2 additions & 2 deletions compiler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@js2eel/compiler",
"version": "0.11.0",
"version": "0.11.1",
"description": "Write REAPER JSFX/EEL2 plugins in JavaScript",
"engines": {
"node": ">=20.0.0"
Expand Down
4 changes: 2 additions & 2 deletions desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js2eel-desktop",
"version": "0.11.0",
"version": "0.11.1",
"homepage": "https://js2eel.org",
"description": "JS2EEL",
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions gui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@js2eel/gui",
"private": true,
"version": "0.11.0",
"version": "0.11.1",
"engines": {
"node": ">=20.0.0"
},
Expand Down
171 changes: 171 additions & 0 deletions gui/src/components/js2eel/examples/08_cab_sim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
export const EXAMPLE_CAB_SIM = {
path: 'example://cab_sim.js',
src: `config({ description: 'cab_sim', inChannels: 2, outChannels: 2, extTailSize: 32768 });
let fftSize = -1;
let needsReFft = true;
let convolutionSource = new EelBuffer(1, 131072); // 128 * 1024;
let lastAmpModel = -1;
let importedBuffer = new EelBuffer(1, 131072); // 128 * 1024;
let importedBufferChAmount = 0;
let importedBufferSize;
let chunkSize;
let chunkSize2x;
let bufferPosition;
let lastBlock = new EelBuffer(1, 65536); // 64 * 1024
let currentBlock = new EelBuffer(1, 65536); // 64 * 1024
let inverseFftSize;
const interpolationStepCount = 1.0;
let ampModel;
fileSelector(1, ampModel, 'amp_models', 'none', 'Impulse Response');
onSlider(() => {
if (ampModel !== lastAmpModel) {
lastAmpModel = ampModel;
const fileHandle = file_open(ampModel);
let importedBufferSampleRate = 0;
if (fileHandle > 0) {
file_riff(
fileHandle,
importedBufferChAmount,
importedBufferSampleRate
);
if (importedBufferChAmount) {
importedBufferSize =
file_avail(fileHandle) / importedBufferChAmount;
needsReFft = true;
// FIXME multi dim buffer?
file_mem(
fileHandle,
importedBuffer.start(),
importedBufferSize * importedBufferChAmount
);
}
file_close(fileHandle);
}
}
});
onBlock(() => {
if (needsReFft) {
if (importedBufferSize > 16384) {
importedBufferSize = 16384;
}
fftSize = 32;
while (importedBufferSize > fftSize * 0.5) {
fftSize += fftSize;
}
chunkSize = fftSize - importedBufferSize - 1;
chunkSize2x = chunkSize * 2;
bufferPosition = 0;
inverseFftSize = 1 / fftSize;
let i = 0;
let i2 = 0;
let interpolationCounter = 0;
while (interpolationCounter < min(fftSize, importedBufferSize)) {
const ipos = i;
const ipart = i - ipos;
convolutionSource[0][i2] =
importedBuffer[0][ipos * importedBufferChAmount] * (1 - ipart) +
importedBuffer[0][(ipos + 1) * importedBufferChAmount - 1] *
ipart;
convolutionSource[0][i2 + 1] =
importedBuffer[0][ipos * importedBufferChAmount - 1] *
(1 - ipart) +
importedBuffer[0][(ipos + 2) * importedBufferChAmount - 1] *
ipart;
i += interpolationStepCount;
i2 += 2;
interpolationCounter++;
}
let zeroPadCounter = 0;
while (zeroPadCounter < fftSize - importedBufferSize) {
convolutionSource[0][i2] = 0;
convolutionSource[0][i2 + 1] = 0;
i2 += 2;
zeroPadCounter++;
}
fft(convolutionSource.start(), fftSize);
i = 0;
let normalizeCounter = 0;
while (normalizeCounter < fftSize * 2) {
convolutionSource[0][i] *= inverseFftSize;
i += 1;
normalizeCounter++;
}
needsReFft = false;
}
});
onSample(() => {
if (importedBufferSize > 0) {
if (bufferPosition >= chunkSize) {
lastBlock.swap(currentBlock);
memset(
currentBlock.start() + chunkSize * 2,
0,
(fftSize - chunkSize) * 2
);
// Perform FFT on currentBlock, convolve, and perform inverse FFT
fft(currentBlock.start(), fftSize);
convolve_c(
currentBlock.start(),
convolutionSource.start(),
fftSize
);
ifft(currentBlock.start(), fftSize);
bufferPosition = 0;
}
// Save sample
const bufferPosition2x = bufferPosition * 2;
lastBlock[0][bufferPosition2x] = spl0;
lastBlock[0][bufferPosition2x + 1] = 0;
spl0 = currentBlock[0][bufferPosition2x];
spl1 = currentBlock[0][bufferPosition2x + 1];
// Apply overlap-and-add for block continuity
if (bufferPosition < fftSize - chunkSize) {
spl0 += lastBlock[0][chunkSize2x + bufferPosition2x];
spl1 += lastBlock[0][chunkSize2x + bufferPosition2x + 1];
}
bufferPosition += 1;
}
});
`
};
4 changes: 3 additions & 1 deletion gui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EXAMPLE_STEREO_DELAY_JS } from './components/js2eel/examples/04_stereo_
import { EXAMPLE_LOWPASS_JS } from './components/js2eel/examples/05_lowpass';
import { EXAMPLE_SATURATION_JS } from './components/js2eel/examples/06_saturation';
import { EXAMPLE_4BAND_EQ_JS } from './components/js2eel/examples/07_4band_eq';
import { EXAMPLE_CAB_SIM } from './components/js2eel/examples/08_cab_sim';

import type { Js2EelLeftTab, Js2EelRightTab } from './types';

Expand Down Expand Up @@ -34,7 +35,8 @@ export const examples = [
EXAMPLE_STEREO_DELAY_JS,
EXAMPLE_LOWPASS_JS,
EXAMPLE_SATURATION_JS,
EXAMPLE_4BAND_EQ_JS
EXAMPLE_4BAND_EQ_JS,
EXAMPLE_CAB_SIM
];

export const COLORS = {
Expand Down

0 comments on commit bb57fc6

Please sign in to comment.