Columns
News
Beginners
Internals
Processing
Departments
Links
Editorial
Contribute
Back Issues
|
|
News
Hans Mikelson
hans@csounds.com
AutoScale
Some people have wished for the ability to generate
normalized output from a Csound file. I believe the
following Perl program accomplishes this. I set this up
in its own directory with the files I wanted to convert.
This requires a console version of Csound to be running
which I placed in the same directory. The program creates
a modified orchestra derived from the input orchestra
then runs it with the original score. This could probably
be modified to process an entire directory of orc/sco
pairs. One problem that I know of is if the numbers are
so large that the console output text gets messed up then
only the left side will end up being normalized. This
program has no warranty expressed or implied and should
be used at your own risk.
# Autoscale script
# This should be run with a command line version of Csound
# such as consound.
$inorc = "julia.orc"; # Put your orc name here
$insco = "julia.sco"; # Put your sco name here
# The following line runs Csound and saves the console output
# to autoscl.out for stdout and autoscl.err for std.error
system("csound.exe -d -W -otest.wav $inorc $insco 1>autoscl.out 2>autoscl.err");
open(INFO, "autoscl.out"); # Open the file with the score amp values.
@LINES=<INFO>; # Read all of the lines in the file into @LINES
close(INFO); # Close the file
foreach $LINE (@LINES) # For each line of the file.
{
# The next line matches the end of score maximum amplitudes.
if ($LINE =~ /end of score.\s+overall amps:\s*(\S+)\s*(\S*)/)
{
$maxleft = $1; # Get the maximum value for the left side
$maxright = $2; # Get the maximum value for the right side
}
}
$max = $maxleft>$maxright ? $maxleft : $maxright; # Is left or right bigger?
print "Max = $max\n";
$maxval = 32767/$max; # Find the scaling factor
open(INORC, $inorc); # Open the offending orchestra
@ORCLINES = <INORC>; # Put it in @ORCLINES
close(INORC); # Close the file
open(OUTORC, ">autoscl.orc"); # Create a new orc called autoscl.orc
# you could put $inorc here if you wanted to
# modify your actual orchestra.
foreach $INOLINE (@ORCLINES) # Scan each line of the orchestra
{
# Search for the outs opcode
if ($INOLINE =~ /\s*outs\s+(\S+)\s*,\s*(\S+)\s*;*/)
{
$op1 = $1; # Save the outs aout1, aout2 values
$op2 = $2; # in op1 and op2
$INOLINE = "outs $op1*$maxval,$op2*$maxval"; # Modify the outs line
}
print OUTORC $INOLINE; # Print the line to the new file
}
close(OUTORC); # Close the new file
# The next line runs the score with the modified orchestra
system("csound.exe -d -W -otest.wav autoscl.orc $insco 1>autoscl.out 2>autoscl.err");
Introduction
I have decided to rename the weekly section news since
I am not able to contribute weekly. I thought that might
be a better name for this section. I will try to
contribute an orchestra and score or some other snippet
of code here approximately once a month.
|
|