SFML
Simple and Fast Multimedia Library
Loading...
Searching...
No Matches
sf::SoundBufferRecorder Class Reference

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

#include <SoundBufferRecorder.hpp>

Inheritance diagram for sf::SoundBufferRecorder:
[legend]

Public Member Functions

 ~SoundBufferRecorder () override
 destructor
const SoundBuffergetBuffer () const
 Get the sound buffer containing the captured audio data.
Public Member Functions inherited from sf::SoundRecorder
virtual ~SoundRecorder ()
 destructor
bool start (unsigned int sampleRate=44100)
 Start the capture.
void stop ()
 Stop the capture.
unsigned int getSampleRate () const
 Get the sample rate.
bool setDevice (const std::string &name)
 Set the audio capture device.
const std::string & getDevice () const
 Get the name of the current audio capture device.
void setChannelCount (unsigned int channelCount)
 Set the channel count of the audio capture device.
unsigned int getChannelCount () const
 Get the number of channels used by this recorder.
const std::vector< SoundChannel > & getChannelMap () const
 Get the map of position in sample frame to sound channel.

Protected Member Functions

bool onStart () override
 Start capturing audio data.
bool onProcessSamples (const std::int16_t *samples, std::size_t sampleCount) override
 Process a new chunk of recorded samples.
void onStop () override
 Stop capturing audio data.
Protected Member Functions inherited from sf::SoundRecorder
 SoundRecorder ()
 Default constructor.

Additional Inherited Members

Static Public Member Functions inherited from sf::SoundRecorder
static std::vector< std::string > getAvailableDevices ()
 Get a list of the names of all available audio capture devices.
static std::string getDefaultDevice ()
 Get the name of the default audio capture device.
static bool isAvailable ()
 Check if the system supports audio capture.

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:

{
// Record some audio data
if (!recorder.start())
{
// Handle error...
}
...
recorder.stop();
// Get the buffer containing the captured audio data
const sf::SoundBuffer& buffer = recorder.getBuffer();
// Save it to a file (for example...)
if (!buffer.saveToFile("my_record.ogg"))
{
// Handle error...
}
}
Storage for audio samples defining a sound.
Definition SoundBuffer.hpp:55
bool saveToFile(const std::filesystem::path &filename) const
Save the sound buffer to an audio file.
Specialized SoundRecorder which stores the captured audio data into a sound buffer.
Definition SoundBufferRecorder.hpp:49
const SoundBuffer & getBuffer() const
Get the sound buffer containing the captured audio data.
bool start(unsigned int sampleRate=44100)
Start the capture.
void stop()
Stop the capture.
static bool isAvailable()
Check if the system supports audio capture.
See also
sf::SoundRecorder

Constructor & Destructor Documentation

◆ ~SoundBufferRecorder()

sf::SoundBufferRecorder::~SoundBufferRecorder ( )
override

destructor

Member Function Documentation

◆ getBuffer()

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

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

◆ onProcessSamples()

bool sf::SoundBufferRecorder::onProcessSamples ( const std::int16_t * samples,
std::size_t sampleCount )
nodiscardoverrideprotectedvirtual

Process a new chunk of recorded samples.

Parameters
samplesPointer to the new chunk of recorded samples
sampleCountNumber of samples pointed by samples
Returns
True to continue the capture, or false to stop it

Implements sf::SoundRecorder.

◆ onStart()

bool sf::SoundBufferRecorder::onStart ( )
nodiscardoverrideprotectedvirtual

Start capturing audio data.

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

Reimplemented from sf::SoundRecorder.

◆ onStop()

void sf::SoundBufferRecorder::onStop ( )
overrideprotectedvirtual

Stop capturing audio data.

Reimplemented from sf::SoundRecorder.


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