adiRecordToMemory

Initiates recording of an RTP stream into a single memory-resident buffer.

Supported board types

Prototype

DWORD adiRecordToMemory ( CTAHD ctahd, unsigned encoding, void *buffer, unsigned bufsize, ADI_RECORD_PARMS *parms)

Argument

Description

ctahd

Context handle returned by ctaCreateContext or ctaAttachContext.

encoding

Encoding type.  See Voice encoding formats for a complete list.

buffer

Pointer into process memory to receive encoded data.

bufsize

Number of bytes pointed by buffer (bufsize can be arbitrarily large and is truncated to a multiple of the framesize for the selected encoding).

If recording a channel using the native record feature and silence compression is enabled (refer to the expandsilence parameter in ADI_NATIVE_PARMS), this buffer size does not imply a specific time limit. If the application requires a specific time limit, use adiStartRecording or adiRecordAsync to set the maximum record time parameter.

parms

Pointer to record parameters according to the following structure (NULL designates default values):

typedef struct
{
  DWORD size;            /* Size of this structure               */
  DWORD DTMFabort;       /* Abort on DTM                         */
  INT32 gain;            /* Recording gain in dB                 */
                         
/*-[SLC parms (used if silence det)]    */
  DWORD novoicetime;     /* Length of initial silence to stop    */
                         /* Recording (ms); use 0 to deactivate  */
                         /* Initial silence detection.           */
  DWORD silencetime;     /* Length of silence to stop recording  */
                         /* After voice has been detected (ms);  */
                         /* Use 0 to deactivate.                 */
  INT32 silenceampl;     /* Qualif level for silence (dBm)       */
  WORD silencedeglitch;  /* Deglitch while qualifying silence(ms)*/
                         /*-[Beep for record]--------------------*/
  DWORD beepfreq;        /* Beep frequency (Hz)                  */
  INT32 beepampl;        /* Beep amplitude (dBm)                 */
  DWORD beeptime;        /* Beep time (ms) 0=no beep             */
                         /*--[AGC parms]-------------------------*/
  WORD AGCenable;        /* Enable AGC; use 1 to activate        */
  INT32 AGCtargetampl;   /* Target AGC level (dBm)               */
  INT32 AGCsilenceampl;  /* Silence level (dBm)                  */
  DWORD AGCattacktime;   /* Attack time (ms)                     */
  DWORD AGCdecaytime;    /* Decay time (ms)                      */

} ADI_RECORD_PARMS;

Note: Fields in bold are not applicable to the native play and record feature.

Refer to ADI_RECORD_PARMS for field descriptions and valid values.

Return values

Return value

Description

SUCCESS

 

ADIERR_INVALID_CALL_STATE

Function not valid in the current call state.

CTAERR_BAD_ARGUMENT

Invalid encoding or NULL buffer.

CTAERR_FUNCTION_ACTIVE

Function already started.

CTAERR_INVALID_CTAHD

Context handle is invalid.

CTAERR_INVALID_STATE

Function not valid in the current port state.

CTAERR_OUTPUT_ACTIVE

Record failed because there is another active output function.

CTAERR_RESOURCE_CONFLICT

Silence detector is in use by adiStartEnergyDetector.

CTAERR_SVR_COMM

Server communication error.

Events

Event

Description

ADIEVN_RECORDING_DONE

Generated when the recording operation terminates. The event size field contains the total number of bytes written into the buffer. The value field contains one of the following termination reasons or error codes:

CTA_REASON_DIGIT

Aborted due to DTMF.

CTA_REASON_FINISHED

Buffer filled.

CTA_REASON_NO_VOICE

No voice detected.

CTA_REASON_RELEASED

Call terminated.

CTA_REASON_STOPPED

Stopped by application request.

CTA_REASON_VOICE_END

User stopped speaking.

CTAERR_FUNCTION_NOT_AVAIL

Required DSP file not loaded on the board.

CTAERR_xxx or ADIERR_xxx

Record failed.

Details

When recording or playing speech files on AG boards, a specific DSP file must be loaded for each encoding type. For more information, refer to Voice encoding formats.

When recording or playing speech files on CG boards, a specific DSP file must be loaded for each encoding type except when using the native play and record feature. The native play and record feature combines an ADI port with an MSPP endpoint and plays or records speech data directly to or from an IP endpoint with no transcoding. For information on the native play and record feature, refer to Performing NMS native play and record.

For more information, see Encoding formats and DSP files. The table lists the DSP files that must be loaded on the AG and CG boards. Refer to the board installation and developer's manual for MIPS usage.

Use adiRecordToMemory to initiate recording to memory-resident buffer of size bufsize and return to the application. The ADI service records data into the buffer until one of the terminating conditions described in ADIEVN_RECORDING_DONE occurs.

Note: You cannot initiate a record operation while playing voice or generating tones unless you disable the record beep by setting either ADI_RECORD.beeptime or ADI_RECORD.beepfreq to 0 (zero). You cannot start a record operation if the energy detector is active, unless both ADI_RECORD.novoicetime and ADI_RECORD.silencetime are 0 (zero).

For more information, refer to Recording.

See also

adiCommandRecord, adiGetEncodingInfo, adiSetNativeInfo, adiStopRecording

Example

/*  Record to supplied buffer, stopping after 1 second of silence. */
int myRecord( CTAHD ctahd, unsigned encoding,
          void *buf, unsigned bufsize, unsigned *bytesrecorded )
{
    ADI_RECORD_PARMS parms;
    CTA_EVENT        event;
    unsigned         datarate;                /* average bytes/sec */
    int              myret;
    unsigned         silencetime = 1000;
    unsigned         trimsize = 0;

    /* Modify default silence timeout */
    ctaGetParms (ADI_RECORD_PARMID, &parms, sizeof parms);
    parms.silencetime = silencetime;

    if( adiRecordToMemory (ctahd, encoding, buf, bufsize, &parms) != SUCCESS )
        return MYFAILURE;

    do
    {
        myGetEvent( &event );          /* see ctaWaitEvent example */
    } while (event.id != ADIEVN_RECORD_DONE);

    switch (event.value)
    {
        case CTA_REASON_FINISHED:                 /* Buffer filled */
            myret = SUCCESS;
            break;

        case CTA_REASON_NO_VOICE:             /* No voice detected */
            *bytesrecorded = 0;
            myret = SUCCESS;
            break;

        case CTA_REASON_RELEASED:       /* The call was terminated */
            myret = MYDISCONNECT;
            break;

        case CTA_REASON_STOPPED:    /* adiStopRecording was called */
        case CTA_REASON_DIGIT:         /* Aborted due to touchtone */
                      /* DTMF is trimmed automatically by AG board */
            *bytesrecorded = event.size;
            myret = SUCCESS;
            break;
        case CTA_REASON_VOICE_END:          /* Silence after voice */
            *bytesrecorded = event.size;
            adiGetEncodingInfo (ctahd, encoding, NULL, &datarate, NULL);
            trimsize = datarate * silencetime / 1000;
            myret = SUCCESS;
            break;

        default:                             /* an error code      */
            myret = MYFAILURE;
            break;
    }

    if (myret == SUCCESS)
    {
        if (*bytesrecorded > trimsize)
            *bytesrecorded -= trimsize;
        else
            *bytesrecorded = 0;
    }

    return myret;
}