|
I've found a technique for maximizing csound output level while
getting no samples out of range that works perfectly every time, and since this is a question that has come up more than once on the list, I thought I'd share. First, in all my instruments, I set my volume as follows: iAmp = ampdbfs(p4 + giDBScale) This gives me a global variable, giDBScale, which functions as a "master volume knob". This is what I will tweak to get the optimal overall level. While I'm working I keep giDBScale low enough so there are no samples out of range; there's no formula for this but since I'm not concerned at this point with optimal levels, I've been taking off 10 db at a time, so that if -10 db is still giving me samples out of range I'll try -20. You won't have to adjust it too often if you use 10 db steps. When I'm done and I'm ready to optimize my levels, first I render what I have to file. Then I find the volume level with sox like so: forrest@supercool:~/csound$ sox test.wav -n stat Samples read: 2143042 Length (seconds): 24.297528 Scaled by: 2147483647.0 Maximum amplitude: 0.405457 Minimum amplitude: -0.222015 Midline amplitude: 0.091721 Mean norm: 0.049194 Mean amplitude: 0.000016 RMS amplitude: 0.064597 Maximum delta: 0.370087 Minimum delta: 0.000000 Mean delta: 0.001209 RMS delta: 0.002654 Rough frequency: 288 Volume adjustment: 2.466 forrest@supercool:~/csound$ Note that last line, "Volume adjustment". This is how much we need to increase the level. We need to convert this to a db value, and add it to our current giDBScale value. The formula is 20 * log10(adjustment). Here's how to do it interactively in python: forrest@supercool:~/csound$ python Python 2.7.2+ (default, Jan 20 2012, 17:51:10) [GCC 4.6.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> 20 * math.log10(2.466) 7.839861445194257 >>> This is what we need to add to giDBScale. In my current file, giDBScale is set to -10. So I usually just use python to compute the exact value I need: >>> 20 * math.log10(2.466) -10 -2.1601385548057426 >>> Now this value is very close to exactly what you need to get maximum level with no samples out of range. If you use this exact value you'll probably get a few (I got 8 just now) and this is probably acceptable. I found that I needed to use -2.6 to actually get 0 samples out of range, so if you're obsessive like me you probably play with the value a bit to get it just right. But you're really super close; it's not a shot in the dark. I hope some of you on the list find this helpful and/or interesting. Forrest Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
|
Very nice and helpful for sure.
Now if only we could add an opcode to Csound that would do this all for us. Or - an option in the Front-ends that would post-process and re-render for us after these measurements were made. -dB
___________________________________ Dr. Richard Boulanger, Ph.D. Professor of Electronic Production and Design Professional Writing and Music Technology Division Berklee College of Music 1140 Boylston Street Boston, MA 02215-3693 617-747-2485 (office) 774-488-9166 (cell) ____________________________________ ____________________________________ ____________________________________ On Feb 5, 2012, at 3:11 AM, Forrest Cahoon wrote:
|
|
On 05/02/2012 08:14, Dr. Richard Boulanger wrote:
> Very nice and helpful for sure. > Now if only we could add an opcode to Csound that would do this all for us. > Or - an option in the Front-ends that would post-process and re-render > for us after these measurements were made. > I provided a mechanism for this some time ago using the PEAK chunk added to the soundfile header. If you write the output as a floating point soundfile, there is no output clipping, and the peak sample value (relative to 0dbfs=1) is written to the header. The file can then be read back into Csound and the same PEAK value is then used (if over-range) to rescale the samples automatically. I haven't looked to see if the code I wrote for that (buried deep down inside the "soundin" code) still esists though. The same facility can be incorporated into any soundfile reader/player (we do it in CDP, for example). However, there is a caveat with all such global solutions - already quiet sounds are rescaled to be even quieter. It will, for example, reduce reverb lengths. In the end there is no proper substitute for tracking down the offending notes/instruments and adjusting those, so that those already OK levels elsewhere do not get reduced out of existence. For integer samples, rescaling to digital maximum is also not recommended; a generally safe upper limit is -1.5dBFS; and with 24bit an upper limit of -6dB (= 0.5 amplitude) does no harm at all. Richard Dobson Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
|
In reply to this post by forrest cahoon-2
I do something similar but using the scale utility
==John ff > I've found a technique for maximizing csound output level while > getting no samples out of range that works perfectly every time, and > since this is a question that has come up more than once on the list, > I thought I'd share. > > First, in all my instruments, I set my volume as follows: > > iAmp = ampdbfs(p4 + giDBScale) > > This gives me a global variable, giDBScale, which functions as a > "master volume knob". This is what I will tweak to get the optimal > overall level. > > While I'm working I keep giDBScale low enough so there are no samples > out of range; there's no formula for this but since I'm not concerned > at this point with optimal levels, I've been taking off 10 db at a > time, so that if -10 db is still giving me samples out of range I'll > try -20. You won't have to adjust it too often if you use 10 db steps. > > When I'm done and I'm ready to optimize my levels, first I render what > I have to file. Then I find the volume level with sox like so: > > forrest@supercool:~/csound$ sox test.wav -n stat > Samples read: 2143042 > Length (seconds): 24.297528 > Scaled by: 2147483647.0 > Maximum amplitude: 0.405457 > Minimum amplitude: -0.222015 > Midline amplitude: 0.091721 > Mean norm: 0.049194 > Mean amplitude: 0.000016 > RMS amplitude: 0.064597 > Maximum delta: 0.370087 > Minimum delta: 0.000000 > Mean delta: 0.001209 > RMS delta: 0.002654 > Rough frequency: 288 > Volume adjustment: 2.466 > forrest@supercool:~/csound$ > > Note that last line, "Volume adjustment". This is how much we need to > increase the level. We need to convert this to a db value, and add it > to our current giDBScale value. The formula is 20 * > log10(adjustment). Here's how to do it interactively in python: > > forrest@supercool:~/csound$ python > Python 2.7.2+ (default, Jan 20 2012, 17:51:10) > [GCC 4.6.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import math >>>> 20 * math.log10(2.466) > 7.839861445194257 >>>> > > This is what we need to add to giDBScale. In my current file, > giDBScale is set to -10. So I usually just use python to compute the > exact value I need: > >>>> 20 * math.log10(2.466) -10 > -2.1601385548057426 >>>> > > Now this value is very close to exactly what you need to get maximum > level with no samples out of range. If you use this exact value you'll > probably get a few (I got 8 just now) and this is probably acceptable. > I found that I needed to use -2.6 to actually get 0 samples out of > range, so if you're obsessive like me you probably play with the value > a bit to get it just right. But you're really super close; it's not a > shot in the dark. > > I hope some of you on the list find this helpful and/or interesting. > > Forrest > > > Send bugs reports to the Sourceforge bug tracker > https://sourceforge.net/tracker/?group_id=81968&atid=564599 > Discussions of bugs and features can be posted here > To unsubscribe, send email [hidden email] with body "unsubscribe > csound" > > > > Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
|
In reply to this post by forrest cahoon-2
Am 05.02.12 09:11, schrieb Forrest Cahoon:
> I've found a technique for maximizing csound output level while > getting no samples out of range that works perfectly every time, and > since this is a question that has come up more than once on the list, > I thought I'd share. Instead of scaling every note amplitude you can do this on the "out"s, since internal computation is done by floats. But this only works for non-realtime (file) output. For realtime you need to have adjusted your amplitudes in earlier non-realtime or realtime test runs and should let much more headroom for safety. Adding an automatic rescaling pass from float to int after a calculation with temporary float output would be a nice thing, but a warning should be printed if used with a realtime option (if possible). The idea with the rescaling float-soundfile player Richard Dobson showed us is also a good idea. It would be nice to be able to have both options. Jörg Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
|
In reply to this post by forrest cahoon-2
One of my preferred csound option is `-n' (or --nosound).
In my scripts I avoid to write the soundfile adding #ifdef _NORM_ 0dbfs = $_NORM_ #endif in the csd file and using this shell script #!/bin/sh # cs_norm [ $# -lt 2 ] && echo "Usage: $(basename $0) <norm> <csopt>" && exit 1 NORM="$1" shift echo "waiting..." PEAK=$(csound -d -n -m0 $@ 2>&1 \ |sed -n '/^end of score.*overall amps:/s/^.*amps://p' \ |xargs -n1|sort -nr|head -1|xargs echo "(1/$NORM)*"|bc -l) [ $? -ne 0 ] && PEAK=0 csound -m167 --omacro:_NORM_="$PEAK" $@ exit For example: cs_norm 0.5 test.csd ... end of score. overall amps: -6.02 -6.94 ... tito On Sun, Feb 05, 2012 at 02:11:14AM -0600, Forrest Cahoon wrote: > I've found a technique for maximizing csound output level while > getting no samples out of range that works perfectly every time, and > since this is a question that has come up more than once on the list, > I thought I'd share. > > First, in all my instruments, I set my volume as follows: > > iAmp = ampdbfs(p4 + giDBScale) > > This gives me a global variable, giDBScale, which functions as a > "master volume knob". This is what I will tweak to get the optimal > overall level. > > While I'm working I keep giDBScale low enough so there are no samples > out of range; there's no formula for this but since I'm not concerned > at this point with optimal levels, I've been taking off 10 db at a > time, so that if -10 db is still giving me samples out of range I'll > try -20. You won't have to adjust it too often if you use 10 db steps. > > When I'm done and I'm ready to optimize my levels, first I render what > I have to file. Then I find the volume level with sox like so: > > forrest@supercool:~/csound$ sox test.wav -n stat > Samples read: 2143042 > Length (seconds): 24.297528 > Scaled by: 2147483647.0 > Maximum amplitude: 0.405457 > Minimum amplitude: -0.222015 > Midline amplitude: 0.091721 > Mean norm: 0.049194 > Mean amplitude: 0.000016 > RMS amplitude: 0.064597 > Maximum delta: 0.370087 > Minimum delta: 0.000000 > Mean delta: 0.001209 > RMS delta: 0.002654 > Rough frequency: 288 > Volume adjustment: 2.466 > forrest@supercool:~/csound$ > > Note that last line, "Volume adjustment". This is how much we need to > increase the level. We need to convert this to a db value, and add it > to our current giDBScale value. The formula is 20 * > log10(adjustment). Here's how to do it interactively in python: > > forrest@supercool:~/csound$ python > Python 2.7.2+ (default, Jan 20 2012, 17:51:10) > [GCC 4.6.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import math > >>> 20 * math.log10(2.466) > 7.839861445194257 > >>> > > This is what we need to add to giDBScale. In my current file, > giDBScale is set to -10. So I usually just use python to compute the > exact value I need: > > >>> 20 * math.log10(2.466) -10 > -2.1601385548057426 > >>> > > Now this value is very close to exactly what you need to get maximum > level with no samples out of range. If you use this exact value you'll > probably get a few (I got 8 just now) and this is probably acceptable. > I found that I needed to use -2.6 to actually get 0 samples out of > range, so if you're obsessive like me you probably play with the value > a bit to get it just right. But you're really super close; it's not a > shot in the dark. > > I hope some of you on the list find this helpful and/or interesting. > > Forrest > > > Send bugs reports to the Sourceforge bug tracker > https://sourceforge.net/tracker/?group_id=81968&atid=564599 > Discussions of bugs and features can be posted here > To unsubscribe, send email [hidden email] with body "unsubscribe csound" Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
|
Hi Tito,
if you do it this way (below) you calculate the sound twice which is less efficient than calculating the sound once and then only convert the samples. Am 05.02.12 13:46, schrieb Tito Latini: > One of my preferred csound option is `-n' (or --nosound). > In my scripts I avoid to write the soundfile adding > > #ifdef _NORM_ > 0dbfs = $_NORM_ > #endif > > in the csd file and using this shell script > > #!/bin/sh > # cs_norm > > [ $# -lt 2 ]&& echo "Usage: $(basename $0)<norm> <csopt>"&& exit 1 > > NORM="$1" > shift > echo "waiting..." > PEAK=$(csound -d -n -m0 $@ 2>&1 \ > |sed -n '/^end of score.*overall amps:/s/^.*amps://p' \ > |xargs -n1|sort -nr|head -1|xargs echo "(1/$NORM)*"|bc -l) > > [ $? -ne 0 ]&& PEAK=0 > csound -m167 --omacro:_NORM_="$PEAK" $@ > exit Your way is useful if you have a fast machine and less complex orchestras. But if your csd cannot run in realtime because your machine is too slow or you have a lot of computation going on in your csd, you have to wait almost twice the time then. Jörg Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
|
of course; I know four possibilities
a) 1 pass and normalize the sound in memory (ala 'nyquist' with `autonorm-on') b) 1 pass -> write soundfile -> normalize c) 1 pass -> write soundfile -> read peak value -> 2 pass with the scaling factor d) 1 pass -> no write soundfile -> read peak value -> 2 pass ... I like 'd' in batch mode with the GNU `parallel' command. On Sun, Feb 05, 2012 at 09:45:50PM +0100, Joerg Spix wrote: > Hi Tito, > > if you do it this way (below) you calculate the sound twice which is > less efficient than calculating the sound once and then only convert the > samples. > > Am 05.02.12 13:46, schrieb Tito Latini: > >One of my preferred csound option is `-n' (or --nosound). > >In my scripts I avoid to write the soundfile adding > > > >#ifdef _NORM_ > >0dbfs = $_NORM_ > >#endif > > > >in the csd file and using this shell script > > > >#!/bin/sh > ># cs_norm > > > >[ $# -lt 2 ]&& echo "Usage: $(basename $0)<norm> <csopt>"&& exit 1 > > > >NORM="$1" > >shift > >echo "waiting..." > >PEAK=$(csound -d -n -m0 $@ 2>&1 \ > > |sed -n '/^end of score.*overall amps:/s/^.*amps://p' \ > > |xargs -n1|sort -nr|head -1|xargs echo "(1/$NORM)*"|bc -l) > > > >[ $? -ne 0 ]&& PEAK=0 > >csound -m167 --omacro:_NORM_="$PEAK" $@ > >exit > > Your way is useful if you have a fast machine and less complex > orchestras. But if your csd cannot run in realtime because your machine > is too slow or you have a lot of computation going on in your csd, you > have to wait almost twice the time then. > > Jörg > > > Send bugs reports to the Sourceforge bug tracker > https://sourceforge.net/tracker/?group_id=81968&atid=564599 > Discussions of bugs and features can be posted here > To unsubscribe, send email [hidden email] with body "unsubscribe > csound" Send bugs reports to the Sourceforge bug tracker https://sourceforge.net/tracker/?group_id=81968&atid=564599 Discussions of bugs and features can be posted here To unsubscribe, send email [hidden email] with body "unsubscribe csound" |
| Powered by Nabble | See how NAML generates this page |
