Audio fades - Equal power and logarithmic | Using avfilter.afade

Human hearing perceives loudness logarithmically. A change in sound pressure level (SPL) is perceived as a change in loudness. Audio engineers often use a logarithmic fade (which is an exponential curve on the linear amplitude scale, or a straight line on the dB scale) for simple fades so that the volume change sounds smooth, steady and “perceptually linearr” to ear. For fading in and out we need logarithmic fade in order to sound “linear”.

Linear fade that is only option in kdenlive is rarely used in reality. It does not sound linear to ear, because we need It is used only when you have two audio signals that are very similar or identical, and phase matched in time to crossfade. A very rare situation. When you crossfade with linear fade, you will hear the dip in the middle, and that is why equal power crossfades are used for a crossfades

there is avfilter.afade, and I am not sure if we implemented that one in kdenlive? In that filter/effect there is a parameter av.curve or av.c that has many options for a curve of the fade, but log is the one we need for fade ins and outs, and qsin (quarter sine wave) + iqsin (inverted quarter sine wave) one we need for a crossfading two clips.

I did the test with crossfading a white noise signal and I can confirm kdenlive uses linear crossfade and fade in/outs.

I assume you’re talking about single track transitions?

If you want full control over audio transitions you probably want to be using multi track transitions, which gives you full control over J/L cuts and keyframeable volume control with configurable keyframe interpolation and curves.

Which is probably separate from “we could improve the default single track crossfade”, but if you want that sort of control that’s the more flexible way to get it.

Correct, I am talking about single track crossfades and fade in/outs. For example you just want a quick audio blend of two neighbour clips with crossfade that is 4-6 frames long using “Mix Clips” tool. But linear crossfade will make audio dip at the center of crossfade.

Or you want to fade out the audio at the end of the video, and you want it to sound linear, not just to be mathematically linear :slight_smile:

