avfilter/af_afftdn: add way to control noise floor link for >1 channels
This commit is contained in:
		
							parent
							
								
									3cb5a5f64c
								
							
						
					
					
						commit
						61224c856c
					
				| @ -1347,6 +1347,26 @@ Set the adaptivity factor, used how fast to adapt gains adjustments per | ||||
| each frequency bin. Value @var{0} enables instant adaptation, while higher values | ||||
| react much slower. | ||||
| Allowed range is from @var{0} to @var{1}. Default value is @var{0.5}. | ||||
| 
 | ||||
| @item noise_link, nl | ||||
| Set the noise link used for multichannel audio. | ||||
| 
 | ||||
| It accepts the following values: | ||||
| @table @option | ||||
| @item none | ||||
| Use unchanged channel's noise floor. | ||||
| 
 | ||||
| @item min | ||||
| Use measured min noise floor of all channels. | ||||
| 
 | ||||
| @item max | ||||
| Use measured max noise floor of all channels. | ||||
| 
 | ||||
| @item average | ||||
| Use measured average noise floor of all channels. | ||||
| 
 | ||||
| Default value is @var{min}. | ||||
| @end table | ||||
| @end table | ||||
| 
 | ||||
| @subsection Commands | ||||
|  | ||||
| @ -41,6 +41,14 @@ enum OutModes { | ||||
|     NB_MODES | ||||
| }; | ||||
| 
 | ||||
| enum NoiseLinkType { | ||||
|     NONE_LINK, | ||||
|     MIN_LINK, | ||||
|     MAX_LINK, | ||||
|     AVERAGE_LINK, | ||||
|     NB_LINK | ||||
| }; | ||||
| 
 | ||||
| enum NoiseType { | ||||
|     WHITE_NOISE, | ||||
|     VINYL_NOISE, | ||||
| @ -103,6 +111,7 @@ typedef struct AudioFFTDeNoiseContext { | ||||
|     int     track_noise; | ||||
|     int     track_residual; | ||||
|     int     output_mode; | ||||
|     int     noise_floor_link; | ||||
|     float   ratio; | ||||
| 
 | ||||
|     float   last_residual_floor; | ||||
| @ -185,6 +194,12 @@ static const AVOption afftdn_options[] = { | ||||
|     {  "n", "noise",                      0,                       AV_OPT_TYPE_CONST,  {.i64 = NOISE_MODE},    0,  0, AFR, "mode" }, | ||||
|     { "adaptivity", "set adaptivity factor",OFFSET(ratio),         AV_OPT_TYPE_FLOAT,  {.dbl = 0.5},           0,  1, AFR }, | ||||
|     { "ad",         "set adaptivity factor",OFFSET(ratio),         AV_OPT_TYPE_FLOAT,  {.dbl = 0.5},           0,  1, AFR }, | ||||
|     { "noise_link", "set the noise floor link",OFFSET(noise_floor_link),AV_OPT_TYPE_INT,{.i64 = MIN_LINK},     0,  NB_LINK-1, AFR, "link" }, | ||||
|     { "nl", "set the noise floor link",        OFFSET(noise_floor_link),AV_OPT_TYPE_INT,{.i64 = MIN_LINK},     0,  NB_LINK-1, AFR, "link" }, | ||||
|     {  "none",    "none",                 0,                       AV_OPT_TYPE_CONST,  {.i64 = NONE_LINK},     0,  0, AFR, "link" }, | ||||
|     {  "min",     "min",                  0,                       AV_OPT_TYPE_CONST,  {.i64 = MIN_LINK},      0,  0, AFR, "link" }, | ||||
|     {  "max",     "max",                  0,                       AV_OPT_TYPE_CONST,  {.i64 = MAX_LINK},      0,  0, AFR, "link" }, | ||||
|     {  "average", "average",              0,                       AV_OPT_TYPE_CONST,  {.i64 = AVERAGE_LINK},  0,  0, AFR, "link" }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
| @ -1103,12 +1118,32 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) | ||||
|     } | ||||
| 
 | ||||
|     if (s->track_noise) { | ||||
|         double average = 0.0, min = DBL_MAX, max = -DBL_MAX; | ||||
| 
 | ||||
|         for (int ch = 0; ch < inlink->channels; ch++) { | ||||
|             DeNoiseChannel *dnch = &s->dnch[ch]; | ||||
|             double levels[NB_PROFILE_BANDS]; | ||||
| 
 | ||||
|             get_auto_noise_levels(s, dnch, levels); | ||||
|             set_noise_profile(s, dnch, levels, 0); | ||||
|             average += dnch->noise_floor; | ||||
|             max = fmax(max, dnch->noise_floor); | ||||
|             min = fmin(min, dnch->noise_floor); | ||||
|         } | ||||
| 
 | ||||
|         average /= inlink->channels; | ||||
| 
 | ||||
|         for (int ch = 0; ch < inlink->channels; ch++) { | ||||
|             DeNoiseChannel *dnch = &s->dnch[ch]; | ||||
| 
 | ||||
|             switch (s->noise_floor_link) { | ||||
|             case MIN_LINK:     dnch->noise_floor = min;     break; | ||||
|             case MAX_LINK:     dnch->noise_floor = max;     break; | ||||
|             case AVERAGE_LINK: dnch->noise_floor = average; break; | ||||
|             case NONE_LINK: | ||||
|             default: | ||||
|                 break; | ||||
|             } | ||||
| 
 | ||||
|             if (dnch->noise_floor != dnch->last_noise_floor) | ||||
|                 set_parameters(s, dnch, 1, 0); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user