4

I have a simple SinOsc which plays a 432 hz tone. I want to be able to set that tone to -97 dB. Here's what I have so far:

{
    SinOsc.ar(432, 0, 0.01 /*edit this for volume*/, 0)
}.play;

Even though I can see how to edit volume, I don't see a way to set the precise dB level.

In case you are wondering why I am doing this, I need a tone to test 24-bit vs. 16-bit audio.

How can I set the precise dB level or get monitoring to show me what level I am at?

2 Answers2

3

Ah, cool to see a SuperCollider question in Top Questions.

I believe the method you're looking for is .dbamp. See the docs.

Example: (from The SuperCollider Book, Chapter 2)

/* Figure 2.6 */
(
SynthDef(\UGen_ex6, {arg gate = 1, roomsize = 200, revtime = 450;
    var src, env, gverb;
    env = EnvGen.kr(Env([0, 1, 0], [1, 4], [4, -4], 1), gate, doneAction: 2);
    src = Resonz.ar(
            Array.fill(4, {Dust.ar(6)}),
            1760 * [1, 2.2, 3.95, 8.76] +
                Array.fill(4, {LFNoise2.kr(1, 20)}),
            0.01).sum * 30.dbamp;
    gverb = GVerb.ar(
        src,
        roomsize,
        revtime,
        // feedback loop damping
        0.99,
        // input bw of signal
        LFNoise2.kr(0.1).range(0.9, 0.7),
        // spread
        LFNoise1.kr(0.2).range(0.2, 0.6),
        // almost no direct source
        -60.dbamp,
        // some early reflection
        -18.dbamp,
        // lots of the tail
        3.dbamp,
        roomsize);
    Out.ar(0, gverb * env)
}).add;
)
a = Synth(\UGen_ex6);
Matthew Hinea
  • 1,872
  • 19
  • 31
1

If that 0.01 value is the gain, then simply replace it with the result of

10^(-97/20) = 0.00001412537
learnvst
  • 15,455
  • 16
  • 74
  • 121
  • Good answer but not as good as the other guy's. Thanks anyway (: – progressiveCavemen Mar 24 '17 at 12:44
  • Sure. I don't know sclang, so I just posted the canonical conversion. That will probably be all that `.dbamp` is doing under the hood – learnvst Mar 24 '17 at 12:46
  • Interesting. How do you know that's the "canonical" conversion? I didn't think this kind of thing would be standard. – progressiveCavemen Mar 24 '17 at 12:48
  • 1
    dB is just a ratio represented in a graspable way when a logarithmic scale is relevant (as is typical for things relating to human perception - Weber's Law). Linear to dB is simply `20*log10(linear_value)`, and as I posted dB to linear is simply `10^(dB/20)`. That's all that those utility functions will be doing under the hood. – learnvst Mar 24 '17 at 12:51