How often is that actually really what “you want”? (open question for the world of 'you’s out there - because it’s not often what I seem to find best for most cuts - but that doesn’t mean nobody does).

linear crossfade will make audio dip at the center of crossfade

Yes, I agree that’s often not going to be the right way to do that if it is what you want to do between tracks of roughly equal loudness - though it also depends a bit on exactly what you’re mixing from/to - but I think the bigger question we ought to be asking is what degrees of freedom/configurability would actually be useful to have when using this sort of transition with audio.

For video we give you options about what sort of mix to do - but for audio the only option is ‘reverse’ (which I’m struggling to imagine when you would ever want), so maybe it makes sense to have a bit more flexibility there in general?

you want to fade out the audio at the end of the video, and you want it to sound linear

I’m not sure offhand what the ‘fade’ effect (which you get by dragging the control dot) is implemented to do, but the volume control keyframes are gain in dB, so a simple ‘linear’ fade between two keyframes with it should dtrt.

Well for every cut I would do a “equal power” crossfade in the lenght of a 1 frame, not linear cross fade that is the only option. And depending on a audio and how abrupt the change in background atmosphere is (and what I want to accomplish), I would do a longer crossfades, again “equal power”.

Where do you think linear crossfades, that are the only option, fit better instead of equal power? Why would you prefer loudness dip in the middle? Linear crossfade is only for highly correlated signals, and that is rare

If you don’t want to have too many options, equal power and linear crossfade would fit 99% of the situations in my experience. And I would use equal power as default

Here is link to Ardour Fade and Crossfade manual: The Ardour Manual - Fades and Crossfades

Once again, from my initial post, if kdenlive uses avfilter.afade, those options are already available as a parameter.

No, I’m not saying I think a naive linear fade ‘is better’ - or that single track audio transitions don’t have plenty of scope for improving for the people who really want to use them.

[Personally I’m a bit surprised if there’s any code measuring audio attentuation with simple multipliers instead of dB power factors in 2025 - but I haven’t worked on any of the code behind this feature yet at all to properly know what/why it’s really doing - and true ‘equal power’ mixing is actually a signal dependent thing, so this can quickly Get Complicated in practice]

My question was about how often skilled editors actually use or want a naive “cross in the middle” fade between two roughly equally loud signals and want that transition to happen with no, or minimal, change of loudness.

Because my personal answer to that is “rarely if ever” … in practice the audio transition is often not in the center, and the new audio does not fade in as a simple mirror of how the old audio fades out (whether that’s equal gain or power or any other curve or function).

So if I’m a crazy outlier in that, then maybe a simple change to the One And Only algorithm is all we need. But I don’t think I am, at least not completely - so I think what we should be thinking about is “how do we give people all the control that they have over audio mixing when using multi-track transitions, in the UI for single track transitions”.

And we already give them control over what video transition to use, so doing that for audio makes sense - it just needs Some Design Thought, so that the first attempt works for as many users as possible, not just Whoever Implements It. Which is the question I’m trying to open up here.

for every cut I would do a “equal power” crossfade in the lenght of a 1 frame

For that specific case, it really probably doesn’t matter a lot how you fade it - you’re at the limits of perception, even at relatively low frame rates - and you’re not really "fading’ the content as much as just de-clicking the transition between them. And if your audio isn’t Really Similar or already silent, you’re going to get a hard edge whatever you do.

So this:

depending on a audio and how abrupt the change in background atmosphere is (and what I want to accomplish), I would do a longer crossfade

is the interesting case, and the “depending on” bit is the interesting clause which I don’t think has a One Size Fits All answer - even if the current one is not the best “if I had to pick one” either. So let’s not pick one as an act of fiat, this is an editor, let’s make it editable.

if kdenlive uses avfilter.afade, those options are already available as a parameter

That’s one option, but it’s still boxing people in to a limited set of parameters and some arbitrarily chosen curves, many of which have dubious usefulness, which it doesn’t seem like a stretch to say will be confusing and poorly understood to many users.

So my next question would be: Do we need a fancy additional ‘effect’ for this at all?

There have already been moves to make ‘volume’ a default built-in effect - so what if we just provide some sort of convenience dialog for single track transitions to keyframe the volume effect in the transition zone with a chosen easing curve?

Would that not give us the Best Of All Worlds? Where people who want some stock choice “99% of the time” can make that their default - without taking away their ability to manually tweak or choose exactly how the volumes should change as each old clip ends and a new one begins. We get one master volume control for the clip, without adding another layer of complexity to the processing pipeline for what really is just keyframed volume control.

What am I missing that might make something else Better Than That for this purpose?

You’re not wrong that this can and should be improved - I’m just saying let’s figure out what we need and want - before picking a how to do it that comes with its own set of strict requirements that will eventually be a problem for some other use case.


Just separately to the main event above (but you asked, and I’m assuming not entirely rhetorically):

Why would you prefer loudness dip in the middle

Assuming the case where you would not prefer that, and that your audio isn’t actually white noise (or its loudness-war pop era equivalent! : ), whether or not you actually get one depends about as much on your actual audio as your fade curve. You could do real equal power dynamic normalisation of the actual content of the mix, but that’s probably not the effect most people ever want for most transitions most of the time either.

Or realistically, probably where you’d choose to place such a cut with that sort of transition anyway. Which is probably why it took an actual audio guy to notice and be annoyed by the current default and lack of better choice for this : )

Linear crossfade is only for highly correlated signals

If you’re crossfading audio that correlated here, you’re probably in a completely different world of pain - because we make no promises about phase preservation, so the result could be anything ranging from Far Too Loud, to near or even complete silence, with a side order of beat frequency distortion. To fix that we’re back to the need for sample-accurate audio manipulation again, which is a longer term can of worms to digest.

Thank you for the detailed opinion, it is very appreciated :+1:

If I have same shot/take with more or less similar background atmosphere, but there are cuts in time between dialogue, I would use crossfade on single track, because it is simple to do, and it does the job. That is also what I would do for a different shot/take, but recorded at the same location and similar real world time so atmosphere is still similiar. And please note, center of audio transition does not have to be at the same timecode as cut in the picture, but left and right clip would be “mirrored” in the crosfade curve.

If I am making a transition from two diferent scenes with completely different atmosperic noises, then I would probably do it in multitrack with more control, only if I want to be very precise. But most of the time I can get away with equal power crossfade, and maybe moving that audio cut left or right.

