Async 1.8.0
Async::AudioRecorder Class Reference

A class for recording raw audio to a file. More...

#include <AsyncAudioRecorder.h>

Inheritance diagram for Async::AudioRecorder:
Async::AudioSink

Public Types

enum  Format { FMT_AUTO , FMT_RAW , FMT_WAV }
 

Public Member Functions

 AudioRecorder (const std::string &filename, AudioRecorder::Format fmt=FMT_AUTO, int sample_rate=INTERNAL_SAMPLE_RATE)
 Default constuctor.
 
 ~AudioRecorder (void)
 Destructor.
 
bool initialize (void)
 Initialize the recorder.
 
void setMaxRecordingTime (unsigned time_ms, unsigned hw_time_ms=0)
 Set the maximum length of this recording.
 
bool closeFile (void)
 Close the file.
 
unsigned samplesWritten (void) const
 Find out how many samples that have been written so far.
 
const struct timeval & beginTimestamp (void) const
 The timestamp of the first stored sample.
 
const struct timeval & endTimestamp (void) const
 The timestamp of the last stored sample.
 
virtual int writeSamples (const float *samples, int count)
 Write samples into this audio sink.
 
virtual void flushSamples (void)
 Tell the sink to flush the previously written samples.
 
std::string errorMsg (void) const
 Return the current error message.
 
- Public Member Functions inherited from Async::AudioSink
 AudioSink (void)
 Default constuctor.
 
virtual ~AudioSink (void)
 Destructor.
 
bool registerSource (AudioSource *source)
 Register an audio source to provide samples to this sink.
 
void unregisterSource (void)
 Unregister the previously registered audio source.
 
bool isRegistered (void) const
 Check if an audio source has been registered.
 
AudioSourcesource (void) const
 Get the registered audio source.
 

Public Attributes

sigc::signal< void > maxRecordingTimeReached
 A signal that's emitted when the max recording time is reached.
 
sigc::signal< void > errorOccurred
 This signal is emitted when an error occurrs in the recorder.
 

Additional Inherited Members

- Protected Member Functions inherited from Async::AudioSink
void sourceResumeOutput (void)
 Tell the source that we are ready to accept more samples.
 
void sourceAllSamplesFlushed (void)
 Tell the source that all samples have been flushed.
 
bool setHandler (AudioSink *handler)
 Setup another sink to handle the incoming audio.
 
void clearHandler (void)
 Clear a handler that was previously setup with setHandler.
 
AudioSinkhandler (void) const
 

Detailed Description

A class for recording raw audio to a file.

Author
Tobias Blomberg / SM0SVX
Date
2005-08-29

Use this class to stream audio into a file. The audio is stored in raw format, (only samples no header) or WAV format.

Definition at line 119 of file AsyncAudioRecorder.h.

Member Enumeration Documentation

◆ Format

Enumerator
FMT_AUTO 
FMT_RAW 
FMT_WAV 

Definition at line 122 of file AsyncAudioRecorder.h.

Constructor & Destructor Documentation

◆ AudioRecorder()

Async::AudioRecorder::AudioRecorder ( const std::string & filename,
AudioRecorder::Format fmt = FMT_AUTO,
int sample_rate = INTERNAL_SAMPLE_RATE )
explicit

Default constuctor.

Parameters
filenameThe name of the file to record audio to
fmtThe file format (
See also
Format)
Parameters
sample_rateThe sample rate (defaults to INTERNAL_SAMPLE_RATE)

◆ ~AudioRecorder()

Async::AudioRecorder::~AudioRecorder ( void )

Destructor.

Member Function Documentation

◆ beginTimestamp()

const struct timeval & Async::AudioRecorder::beginTimestamp ( void ) const
inline

The timestamp of the first stored sample.

Returns
Returns the timestamp

Definition at line 187 of file AsyncAudioRecorder.h.

◆ closeFile()

bool Async::AudioRecorder::closeFile ( void )

Close the file.

Returns
Return true if closing went well or false otherwise

This function will close the file being recorded to. When the file has been closed, all samples coming in after that will be discarded. If an error occurr, this function will return false. The error message can be retrieved using the errorMsg function.

◆ endTimestamp()

const struct timeval & Async::AudioRecorder::endTimestamp ( void ) const
inline

The timestamp of the last stored sample.

Returns
Returns the timestamp

Definition at line 193 of file AsyncAudioRecorder.h.

◆ errorMsg()

std::string Async::AudioRecorder::errorMsg ( void ) const
inline

Return the current error message.

Returns
Returns the currently set error message

This function is used to retrieve the last set error message. It can for example be used when the initialize method return false or when the error signal is emitted.

Definition at line 226 of file AsyncAudioRecorder.h.

◆ flushSamples()

virtual void Async::AudioRecorder::flushSamples ( void )
virtual

Tell the sink to flush the previously written samples.

This function is used to tell the sink to flush previously written samples. When done flushing, the sink should call the sourceAllSamplesFlushed function. This function is normally only called from a connected source object.

Reimplemented from Async::AudioSink.

◆ initialize()

bool Async::AudioRecorder::initialize ( void )

Initialize the recorder.

Returns
Return true if the initialization was successful

This function will initialize the recorder and open the file. On error, this function returns false. The error message can be retrieved using the errorMsg function.

◆ samplesWritten()

unsigned Async::AudioRecorder::samplesWritten ( void ) const
inline

Find out how many samples that have been written so far.

Returns
Returns the number of samples written so far

Definition at line 181 of file AsyncAudioRecorder.h.

◆ setMaxRecordingTime()

void Async::AudioRecorder::setMaxRecordingTime ( unsigned time_ms,
unsigned hw_time_ms = 0 )

Set the maximum length of this recording.

Parameters
time_msThe maximum time in milliseconds
hw_time_msThe high watermark time in milliseconds

Use this function to set the maximum time for a recording. When the limit has been reached, the file will be closed and any incoming samples will be thrown away. The high watermark time is a soft limit. After reaching the high watermark, the recording will be ended as soon as the audio source call flushSamples. The high watermark need to be set to less than the maximum time to have any effect. A time of 0 disables it. The sampling rate given in the constructor call is used to calculate the time. Setting the time to 0 will allow the file to grow indefinetly.

◆ writeSamples()

virtual int Async::AudioRecorder::writeSamples ( const float * samples,
int count )
virtual

Write samples into this audio sink.

Parameters
samplesThe buffer containing the samples
countThe number of samples in the buffer
Returns
Returns the number of samples that has been taken care of

This function is used to write audio into this audio sink. If it returns 0, no more samples should be written until the resumeOutput function in the source have been called. This function is normally only called from a connected source object.

Reimplemented from Async::AudioSink.

Member Data Documentation

◆ errorOccurred

sigc::signal<void> Async::AudioRecorder::errorOccurred

This signal is emitted when an error occurrs in the recorder.

This signal will be emitted when an error occurrs in the recorder. After emitting the signal the associated file will be closed. All audio that is written after an error has occurred will be thrown away. To open a new file, call the initialize method again.

Definition at line 246 of file AsyncAudioRecorder.h.

◆ maxRecordingTimeReached

sigc::signal<void> Async::AudioRecorder::maxRecordingTimeReached

A signal that's emitted when the max recording time is reached.

This signal will be emitted when any of the maximum recording time or the high watermark limits are reached. Before this signal is emitted, the file is closed. It is safe to delete the audio recorder from the slot that is connected to this signal.

Definition at line 236 of file AsyncAudioRecorder.h.


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