Promoted pypo to top level because it isnt 3rd party.

Removed the portage stuff since it is way outdated.
This commit is contained in:
Paul Baranowski 2010-12-02 15:30:40 -05:00
parent 4300fd8d36
commit 51a1fde9ee
82 changed files with 0 additions and 6013 deletions

View file

@ -0,0 +1,149 @@
# Decoders, enabled when the binary is detected and the os is not Win32.
# Get_mime is not always defined
# so we define a default in this case..
my_get_mime = fun (_) -> ""
%ifdef get_mime
my_get_mime = get_mime
%endif
get_mime = my_get_mime
%ifdef add_decoder
if test_process("which flac") then
log(level=3,"Found flac binary: enabling flac external decoder.")
flac_p = "flac -d -c - 2>/dev/null"
def test_flac(file) =
if test_process("which metaflac") then
channels = list.hd(get_process_lines("metaflac \
--show-channels #{quote(file)} \
2>/dev/null"))
# If the value is not an int, this returns 0 and we are ok :)
int_of_string(channels)
else
# Try to detect using mime test..
mime = get_mime(file)
if string.match(pattern="flac",file) then
# We do not know the number of audio channels
# so setting to -1
(-1)
else
# All tests failed: no audio decodable using flac..
0
end
end
end
add_decoder(name="FLAC",description="Decode files using the flac \
decoder binary.", test=test_flac,flac_p)
else
log(level=3,"flac binary not found: flac decoder disabled.")
end
%endif
if os.type != "Win32" then
if test_process("which metaflac") then
log(level=3,"Found metaflac binary: enabling flac external metadata \
resolver.")
def flac_meta(file)
ret = get_process_lines("metaflac --export-tags-to=- \
#{quote(file)} 2>/dev/null")
ret = list.map(string.split(separator="="),ret)
# Could be made better..
def f(l',l)=
if list.length(l) >= 2 then
list.append([(list.hd(l),list.nth(l,1))],l')
else
if list.length(l) >= 1 then
list.append([(list.hd(l),"")],l')
else
l'
end
end
end
list.fold(f,[],ret)
end
add_metadata_resolver("FLAC",flac_meta)
else
log(level=3,"metaflac binary not found: flac metadata resolver disabled.")
end
end
# A list of know extensions and content-type for AAC.
# Values from http://en.wikipedia.org/wiki/Advanced_Audio_Coding
# TODO: can we register a setting for that ??
aac_mimes = ["audio/aac", "audio/aacp", "audio/3gpp", "audio/3gpp2", "audio/mp4",
"audio/MP4A-LATM", "audio/mpeg4-generic", "audio/x-hx-aac-adts"]
aac_filexts = ["m4a", "m4b", "m4p", "m4v",
"m4r", "3gp", "mp4", "aac"]
# Faad is not very selective so
# We are checking only file that
# end with a known extension or mime type
def faad_test(file) =
# Get the file's mime
mime = get_mime(file)
# Test mime
if list.mem(mime,aac_mimes) then
true
else
# Otherwise test file extension
ret = string.extract(pattern='\.(.+)$',file)
if list.length(ret) != 0 then
ext = ret["1"]
list.mem(ext,aac_filexts)
else
false
end
end
end
if os.type != "Win32" then
if test_process("which faad") then
log(level=3,"Found faad binary: enabling external faad decoder and \
metadata resolver.")
faad_p = (fun (f) -> "faad -w #{quote(f)} 2>/dev/null")
def test_faad(file) =
if faad_test(file) then
channels = list.hd(get_process_lines("faad -i #{quote(file)} 2>&1 | \
grep 'ch,'"))
ret = string.extract(pattern=", (\d) ch,",channels)
ret =
if list.length(ret) == 0 then
# If we pass the faad_test, chances are
# high that the file will contain aac audio data..
"-1"
else
ret["1"]
end
int_of_string(default=(-1),ret)
else
0
end
end
%ifdef add_oblivious_decoder
add_oblivious_decoder(name="FAAD",description="Decode files using \
the faad binary.", test=test_faad, faad_p)
%endif
def faad_meta(file) =
if faad_test(file) then
ret = get_process_lines("faad -i \
#{quote(file)} 2>&1")
# Yea, this is tuff programming (again) !
def get_meta(l,s)=
ret = string.extract(pattern="^(\w+):\s(.+)$",s)
if list.length(ret) > 0 then
list.append([(ret["1"],ret["2"])],l)
else
l
end
end
list.fold(get_meta,[],ret)
else
[]
end
end
add_metadata_resolver("FAAD",faad_meta)
else
log(level=3,"faad binary not found: faad decoder disabled.")
end
end

View file

@ -0,0 +1,73 @@
#!/usr/bin/perl -w
use strict ;
my $file = $ARGV[0] || die ;
sub test_mime {
my $file = shift ;
if (`which file`) {
return `file -b --mime-type "$file"`;
}
}
if (($file =~ /\.mp3$/i) || (test_mime($file) =~ /audio\/mpeg/)) {
if (`which mp3gain`) {
my $out = `nice -n 20 mp3gain -q "$file" 2> /dev/null` ;
$out =~ /Recommended "Track" dB change: (.*)$/m || die ;
print "$1 dB\n" ;
} else {
print STDERR "Cannot find mp3gain binary!\n";
}
} elsif (($file =~ /\.ogg$/i) || (test_mime($file) =~ /application\/ogg/)) {
if ((`which vorbisgain`) && (`which ogginfo`)) {
system("nice -n 20 vorbisgain -q -f \"$file\" 2>/dev/null >/dev/null") ;
my $info = `ogginfo "$file"` ;
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die ;
print "$1 dB\n" ;
} else {
print STDERR "Cannot find vorbisgain or ogginfo!\n";
}
} elsif (($file =~ /\.flac$/i) || (test_mime($file) =~ /audio\/x-flac/)) {
if (`which metaflac`) {
my $info = `metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$file"` ;
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/;
if (defined($1)) {
print "$1 dB\n" ;
} else {
system("nice -n 20 metaflac --add-replay-gain \"$file\" \
2>/dev/null >/dev/null") ;
$info = `metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$file"` ;
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die "Error in $file" ;
print "$1 dB\n" ;
}
} else {
print STDERR "Cannot find metaflac!\n";
}
} else {
print STDERR "File format not supported...\n";
}

View file

@ -0,0 +1,133 @@
dummy = fun () -> log("Lastfm/audioscrobbler support was not compiled.")
%ifdef input.lastfm
dummy = fun () -> ()
# Utility to compose last.fm URIs.
# @category String
# @param ~user Lastfm user
# @param ~password Lastfm password
# @param ~discovery Allow lastfm suggestions
# @param radio URI, e.g. user/toots5446/playlist, globaltags/rocksteady.
def lastfm.uri(~user="",~password="",~discovery=false,
radio="globaltags/creative-commons")
auth = if user == "" then "" else "#{user}:#{password}@" end
discovery = if discovery == true then "1" else "0" end
"lastfm://#{auth}#{radio}?discovery=#{discovery}"
end
# Submit metadata to libre.fm using the audioscrobbler protocol.
# @category Interaction
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
def librefm.submit(~user,~password,~source="broadcast",~length=false,m) =
audioscrobbler.submit(user=user,password=password,
source=source,length=length,
host="turtle.libre.fm",port=80,
m)
end
# Submit metadata to lastfm.fm using the audioscrobbler protocol.
# @category Interaction
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
def lastfm.submit(~user,~password,~source="broadcast",~length=false,m) =
audioscrobbler.submit(user=user,password=password,
source=source,length=length,
host="post.audioscrobbler.com",port=80,
m)
end
# Submit metadata to libre.fm using the audioscrobbler protocol (nowplaying mode).
# @category Interaction
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
def librefm.nowplaying(~user,~password,~length=false,m) =
audioscrobbler.nowplaying(user=user,password=password,length=length,
host="turtle.libre.fm",port=80,
m)
end
# Submit metadata to lastfm.fm using the audioscrobbler protocol (nowplaying mode).
# @category Interaction
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
def lastfm.nowplaying(~user,~password,~length=false,m) =
audioscrobbler.nowplaying(user=user,password=password,length=length,
host="post.audioscrobbler.com",port=80,
m)
end
# Submit songs using audioscrobbler, respecting the full protocol:
# First signal song as now playing when starting, and
# then submit song when it ends.
# @category Interaction
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
# @param ~delay Submit song when there is only this delay left, in seconds.
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
def audioscrobbler.submit.full(
~user,~password,
~host="post.audioscrobbler.com",~port=80,
~source="broadcast",~length=false,
~delay=10.,~force=false,s) =
f = audioscrobbler.nowplaying(
user=user,password=password,
host=host,port=port,length=length)
s = on_metadata(f,s)
f = fun (rem,m) ->
# Avoid skipped songs
if rem > 0. or force then
audioscrobbler.submit(
user=user,password=password,
host=host,port=port,length=length,
source=source,m)
else
log(label="audioscrobbler.submit.full",
level=4,"Remaining time null: \
will not submit song (song skipped ?)")
end
on_end(delay=delay,f,s)
end
# Submit songs to librefm using audioscrobbler, respecting the full protocol:
# First signal song as now playing when starting, and
# then submit song when it ends.
# @category Interaction
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
# @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
def librefm.submit.full(
~user,~password,
~source="broadcast",~length=false,
~delay=10.,~force=false,s) =
audioscrobbler.submit.full(
user=user,password=password,
source=source,length=length,
host="turtle.libre.fm",port=80,
delay=delay,force=force,s)
end
# Submit songs to lastfm using audioscrobbler, respecting the full protocol:
# First signal song as now playing when starting, and
# then submit song when it ends.
# @category Interaction
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
# @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
def lastfm.submit.full(
~user,~password,
~source="broadcast",~length=false,
~delay=10.,~force=false,s) =
audioscrobbler.submit.full(
user=user,password=password,
source=source,length=length,
host="post.audioscrobbler.com",port=80,
delay=delay,force=force,s)
end
%endif
dummy ()

11
pypo/scripts/library/liquidtts Executable file
View file

@ -0,0 +1,11 @@
#!/bin/sh
# This script is called from liquidsoap for generating a file
# for "say:voice/text" URIs.
# Usage: liquidtts text output_file voice
echo $1 | /usr/bin/text2wave -f 44100 > $2.tmp.wav && /usr/bin/sox $2.tmp.wav -t wav -c 2 -r 44100 $2 2> /dev/null > /dev/null
return=$?
/bin/rm $2.tmp.wav
false $2 2> /dev/null > /dev/null
exit $return

View file

@ -0,0 +1,4 @@
%include "utils.liq"
%include "externals.liq"
%include "shoutcast.liq"
%include "lastfm.liq"

View file

@ -0,0 +1,49 @@
%ifdef output.icecast
# Output to shoutcast.
# @category Source / Output
# @param ~id Output's ID
# @param ~start Start output threads on operator initialization.
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
# @param ~icy_reset Reset shoutcast source buffer upon connecting (necessary for NSV).
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
# @param ~on_start Callback executed when outputting starts.
# @param ~on_stop Callback executed when outputting stops.
# @param ~on_connect Callback executed when connection starts.
# @param ~on_disconnect Callback executed when connection stops.
# @param ~icy_metadata Send new metadata using the ICY protocol. One of: "guess", "true", "false"
# @param ~format Format, e.g. "audio/ogg". When empty, the encoder is used to guess.
# @param e Endoding format. For shoutcast, should be mp3 or AAC(+).
# @param s The source to output
def output.shoutcast(
~id="output.shoutcast",~start=true,
~restart=false,~restart_delay=3,
~host="localhost",~port=8000,
~user="source",~password="hackme",
~genre="Misc",~url="http://savonet.sf.net/",
~name="OCaml Radio!",~public=true, ~format="",
~dumpfile="", ~icy_metadata="guess",
~on_connect={()}, ~on_disconnect={()},
~aim="",~icq="",~irc="",~icy_reset=true,
~fallible=false,~on_start={()},~on_stop={()},
e,s) =
icy_reset = if icy_reset then "1" else "0" end
headers = [("icy-aim",aim),("icy-irc",irc),
("icy-icq",icq),("icy-reset",icy_reset)]
output.icecast(
e, format=format,
id=id, headers=headers,
start=start,icy_metadata=icy_metadata,
on_connect=on_connect, on_disconnect=on_disconnect,
restart=restart, restart_delay=restart_delay,
host=host, port=port, user=user, password=password,
genre=genre, url=url, description="UNUSED",
public=public, dumpfile=dumpfile,
name=name, mount="/", protocol="icy",
fallible=fallible,on_start=on_start,on_stop=on_stop,
s)
end
%endif

View file

@ -0,0 +1,578 @@
# Turn a source into an infaillible source.
# by adding blank when the source is not available.
# @param s the source to turn infaillible
# @category Source / Input
def mksafe(s)
fallback(id="mksafe",track_sensitive=false,[s,blank(id="safe_blank")])
end
# Alias for the <code>l[k]</code> notation.
# @category List
# @param a Key to look for
# @param l List of pairs (key,value)
def list.assoc(a,l)
l[a]
end
# list.mem_assoc(key,l) returns true if l contains a pair
# (key,value)
# @category List
# @param a Key to look for
# @param l List of pairs (key,value)
def list.mem_assoc(a,l)
v = list.assoc(a,l)
# We check for existence, since "" may indicate
# either a binding (a,"") or no binding..
list.mem((a,v),l)
end
# Remove a pair from an associative list
# @category List
# @param a Key of pair to be removed
# @param l List of pairs (key,value)
def list.remove_assoc(a,l)
list.remove((a,list.assoc(a,l)),l)
end
# Rewrite metadata on the fly using a list of (target,rules).
# @category Source / Track Processing
# @param l \
# List of (target,value) rewriting rules.
# @param ~insert_missing \
# Treat track beginnings without metadata as having empty ones. \
# The operational order is: \
# create empty if needed, map and strip if enabled.
# @param ~update \
# Only update metadata. \
# If false, only returned values will be set as metadata.
# @param ~strip \
# Completly remove empty metadata. \
# Operates on both empty values and empty metadata chunk.
def rewrite_metadata(l,~insert_missing=true,
~update=true,~strip=false,
s)
# We don't need to return all values, since
# map_metadata only update returned values.
# So, we simply apply all rewrite rules !
def map(m)
def apply(x)
label = fst(x)
value = snd(x)
(label,value % m)
end
list.map(apply,l)
end
map_metadata(map,insert_missing=insert_missing,
update=update,strip=strip,s)
end
# Add a skip function to a source
# when it does not have one
# by default
# @category Interaction
# @param s The source to attach the command to.
def add_skip_command(s) =
# A command to skip
def skip(_) =
source.skip(s)
"Done!"
end
# Register the command:
server.register(namespace="#{source.id(s)}",
usage="skip",
description="Skip the current song.",
"skip",skip)
end
# Removes all metadata coming from a source
# @category Source / Track Processing
def clear_metadata(s)
def map(m)
[]
end
map_metadata(map,update=false,strip=true,s)
end
output.prefered=output.dummy
%ifdef output.oss
output.prefered=output.oss
%endif
%ifdef output.alsa
output.prefered=output.alsa
%endif
%ifdef output.pulseaudio
output.prefered=output.pulseaudio
%endif
%ifdef output.ao
output.prefered=output.ao
%endif
# Output to local audio card using the first available driver in this list:
# ao, pulseaudio, alsa, oss, dummy
# @category Source / Output
def output.prefered(~id="",s)
output.prefered(id=id,s)
end
in = fun () -> blank()
%ifdef input.oss
in = fun () -> input.oss(id="oss_mic")
%endif
%ifdef input.alsa
in = fun () -> input.alsa(id="alsa_mic")
%endif
%ifdef input.portaudio
in = fun () -> input.portaudio(id="pa_mic")
%endif
# Create a source from the first available input driver in this list:
# portaudio, alsa, oss, blank
# @category Source / Input
def in()
in()
end
# Output a stream using the 'output.prefered' operator. The input source does
# not need to be infallible, blank will just be played during failures.
# @param s the source to output
# @category Source / Output
def out(s)
output.prefered(mksafe(s))
end
# Special track insensitive fallback that
# always skip current song before switching.
# @category Source / Track Processing
# @param ~input The input source
# @param f The fallback source
def fallback.skip(~input,f)
def transition(a,b) =
source.skip(a)
# This eats the last remaining frame from a
sequence([a,b])
end
fallback(track_sensitive=false,transitions=[transition,transition],[input,f])
end
# Compress and normalize, producing a more uniform and "full" sound.
# @category Source / Sound Processing
# @param s The input source.
def nrj(s)
compress(threshold=-15.,ratio=3.,gain=3.,normalize(s))
end
# Multiband-compression.
# @category Source / Sound Processing
# @param s The input source.
def sky(s)
# 3-band crossover
low = filter.iir.eq.low(frequency = 168.)
mh = filter.iir.eq.high(frequency = 100.)
mid = filter.iir.eq.low(frequency = 1800.)
high = filter.iir.eq.high(frequency = 1366.)
# Add back
add(normalize = false,
[ compress(attack = 100., release = 200., threshold = -20.,
ratio = 6., gain = 6.7, knee = 0.3,
low(s)),
compress(attack = 100., release = 200., threshold = -20.,
ratio = 6., gain = 6.7, knee = 0.3,
mid(mh(s))),
compress(attack = 100., release = 200., threshold = -20.,
ratio = 6., gain = 6.7, knee = 0.3,
high(s))
])
end
# Simple crossfade.
# @category Source / Track Processing
# @param ~start_next Duration in seconds of the crossed end of track.
# @param ~fade_in Duration of the fade in for next track
# @param ~fade_out Duration of the fade out for previous track
# @param s The source to use
def crossfade(~id="",~start_next,~fade_in,~fade_out,s)
s = fade.in(duration=fade_in,s)
s = fade.out(duration=fade_out,s)
fader = fun (a,b) -> add(normalize=false,[b,a])
cross(id=id,conservative=true,duration=start_next,fader,s)
end
# Append speech-synthesized tracks reading the metadata.
# @category Source / Track Processing
# @param ~pattern Pattern to use
# @param s The source to use
def say_metadata
p = 'say:$(if $(artist),"It was $(artist)$(if $(title),\", $(title)\").")'
fun (s,~pattern=p) ->
append(s,fun (m) -> request.queue(queue=[request.create(pattern % m)],
interactive=false))
end
# Relay the audio stream of Dolebraï, a libre music netradio running liquidsoap.
# @category Source / Input
def dolebrai ()
input.http(id="dolebrai","http://dolebrai.net:8000/dolebrai.ogg")
end
%ifdef soundtouch
# Increases the pitch, making voices sound like on helium.
# @category Source / Sound Processing
# @param s The input source.
def helium(s)
soundtouch(pitch=1.5,s)
end
%endif
# Return true if process exited with 0 code.
# Command should return quickly.
# @category System
# @param command Command to test
def test_process(command)
lines =
get_process_lines("(" ^ command ^ " >/dev/null 2>&1 && echo 0) || echo 1")
if list.length(lines) == 0 then
false
else
"0" == list.hd(lines)
end
end
# Get the base name of a path.
# Implemented using the corresponding shell command.
# @category System
# @param s Path
def basename(s)
lines = get_process_lines("basename #{quote(s)}")
if list.length(lines) > 0 then
list.hd(lines)
else
# Don't know what to do.. output s
s
end
end
# Get the directory name of a path.
# Implemented using the corresponding shell command.
# @category System
# @param s Path
# @param ~default Value returned in case of error.
def dirname(~default="/nonexistent",s)
lines = get_process_lines("dirname #{quote(s)}")
if list.length(lines) > 0 then
list.hd(lines)
else
default
end
end
# Read some value from standard input (console).
# @category System
# @param ~hide Hide typed characters (for passwords).
def read(~hide=false)
if hide then
system("stty -echo")
end
s = list.hd(get_process_lines("read BLA && echo $BLA"))
if hide then
system("stty echo")
end
print("")
s
end
# Generic mime test. First try to use file.mime if it exist.
# Otherwise try to get the value using the file binary.
# Returns "" (empty string) if no value can be find.
# @category System
# @param file The file to test
def get_mime(file) =
def file_method(file) =
if test_process("which file") then
list.hd(get_process_lines("file -b --mime-type \
#{quote(file)}"))
else
""
end
end
def mime_method(file) =
ret = ""
%ifdef file.mime
ret = file.mime(file)
%endif
ret
end
# First try mime method
ret = mime_method(file)
if ret != "" then
ret
else
# Now try file method
file_method(file)
end
end
# Remove low frequencies often produced by microphones.
# @category Source / Sound Processing
# @param s The input source.
def mic_filter(s)
filter(freq=200.,q=1.,mode="high",s)
end
# Creates a source that fails to produce anything.
# @category Source / Input
def fail()
fallback([])
end
# Creates a source that plays only one track of the input source.
# @category Source / Track Processing
# @param s The input source.
def once(s)
sequence([s,fail()])
end
# Crossfade between tracks, taking the respective volume levels into account in
# the choice of the transition.
# @category Source / Track Processing
# @param ~start_next Crossing duration, if any.
# @param ~fade_in Fade-in duration, if any.
# @param ~fade_out Fade-out duration, if any.
# @param ~width Width of the volume analysis window.
# @param ~conservative Always prepare for a premature end-of-track.
# @param ~default Transition used when no rule applies \
# (default: sequence).
# @param ~high Value, in dB, for loud sound level
# @param ~medium Value, in dB, for medium sound level
# @param ~margin Margin to detect sources that have too different \
# sound level for crossing.
# @param s The input source.
def smart_crossfade (~start_next=5.,~fade_in=3.,~fade_out=3.,
~default=(fun (a,b) -> sequence([a, b])),
~high=-15., ~medium=-32., ~margin=4.,
~width=2.,~conservative=false,s)
fade.out = fade.out(type="sin",duration=fade_out)
fade.in = fade.in(type="sin",duration=fade_in)
add = fun (a,b) -> add(normalize=false,[b, a])
log = log(label="smart_crossfade")
def transition(a,b,ma,mb,sa,sb)
list.iter(fun(x)-> log(level=4,"Before: #{x}"),ma)
list.iter(fun(x)-> log(level=4,"After : #{x}"),mb)
if
# If A and B are not too loud and close, fully cross-fade them.
a <= medium and b <= medium and abs(a - b) <= margin
then
log("Old <= medium, new <= medium and |old-new| <= margin.")
log("Old and new source are not too loud and close.")
log("Transition: crossed, fade-in, fade-out.")
add(fade.out(sa),fade.in(sb))
elsif
# If B is significantly louder than A, only fade-out A.
# We don't want to fade almost silent things, ask for >medium.
b >= a + margin and a >= medium and b <= high
then
log("new >= old + margin, old >= medium and new <= high.")
log("New source is significantly louder than old one.")
log("Transition: crossed, fade-out.")
add(fade.out(sa),sb)
elsif
# Opposite as the previous one.
a >= b + margin and b >= medium and a <= high
then
log("old >= new + margin, new >= medium and old <= high")
log("Old source is significantly louder than new one.")
log("Transition: crossed, fade-in.")
add(sa,fade.in(sb))
elsif
# Do not fade if it's already very low.
b >= a + margin and a <= medium and b <= high
then
log("new >= old + margin, old <= medium and new <= high.")
log("Do not fade if it's already very low.")
log("Transition: crossed, no fade.")
add(sa,sb)
# What to do with a loud end and a quiet beginning ?
# A good idea is to use a jingle to separate the two tracks,
# but that's another story.
else
# Otherwise, A and B are just too loud to overlap nicely,
# or the difference between them is too large and overlapping would
# completely mask one of them.
log("No transition: using default.")
default(sa, sb)
end
end
smart_cross(width=width, duration=start_next, conservative=conservative,
transition,s)
end
# Custom playlist source written using the script language.
# Will read directory or playlist, play all files and stop
# @category Source / Input
# @param ~random Randomize playlist content
# @param ~on_done Function to execute when the playlist is finished
# @param uri Playlist URI
def playlist.once(~random=false,~on_done={()},uri)
x = ref 0
def playlist.custom(files)
length = list.length(files)
if length == 0 then
log("Empty playlist..")
fail ()
else
files =
if random then
list.sort(fun (x,y) -> int_of_float(random.float()), files)
else
files
end
def next () =
state = !x
file =
if state < length then
x := state + 1
list.nth(files,state)
else
# Playlist finished
on_done ()
""
end
request.create(file)
end
request.dynamic(next)
end
end
if test_process("test -d #{quote(uri)}") then
files = get_process_lines("find #{quote(uri)} -type f | sort")
playlist.custom(files)
else
playlist = request.create.raw(uri)
result =
if request.resolve(playlist) then
playlist = request.filename(playlist)
files = playlist.parse(playlist)
files = list.map(snd,files)
playlist.custom(files)
else
log("Couldn't read playlist: request resolution failed.")
fail ()
end
request.destroy(playlist)
result
end
end
# Mixes two streams, with faded transitions between the state when only the
# normal stream is available and when the special stream gets added on top of
# it.
# @category Source / Track Processing
# @param ~delay Delay before starting the special source.
# @param ~p Portion of amplitude of the normal source in the mix.
# @param ~normal The normal source, which could be called the carrier too.
# @param ~special The special source.
def smooth_add(~delay=0.5,~p=0.2,~normal,~special)
d = delay
fade.final = fade.final(duration=d*2.)
fade.initial = fade.initial(duration=d*2.)
q = 1. - p
c = amplify
fallback(track_sensitive=false,
[special,normal],
transitions=[
fun(normal,special)->
add(normalize=false,
[c(p,normal),
c(q,fade.final(type="sin",normal)),
sequence([blank(duration=d),c(q,special)])]),
fun(special,normal)->
add(normalize=false,
[c(p,normal),
c(q,fade.initial(type="sin",normal))])
])
end
# Restrict a source to play only when a predicate is true.
# @category Source / Track Processing
# @param pred The predicate, typically a time interval such as \
# <code>{10h-10h30}</code>.
def at(pred,s)
switch([(pred,s)])
end
# Execute a given action when a predicate is true.
# This will be run in background.
# @category System
# @param ~freq Frequency for checking the predicate, in seconds.
# @param ~pred Predicate indicating when to execute the function, \
# typically a time interval such as <code>{10h-10h30}</code>.
# @param f Function to execute when the predicate is true.
def exec_at(~freq=1.,~pred,f)
def check()
if pred() then
f()
end
freq
end
add_timeout(freq,check)
end
# Register the replaygain protocol
def replaygain_protocol(arg,delay)
# The extraction program
extract_replaygain = "#{configure.libdir}/extract-replaygain"
x = get_process_lines("#{extract_replaygain} #{quote(arg)}")
if list.hd(x) != "" then
["annotate:replay_gain=\"#{list.hd(x)}\":#{arg}"]
else
[arg]
end
end
add_protocol("replay_gain", replaygain_protocol)
# Enable replay gain metadata resolver. This resolver will
# process any file decoded by liquidsoap and add a @replay_gain@
# metadata when this value could be computed. For a finer-grained
# replay gain processing, use the @replay_gain@ protocol.
# @category Liquidsoap
# @param ~extract_replaygain The extraction program
def enable_replaygain_metadata(
~extract_replaygain="#{configure.libdir}/extract-replaygain")
def replaygain_metadata(file)
x = get_process_lines("#{extract_replaygain} \
#{quote(file)}")
if list.hd(x) != "" then
[("replay_gain",list.hd(x))]
else
[]
end
end
add_metadata_resolver("replay_gain", replaygain_metadata)
end
# Create a log of clock times for all the clocks initially present.
# The log is in simple format, which you can notably directly use with gnuplot.
# @category Liquidsoap
# @param ~interval Polling interval.
def log_clocks(~interval=1.,logfile)
# Get the current clocks
clocks = list.map(fst,get_clock_status())
# Column headers
system("echo \# #{string.concat(separator=' ',clocks)} > #{logfile}")
def report()
status = get_clock_status()
status = list.map(fun (x) -> (fst(x),string_of(snd(x))), status)
status = list.map(fun (c) -> status[c], clocks)
system("echo #{string.concat(separator=' ',status)} >> #{logfile}")
interval
end
add_timeout(interval,report)
end