28 #include <SFML/Audio/SoundRecorder.hpp> 29 #include <SFML/Audio/AudioDevice.hpp> 30 #include <SFML/Audio/OpenAL.hpp> 31 #include <SFML/System/Sleep.hpp> 40 ALCdevice* CaptureDevice = NULL;
74 std::cerr <<
"Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl;
81 std::cerr <<
"Trying to start audio capture, but another capture is already running" << std::endl;
86 CaptureDevice = alcCaptureOpenDevice(NULL, SampleRate, AL_FORMAT_MONO16, SampleRate);
89 std::cerr <<
"Failed to open the audio capture device" << std::endl;
97 mySampleRate = SampleRate;
103 alcCaptureStart(CaptureDevice);
106 myIsCapturing =
true;
118 myIsCapturing =
false;
138 ALCdevice* Device = priv::AudioDevice::GetInstance().GetDevice();
140 return (alcIsExtensionPresent(Device,
"ALC_EXT_CAPTURE") != AL_FALSE) ||
141 (alcIsExtensionPresent(Device,
"ALC_EXT_capture") != AL_FALSE);
148 bool SoundRecorder::OnStart()
158 void SoundRecorder::OnStop()
167 void SoundRecorder::Run()
169 while (myIsCapturing)
172 ProcessCapturedSamples();
189 void SoundRecorder::ProcessCapturedSamples()
192 ALCint SamplesAvailable;
193 alcGetIntegerv(CaptureDevice, ALC_CAPTURE_SAMPLES, 1, &SamplesAvailable);
195 if (SamplesAvailable > 0)
198 mySamples.resize(SamplesAvailable);
199 alcCaptureSamples(CaptureDevice, &mySamples[0], SamplesAvailable);
202 if (!OnProcessSamples(&mySamples[0], mySamples.size()))
205 myIsCapturing =
false;
214 void SoundRecorder::CleanUp()
217 alcCaptureStop(CaptureDevice);
220 ProcessCapturedSamples();
223 alcCaptureCloseDevice(CaptureDevice);
224 CaptureDevice = NULL;
void Stop()
Stop the capture.
void Start(unsigned int SampleRate=44100)
Start the capture.
virtual ~SoundRecorder()
Virtual destructor.
void Wait()
Wait until the thread finishes.
SoundRecorder()
Default constructor.
static bool CanCapture()
Tell if the system supports sound capture.
unsigned int GetSampleRate() const
Get the sample rate.
void Launch()
Create and run the thread.