From: Dan Dennedy Date: Wed, 6 Nov 2013 06:35:51 +0000 (-0800) Subject: Add analysis_level property to sox filter. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=847b05150117315546f683b63ece888c9dc61170;p=mlt Add analysis_level property to sox filter. For normalization analysis when not use_peak, sets the target amplitude. --- diff --git a/src/modules/sox/filter_sox.c b/src/modules/sox/filter_sox.c index 004c2be8..bc4ff44d 100644 --- a/src/modules/sox/filter_sox.c +++ b/src/modules/sox/filter_sox.c @@ -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 ); diff --git a/src/modules/sox/filter_sox.yml b/src/modules/sox/filter_sox.yml index e425281a..a70c4fd2 100644 --- a/src/modules/sox/filter_sox.yml +++ b/src/modules/sox/filter_sox.yml @@ -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