2 # Ardour session synthesizer
3 # (c)Sampo Savolainen 2007-2008
6 # This reads an Ardour session file and creates zero-signal source files
7 # for each missing source file. The length of each file is determined
8 # by how far regions using that source file go into the sample data.
12 use XML
::Parser
::PerlSAX
;
13 use XML
::Handler
::XMLWriter
;
16 use ARDOUR
::SourceInfoLoader
;
18 my $usage = "usage: synthesize_sources.pl samplerate [session name, the name must match the directory and the .ardour file in it] [options: -sine for 440hz sine waves in wave files]\n";
20 my ($samplerate, $sessionName, @options) = @ARGV;
22 if ( ! -d
$sessionName || ! -f
$sessionName."/".$sessionName.".ardour" ) {
27 my $waveType = "silent";
29 foreach my $o (@options) {
32 } elsif ($o eq "-silent") {
35 print "unknown parameter ".$o."\n";
43 my $sessionFile = $sessionName."/".$sessionName.".ardour";
46 my $handler = new ARDOUR
::SourceInfoLoader
($sessionName);
48 my $parser = XML
::Parser
::PerlSAX
->new( Handler
=> $handler );
50 $parser->parse(Source
=> { SystemId
=> $sessionFile });
52 if ( ! -d
$sessionName."/interchange" ) {
53 mkdir $sessionName."/interchange/" || die "couldn't create ".$sessionName."/interchange";
56 if ( ! -d
$sessionName."/interchange/".$sessionName ) {
57 mkdir $sessionName."/interchange/".$sessionName || die "couldn't create ".$sessionName."/interchange/".$sessionName;
60 if ( ! -d
$sessionName."/interchange/".$sessionName."/audiofiles" ) {
61 mkdir $sessionName."/interchange/".$sessionName."/audiofiles" || die "couldn't create ".$sessionName."/interchange/".$sessionName."/audiofiles";
64 if ( ! -d
$sessionName."/peaks") {
65 mkdir $sessionName."/peaks/" || die "couldn't create ".$sessionName."/peaks";
68 my $audioFileDirectory = $sessionName."/interchange/".$sessionName."/audiofiles";
70 my %sources = %{$handler->{Sources
}};
72 foreach my $tmp (keys %sources) {
74 print "Generating ".$audioFileDirectory."/".$sources{$tmp}->{name
}."\n";
78 "-t", "raw", # /dev/zero is raw :)
79 "-r", $samplerate, # set sample rate
80 "-c", "1", # 1 channel
81 "-b", "8" # input in 8 bit chunks
83 "/dev/zero", # input signal
85 "-b", "16" # input in 16 bit chunks
86 "-t", "wav", # format wav
87 $audioFileDirectory."/".$sources{$tmp}->{name
}, # filename
88 "trim", "0", $sources{$tmp}->{calculated_length
}."s" # trim silence to wanted sample amount
91 if ($waveType eq "sine") {
92 @cmd = (@cmd, "synth","sin","%0", "vol", "0.2", "fade","q","0.01s", $sources{$tmp}->{calculated_length
}."s" , "0.01s");