]> git.sesse.net Git - mlt/commitdiff
Add analysis_level property to sox filter.
authorDan Dennedy <dan@dennedy.org>
Wed, 6 Nov 2013 06:35:51 +0000 (22:35 -0800)
committerDan Dennedy <dan@dennedy.org>
Wed, 6 Nov 2013 06:35:51 +0000 (22:35 -0800)
For normalization analysis when not use_peak, sets the target amplitude.

src/modules/sox/filter_sox.c
src/modules/sox/filter_sox.yml

index 004c2be8a83c21818044e91599dc0b3e4b4f884a..bc4ff44da4e660d690a6b33ca11c3dc2983a7fde 100644 (file)
@@ -57,6 +57,7 @@
 #define BUFFER_LEN 8192
 #define AMPLITUDE_NORM 0.2511886431509580 /* -12dBFS */
 #define AMPLITUDE_MIN 0.00001
+#define DBFSTOAMP(x) pow(10,(x)/20.0)
 
 /** Compute the mean of a set of doubles skipping unset values flagged as -1
 */
@@ -311,7 +312,17 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
                                        if ( use_peak )
                                                normalised_gain = ST_SSIZE_MIN / -peak;
                                        else
-                                               normalised_gain = AMPLITUDE_NORM / rms;
+                                       {
+                                               double gain = DBFSTOAMP(-12); // default -12 dBFS
+                                               char *p = mlt_properties_get( filter_properties, "analysis_level" );
+                                               if (p)
+                                               {
+                                                       gain = mlt_properties_get_double( filter_properties, "analysis_level" );
+                                                       if ( strstr( p, "dB" ) )
+                                                               gain = DBFSTOAMP( gain );
+                                               }
+                                               normalised_gain = gain / rms;
+                                       }
 
                                        // Set properties for serialization
                                        snprintf( effect, sizeof(effect), "vol %f", normalised_gain );
index e425281a8593909f9a42dd694c690c7eb94522ec..a70c4fd205353b586385a7de0849e5f188886be5 100644 (file)
@@ -16,7 +16,8 @@ bugs:
   - Some effects have a temporal side-effect that do not work well.
 
 parameters:
-  - identifier: argument
+  - identifier: effect
+    argument: yes
     title: Effect name and options
     type: string
     format: effect [options]
@@ -26,6 +27,17 @@ parameters:
       The results are put into the level, peak, and gain properties as well
       as this effect property as the parameter to the vol effect.
 
+  - identifier: analysis_level
+    title: Normalization level
+    type: string
+    default: -12dBFS
+    description: >
+      Normalize the volume to the specified amplitude.
+      The normalization may be indicated as a floating point value of the
+      relative volume with 1.0 being maximum.
+      The normalization may also be indicated as a numeric value with the
+      suffix "dB" to set the amplitude in decibels.
+
   - identifier: level
     title: Signal power level (RMS)
     type: float