Totally agree, not provide all the curves possible by avfilder.afade, but useful ones. I also wanted to suggest in another thread a choice of video and audio effects/filter available in kdenlive to be a little bit more selected/curated, as there are many “duplicates”, and that can be overwhelming for a new users or someone not too savvy in this field. (or to give an option “show extendend list of effects”, so we don’t limit the user by curated list). But that is for another thread.

That is a very good option too

I don’t understand what you wanted to say. Are you still refereing to a crossfade curves? I guess you meant if we want a crossfade we would edit fade out of the left clip, and fade in on the right clip in that master volume control for the clip

This is how crossdade editor looks like in professional audio software / DAW:

but that is too much for a video editor, and first step on improving fades in kdenlive I think. What would be “enough” in my opinion is just this fade editor that can be accessed with right click on the faded region with predefined curve shapes.

For fade in:

Fade out:

Crossfade:

…And if you need more control, you can do it on multi track with same fade in and fade out editors.

And that is very similar or even the same to what you suggested with keyframes easing method.

Volume control should not introduce phase shifts, like EQ can. Or maybe you refered to timing on the timeline that can not be more precise that one frame in most video editors that can introduce phase cancelations or gains when two overlaping clips are summed


IMHO, It depends how much development time there is to invest. Let’s split it into a 3 levels from perspective of development complexity (I am making a guesstimate here):

  1. We need to choose only one option → Equal power (logarithmic) insead of linear for a crossfade, exponential gain/decay for a fade in/out. I sketched the curves below. I might gave wrong name suggestions in the first post for log and quarter sine wave
  2. Let’s give some flexibility → user can select by right click on the fade region / edit fade / toggle switch: [linear | exponential |logarithmic]
  3. Let’s give ALL fexibility → Make audio transition curve editor like keyframe one you suggested or predefined curve editor or similar

Once again, those curves are meant to make audio sound linear fade in/out to ear, even if they are not visually and mathematicaly linear. So this is not about making some special “easing” effects, just linear to ears :slight_smile:

So I measured the dB values of fade in on kdenlive audio mixer using 1000Hz sine wave of constant volume every 10 frames and wrote it down into a table, then made a graph.

I did not measure it from the start of the clip, because there is very large change in dB, on second frame you are already on ~-40dB. And that is why those fades does not sound natural/linear to my ear. So 0th frame in table is some arbitrary start around 1 seconds after fade starts.

Conclusion of this experiment shows that linear fade in kdenlive is not linear in dB but makes logarithmic curve in dB

Like I said, I haven’t been in the code for this yet to know offhand exactly what it (or the trivial ‘fade’ in/out) is doing - but I can’t think of any user visible control that isn’t purporting to operate in dB - and as a general thing I would have thought that “digital audio” is mature enough in 2025 that most things are unless they have some reason to deliberately not be.

I do know all too well that there are lots of places for subtle bugs to hide in DSP code, so it was safe to say you’ve found something we should investigate, but not to just pile on to the assertion of what was wrong without actually investigating.

So having a quick look around now:

  • it looks like MLT provides an autofade filter, that is indeed just a naive fade with a linear stepped decay_factor - used for both audio and video - and since vision (like audio and pretty much all our senses) has an also approximately logarithmic relationship between stimulus and sensation - that will do neither of them in a perceptually linear manner.

  • It also provides an audioseam filter, which is correctly computing dBFS (20 * log10 of amplitude) - and which at first blush I thought might actually be doing a dynamic constant power transition of the kind I figured was overkill - but is actually doing something much weirder. It looks at only two sample values, the last sample of the old clip and first of the new - and if those two in isolation differ by some ‘dB’ threshold, then it sythesises a (linear) crossfade by reversing the last frame of the old clip and mixing that with the first frame of the new clip …

    Which is an … interesting … idea - but not how I’d be looking to detect and smooth a discontinuous seam.

But neither of those appear to actually be in play here. It would seem that single track transitions are handled with yet another implementation, in the mix transition - which does a ‘weighted’ linear fade, with some sides of decimation and low-pass filtering and drift compensation and channel count matching - because the old and new clips may have different sample rates and channel counts, and both of those may be different to the project output audio stream.

And at first blush that all seems to be entirely independent of any manipulation done by the volume control - but definitely earns itself a place on the cans’o’worms league table.

