
Description | Cautions | Example 1: | Example 2: | Errors | See Also
Name: |
int dx_rec(chdev,iottp,tptp,mode) | |
Inputs: |
int chdev |
|
DX_IOTT *iottp |
| |
DV_TPT *tptp |
| |
unsigned short mode |
| |
Returns: |
0 if successful | |
-1 if failure | ||
Includes: |
srllib.h | |
dxxxlib.h | ||
Category: |
I/O | |
Mode: |
synchronous/asynchronous | |
The dx_rec( ) function records voice data from a single channel. The data may be recorded to a combination of data files, memory, or custom devices.
The order in which voice data is recorded is specified in the DX_IOTT structure. The DX_IOTT structure must remain in scope for the duration of the function if running asynchronously.
After dx_rec( ) is called, recording continues until dx_stopch( ) is called, the data requirements specified in the DX_IOTT are fulfilled, or until one of the conditions for termination in the DV_TPT is satisfied. When dx_rec( ) terminates, the current channel's status information, including the reason for termination, can be accessed using Extended Attribute functions.
Asynchronous Operation
To run this function asynchronously set the mode field to EV_ASYNC. When running asynchronously, this function will return 0 to indicate it has initiated successfully, and will generate a TDX_RECORD termination event to indicate completion.
Set termination conditions using the DV_TPT structure. This structure is pointed to by the tptp parameter described below.
Termination of asynchronous recording is indicated by a TDX_RECORD event.
Use the SRL Event Management functions to handle the termination event.
After dx_rec( ) terminates, use the ATDX_TERMMSK( ) function to determine the reason for termination.
Synchronous Operation
By default, this function runs synchronously, and will return a 0 to indicate that it has completed successfully.
Set termination conditions using the DV_TPT structure. This structure is pointed to by the tptp parameter described below. After dx_rec( ) terminates, use the ATDX_TERMMSK( ) function to determine the reason for termination.
The function parameters are defined as follows:
|
Parameter |
Description |
|||||||||||||||||||||||||||||||||
|
chdev |
specifies the valid channel device handle obtained when the channel was opened using dx_open( ). |
|||||||||||||||||||||||||||||||||
|
iottp |
points to the I/O Transfer Table Structure, DX_IOTT, which specifies the order in which and media onto which the voice data will be recorded. This structure is defined in the chapter on Data Structures and must remain in scope for the duration of the function if using asynchronously. |
|||||||||||||||||||||||||||||||||
|
tptp |
points to the Termination Parameter Table Structure, DV_TPT, which specifies termination conditions for recording. Valid termination conditions for this function are listed below:
NOTE:
|
|||||||||||||||||||||||||||||||||
|
mode |
defines the recording mode. One or more of the values listed below may be selected in the bit mask (see Table 15 for record mode combinations). Choose one only:
Choose one or more: |
|||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Table 15 shows recording mode selections. The first column of the table lists all possible combinations of record features, and the first row lists each type of encoding algorithm (ADPCM or PCM) and the data-storage rate for each algorithm/sampling rate combination in parenthesis (24 Kbps, 32 Kbps, 48 Kbps, or 64 Kbps).
Select the desired record feature in the first column of the table and move across that row until the column containing the desired encoding algorithm and data-storage rate is reached. The record modes that must be entered in dx_rec( ) are provided where the features row, and encoding algorithm/data-storage rate column intersect. Parameters listed in { } are default settings and do not have to be specified.
Table 15. Record Mode Selections
|
ADPCM |
ADPCM |
PCM |
PCM |
_ AGC |
RM_SR6 |
RM_SR8 |
RM_SR6 |
RM_SR8 |
_ No AGC |
MD_NOGAIN |
MD_NOGAIN |
MD_NOGAIN |
MD_NOGAIN |
_ AGC |
RM_TONE |
RM_TONE |
RM_TONE |
RM_TONE |
_ No AGC |
MD_NOGAIN |
MD_NOGAIN |
MD_NOGAIN |
MD_NOGAIN |
{ } = Default modes. | ||||
| ||||
None.
Example 1: Using dx_rec( ) in synchronous mode
#include <fcntl.h>
#include <srllib.h>
#include <dxxxlib.h>
#include <windows.h>
#define MAXLEN 10000
main()
{
DV_TPT tpt;
DX_IOTT iott[2];
int chdev;
char basebufp[MAXLEN];
/*
* open the channel using dx_open( )
*/
if ((chdev = dx_open("dxxxB1C1",NULL)) == -1) {
/* process error */
}
/*
* Set up the DV_TPT structures for MAXDTMF
*/
dx_clrtpt(&tpt,1);
tpt.tp_type = IO_EOT; /* last entry in the table */
tpt.tp_termno = DX_MAXDTMF; /* Maximum digits */
tpt.tp_length = 1; /* terminate on the first digit */
tpt.tp_flags = TF_MAXDTMF; /* Use the default flags */
/*
* Set up the DX_IOTT. The application records the voice data to memory
* allocated by the user.
*/
iott[0].io_type = IO_MEM|IO_CONT; /* Record to memory */
iott[0].io_bufp = basebufp; /* Set up pointer to buffer */
iott[0].io_offset = 0; /* Start at beginning of buffer */
iott[0].io_length = MAXLEN; /* Record 10,000 bytes of voice data */
iott[1].io_type = IO_DEV|IO_EOT; /* Record to file, last DX_IOTT
* entry */
iott[1].io_bufp = 0; /* Set up pointer to buffer */
iott[1].io_offset = 0; /* Start at beginning of buffer */
iott[1].io_length = MAXLEN; /* Record 10,000 bytes of voice
* data */
if((iott[1].io_fhandle = dx_fileopen("file.vox",
O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0666)) == -1) {
/* process error */
}
/* clear previously entered digits */
if (dx_clrdigbuf(chdev) == -1) {
/* process error */
}
if (dx_rec(chdev,&iott[0],&tpt,RM_TONE|EV_SYNC) == -1) {
/* process error */
}
/* Analyze the data recorded */
.
.
}
Example 2: Using dx_rec( ) in asynchronous mode
#include <stdio.h>
#include <fcntl.h>
#include <srllib.h>
#include <dxxxlib.h>
#include <windows.h>
#define MAXLEN 10000
#define MAXCHAN 24
int record_handler();
DV_TPT tpt;
DX_IOTT iott[MAXCHAN];
int chdev[MAXCHAN];
char basebufp[MAXCHAN][MAXLEN];
main()
{
int i, srlmode;
char *chname;
/* Set SRL to run in polled mode. */
srlmode = SR_POLLMODE;
if (sr_setparm(SRL_DEVICE, SR_MODEID, (void *)&srlmode) == -1) {
/* process error */
}
/* Start asynchronous dx_rec() on all the channels. */
for (i=0; i<MAXCHAN; i++) {
/* Set chname to the channel name, e.g., dxxxB1C1, dxxxB1C2,... */
/*
* open the channel using dx_open( )
*/
if ((chdev[i] = dx_open(chname,NULL)) == -1) {
/* process error */
}
/* Using sr_enbhdlr(), set up handler function to handle record
* completion events on this channel.
*/
if (sr_enbhdlr(chdev[i], TDX_RECORD, record_handler) == -1) {
/* process error */
}
/*
* Set up the DV_TPT structures for MAXDTMF
*/
dx_clrtpt(&tpt,1);
tpt.tp_type = IO_EOT; /* last entry in the table */
tpt.tp_termno = DX_MAXDTMF; /* Maximum digits */
tpt.tp_length = 1; /* terminate on the first digit */
tpt.tp_flags = TF_MAXDTMF; /* Use the default flags */
/*
* Set up the DX_IOTT. The application records the voice data to memory
* allocated by the user.
*/
iott[i].io_type = IO_MEM|IO_EOT; /* Record to memory, last DX_IOTT
* entry */
iott[i].io_bufp = basebufp[i]; /* Set up pointer to buffer */
iott[i].io_offset = 0; /* Start at beginning of buffer */
iott[i].io_length = MAXLEN; /* Record 10,000 bytes voice data */
/* clear previously entered digits */
if (dx_clrdigbuf(chdev) == -1) {
/* process error */
}
/* Start asynchronous dx_rec() on the channel */
if (dx_rec(chdev[i],&iott[i],&tpt,RM_TONE|EV_ASYNC) == -1) {
/* process error */
}
}
/* Use sr_waitevt to wait for the completion of dx_rec().
* On receiving the completion event, TDX_RECORD, control is transferred
* to a handler function previously established using sr_enbhdlr().
*/
.
.
}
int record_handler()
{
long term;
/* Use ATDX_TERMMSK() to get the reason for termination. */
term = ATDX_TERMMSK(sr_getevtdev());
if (term & TM_MAXDTMF) {
printf("record terminated on receiving DTMF digit(s)\n");
} else if (term & TM_NORMTERM) {
printf("normal termination of dx_rec()\n");
} else {
printf("Unknown termination reason: %x\n", term);
}
/* Kick off next function in the state machine model. */
.
.
return 0;
}
If this function returns -1 to indicate failure, use ATDV_LASTERR( ) and ATDV_ERRMSGP( ) to retrieve one of the following error reasons:
EDX_BADDEV |
Invalid Device Descriptor |
EDX_BADPARM |
Invalid Parameter |
EDX_BADIOTT |
Invalid DX_IOTT entry |
EDX_BADTPT |
Invalid DX_TPT entry |
EDX_BUSY |
Busy executing I/O function |
EDX_SYSTEM |
Error from operating system; use dx_fileerrno( ) to obtain error value |
Related Functions:
Setting Order and Location for Voice Data:
Retrieving and Handling Record Termination Events:
Click here to contact Dialogic Customer Engineering
Copyright 2002, Dialogic Corporation