MCPcopy Create free account
hub / github.com/SFML/SFML / start

Method start

src/SFML/Audio/SoundRecorder.cpp:269–320  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

267
268////////////////////////////////////////////////////////////
269bool SoundRecorder::start(unsigned int sampleRate)
270{
271 // Check if the device can do audio capture
272 if (!isAvailable())
273 {
274 err() << "Failed to start capture: your system cannot capture audio data (call SoundRecorder::isAvailable to "
275 "check it)"
276 << std::endl;
277 return false;
278 }
279
280 // Store the sample rate and re-initialize if necessary
281 if (m_impl->sampleRate != sampleRate)
282 {
283 m_impl->sampleRate = sampleRate;
284
285 if (!m_impl->initialize())
286 {
287 err() << "Failed to set audio capture device sample rate to " << sampleRate << std::endl;
288 return false;
289 }
290 }
291
292 // Ensure we have a capture device
293 if (!m_impl->captureDevice)
294 {
295 err() << "Trying to start audio capture, but no device available" << std::endl;
296 return false;
297 }
298
299 // Check that another capture is not already running
300 if (ma_device_is_started(&*m_impl->captureDevice))
301 {
302 err() << "Trying to start audio capture, but another capture is already running" << std::endl;
303 return false;
304 }
305
306 // Notify derived class
307 if (onStart())
308 {
309 // Start the capture
310 if (const auto result = ma_device_start(&*m_impl->captureDevice); result != MA_SUCCESS)
311 {
312 err() << "Failed to start audio capture device: " << ma_result_description(result) << std::endl;
313 return false;
314 }
315
316 return true;
317 }
318
319 return false;
320}
321
322
323////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

onStartFunction · 0.85
isAvailableFunction · 0.50
initializeMethod · 0.45

Tested by

no test coverage detected