Repository: librosa/librosa

Issue:
CI failure on windows with resampy 0.4.1
**Describe the bug**

This popped up yesterday after releasing resampy 0.4.1.  Our test suite generally works fine, except for one test on windows that's failing.

The relevant part of the error log is

```python
        shape[axis] = int(shape[axis] * sr_new / sr_orig)
    
        if shape[axis] < 1:
>           raise ValueError(
                "Input signal length={} is too small to "
                "resample from {}->{}".format(x.shape[axis], sr_orig, sr_new)
            )
E           ValueError: Input signal length=720200 is too small to resample from 22050->4000
```

Actual build log is here: https://github.com/librosa/librosa/runs/8276453091?check_suite_focus=true

Note that the same test works fine on all other platforms.  Scrolling up the error log, what I'm seeing is:

```python
tests\test_core.py:1880: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
librosa\core\spectrum.py:1591: in iirt
    y_resampled.append(resample(y, orig_sr=sr, target_sr=cur_sr, res_type=res_type))
librosa\core\audio.py:648: in resample
    y_hat = resampy.resample(y, orig_sr, target_sr, filter=res_type, axis=axis)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x = array([0., 0., 0., ..., 0., 0., 0.]), sr_orig = 22050, sr_new = 4000
axis = -1, filter = 'kaiser_best', parallel = False, kwargs = {}
sample_ratio = 0.18140589569160998, shape = [-64134]
```

So it looks like somehow the shape calculation is overflowing and becoming a negative int (?!).  I don't see any what that this makes sense though, as the resulting shape (-64134) is not what you would get be a 16-bit signed integer overflow of the true shape `int(720200 * 4000 / 22050) = 130648`.  At any rate, all numbers in the shape calculation of resampy are Python ints and not numpy ints (up until the division anyway), and this would not overflow in the first place.  So I'm pretty puzzled.

My first instinct was to push this back as a resampy issue, but I don't think there's actually a problem there.  Rather, I think there's something subtly broken in the windows CI environment to trigger this.

As a side note, #1566 would obviate this issue in the tests, but I'd still like to figure out what's going on here.


Discussion:
```python
>>> np.array([720200*4000], dtype='int32') / 22050
array([-64134.57124717])
```

type inference, associativity, overflow, and rounding !!!
That seems like it could be the issue, but as we mentioned in chat, the `shape[axis]` should be a Python int, not a numpy int32.  Super weird that this is behaving differently on different platforms.  Possibly a numpy bug?
Okay, I've got this figured out.  It's a doozy.

The culprit here is not ndarray.shape, which is correctly returning Tuple(int).  The problem is that `iirt` iterates over an ndarray of target sampling rates:
https://github.com/librosa/librosa/blob/ed422f8ab76ae2eb80790778fe732d90d1bf3cc0/librosa/core/spectrum.py#L1580-L1591
and it is these values that are coming out as `np.int32` on the windows platform.  (No idea why *that* is happening, since our CI runs on x86_64, but that appears to be the issue.)

Now there are a couple of ways around this, all of which are probably good ideas:

1. Force-cast to floats on the resampy side.  (This would bump resampy to 0.4.2, but not require action from librosa.)
2. Update this bit https://github.com/librosa/librosa/blob/ed422f8ab76ae2eb80790778fe732d90d1bf3cc0/librosa/filters.py#L1357-L1370 to explicitly be floating-point sample rates.  This is probably a good idea anyway, as there's no reason to require sampling rates to be integers.



Resolving patch:
diff --git a/librosa/filters.py b/librosa/filters.py
--- a/librosa/filters.py
+++ b/librosa/filters.py
@@ -1357,15 +1357,15 @@ def mr_frequencies(tuning):
     sample_rates = np.asarray(
         len(np.arange(0, 36))
         * [
-            882,
+            882.0,
         ]
         + len(np.arange(36, 70))
         * [
-            4410,
+            4410.0,
         ]
         + len(np.arange(70, 85))
         * [
-            22050,
+            22050.0,
         ]
     )
 


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -1865,15 +1865,15 @@ def test_iirt_peaks():
     sample_rates = np.asarray(
         len(np.arange(40, 46))
         * [
-            1000,
+            1000.0,
         ]
         + len(np.arange(46, 80))
         * [
-            1750,
+            1750.0,
         ]
         + len(np.arange(80, 95))
         * [
-            4000,
+            4000.0,
         ]
     )