Permalink
Browse files

Add analysis_level property to sox filter.

For normalization analysis when not use_peak, sets the target amplitude.
  • Loading branch information...
ddennedy committed Nov 6, 2013
1 parent 5ecf862 commit 847b05150117315546f683b63ece888c9dc61170
Showing with 25 additions and 2 deletions.
  1. +12 −1 src/modules/sox/filter_sox.c
  2. +13 −1 src/modules/sox/filter_sox.yml
@@ -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 );
@@ -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

0 comments on commit 847b051

Please sign in to comment.