SFML

- Main Page
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
sf::SoundBufferRecorder Class Reference
Audio module

Specialized SoundRecorder which stores the captured audio data into a sound buffer. More...

`#include <SoundBufferRecorder.hpp>`

Inheritance diagram for sf::SoundBufferRecorder:

## Public Member Functions

const SoundBuffer & | getBuffer () const
| Get the sound buffer containing the captured audio data. More...
void | start (unsigned int sampleRate=44100)
| Start the capture. More...
void | stop ()
| Stop the capture. More...
unsigned int | getSampleRate () const
| Get the sample rate. More...

## Static Public Member Functions

static bool | isAvailable ()
| Check if the system supports audio capture. More...

## Protected Member Functions

virtual bool | onStart ()
| Start capturing audio data. More...
virtual bool | onProcessSamples (const Int16 *samples, std::size_t sampleCount)
| Process a new chunk of recorded samples. More...
virtual void | onStop ()
| Stop capturing audio data. More...

## Detailed Description

Specialized SoundRecorder which stores the captured audio data into a sound buffer.

sf::SoundBufferRecorder allows to access a recorded sound through a sf::SoundBuffer, so that it can be played, saved to a file, etc.

It has the same simple interface as its base class (start(), stop()) and adds a function to retrieve the recorded sound buffer (getBuffer()).

As usual, don't forget to call the isAvailable() function before using this class (see sf::SoundRecorder for more details about this).

Usage example:

* if (sf::SoundBufferRecorder::isAvailable())
* {
* // Record some audio data
* sf::SoundBufferRecorder recorder;
* recorder.start();
* ...
* recorder.stop();
*
* // Get the buffer containing the captured audio data
* const sf::SoundBuffer& buffer = recorder.getBuffer();
*
* // Save it to a file (for example...)
* buffer.saveToFile("my_record.ogg");
* }
*

See Also
  sf::SoundRecorder

Definition at line 44 of file SoundBufferRecorder.hpp.

## Member Function Documentation

const SoundBuffer& sf::SoundBufferRecorder::getBuffer | ( |  | ) | const

Get the sound buffer containing the captured audio data.

The sound buffer is valid only after the capture has ended. This function provides a read-only access to the internal sound buffer, but it can be copied if you need to make any modification to it.

Returns
  Read-only access to the sound buffer

unsigned int sf::SoundRecorder::getSampleRate | ( |  | ) | const

inherited

Get the sample rate.

The sample rate defines the number of audio samples captured per second. The higher, the better the quality (for example, 44100 samples/sec is CD quality).

Returns
  Sample rate, in samples per second

static bool sf::SoundRecorder::isAvailable | ( |  | ) |

static inherited

Check if the system supports audio capture.

This function should always be called before using the audio capture features. If it returns false, then any attempt to use sf::SoundRecorder or one of its derived classes will fail.

Returns
  True if audio capture is supported, false otherwise

virtual bool sf::SoundBufferRecorder::onProcessSamples | ( | const Int16 * | samples,
|  | std::size_t | sampleCount
| ) |  |

protected virtual

Process a new chunk of recorded samples.

Parameters

  samples | Pointer to the new chunk of recorded samples
  sampleCount | Number of samples pointed by samples

Returns
  True to continue the capture, or false to stop it

Implements sf::SoundRecorder.

virtual bool sf::SoundBufferRecorder::onStart | ( |  | ) |

protected virtual

Start capturing audio data.

Returns
  True to start the capture, or false to abort it

Reimplemented from sf::SoundRecorder.

virtual void sf::SoundBufferRecorder::onStop | ( |  | ) |

protected virtual

Stop capturing audio data.

Reimplemented from sf::SoundRecorder.

void sf::SoundRecorder::start | ( | unsigned int | sampleRate = `44100` | ) |

inherited

Start the capture.

The sampleRate parameter defines the number of audio samples captured per second. The higher, the better the quality (for example, 44100 samples/sec is CD quality). This function uses its own thread so that it doesn't block the rest of the program while the capture runs. Please note that only one capture can happen at the same time.

Parameters

  sampleRate | Desired capture rate, in number of samples per second

See Also
  stop

void sf::SoundRecorder::stop | ( |  | ) |

inherited

Stop the capture.

See Also
  start

The documentation for this class was generated from the following file:

- SoundBufferRecorder.hpp