Skip to content

index out of range for inputs slightly longer than 12 seconds (or multiples) #2

Description

@mtorcoli

Hi,

First of all, thanks for making binaqual openly available.

Issue

I’m encountering an IndexError: list index out of range when the input audio length is slightly longer than a multiple of 12 seconds.


File ".../Binaqual/vnsim.py", line 107, in calc_ref_test_similarity
    neurogram_map = mask_patches[patch_index] * neurogram_map
                    ~~~~~~~~~~~~^^^^^^^^^^^^^
IndexError: list index out of range

Observation

It appears that mask_patches contains fewer patches than ref_patches and test_patches, which leads to the out-of-range access.

Reproduction

I can consistently reproduce the issue using randomly generated audio whose length is just a few samples longer than an exact multiple of 12 seconds:

FS = 48000
# random integer number
N = np.random.randint(1, 20) # random multiplier of 12 seconds
remainder = np.random.randint(1, 60)  # random number of remaining samples to add 
print(f"N: {N}, remainder: {remainder}")
length = 12*N*FS + remainder

# Generate random stereo noise
noise_ref = np.random.randn(length, 2)
noise_test = np.random.randn(length, 2)

# Create temp files
ref_temp = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
test_temp = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)

try:
    sf.write(ref_temp.name, noise_ref, FS)
    sf.write(test_temp.name, noise_test, FS)

    nsim_values, LS = calculate_binaqual(
        Path(ref_temp.name),
        Path(test_temp.name),
        intensity_threshold=-180,
        elc=0,
        ignore_freq_bands=0
    )
    print(f"NSIM values: {nsim_values}")
    print(f"LS: {LS}")
finally:
    ref_temp.close()
    test_temp.close()
    os.unlink(ref_temp.name)
    os.unlink(test_temp.name)

I hope this issue report helps!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions