-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing some alignment issues in time-frequency sonification #410
Conversation
Codecov ReportAttention: Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Looks good but get those coverage numbers up to 100%!! 📈 |
Will add tests on this once the dependent stops oozing everywhere and I have the brain cycles to put into it. For now it'd be good if @giovana-morais could kick the tires on this with the downstream jams test that revealed the issue originally. |
hey there! most tests are fixed, but there seems to be another corner case. this function breaks whenever we provide a
|
That's interesting. I'd think either all of the last 3 should break or they should all work. But I guess we don't have much in the way of intelligent bounds processing here. Maybe this function really just does need a whole rewrite. |
Ok, I see what's going on here, and the length parameters are actually just surfacing different variations of the same bug as before. Specifically, this line:
simultaneously does the expansion and truncation of the time intervals array to fully cover The |
Ok, I think this PR is good to go, at least for the sake of getting the sonifier to behave sanely. That said, I think there are some pretty serious issues with the interpolator here: Lines 190 to 196 in a0a8672
we're doing linear interpolation between interval midpoints to sample the amplitudes applied to the synthesized signal. This is fine when intervals are short and equally spaced, but for long and irregular intervals (eg chord annotations), this leads to long and irregular ramps that put the sonified signal well outside the bounds of the original annotation. For example, the motivating use case in 408 had a single annotation spanning [3, 4]. When we prepend a silence from [0, 3], we now end up with a linear ramp up from 1.5 to 3.5, and down from 3.5 to 4. When the length= parameter is used, this can result in divergent outputs for different length values because the fade-out will have varying length. I think we should replace this with a nearest-neighbor interpolation, which would A) be consistent across different length= settings, and B) more clearly conform to the annotation. We can take this in a separate issue, but as it's only a 1-liner fix here, I could easily merge it into this PR as well. |
Since my head is in this code and i have a few minutes now, I went ahead and implemented the nearest neighbor interpolation mode. Since we're now sonifying over the entire time range and then using interpolated gram values to mask out, this leads to transients at interval boundaries. I've put in a hack around this that convolves each nn-interpolated row of gram by an averaging filter with order set to match two cycles of the frequency in question. This gives us a smooth ramp up and down at the boundaries, and constant values within the interval. Results sound good and seem just as fast as the older implementation. That said, I'm now seeing a bunch of opportunities to vectorize and speed this up further, eg by doing all frequency interpolations at once instead of over a loop. That can definitely be a separate PR. |
One last couple of updates here:
|
It appears that removing I'm personally okay with this, but scipy 1.10 would bump our min python up to 3.8. I think that would probably lift this PR up from a 0.8.1 to a 0.9 feature. In the interest of making maintenance a little easier, I'll revert the const_interpolator hack for now, but leave a comment that it will not be necessary going forward. |
Sounds good to me! Thanks for working on this. |
👍 I've got one more optimization I want to put into this, but don't have time this minute. Will come back to it. |
Fixes #408
It appears that fixing the interval padding issue resolved the error with single-interval sonification.