pytorch/audio

Division by zero in loudness calculation

dhanvanth-pk-13760 opened this issue · 0 comments

The following line in the functional method loudness results in nan value when the entire waveform is below the hardcoded loudness threshold value gamma_abs = -70.

# Apply relative gating of the blocks
gated_blocks = torch.logical_and(gated_blocks.squeeze(-2), loudness > gamma_rel.unsqueeze(-1))
gated_blocks = gated_blocks.unsqueeze(-2)
energy_filtered = torch.sum(gated_blocks * energy, dim=-1) / torch.count_nonzero(gated_blocks, dim=-1)

An example case is while trying to find loudness of an ambient sound signal.

The threshold can probably be made configurable with mention in documentation.