That’s all from just a very quick look at some of the code - so I wouldn’t bet too heavily that I’m not missing some important things in that description - but that quick look did make doing something fundamentally much simpler to achieve the same goal seem like a pretty attractive idea. And it doesn’t look like something you could just replace with afade, it’s doing a lot more than just fading, but it’s all very hardwired together.

I would probably do it in multitrack with more control, only if I want to be very precise.

That’s kind of the crux of the angle I’m looking at this from - the style of transitions you choose to use for your editing (multi or single track) should mostly be a purely UI preference thing. It shouldn’t effect your ability to be precise or to be able to perform some fundamental operation.

And from what I’m seeing right now, it really is just this entanglement of a hardcoded fade with the mix operation that makes this troublesome. The volume control is still functional over the full extent of both clips, so you can already use it to (re)shape the mix more or less however you like - though it’s not terribly intuitive and may not interact well with the hardcoded fade if you try to force things too hard. But you could definitely compensate for the (non)linearity in the (probably few) cases where that is actually audible.

not provide all the curves possible by avfilder.afade, but useful ones

Who gets to decide what is useful? Limiting people to just what someone else arbitrarily considered useful pretty is pretty much always guaranteed to upset someone and come back to bite you later. It’s ok to have simple defaults, but if something is possible, eventually there will be someone or some use that really needs to do it. Limiting possibility to just a subset of already limited possibilities is just a recipe for needing to do this all again later for someone else with different needs.

be a little bit more selected/curated, as there are many “duplicates”, and that can be overwhelming

Yeah, let’s not get that tangled up in this thread - but you’re not alone in thinking that either, Bernd has been putting a lot of work into improving this, but it’s an iterative process - and as we’ve just seen in the last few days can be confounded by each ‘duplicate’ having one tiny little useful thing that it can do which the other versions can’t. The ‘main effects’ category tries to prune out some without completely removing them for people who need them (or historically used them in old projects).

I guess you meant if we want a crossfade we would edit fade out of the left clip, and fade in on the right clip

Yes, that’s effectively all a cross fade is, a mix where the gain of each channel varies with time. I’m not suggesting we force people to create them manually like that for the simple cases, for a few selected common cases we can have magic buttons and a default option. But if we implement it this way we get both a very simple front end for the “common” cases, while still exposing full control when that is what you need - without actually creating anything new or more complicated than what already exists, and without adding even more layers and complexity to the DSP pipeline.

So we’d go from having two (as it is now) or maybe three (if we threw afade into the mix) things potentially trying to multiply the volume up and/or down to just one doing that, with some shortcuts for adding commonly desired keyframes.

This is how crossdade editor looks like in professional audio software
…but that is too much for a video editor

A continental breakfast dialog like that probably is - but we already have all the features that it provides (including user-defined spline curves) in the standard Volume effect. So all we’d need to do is stop using the hard-coded fade in that mix and provide buttons in the audio mix widget to create suitable keyframes for whatever ‘standard’ crossfade styles we want to offer.

Anyone that doesn’t work for remains free to fix those keyframes manually however they like. And we get both a cleaner UI and DSP pipeline, just by removing limits instead of adding more of them.


Volume control should not introduce phase shifts

Right, but you don’t get to pick the start of what you’re mixing in with better than video-frame size granularity, and other audio effects can/will. The FIR lowpass in the samplerate matching mixer certainly will.

Let’s split it into a 3 levels from perspective of development complexity

Yeah, I think that’s overcomplicating what I’m thinking of here. : )

I’m (increasingly) thinking the problem is that’s it’s already overcomplicated with too much duplication of basic DSP tasks - and the way to make it simpler, more correct, more powerful, and less computationally complex - is not to spend more time developing new layers and processing modules, but to delete the duplication we already have that’s just getting in the way of using the things that we’re already considering to be intrinsic to their fullest potential.

I’m just waiting to see what someone points out that I’ve forgotten which makes this too Not That Simple …

Yeah, I’m no less “a bit surprised” at this - but that’s what the code says MLT is doing too.

I did not measure it from the start of the clip, because there is very large change in dB

That’s probably a function of the number of ‘steps’ the decay_factor takes with the first step jumping the gain from -infinity to 1.0/nsteps. It screws up your graph fit, but not your conclusion.