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
@@ -28,6 +28,11 @@ export interface AudioSink {
|
||||
* where it is not given). 0 is a quick glide.
|
||||
*/
|
||||
tune(voice: number, params: FxParams, time?: number, ease?: EaseShare): void;
|
||||
/**
|
||||
* How many seconds one run of that file lasts, the same with a pitch it starts on (#312); 0 while
|
||||
* its bytes have not arrived.
|
||||
*/
|
||||
length(file: string): number;
|
||||
/** Silences every voice of that file; `''` silences all of them. */
|
||||
stop(file: string): void;
|
||||
/** Silences every voice started by that owner – what destroying a behavior does. */
|
||||
@@ -37,6 +42,7 @@ export interface AudioSink {
|
||||
export const SILENT_AUDIO: AudioSink = {
|
||||
play: () => 0,
|
||||
tune: () => {},
|
||||
length: () => 0,
|
||||
stop: () => {},
|
||||
stopOwner: () => {},
|
||||
};
|
||||
@@ -166,6 +166,10 @@ export function behaviorContext(
|
||||
},
|
||||
playSound: (assetId, volume, loop, detached, fx, fxParams) =>
|
||||
playSound(run, assetId, volume, loop, detached ? '' : entity.id, fx, fxParams),
|
||||
soundLength: (assetId) => {
|
||||
const file = soundFileOf(project, assetId);
|
||||
return file ? run.audio.length(file) : 0;
|
||||
},
|
||||
// An id nothing resolves stops nothing, rather than silencing the whole run by accident;
|
||||
// only the empty id means "everything", which is what the node promises.
|
||||
stopSound: (assetId) => {
|
||||
|
||||
Reference in new issue
Block a user