Rikorose / DeepFilterNet

Noise supression using deep filtering
https://huggingface.co/spaces/hshr/DeepFilterNet2
Other
2.58k stars 239 forks source link

Fixed rust capi RuntimeParams struct default value. #607

Closed whyb closed 1 month ago

whyb commented 2 months ago

Why do this changes

When I use the C API, the audio noise reduction effect is different from the binary execution effect downloaded from the github release page.

Finding the difference

I carefully compared the implementation of the following two files: libDF/src/bin/enhance_wav.rs libDF/src/capi.rs

I found that RuntimeParams did not initialize all parameters in the capi.rs file. It only publish two functions, df_set_atten_lim() and df_set_post_filter_beta(), to set the values ​​of atten_lim_db and post_filter_beta in RuntimeParams.

In the enhance_wav.rs file, the command parser default_value_t is used to assign initial values ​​to each member variable of struct RuntimeParams.

enhance_wav.rs RuntimeParams default value:

pub struct RuntimeParams {
    pub n_ch: usize,         // enhance_wav.rs default: 1
    pub post_filter: bool,  // enhance_wav.rs default: false
    pub post_filter_beta: f32,  // enhance_wav.rs default: 0.02
    pub atten_lim_db: f32,  // enhance_wav.rs default: 100
    pub min_db_thresh: f32,   // enhance_wav.rs default: -15.0f32
    pub max_db_erb_thresh: f32,    // enhance_wav.rs default: 35.0f32
    pub max_db_df_thresh: f32,   // enhance_wav.rs default: 35.0f32
    pub reduce_mask: ReduceMask,  // enhance_wav.rs default: ReduceMask::MAX
}

Currently(before this pull requests) capi.rs RuntimeParams's default value:

pub fn default_with_ch(channels: usize) -> Self {
        RuntimeParams {
            n_ch: 1,
            post_filter: false,
            post_filter_beta: 0.02,
            atten_lim_db: 100.,
            min_db_thresh: -10.,
            max_db_erb_thresh: 30.,
            max_db_df_thresh: 20.,
            reduce_mask: ReduceMask::MEAN,
        }
    }

reference link: libDF/src/tract.rs#L176C1-L187C6