Yo,

The cross operator is a generic one, it doesn't do much alone. You
need to pass it a function that does what you want. Since this is
complicated for a beginner, we have included basic usage examples in
utils.liq -- this file, if correctly installed, is automatically
loaded by liquidsoap. The crossfade() function from the wiki is in
utils.liq, and also smart_crossfade() which tries to take respective
amplitudes into account. In a nutshell it means that you can simply
add the feature to your script as follows:

>  # Ce que l'on passe a la radio - What we feed to the radio
>  radio = myplaylist
would become:
  radio = crossfade(radio)

If you want the crossfade to also apply on your promotion tracks, then
modify the line defining your flux_final:
  flux_final = crossfade(fallback(track_sensitive=false, [timed_promo,
radio, security]))

Optionally, you can override the default values of some parameters,
see liquidsoap -h crossfade for details.

Now I answer your questions about the advanced usage of cross(). I'm
going to comment a lot our example:

1. def crossfade(~start_next,~fade_in,~fade_out,s)
2.  s = fade.in(duration=fade_in,s)
3.  s = fade.out(duration=fade_out,s)
4.  fader = fun (a,b) -> add(normalize=false,[b,a])
5.  cross(fader,s)
6. end
7. my_source=crossfade(start_next=1.,fade_out=1.,fade_in=1.,my_source)

First, you can have a look at
http://www.lix.polytechnique.fr/~dbaelde/productions/pool/jfla08.pdf
on pages 4/5, there are some graphics explaining this transition.

We do not immediately define a transition from A to B here. The
crossfade() functions takes only one source S and wraps it in a
crossfader.

First, lines 2 and 3, it applies fade-in and fade-out to S (first and
second graphics, page 4 of our paper). For now it does not involve
crossing anything, just reshaping the enveloppe the ends and
beginnings of tracks.

(In your code you wrote s = fade_in(duration=7.) which defined s to be
a fade_in function with a fixed duration parameter: s is not a source
but a function. You needed to write s = fade_in(duration=7.,s) so that
s is correctly redefined to be a source, made of the original s but
wrapped in the fader.)

Then on line 4 we cross the ends and beginnings of tracks. How do we
do that ? they already have the right faded enveloppe, so it only
remains to superpose them, or add() them in other words. Building
add([a,b]) would be OK but bad-sounding because it would renormalize
the volumes of the A and B inputs: dividing it by 2 when both A and B
are available, and stop suddenly doing that when B is the only
available one -- that is when the A track is finished. Since our
sources have a faded enveloppe, we can add them directly without
renormalizing, thus add(normalize=false,[a,b]) is better. Finally we
write [b,a] instead of [a,b] because add() only forwards the metadata
from the first source in the list. So our fading function (it has to
be a function, A and B are not known yet, will be different for each
transition) is fun (a,b) -> add(normalize=false,[b,a]).

Finally we arrive on line 5, where the function returns its result.
You did not copy line 5 as it was on the wiki, I've put it back to
what it was, cause it was right. What we do on this line is to wrap
our source s (which is not the original s but the one with
fade-in/out) in cross() with the fader function that we defined. What
we get is the third diagram (page 5 of the paper) where the tracks
limits are combined with the fader function.

On line 7, we're just applying this crossfade function on my_source,
maskin the definition of my_source with the new one.

Hope that helps,

Have fun.
-- 
David

Reply via email to