Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cpp3ds::SoundBufferRecorder Class Reference

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

#include <SoundBufferRecorder.hpp>

Inheritance diagram for cpp3ds::SoundBufferRecorder:
cpp3ds::SoundRecorder cpp3ds::AlResource

Public Member Functions

const SoundBuffergetBuffer () const
 Get the sound buffer containing the captured audio data. More...
 
bool start (unsigned int sampleRate=44100)
 Start the capture. More...
 
void stop ()
 Stop the capture. More...
 
unsigned int getSampleRate () const
 Get the sample rate. More...
 
bool setDevice (const std::string &name)
 Set the audio capture device. More...
 
const std::string & getDevice () const
 Get the name of the current audio capture device. More...
 

Static Public Member Functions

static std::vector< std::string > getAvailableDevices ()
 Get a list of the names of all availabe audio capture devices. More...
 
static std::string getDefaultDevice ()
 Get the name of the default audio capture device. More...
 
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...
 
void setProcessingInterval (cpp3ds::Time interval)
 Set the processing interval. More...
 

Detailed Description

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

cpp3ds::SoundBufferRecorder allows to access a recorded sound through a cpp3ds::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 cpp3ds::SoundRecorder for more details about this).

Usage example:

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

Definition at line 45 of file SoundBufferRecorder.hpp.

Member Function Documentation

static std::vector<std::string> cpp3ds::SoundRecorder::getAvailableDevices ( )
staticinherited

Get a list of the names of all availabe audio capture devices.

This function returns a vector of strings, containing the names of all availabe audio capture devices.

Returns
A vector of strings containing the names
const SoundBuffer& cpp3ds::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
static std::string cpp3ds::SoundRecorder::getDefaultDevice ( )
staticinherited

Get the name of the default audio capture device.

This function returns the name of the default audio capture device. If none is available, an empty string is returned.

Returns
The name of the default audio capture device
const std::string& cpp3ds::SoundRecorder::getDevice ( ) const
inherited

Get the name of the current audio capture device.

Returns
The name of the current audio capture device
unsigned int cpp3ds::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 cpp3ds::SoundRecorder::isAvailable ( )
staticinherited

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 cpp3ds::SoundRecorder or one of its derived classes will fail.

Returns
True if audio capture is supported, false otherwise
virtual bool cpp3ds::SoundBufferRecorder::onProcessSamples ( const Int16 *  samples,
std::size_t  sampleCount 
)
protectedvirtual

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 cpp3ds::SoundRecorder.

virtual bool cpp3ds::SoundBufferRecorder::onStart ( )
protectedvirtual

Start capturing audio data.

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

Reimplemented from cpp3ds::SoundRecorder.

virtual void cpp3ds::SoundBufferRecorder::onStop ( )
protectedvirtual

Stop capturing audio data.

Reimplemented from cpp3ds::SoundRecorder.

bool cpp3ds::SoundRecorder::setDevice ( const std::string &  name)
inherited

Set the audio capture device.

This function sets the audio capture device to the device with the given name. It can be called on the fly (i.e: while recording). If you do so while recording and opening the device fails, it stops the recording.

Parameters
nameThe name of the audio capture device
Returns
True, if it was able to set the requested device
See also
getAvailableDevices, getDefaultDevice
void cpp3ds::SoundRecorder::setProcessingInterval ( cpp3ds::Time  interval)
protectedinherited

Set the processing interval.

The processing interval controls the period between calls to the onProcessSamples function. You may want to use a small interval if you want to process the recorded data in real time, for example.

Note: this is only a hint, the actual period may vary. So don't rely on this parameter to implement precise timing.

The default processing interval is 100 ms.

Parameters
intervalProcessing interval
bool cpp3ds::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. You can select which capture device will be used, by passing the name to the setDevice() method. If none was selected before, the default capture device will be used. You can get a list of the names of all available capture devices by calling getAvailableDevices().

Parameters
sampleRateDesired capture rate, in number of samples per second
Returns
True, if start of capture was successful
See also
stop, getAvailableDevices
void cpp3ds::SoundRecorder::stop ( )
inherited

Stop the capture.

See also
start

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