Skip to content

Commit

Permalink
Added time adjustment for large FFT sizes in renderer
Browse files Browse the repository at this point in the history
added wave sign for inverting the waveform
updated min db to be more aggressive
  • Loading branch information
spessasus committed Aug 31, 2024
1 parent 1d347f1 commit db3933d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion 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 @@ -9,7 +9,7 @@ import { generatorTypes } from '../../../soundfont/read_sf2/generators.js'
export const VOLUME_ENVELOPE_SMOOTHING_FACTOR = 0.001;

const DB_SILENCE = 100;
const PERCEIVED_DB_SILENCE = 96;
const PERCEIVED_DB_SILENCE = 80;

/**
* VOL ENV STATES:
Expand Down
11 changes: 9 additions & 2 deletions src/website/js/renderer/channel_analysers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ export function updateFftSize()
{
const drum = this.synth.channelProperties[i].isDrum;
const fft = drum ? this._drumAnalyserFft : this._normalAnalyserFft;
const mul = drum ? STABILIZE_WAVEFORMS_FFT_MULTIPLIER / 2 : STABILIZE_WAVEFORMS_FFT_MULTIPLIER
this.channelAnalysers[i].fftSize = Math.min(32768, this._stabilizeWaveforms ? fft * mul : fft);
const mul = drum ? STABILIZE_WAVEFORMS_FFT_MULTIPLIER / 2 : STABILIZE_WAVEFORMS_FFT_MULTIPLIER;
const fftSize = Math.min(32768, this._stabilizeWaveforms ? fft * mul : fft);
this.channelAnalysers[i].fftSize = fftSize;
if(!drum)
{
// calculate delay:
// 16384 fft size = 0.1 s
this.delayNode.delayTime.value = fftSize / 16384 * 0.1
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/website/js/renderer/render_waveforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function renderWaveforms()

const relativeX = waveWidth * x;
const relativeY = waveHeight * y + waveHeight / 2;
const multiplier = this.waveMultiplier * waveHeight;
const multiplier = this.waveMultiplier * waveHeight * this.waveSign;

// draw
this.drawingContext.lineWidth = this.lineThickness;
Expand Down
5 changes: 4 additions & 1 deletion src/website/js/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class Renderer
* @param channelColors {Array<string>}
* @param synth {Synthetizer}
* @param canvas {HTMLCanvasElement}
* @param delayNode {DelayNode} used for correcting time for large fft sizes
*/
constructor(channelColors, synth, canvas)
constructor(channelColors, synth, canvas, delayNode)
{
// variables
/**
Expand Down Expand Up @@ -85,6 +86,7 @@ class Renderer
this._normalAnalyserFft = CHANNEL_ANALYSER_FFT;
this._drumAnalyserFft = DRUMS_ANALYSER_FFT;
this.waveMultiplier = WAVE_MULTIPLIER;
this.waveSign = 1;

/**
* @type {boolean}
Expand Down Expand Up @@ -124,6 +126,7 @@ class Renderer

// synth and analysers
this.synth = synth;
this.delayNode = delayNode;
this.notesOnScreen = 0;

/**
Expand Down
9 changes: 7 additions & 2 deletions src/website/manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ class Manager
const data = await response.arrayBuffer();
this.impulseResponse = await context.decodeAudioData(data);

this.audioDelay = new DelayNode(context, {
delayTime: 0
});
this.audioDelay.connect(context.destination);

// set up synthetizer
this.synth = new Synthetizer(
context.destination,
this.audioDelay,
this.soundFont,
undefined,
undefined,
Expand Down Expand Up @@ -169,7 +174,7 @@ class Manager
canvas.width = window.innerWidth * window.devicePixelRatio;
canvas.height = window.innerHeight * window.devicePixelRatio;

this.renderer = new Renderer(this.channelColors, this.synth, canvas);
this.renderer = new Renderer(this.channelColors, this.synth, canvas, this.audioDelay);
this.renderer.render(true);

let titleSwappedWithSettings = false;
Expand Down
34 changes: 17 additions & 17 deletions src/website/minified/demo_main.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/website/minified/local_main.min.js

Large diffs are not rendered by default.

0 comments on commit db3933d

Please sign in to comment.