Two interesting things from the last couple days:
- Found myself typing the comment
// FIXME: Guarantee this doesn't somehow cause OH FUCK.
...those last two words sort of coming out involuntarily as at that exact moment I realized (1) that yes, the commented block of code
did cause heap corruption; and (2) why.
- So I write what I think is a very nice linear interpolate/decimate filter that works without having to allocate any scratch buffers! I use it to play back PCM samples at various speeds. But then I run it, and everything I play back with interpolation has this
nasty hissing noise overlaid on it-- like there's a triangle wave of something like 11025 or 22050 hz overlaid on everything, getting louder and softer with the audio data. In other words, it sounds like classic aliasing. But it's loud,
really loud-- it more or less overpowers the sample itself. And aliasing shouldn't be that clear or that audible either with the kind of interpolation I'm using or at the ratios I'm using (like, 2x interpolation)-- or so I thought. I check and re-check the code but there is clearly nothing wrong with it. I begin to doubt everything I know about sample interpolation. Is it possible you really just
can't resample a sound without doing the low-pass thing?
Then I poke some more. And I discover something weird.
Apparently, when I prepared my sample files in Audacity, I sort of messed up. I'd thought my samples were all 16-bit mono PCM. It turns out, however, that they were all 16-bit
stereo PCM-- and the right channel was always just silence! So all along, effectively, all of the samples I'd been playing back were slowed to 1/2 speed. Since they were all drum sounds this wasn't completely noticeable. And they were slowed effectively by inserting silence gaps between each PCM value-- something which normally wouldn't be noticeable. Except then after this accidental, inaudibly-aliased slowdown, I go and perform a second, intentional, inaudibly-aliased slowdown, and my second slowdown faithfully takes the aliasing from the first slowdown and blows it up in to VERY LOUD triangle waves...
I go and fix my source audio files and everything sounds fantastic!!!