Skip to main content

Function: diffAudioFilterParams()

function diffAudioFilterParams(from: readonly AudioFilter[], to: readonly AudioFilter[]):
| readonly AudioFilterParamChange[]
| undefined;

Defined in: packages/player/src/filters.ts:359

Work out whether one chain can be turned into another in place.

The question a slider asks sixty times a second: is this change a new filter graph, or the same graph with a different number in it? Only the second can be applied with Player.setAudioFilterParam; the first needs the whole af property rewritten, which recreates the changed entries.

Two chains are the same graph when they have the same entries, in the same order, with the same names, labels, enabled flags and sub-option keys — and every differing value sits on a labelled entry and is listed in AUDIO_FILTER_RUNTIME_PARAMS for that filter. A label is required because af-command addresses entries by label (player/command.c:6716-6738filters/f_output_chain.c:445-465).

Parameters

ParameterTypeDescription
fromreadonly AudioFilter[]The chain mpv is currently running.
toreadonly AudioFilter[]The chain wanted.

Returns

| readonly AudioFilterParamChange[] | undefined

The commands that get from one to the other — [] when they are identical — or undefined when the chain has to be rewritten instead.

Example

const changes = diffAudioFilterParams(current, next)
if (changes === undefined) {
player.setAudioFilters(next)
} else {
for (const change of changes) {
await player.setAudioFilterParam(change.filter, change.param, change.value)
}
}