Skip to content

Commit

Permalink
Life support patch
Browse files Browse the repository at this point in the history
Minor QoL changes
moved the panning algorithm
fixes #71
fixes #67

Should i release v3.22? or wait until write dls is completed?
  • Loading branch information
spessasus committed Oct 30, 2024
1 parent 2493a57 commit 1405096
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 114 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SpessaSynth",
"version": "3.21.13",
"version": "3.21.14",
"type": "module",
"scripts": {
"start": "node src/website/server/server.js"
Expand Down
32 changes: 26 additions & 6 deletions src/spessasynth_lib/synthetizer/synthetizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ export class Synthetizer
processorChannelCount = [32];
}

// check for config data in snapshot
if (startRenderingData?.snapshot?.effectsConfig !== undefined)
{
/**
* @type {EffectsConfig}
*/
this.effectsConfig = startRenderingData.snapshot.effectsConfig;
// remove from config as it can't be cloned
delete startRenderingData.snapshot.effectsConfig;
}
else
{
/**
* @type {EffectsConfig}
*/
this.effectsConfig = effectsConfig;
}

// first two outputs: reverb, chorsu, the others are the channel outputs
try
{
Expand All @@ -143,6 +161,7 @@ export class Synthetizer
}
catch (e)
{
console.error(e);
throw new Error("Could not create the audioWorklet. Did you forget to addModule()?");
}

Expand Down Expand Up @@ -175,18 +194,17 @@ export class Synthetizer
* @type {function(WorkletSequencerReturnMessageType, any)}
*/
this.sequencerCallbackFunction = undefined;

// add reverb
if (effectsConfig.reverbEnabled && !oneOutputMode)
if (this.effectsConfig.reverbEnabled && !oneOutputMode)
{
this.reverbProcessor = getReverbProcessor(this.context, effectsConfig.reverbImpulseResponse);
this.reverbProcessor = getReverbProcessor(this.context, this.effectsConfig.reverbImpulseResponse);
this.reverbProcessor.connect(targetNode);
this.worklet.connect(this.reverbProcessor, 0);
}

if (effectsConfig.chorusEnabled && !oneOutputMode)
if (this.effectsConfig.chorusEnabled && !oneOutputMode)
{
this.chorusProcessor = new FancyChorus(targetNode, effectsConfig.chorusConfig);
this.chorusProcessor = new FancyChorus(targetNode, this.effectsConfig.chorusConfig);
this.worklet.connect(this.chorusProcessor.input, 1);
}

