[Csnd] My technique for maximizing output level
Date | 2012-02-05 08:11 |
From | Forrest Cahoon |
Subject | [Csnd] My technique for maximizing output level |
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 |
Date | 2012-02-05 08:14 |
From | "Dr. Richard Boulanger" |
Subject | Re: [Csnd] My technique for maximizing output level |
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:
|
Date | 2012-02-05 09:42 |
From | Richard Dobson |
Subject | Re: [Csnd] My technique for maximizing output level |
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 |
Date | 2012-02-05 12:35 |
From | Joerg Spix |
Subject | Re: [Csnd] My technique for maximizing output level |
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 |
Date | 2012-02-05 12:46 |
From | Tito Latini |
Subject | Re: [Csnd] My technique for maximizing output level |
Attachments | None |
Date | 2012-02-05 20:45 |
From | Joerg Spix |
Subject | Re: [Csnd] My technique for maximizing output level |
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) |
Date | 2012-02-05 21:41 |
From | Tito Latini |
Subject | Re: [Csnd] My technique for maximizing output level |
Attachments | None |