ttencate / jfxr

A browser-based tool to create sound effects for games.
http://jfxr.frozenfractal.com/
429 stars 45 forks source link

Sounds of length 0.28s are not generated #41

Closed ttencate closed 5 years ago

ttencate commented 5 years ago

E.g.. I got this to repro with attack = 0.08, sustain = 0.2 as well, but it doesn't seem to be deterministic.

ttencate commented 5 years ago

In synth.js we compute the sample count like this:

var numSamples = Math.max(1, Math.ceil(sampleRate * this.sound.duration()));

We'd expect 0.28 * 44100 = 12348 samples, but due to floating point error, the ceil causes one sample too many to exist here. The excessive sample at index 12348 ends up after the attack and sustain periods and goes into the decay period, where we divide by this.decay.value which is 0, resulting in a single NaN sample at the end.