Expand Down Expand Up @@ -361,6 +379,7 @@ export class Synthetizer
this._snapshotCallback = s =>
{
this._snapshotCallback = undefined;
s.effectsConfig = this.effectsConfig;
resolve(s);
};
this.post({
Expand Down Expand Up @@ -821,6 +840,7 @@ export class Synthetizer
setReverbResponse(buffer)
{
this.reverbProcessor.buffer = buffer;
this.effectsConfig.reverbImpulseResponse = buffer;
}

/**
Expand All @@ -829,12 +849,12 @@ export class Synthetizer
*/
setChorusConfig(config)
{
console.log(config);
this.worklet.disconnect(this.chorusProcessor.input);
this.chorusProcessor.delete();
delete this.chorusProcessor;
this.chorusProcessor = new FancyChorus(this.targetNode, config);
this.worklet.connect(this.chorusProcessor.input, 1);
this.effectsConfig.chorusConfig = config;
}

reverbateEverythingBecauseWhyNot()
Expand Down
20 changes: 10 additions & 10 deletions src/spessasynth_lib/synthetizer/worklet_processor.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { applySynthesizerSnapshot, sendSynthesizerSnapshot } from "./worklet_met
import { WorkletSoundfontManager } from "./worklet_methods/worklet_soundfont_manager/worklet_soundfont_manager.js";
import { interpolationTypes } from "./worklet_utilities/wavetable_oscillator.js";
import { getWorkletVoices } from "./worklet_utilities/worklet_voice.js";
import { panVoice } from "./worklet_utilities/stereo_panner.js";


/**
Expand Down Expand Up @@ -144,7 +145,7 @@ class SpessaSynthProcessor extends AudioWorkletProcessor
* the pan of the left channel
* @type {number}
*/
this.panLeft = 0.5 * this.currentGain;
this.panLeft = 0.5;

this.highPerformanceMode = false;

Expand All @@ -158,7 +159,7 @@ class SpessaSynthProcessor extends AudioWorkletProcessor
* the pan of the right channel
* @type {number}
*/
this.panRight = 0.5 * this.currentGain;
this.panRight = 0.5;
try
{
/**
Expand Down Expand Up @@ -445,4 +446,6 @@ SpessaSynthProcessor.prototype.sendPresetList = sendPresetList;
SpessaSynthProcessor.prototype.sendSynthesizerSnapshot = sendSynthesizerSnapshot;
SpessaSynthProcessor.prototype.applySynthesizerSnapshot = applySynthesizerSnapshot;

SpessaSynthProcessor.prototype.panVoice = panVoice;

export { SpessaSynthProcessor };
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export function setMasterPan(pan)
this.pan = pan;
// clamp to 0-1 (0 is left)
pan = (pan / 2) + 0.5;
this.panLeft = (1 - pan) * this.currentGain;
this.panRight = (pan) * this.currentGain;
this.panLeft = (1 - pan);
this.panRight = (pan);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @property {interpolationTypes} interpolation - the synth's interpolation type
* @property {SynthSystem} system - the synths system. Values can be "gs", "gm", "gm2" or "xg"
* @property {number} transposition - the current synth transpositon in semitones. can be a float
* @property {EffectsConfig} effectsConfig - the effects configuration object
*/

import { returnMessageType } from "../message_protocol/worklet_message.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import {
getSampleNearest,
interpolationTypes
} from "../worklet_utilities/wavetable_oscillator.js";
import { panVoice } from "../worklet_utilities/stereo_panner.js";
import { WorkletLowpassFilter } from "../worklet_utilities/lowpass_filter.js";
import { MIN_NOTE_LENGTH } from "../main_processor.js";
import { WorkletVolumeEnvelope } from "../worklet_utilities/volume_envelope.js";
import { generatorTypes } from "../../../soundfont/basic_soundfont/generator.js";
import { customControllers } from "../worklet_utilities/controller_tables.js";


const HALF_PI = Math.PI / 2;
export const PAN_SMOOTHING_FACTOR = 0.05;

/**
Expand Down Expand Up @@ -157,8 +154,6 @@ export function renderVoice(
voice.currentTuningCalculated = Math.pow(2, centsTotal / 1200);
}

// PANNING
const pan = ((Math.max(-500, Math.min(500, voice.modulatedGenerators[generatorTypes.pan])) + 500) / 1000); // 0 to 1

// SYNTHESIS
const bufferOut = new Float32Array(outputLeft.length);
Expand Down Expand Up @@ -189,20 +184,12 @@ export function renderVoice(
// volenv
WorkletVolumeEnvelope.apply(voice, bufferOut, modLfoCentibels, this.volumeEnvelopeSmoothingFactor);

// pan the voice and write out
voice.currentPan += (pan - voice.currentPan) * this.panSmoothingFactor; // smooth out pan to prevent clicking
const panLeft = Math.cos(HALF_PI * voice.currentPan) * this.panLeft;
const panRight = Math.sin(HALF_PI * voice.currentPan) * this.panRight;
// disable reverb and chorus in one output mode
const reverb = this.oneOutputMode ? 0 : voice.modulatedGenerators[generatorTypes.reverbEffectsSend];
const chorus = this.oneOutputMode ? 0 : voice.modulatedGenerators[generatorTypes.chorusEffectsSend];
panVoice(
panLeft,
panRight,
this.panVoice(
voice,
bufferOut,
outputLeft, outputRight,
reverbOutput, reverb,
chorusOutput, chorus
reverbOutput,
chorusOutput
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { generatorTypes } from "../../../soundfont/basic_soundfont/generator.js";

export const WORKLET_SYSTEM_REVERB_DIVIDER = 4600;
export const WORKLET_SYSTEM_CHORUS_DIVIDER = 2000;
const HALF_PI = Math.PI / 2;

/**
* stereo_panner.js
Expand All @@ -8,53 +11,53 @@ export const WORKLET_SYSTEM_CHORUS_DIVIDER = 2000;

/**
* Pans the voice to the given output buffers
* @param gainLeft {number} the left channel gain
* @param gainRight {number} the right channel gain
* @param voice {WorkletVoice} the voice to pan
* @param inputBuffer {Float32Array} the input buffer in mono
* @param outputLeft {Float32Array} left output buffer
* @param outputRight {Float32Array} right output buffer
* @param reverb {Float32Array[]} stereo reverb input
* @param reverbLevel {number} 0 to 1000, the level of reverb to send
* @param chorus {Float32Array[]} stereo chorus buttfer
* @param chorusLevel {number} 0 to 1000, the level of chorus to send
* @param chorus {Float32Array[]} stereo chorus buffer
* @this {SpessaSynthProcessor}
*/
export function panVoice(gainLeft,
gainRight,
export function panVoice(voice,
inputBuffer,
outputLeft, outputRight,
reverb,
reverbLevel,
chorus,
chorusLevel)
chorus)
{
if (isNaN(inputBuffer[0]))
{
return;
}
const pan = ((Math.max(-500, Math.min(500, voice.modulatedGenerators[generatorTypes.pan])) + 500) / 1000); // 0 to 1
voice.currentPan += (pan - voice.currentPan) * this.panSmoothingFactor; // smooth out pan to prevent clicking

const gain = this.currentGain;
// pan the voice and write out
const gainLeft = Math.cos(HALF_PI * voice.currentPan) * gain * this.panLeft;
const gainRight = Math.sin(HALF_PI * voice.currentPan) * gain * this.panRight;
// disable reverb and chorus in one output mode

const reverbLevel = voice.modulatedGenerators[generatorTypes.reverbEffectsSend] / WORKLET_SYSTEM_REVERB_DIVIDER * gain;
const chorusLevel = voice.modulatedGenerators[generatorTypes.chorusEffectsSend] / WORKLET_SYSTEM_CHORUS_DIVIDER;

if (reverbLevel > 0)
if (reverbLevel > 0 && !this.oneOutputMode)
{
const reverbLeft = reverb[0];
const reverbRight = reverb[1];
// cap reverb
reverbLevel = Math.min(reverbLevel, 1000);
const reverbGain = reverbLevel / WORKLET_SYSTEM_REVERB_DIVIDER;
for (let i = 0; i < inputBuffer.length; i++)
{
reverbLeft[i] += reverbGain * inputBuffer[i];
reverbRight[i] += reverbGain * inputBuffer[i];
reverbLeft[i] += reverbLevel * inputBuffer[i];
reverbRight[i] += reverbLevel * inputBuffer[i];
}
}

if (chorusLevel > 0)
if (chorusLevel > 0 && !this.oneOutputMode)
{
const chorusLeft = chorus[0];
const chorusRight = chorus[1];
// cap chorus
chorusLevel = Math.min(chorusLevel, 1000);
const chorusGain = chorusLevel / WORKLET_SYSTEM_CHORUS_DIVIDER;
const chorusLeftGain = gainLeft * chorusGain;
const chorusRightGain = gainRight * chorusGain;
const chorusLeftGain = gainLeft * chorusLevel;
const chorusRightGain = gainRight * chorusLevel;
for (let i = 0; i < inputBuffer.length; i++)
{
chorusLeft[i] += chorusLeftGain * inputBuffer[i];
Expand Down
12 changes: 6 additions & 6 deletions src/website/js/locale/locale_files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ I welcome contributions from translators! To add a new locale, please follow the
- After completing the translation and updates, create a pull request with your changes. Thank you for helping
SpessaSynth!

**If you have any questions about this guide or something is unclear, let me know by opening an issue!**
*If you have any questions about this guide or something is unclear, let me know by opening an issue!*

<!--don't use github !NOTE here as people might open this README in a text editor-->
> **Note:** Strings containing placeholders, like `Channel {0}`, should keep the placeholders intact. They are used for
> formatting and should not be altered.
**Note:** Strings containing placeholders, like `Channel {0}`, should keep the placeholders intact. They are used for
formatting and should not be altered.

> **Note 2:** The code sets `textContent` property, so doing HTMl characters like `&lt;`
> is not needed.
> For new line, use `\n`
**Note 2:** The code sets `textContent` property, so doing HTMl characters like `&lt;`
is not needed.
For new line, use `\n`
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const settingsLocale = {

selectLanguage: {
title: "Language",
description: "Change the program language"
description: "Change the program language",
helpTranslate: "Translate SpessaSynth"
},

layoutDirection: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const settingsLocale = {

selectLanguage: {
title: "Język",
description: "Zmień język programu"
description: "Zmień język programu",
helpTranslate: "Przetłumacz SpessaSynth"
},

layoutDirection: {
Expand Down
7 changes: 7 additions & 0 deletions src/website/js/settings_ui/handlers/interface_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export function _createInterfaceSettingsHandler()
}
select.onchange = () =>
{
if (select.value === "help-translate")
{
window.open(
"https://github.com/spessasus/SpessaSynth/blob/master/src/website/js/locale/locale_files/README.md");
select.value = this.locale.localeCode;
return;
}
this.locale.changeGlobalLocale(select.value);
this._saveSettings();
};
Expand Down
3 changes: 2 additions & 1 deletion src/website/js/settings_ui/settings_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const settingsHtml = `
<div class='switch_label'>
<label translate-path-title='locale.settings.keyboardSettings.show'></label>
<label class='switch'>
<input type="checkbox" checked id="keyboard_show">
<input type='checkbox' checked id='keyboard_show'>
<span class='switch_slider'></span>
</label>
</div>
Expand Down Expand Up @@ -123,6 +123,7 @@ export const settingsHtml = `
<label for='language_selector' translate-path-title='locale.settings.interfaceSettings.selectLanguage'></label>
<select id='language_selector'>
<option value='help-translate' translate-path='locale.settings.interfaceSettings.selectLanguage.helpTranslate'></option>
<!-- will be added via javascript -->
</select>
Expand Down
3 changes: 1 addition & 2 deletions src/website/js/synthesizer_ui/methods/effects_config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { closeNotification, showNotification } from "../../notification/notification.js";
import { showNotification } from "../../notification/notification.js";
import { SpessaSynthInfo } from "../../../../spessasynth_lib/utils/loggin.js";
import { consoleColors } from "../../../../spessasynth_lib/utils/other.js";
import { DEFAULT_CHORUS_CONFIG } from "../../../../spessasynth_lib/synthetizer/audio_effects/fancy_chorus.js";
Expand Down Expand Up @@ -158,7 +158,6 @@ export function showEffectsConfigWindow(locale, path, synth)
"input[setting='freq-var']").value);
USER_CONFIG.oscillatorGain = parseFloat(n.div.querySelector("input[setting='osc-gain']").value);
synth.setChorusConfig(USER_CONFIG);
closeNotification(n.id);
}
}
],
Expand Down
6 changes: 6 additions & 0 deletions src/website/js/synthesizer_ui/methods/synthui_meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* purpose: manages a single visualization meter, handles user changing the value if set to do so
*/

import { isMobile } from "../../utils/is_mobile.js";

/**
* @typedef {Function} MeterCallbackFunction
* @param clickedValue {number} the value, calculated with min and max values
Expand Down Expand Up @@ -126,6 +128,10 @@ export class Meter
this.isActive = true;
this.div.onmousemove(e);
this.isActive = false;
if (isMobile)
{
this.lockMeter();
}
};
this.div.classList.add("editable");
}
Expand Down
Loading

0 comments on commit 1405096

Please sign in to comment.