Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

AudioReceive Class Reference

Call Module for receiving audio. More...

#include <audioreceive.h>

Inheritance diagram for AudioReceive:

CallModule CallInterface List of all members.

Public Methods

 AudioReceive (Connection *conn, string file, int timeout, int silence_timeout, bool DTMF_exit) throw (CapiWrongState,CapiExternalError)
 Constructor. Create an object and test for audio mode.

void mainLoop () throw (CapiWrongState,CapiExternalError)
 Start file reception, wait for one of the timeouts or disconnection and stop the reception.

void dataIn (unsigned char *data, unsigned length)
 Test all received audio packets for silence and count silent packets.

long duration ()
 Return the time in seconds since start of mainLoop().


Private Attributes

unsigned int silence_count
 counter how many consecutive samples (bytes) have been silent

unsigned int silence_timeout
 amount of silence samples after which record is finished

string file
 file name to save audio data to

long start_time
 time in seconds since the epoch when the recording was started

long end_time
 time in seconds since the epoch when the recording was finished


Detailed Description

Call Module for receiving audio.

This module handles the reception of an audio wave file. It can recognize silence in the signal and timeout after a given period of silence, after a general timeout or after the reception of a DTMF signal.

If DTMF abort is enabled, the module will abort immediately if the DTMF receiving buffer (see Connection::getDTMF) isn't empty when it is created. That allows the user to abort subsequent audio receive and send commands with one DTMF signal w/o needing to check for received DTMF after each command.

The call must be in audio mode (by connecting with service VOICE), otherwise an exception will be caused.

CapiWrongState will only be thrown if connection is not up at startup, not later on. We see a later disconnect as normal event, no error.

The created file will be saved in the format given by Capi, that is bit-reversed A-Law (or u-Law), 8 kHz, mono.

Author:
Gernot Hillier


Constructor & Destructor Documentation

AudioReceive::AudioReceive Connection   conn,
string    file,
int    timeout,
int    silence_timeout,
bool    DTMF_exit
throw (CapiWrongState,CapiExternalError)
 

Constructor. Create an object and test for audio mode.

The constructor also converts the given silence_timeout from seconds to number of samples (bytes).

Parameters:
conn  reference to Connection object
file  name of file to save received audio stream to.
timeout  timeout in seconds after which record is finished, 0=record forever (until call is finished)
silence_timeout  duration of silence in seconds after which record is finished, 0=no silence detection
DTMF_exit  true: abort if we receive DTMF during mainLoop() or if DTMF was received before
Exceptions:
CapiExternalError  Thrown if connection is not in speech mode
CapiWrongState  Thrown if connection is not up (thrown by base class constructor)


Member Function Documentation

void AudioReceive::dataIn unsigned char *    data,
unsigned    length
[virtual]
 

Test all received audio packets for silence and count silent packets.

All bytes of a received packages (i.e. 2048 bytes) are partly A-Law decoded, added and compared to a threshhold. If silence is found, silence_count is increased, otherwise the counter is reset to 0.

If the silence_timeout value is reached, the mainLoop is signalled to finish.

Reimplemented from CallModule.

long AudioReceive::duration  
 

Return the time in seconds since start of mainLoop().

Returns:
time in seconds since start of mainLoop()

void AudioReceive::mainLoop   throw (CapiWrongState,CapiExternalError) [virtual]
 

Start file reception, wait for one of the timeouts or disconnection and stop the reception.

If the recording was finished because of silence, the silence is truncated away from the recorded file

Exceptions:
CapiExternalError  Thrown by Connection::start_file_reception().
CapiWrongState  Thrown if connection is not up at start of transfer (thrown by Connection::start_file_reception)

Reimplemented from CallModule.


Member Data Documentation

long AudioReceive::end_time [private]
 

time in seconds since the epoch when the recording was finished

string AudioReceive::file [private]
 

file name to save audio data to

unsigned int AudioReceive::silence_count [private]
 

counter how many consecutive samples (bytes) have been silent

unsigned int AudioReceive::silence_timeout [private]
 

amount of silence samples after which record is finished

long AudioReceive::start_time [private]
 

time in seconds since the epoch when the recording was started


The documentation for this class was generated from the following files:
Generated on Mon Jan 5 12:20:00 2004 for CapiSuite by doxygen1.2.18