Hand out the length of a played sound from Play sound
Wired into the time of Set sound FX parameters, a change then spans exactly one run of the clip, so a fade or a filter sweep ends with its last sample. - Play sound has a second output, length, in seconds. It is 0 where nothing was played or the sound has not loaded yet. - The AudioSink gives the length of a file, the SoundLibrary takes it from the decoded buffer. A pitch the voice starts on keeps it (#312). - A pitch changed while the voice plays still changes its length, so a pitch sweep over length does not end with the sound. A pitch that keeps the length in real time is #317. Tests: - soundfx, sounds, keep-on-scene-load, node-catalog, sound-library: 462 tests green. - Counter-check: with length always 0, the catalog case and the new soundfx case fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
297fca3e94
commit
804a97b0a9
10 files changed
+53
-11
No files matched your search
@@ -61,7 +61,9 @@ export const PlaySound: NodeDef = {
|
||||
'unless "detached" is on. "fx" sends it through a sound FX asset; left empty, it plays as it is. ' +
|
||||
'"fx params" takes values for its parameters from a Sound FX parameters node. "voice" is the ' +
|
||||
'number of this one play, for Set sound FX parameters to change it while it plays; 0 where ' +
|
||||
'nothing was played.',
|
||||
'nothing was played. "length" is how many seconds one run of the sound lasts, to hand to the ' +
|
||||
'"time" of Set sound FX parameters so a change spans the sound; 0 where nothing was played or ' +
|
||||
'the sound has not been loaded yet. A pitch changed while it plays makes it longer or shorter.',
|
||||
inputs: [
|
||||
exec(),
|
||||
soundPort(),
|
||||
@@ -71,7 +73,7 @@ export const PlaySound: NodeDef = {
|
||||
soundFxPort(),
|
||||
{ key: 'fxParams', label: 'fx params', type: 'fxparams' },
|
||||
],
|
||||
outputs: [exec(), num('voice')],
|
||||
outputs: [exec(), num('voice'), num('length')],
|
||||
params: [],
|
||||
run: (ctx, inputs) => {
|
||||
const sound = asString(inputs.sound);
|
||||
@@ -85,7 +87,8 @@ export const PlaySound: NodeDef = {
|
||||
fxParamsOf(inputs.fxParams),
|
||||
)
|
||||
: 0;
|
||||
return { next: 'exec', outputs: { voice } };
|
||||
const length = voice ? ctx.soundLength(sound) : 0;
|
||||
return { next: 'exec', outputs: { voice, length } };
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user