What is chuck's .gain measured in? Neither std.dbtorms() nor std.dbtopow() seem to work... I have a bunch of data about a sound, (frequency, dB): 86.132812, 9.996495, 172.265625, 6.996109, 258.398438, -0.955794, 344.531250, -11.900859, ... and I'd like to try some additive synthesis in chuck. The first value (frequency) is obvious, but I'm at a loss as to what to do with the second value (dB). What's the conversion factor between dB and .gain ? Cheers, - Graham
I think gain is just linear amplitude multiplication, like 0.0 is nothing, and 1.0 is nominal amplitude, and 0.5 is halfway between in amplitude space, thus -3dB from 1.0. PRc On Wed, 8 Mar 2006, Graham Percival wrote:
What is chuck's .gain measured in? Neither std.dbtorms() nor std.dbtopow() seem to work...
I have a bunch of data about a sound, (frequency, dB): 86.132812, 9.996495, 172.265625, 6.996109, 258.398438, -0.955794, 344.531250, -11.900859, ...
and I'd like to try some additive synthesis in chuck. The first value (frequency) is obvious, but I'm at a loss as to what to do with the second value (dB). What's the conversion factor between dB and .gain ?
Cheers, - Graham
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
I think the relationship is: fun float dbtogain( float db ) { return math.pow( 2, db/3 ); } fun float gaintodb( float gain ) { return 3 * math.log(gain) / math.log(2); } This is using 1.0 gain as reference (0 dB down). * You may have to normalize your input data. (offset all dB values by constant amount) * Both functions probably could be optimized. * gaintodb prefers positive values. * feel free to call me an idiot as always. Best, Ge! On Wed, 8 Mar 2006, Perry R Cook wrote:
I think gain is just linear amplitude multiplication, like 0.0 is nothing, and 1.0 is nominal amplitude, and 0.5 is halfway between in amplitude space, thus -3dB from 1.0.
PRc
On Wed, 8 Mar 2006, Graham Percival wrote:
What is chuck's .gain measured in? Neither std.dbtorms() nor std.dbtopow() seem to work...
I have a bunch of data about a sound, (frequency, dB): 86.132812, 9.996495, 172.265625, 6.996109, 258.398438, -0.955794, 344.531250, -11.900859, ...
and I'd like to try some additive synthesis in chuck. The first value (frequency) is obvious, but I'm at a loss as to what to do with the second value (dB). What's the conversion factor between dB and .gain ?
Cheers, - Graham
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
slightly optimized: fun float gaintodb( float gain ) { return 4.3280851226668906 * math.log(gain); } quick sanity check - gaintodb( 1/1000000000000.0 ) should yield close to 120 dB down, roughly the dynamic range of hearing. Should we put these in math/std? Ge!
On 8-Mar-06, at 9:25 PM, Ge Wang wrote:
fun float dbtogain( float db ) { return math.pow( 2, db/3 ); }
fun float gaintodb( float gain ) { return 3 * math.log(gain) / math.log(2); }
Thanks, that's great! Please add these to std, since there's already std.dbtorms and std.dbtopow in there. I'm not certain how those functions are supposed to work, though. The below code gives me "0.000 0.000 / 0.000 0.000". This is with chuck 1.2.0.4. float f1, f2; 0 => f1; -6 => f2; std.dbtorms(f1) => f1; std.dbtorms(f2) => f2; <<< f1, f2>>>; 0 => f1; -6 => f2; std.dbtopow(f1) => f1; std.dbtopow(f2) => f2; <<< f1, f2>>>;
participants (3)
-
Ge Wang
-
Graham Percival
-
Perry R Cook