factor db

Hello.
I try to use the scale-db function: (scale-db db sound) [LISP]
“db” is the factor. In this code

  (defun note (pitch dur amp)
      (scale-db   (-  amp 12 )(osc pitch dur *table*)))

    (abs-env
    (seq
     (note c4 i lp)
     (note d4 i lpp)
     (note f4 i lmp)
     (note g4 i lmf)
     (note d4 q lf)))

the factor is determined by: (- amp 12).
My question is the following one: after all, what is the value of the factor?
Thank you for your answer.

(- amp 12 ) means amp - 12.
Whatever value “amp” is, (- amp 12) means 12 less.
So if amp = 18, then (- amp 12) is 6.

(scale-db (- amp 12 ) sound) will amplify “sound” by “amp - 12” dB.

The actual amplitude is given within the ‘sec’ statement.
There are some variables that define a constant loudness.
They refer to the usual terms in a score, such as

  • forte fortissimo = lfff
  • mezzo piano = lmp
    ranging from lppp to lfff.

There are another 12 dB subtracted, presumably to keep the output volume low.

Thank you.
Thus we choose the value of the factor after all to avoid of the saturation.It is thus necessary to think of the following equivalences:lfff = 12 db = …? (peak),
lff = 9.0 dB = 4.0, lf = 6.0 dB = 2.0, lmp = -3.0 dB = …?, lp = -6.0 dB = 0.5,lpp = -9.0 dB = 0.25, lppp = -12 dB = 0.125.
It is right?
Thus, we can write the following code if we want to use the note: [note d4 q lff]

(defun note (pitch dur amp )
 (scale-db (- amp 9.01) (osc pitch dur *table*)))

I can write the following code if the most powerful note is: [note d4 q lmp]

(defun note (pitch dur amp )
 (scale-db (+ amp 2.99) (osc pitch dur *table*)))

    (abs-env
    (seq
     (note c4 i lp)
     (note d4 i lpp)
     (note f4 i lpp)
     (note g4 i lppp)
     (note d4 q lmp)))

I listened to well the audio file generated by this code. There is a problem. Why has your not the impression that it is the last note which is the most powerful? We would almost have the impression that it is the f4. The impression is very different if I write:

 (abs-env
    (seq
     (note c4 i lp)
     (note d4 i lpp)
     (note f4 i lpp)
     (note g4 i lppp)
     (note f4 q lmp)))

Beforehand thank you for your answer.

Using the default sine oscillator:

(defun note (pitch dur amp )
 (scale-db (+ amp 2.99) (osc pitch dur)))

    (abs-env
    (seq
     (note c4 i lp)
     (note d4 i lpp)
     (note f4 i lpp)
     (note g4 i lppp)
     (note d4 q lmp)))

The amplitudes clearly follow the defined dynamics:
firsttrack000.png

Not quite. The highest factor is x 4 for lfff:

Musical term	dB	Linear	MIDI Velocity	MIDI absolute (dB)		
lfff	12	4	127	0		
lff	9	2.8282	112	-1.091713966		
lf	6	2	96	-2.430649758		
lmf	3	1.4141	80	-4.014274679		
lmp	-3	0.7071	64	-5.952474939		
lp	-6	0.5	48	-8.451249672		
lpp	-9	0.35355	32	-11.97307485	-12	0.125
lppp	-12	0.25	16	-17.99367477

The fact that there is no value for 0 dB = factor 1 indicates that all those loudness values are relative.
The dB values for MIDI aren’t to be taken seriously. It depends on the machine how the 127 possible values are mapped to a specific volume/loudness/velocity.