(Page 41 of 80 in this chapter)


adiRecordToMemory

Description

Initiates recording into a single memory-resident buffer.

Prototype

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

ctahd Context handle returned by adiOpenPort.

encoding Encoding type (refer to adidef.h for a complete list of ADI_ENCODING_xxx values).

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).

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 DTMF; */
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) */
DWORD 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]-------------------------*/
DWORD 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;

Return Values

Events

DSP File Requirement

Each encoding rate of this function requires a specific DSP file to be loaded by agmon as shown in the following table:

DSP File

Encoding Rate

voice.dsp/voxr.dsp

ADI_ENCODE_NMS_16,

ADI_ENCODE_NMS_24,

ADI_ENCODE_NMS_32,

ADI_ENCODE_NMS_64

rvoice.dsp

ADI_ENCODE_MULAW, ADI_ENCODE_ALAW, ADI_ENCODE_PCM8M16

okirec.dsp

ADI_ENCODE_OKI_24, ADI_ENCODE_OKI_32

wavrec.dsp

ADI_ENCODE_PCM11M8, ADI_ENCODE_PCM11M16

g726r.dsp

ADI_ENCODE_G726

Details

Initiates recording to a memory-resident buffer of specified size and returns to the application. AG Access records data into the buffer until one of the terminating conditions described in the ADIEVN_RECORDING_DONE event occurs.

See the AG Access Developer's Manual for a complete discussion of encoding methods, buffer sizes, and recording operations.

Note: You cannot initiate a record operation while playing voice or generating tones. You cannot start a record operation if the energy detector is active, unless both novoicetime and silencetime are zero.

See Also

adiStartRecording, adiRecordAsync, adiStopRecording, adiGetEncodingInfo

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;
    ADI_EVENT        event;
    unsigned         datarate;          /* average bytes/sec */
    int              myret;
    unsigned         silencetime = 1000;
    unsigned         trimsize = 0;

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

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

    do 
    {
        myGetEvent( &event );           /* see adiFetchAndProcess 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;
}



(Page 41 of 80 in this chapter)


Tech_Support@nmss.com
Copyright © 1996, Natural MicroSystems, Inc. All rights reserved.