Skip to content

Add RMSNormalization transform for target-level RMS normalisation (closes #176)#183

Open
Shohail-Ismail wants to merge 4 commits intoiver56:mainfrom
Shohail-Ismail:feature/rms-normalisation
Open

Add RMSNormalization transform for target-level RMS normalisation (closes #176)#183
Shohail-Ismail wants to merge 4 commits intoiver56:mainfrom
Shohail-Ismail:feature/rms-normalisation

Conversation

@Shohail-Ismail
Copy link

Summary

Adds a new RMSNormalization transform (subclass of BaseWaveformTransform) that:

  • Converts a target RMS level in dBFS into a linear gain factor
  • Computes the combined‐signal RMS, applies gain = target_amp / (rms + eps)
  • Returns results in an ObjectDict (samples, sample_rate, etc.)

Tests

Includes three basic tests covering:

  1. Adjusting a 440 Hz sine wave from -20 dBFS to -10 dBFS
  2. Leaving silent input unchanged
  3. Applying equal gain to both channels of a stereo signal

Issue

Closes issue #176


Let me know if you’d like any further tweaks, thanks!

@iver56 iver56 self-requested a review June 28, 2025 06:56
Copy link
Owner

@iver56 iver56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

For consistency with the other transforms, I would like RMSNormalization to also have/support mode and p_mode arguments.

Also, let p default to 0.5 for now, so it has the same default as the others. I realize that this default might not be ideal, but consistency is good. An overall change in the default p in the future will need to be a separate effort.

@Shohail-Ismail
Copy link
Author

Shohail-Ismail commented Jun 28, 2025

Thanks for the feedback! Args mode and p_mode are now supported, and p defaults to 0.5 Let me know if there is anything further.

@Shohail-Ismail Shohail-Ismail requested a review from iver56 July 2, 2025 20:06
@iver56
Copy link
Owner

iver56 commented Jul 2, 2025

Thanks for the update! I will have another look soon. I'm on vacation these days. That is what has delayed the review. Thanks for the patience

@Shohail-Ismail
Copy link
Author

Hi @iver56, I would appreciate it if you could take a look when you get the chance. Thanks!

Copy link
Owner

@iver56 iver56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran pytest. It gave me an error:

torch_audiomentations\augmentations\rms_normalization.py:7: in <module>
    from ..utils import db_to_amplitude
E   ImportError: cannot import name 'db_to_amplitude' from 'torch_audiomentations.utils' (C:\Users\iver5\Code\torch-audiomentations\torch_audiomentations\utils\__init__.py)

@Shohail-Ismail
Copy link
Author

Shohail-Ismail commented Jul 31, 2025

@iver56 Apologies, I'm not sure why this wasn't apparent in my pytest a month ago, but regardless I have made the changes and pytest finishes cleanly.

@iver56
Copy link
Owner

iver56 commented Aug 3, 2025

Thanks! I will have a look

@Shohail-Ismail Shohail-Ismail requested a review from iver56 August 26, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants