Fade a sound's start and end apart, each along its own curve (#345)
A cut sound had one edge fade for both ends, always a straight ramp. Now its start and its end each have a fade of their own, and each fade has a curve of its own. - Fade in (ms) and Fade out (ms) replace Edge fade (ms), 5 ms each by default. Like before they apply only to an edge inside the file. - Fade in curve and Fade out curve each offer Linear (the default), Equal power, S-curve, Exponential and Logarithmic. A fade out runs its curve backwards. - The Sound tab's header has a field and a curve dropdown per edge. Each dropdown shows its curve as a small picture, rising or falling, and names it in its tooltip. With two named dropdowns the header was too wide at 1280 px and cut off the readout on the right. - The inspector shows the same four rows, the curves by name. - The wave draws each ramp in its curve rather than as a line. - A cut plays by <file>#<start>~<end>~<fadeIn>~<fadeOut>~<curveIn>~<curveOut>. - No migration, as asked in the issue: the old fade key is no longer read, so saved sounds start with 5 ms each and Linear on both. Tests: - Unit sounds, sound-library: 96 tests - Counter-check (fade out along the fade in's curve): 1 red - e2e 34 (melektaus-atx): ALL PASSED - 69 checks - Gate (melektaus-atx): CHECK EXIT 0, 256 files, 3978 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b49a0bea7
commit
29b604dc07
10 files changed
+421
-96
No files matched your search
+92
-20
@@ -15,6 +15,8 @@ import {
|
||||
cutChannels,
|
||||
cutName,
|
||||
cutRange,
|
||||
FADE_CURVES,
|
||||
fadeGain,
|
||||
isSoundFile,
|
||||
parseCutName,
|
||||
soundFileOf,
|
||||
@@ -25,7 +27,10 @@ import { playedSoundById, playedSoundOf } from '../../src/core/properties/played
|
||||
import {
|
||||
cutOf,
|
||||
END_KEY,
|
||||
FADE_KEY,
|
||||
FADE_IN_CURVE_KEY,
|
||||
FADE_OUT_CURVE_KEY,
|
||||
FADE_IN_KEY,
|
||||
FADE_OUT_KEY,
|
||||
LOOP_KEY,
|
||||
loopsOf,
|
||||
START_KEY,
|
||||
@@ -121,9 +126,19 @@ describe('the sound asset', () => {
|
||||
LOOP_KEY,
|
||||
START_KEY,
|
||||
END_KEY,
|
||||
FADE_KEY,
|
||||
FADE_IN_KEY,
|
||||
FADE_IN_CURVE_KEY,
|
||||
FADE_OUT_KEY,
|
||||
FADE_OUT_CURVE_KEY,
|
||||
]);
|
||||
expect(cutOf(asset.props)).toEqual({ start: 0, end: 0, fade: 0.01 });
|
||||
expect(cutOf(asset.props)).toEqual({
|
||||
start: 0,
|
||||
end: 0,
|
||||
fadeIn: 0.005,
|
||||
fadeOut: 0.005,
|
||||
curveIn: 'linear',
|
||||
curveOut: 'linear',
|
||||
});
|
||||
});
|
||||
|
||||
it('refuses a file name the server could not have produced', () => {
|
||||
@@ -168,51 +183,108 @@ describe('the sound asset', () => {
|
||||
|
||||
describe('the cut of a sound (#343)', () => {
|
||||
it('is no cut at all over the whole file, and a name of its own otherwise', () => {
|
||||
const whole = { start: 0, end: 0, fade: 0.01 };
|
||||
const linear = { curveIn: 'linear', curveOut: 'linear' } as const;
|
||||
const whole = { start: 0, end: 0, fadeIn: 0.005, fadeOut: 0.005, ...linear };
|
||||
expect(cutName(FILE, whole)).toBe(FILE);
|
||||
expect(cutName('', { ...whole, start: 1 })).toBe('');
|
||||
const name = cutName(FILE, { start: 0.25, end: 1.5, fade: 0.01 });
|
||||
expect(name).toBe(`${FILE}#0.25~1.5~0.01`);
|
||||
expect(parseCutName(name)).toEqual({ file: FILE, cut: { start: 0.25, end: 1.5, fade: 0.01 } });
|
||||
const cut = {
|
||||
start: 0.25,
|
||||
end: 1.5,
|
||||
fadeIn: 0.005,
|
||||
fadeOut: 0.2,
|
||||
curveIn: 'sCurve',
|
||||
curveOut: 'equalPower',
|
||||
} as const;
|
||||
const name = cutName(FILE, cut);
|
||||
expect(name).toBe(`${FILE}#0.25~1.5~0.005~0.2~sCurve~equalPower`);
|
||||
expect(parseCutName(name)).toEqual({ file: FILE, cut });
|
||||
expect(parseCutName(FILE)).toEqual({ file: FILE, cut: null });
|
||||
expect(parseCutName(`${FILE}#x~-2`)).toEqual({ file: FILE, cut: { start: 0, end: 0, fade: 0 } });
|
||||
expect(parseCutName(`${FILE}#x~-2`)).toEqual({
|
||||
file: FILE,
|
||||
cut: { start: 0, end: 0, fadeIn: 0, fadeOut: 0, ...linear },
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps at least a sample inside the file, and ramps only the edges inside it', () => {
|
||||
it('keeps at least a sample inside the file, and ramps only the edges inside it, each by its own fade', () => {
|
||||
// 10 samples at 10 Hz: one sample per tenth of a second.
|
||||
expect(cutRange(10, 10, { start: 0.2, end: 0.8, fade: 0.2 })).toEqual({
|
||||
const fades = (fadeIn: number, fadeOut = fadeIn) => ({
|
||||
fadeIn,
|
||||
fadeOut,
|
||||
curveIn: 'linear' as const,
|
||||
curveOut: 'linear' as const,
|
||||
});
|
||||
expect(cutRange(10, 10, { start: 0.2, end: 0.8, ...fades(0.2) })).toEqual({
|
||||
from: 2,
|
||||
to: 8,
|
||||
fadeIn: 2,
|
||||
fadeOut: 2,
|
||||
curveIn: 'linear',
|
||||
curveOut: 'linear',
|
||||
});
|
||||
expect(cutRange(10, 10, { start: 0, end: 0.5, fade: 0.2 })).toMatchObject({ fadeIn: 0, fadeOut: 2 });
|
||||
expect(cutRange(10, 10, { start: 0.5, end: 0, fade: 0.2 })).toMatchObject({
|
||||
expect(cutRange(10, 10, { start: 0.1, end: 0.9, ...fades(0.1, 0.3) })).toMatchObject({
|
||||
fadeIn: 1,
|
||||
fadeOut: 3,
|
||||
});
|
||||
expect(cutRange(10, 10, { start: 0, end: 0.5, ...fades(0.2) })).toMatchObject({ fadeIn: 0, fadeOut: 2 });
|
||||
expect(cutRange(10, 10, { start: 0.5, end: 0, ...fades(0.2) })).toMatchObject({
|
||||
to: 10,
|
||||
fadeIn: 2,
|
||||
fadeOut: 0,
|
||||
});
|
||||
// Past the end, an end before the start, and a fade longer than half of what is kept.
|
||||
expect(cutRange(10, 10, { start: 5, end: 0, fade: 0 })).toMatchObject({ from: 9, to: 10 });
|
||||
expect(cutRange(10, 10, { start: 0.6, end: 0.3, fade: 0 })).toMatchObject({ from: 6, to: 7 });
|
||||
expect(cutRange(10, 10, { start: 0.2, end: 0.6, fade: 1 })).toMatchObject({ fadeIn: 2, fadeOut: 2 });
|
||||
// Past the end, an end before the start, and fades longer than half of what is kept.
|
||||
expect(cutRange(10, 10, { start: 5, end: 0, ...fades(0) })).toMatchObject({ from: 9, to: 10 });
|
||||
expect(cutRange(10, 10, { start: 0.6, end: 0.3, ...fades(0) })).toMatchObject({ from: 6, to: 7 });
|
||||
expect(cutRange(10, 10, { start: 0.2, end: 0.6, ...fades(1, 0.1) })).toMatchObject({
|
||||
fadeIn: 2,
|
||||
fadeOut: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('cuts every channel alike, rising from silence and falling to it at an inner edge', () => {
|
||||
const left = new Float32Array(10).fill(1);
|
||||
const right = new Float32Array(10).fill(-0.5);
|
||||
const [l, r] = cutChannels([left, right], { from: 2, to: 8, fadeIn: 2, fadeOut: 2 });
|
||||
const [l, r] = cutChannels([left, right], {
|
||||
from: 2,
|
||||
to: 8,
|
||||
fadeIn: 2,
|
||||
fadeOut: 2,
|
||||
curveIn: 'linear',
|
||||
curveOut: 'linear',
|
||||
});
|
||||
expect(Array.from(l!)).toEqual([0, 0.5, 1, 1, 0.5, 0]);
|
||||
expect(Array.from(r!)).toEqual([-0, -0.25, -0.5, -0.5, -0.25, -0]);
|
||||
expect(Array.from(left)).toEqual(new Array(10).fill(1));
|
||||
});
|
||||
|
||||
it('is what every way of playing the asset is given, its fade in milliseconds on the asset', () => {
|
||||
it('shapes each ramp by its own curve, the end running it backwards (#345)', () => {
|
||||
for (const { value } of FADE_CURVES) {
|
||||
expect(fadeGain(value, 0)).toBeCloseTo(0, 12);
|
||||
expect(fadeGain(value, 1)).toBeCloseTo(1, 12);
|
||||
}
|
||||
expect(fadeGain('linear', 0.5)).toBe(0.5);
|
||||
expect(fadeGain('equalPower', 0.5)).toBeCloseTo(Math.SQRT1_2, 12);
|
||||
expect(fadeGain('sCurve', 0.25)).toBeCloseTo(1 - fadeGain('sCurve', 0.75), 12);
|
||||
expect(fadeGain('exponential', 0.5)).toBe(0.25);
|
||||
expect(fadeGain('logarithmic', 0.5)).toBe(0.75);
|
||||
const [kept] = cutChannels([new Float32Array(12).fill(1)], {
|
||||
from: 0,
|
||||
to: 12,
|
||||
fadeIn: 4,
|
||||
fadeOut: 4,
|
||||
curveIn: 'exponential',
|
||||
curveOut: 'logarithmic',
|
||||
});
|
||||
expect(Array.from(kept!)).toEqual([0, 0.0625, 0.25, 0.5625, 1, 1, 1, 1, 0.9375, 0.75, 0.4375, 0]);
|
||||
});
|
||||
|
||||
it('is what every way of playing the asset is given, its fades in milliseconds on the asset', () => {
|
||||
const f = playingScene();
|
||||
expect(playedSoundOf(f.project, f.sound)).toBe(FILE);
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.sound.id, START_KEY, 0.5));
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.sound.id, FADE_KEY, 25));
|
||||
const name = `${FILE}#0.5~0~0.025`;
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.sound.id, FADE_IN_KEY, 25));
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.sound.id, FADE_OUT_KEY, 40));
|
||||
f.stack.execute(new SetAssetPropertyCommand(f.sound.id, FADE_OUT_CURVE_KEY, 'equalPower'));
|
||||
const name = `${FILE}#0.5~0~0.025~0.04~linear~equalPower`;
|
||||
expect(playedSoundOf(f.project, f.sound)).toBe(name);
|
||||
expect(playedSoundById(f.project, f.sound.id)).toBe(name);
|
||||
expect(playedSoundById(f.project, '')).toBe('');
|
||||
|
||||
Reference in new issue
Block a user