
      iQ                     $    d dl Z d Zd Zd Zd Zy)    Nc                 ~    t        j                  t        j                  t        j                  |       dd            S )z
    Calculates the root mean square.

    Based on https://github.com/iver56/audiomentations/blob/master/audiomentations/core/utils.py
    F)dimkeepdim)torchsqrtmeansquare)sampless    t/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torch_audiomentations/utils/dsp.pycalculate_rmsr      s)     ::ejjg!6BNOO    c                     | d|dz  z  z  }|S )a  
    Given the Root Mean Square (RMS) of a clean sound and a desired signal-to-noise ratio (SNR),
    calculate the desired RMS of a noise sound to be mixed in.
    Based on https://github.com/Sato-Kunihiko/audio-SNR/blob/8d2c933b6c0afe6f1203251f4877e7a1068a6130/create_mixed_audio_file.py#L20

    :param clean_rms: Root Mean Square (RMS) - a value between 0.0 and 1.0
    :param snr: Signal-to-Noise (SNR) Ratio in dB - typically somewhere between -20 and 60
    :return:
    
       )	clean_rmssnr	noise_rmss      r   calculate_desired_noise_rmsr      s     RC"H-.Ir   c                     d| dz  z  S )Nr   r   r   )decibelss    r   #convert_decibels_to_amplitude_ratior      s    (R-  r   c                 2    dt        j                  |       z  S )Nr   )r   log10)amplitude_ratios    r   #convert_amplitude_ratio_to_decibelsr      s    O,,,r   )r   r   r   r   r   r   r   r   <module>r      s    P!-r   