Thursday, May 19, 2011

click

I think I wrote about this a few months ago, but I had more thoughts on it. I wrote a program at work to play a click whenever certain things happened in the data acquisition system. These things happened fast - potentially every 800 microseconds although realistically it's not that fast. Maybe 4-5 milliseconds at the fastest? I should look. The point is that the Windows function I was using to play the sound was slow and calling it faster than it could respond created unpredictable results - that is to say I'd try to play two sounds before the first one was done playing. It SHOULD have supported this (it had a flag you could pass to allow overlapping) and to some extent it worked but the behavior was inconsistent. I wrote the same program in Matlab with Matlab's function for playing sound and it behaved rather well.

This kind of irritates me because I had expected the C program to perform better. The bottleneck is the generic PlaySound() function I was using (part of the Windows SDK). I want to rewrite the program with SDL's sound playing libraries.

There MIGHT be a chance I'm just doing something stupid that's making it slow. Oh, the other crappy thing is that I can't just play a click - I had to make a .wav file of a 0 to 1 edge to be my click. I spent forever trying to figure out why it wasn't working and it turns out my .wav file was too short. I had to play "guess and check" to see how short I could make it before it stopped working. The minimum sample size wasn't documented anywhere I could see. I forget what the end result was.

No comments:

Post a Comment