Hello everybody!
I have been using SoundRecorder quiet a bit in the past for different things and I noticed a couple things that need improvment. I have been using some of these improvments in my own code for a while, but I found the time now to make some clean commits.
So first up I noticed an error when you destroy a
sf::SoundBufferRecorder while it's recording. You get a
pure virtual method called
terminate called without an active exception
error in the console when doing so. After diging into the code I think I found the answer. It's a threading issue.
SoundBufferRecorder::onProcessSamples overwrittes the pure virtual function
SoundRecorder::onProcessSamples which is called by the audio capture thread. When
SoundBufferRecorder is destroyed it's method gets deleted, before the thread stops using it. Calling
stop() in
SoundBufferRecorders destructor fixes this problem. I think we should notice in a red box in the tutorials that a derived class has to call
stop in it's destructor, since there is already a section on threading issues. Here is
my fix.
Secondly I would like to suggest a new feature: Stereo recording. I have used it for quiet some time now and it comes in really handy. I saw there are also a couple threads on the forum with people requesting it. The answers suggest that it will be implemented later on. Here is
my commit.
The last thing is something that I have implemented myself, but using it I noticed it would be better to do it differently. Right now if you call
setDevice with an invalid device name while you are already recording the recording stops. Of course sometimes that's not what you want. So I think it would be a better behaviour to print an error message and fall back to device already in use if the one you specified is not available. Think of an application like VOIP or a sound installation where you want to make sure that there are always samples available. The commit can be found
here. This commit also fixes another small issue when the method is called with an empty string.
So tell me what you think. The commits are ready to go and I'll send a PR once I heard some feedback.