summaryrefslogtreecommitdiff
path: root/src/SFML/Audio/SoundRecorder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Audio/SoundRecorder.cpp')
-rw-r--r--src/SFML/Audio/SoundRecorder.cpp61
1 files changed, 26 insertions, 35 deletions
diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp
index 40c1ae8..a1a9601 100644
--- a/src/SFML/Audio/SoundRecorder.cpp
+++ b/src/SFML/Audio/SoundRecorder.cpp
@@ -43,25 +43,9 @@ namespace
namespace sf
{
////////////////////////////////////////////////////////////
-/// Construct the sound recorder with a callback function
-/// for processing captured samples
-////////////////////////////////////////////////////////////
-SoundRecorder::SoundRecorder(FuncType Callback, void* UserData) :
-myCallback (Callback),
-myUserData (UserData),
-mySampleRate (0),
-myIsCapturing(false)
-{
-
-}
-
-
-////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
SoundRecorder::SoundRecorder() :
-myCallback (NULL),
-myUserData (NULL),
mySampleRate (0),
myIsCapturing(false)
{
@@ -112,12 +96,16 @@ void SoundRecorder::Start(unsigned int SampleRate)
// Store the sample rate
mySampleRate = SampleRate;
- // Start the capture
- alcCaptureStart(CaptureDevice);
+ // Notify derived class
+ if (OnStart())
+ {
+ // Start the capture
+ alcCaptureStart(CaptureDevice);
- // Start the capture in a new thread, to avoid blocking the main thread
- myIsCapturing = true;
- Launch();
+ // Start the capture in a new thread, to avoid blocking the main thread
+ myIsCapturing = true;
+ Launch();
+ }
}
@@ -126,13 +114,6 @@ void SoundRecorder::Start(unsigned int SampleRate)
////////////////////////////////////////////////////////////
void SoundRecorder::Stop()
{
- // If capture has not been started, we cannot stop
- if (!myIsCapturing)
- {
- std::cerr << "Trying to stop audio capture, but the capture has not been started ; call Start() first" << std::endl;
- return;
- }
-
// Stop the capturing thread
myIsCapturing = false;
Wait();
@@ -161,14 +142,21 @@ bool SoundRecorder::CanCapture()
////////////////////////////////////////////////////////////
-/// Process a new chunk of recorded samples
+/// Start recording audio data
+////////////////////////////////////////////////////////////
+bool SoundRecorder::OnStart()
+{
+ // Nothing to do
+ return true;
+}
+
+
+////////////////////////////////////////////////////////////
+/// Stop recording audio data
////////////////////////////////////////////////////////////
-bool SoundRecorder::ProcessSamples(const Int16* Samples, std::size_t SamplesCount)
+void SoundRecorder::OnStop()
{
- if (myCallback)
- return myCallback(Samples, SamplesCount, myUserData);
- else
- return false;
+ // Nothing to do
}
@@ -188,6 +176,9 @@ void SoundRecorder::Run()
// Capture is finished : clean up everything
CleanUp();
+
+ // Notify derived class
+ OnStop();
}
@@ -207,7 +198,7 @@ void SoundRecorder::ProcessCapturedSamples()
alcCaptureSamples(CaptureDevice, &mySamples[0], SamplesAvailable);
// Forward them to the derived class
- if (!ProcessSamples(&mySamples[0], mySamples.size()))
+ if (!OnProcessSamples(&mySamples[0], mySamples.size()))
{
// The user wants to stop the capture
myIsCapturing = false;