Breakpoint demolog, day 31: the culprit has been identified and reduced

Sometimes it's just better to get away from the computer and come back to it a day later or so. While yesterday I didn't do much in the productive side of things and I spent something like four hours like that, today I managed to identify what the insidious, mysterious problem was in half an hour. However, I can't categorically say that those four hours were a total waste of time; probably staying there in front of the code helped into having it permeate my brain, which quite probably has been working at this problem (in a low priority thread, as I like to call it) while I have been doing totally unrelated tasks the rest of the day.

However, the a-ha moment has been more of a grumpy "TSK!" moment than a long list of joyous exclamations. Remember I told you that the sound was very stuttered? I went layer by layer commenting out its code and replacing it with a couple of lines that would output a simple sine wave into the output buffer provided to each layer, so that I could distinguish if the gaps were created by the synth or if I was touching some pointers inadequately. Everything seemed fine and I couldn't understand where did the stuttering come from until I thought: if there were true gaps, there shouldn't be any audio AT ALL in these "gaps". But there is audio. Where does it come from, if I am zeroing the data in each iteration...? And then I thought: I'll check this anyway, although I'm sure I'm zeroing the buffer...

... and guess what...?

I WASN'T!!!

Since the output buffer is pre-allocated (it's a member of SorolletPlayer) so that I'm not creating and assigning vector space on each getBuffer invocation, it maintains the values from run to run, unless it's zeroed. As I was just accumulating on it the values that the voices had just rendered, what I was doing in fact was adding values to a non-empty array. And that's why I was getting those strange results.

So it was a suuuper silly thing, as I expected it to be. Why didn't I find that yesterday? Maybe I took that for granted. Today I probably approached the code in a more inquisitive way :D

The good news: I could finally render a full dump of a test song. Yeah! The bad news: I haven't got it totally working with the "real time" part (I'm still fixing a couple of leaks that Valgrind has graciously told me about) but at least things are moving again.

P H E W !

For a moment I was even considering going back to BASS or Fmod :-S