(Page 6 of 8 in this chapter)
6.5 Using the Voice Play Functions
This section provides a detailed description of AG Access voice play functions that initiate a play operation, terminate a play operation and transfer data.
The general procedure for playing involves the following steps:
The application invokes a function to initiate playing.
AG Access prompts the application for data.
The application provides data to AG Access, and can instruct AG Access to automatically stop playing after the buffer has played (by setting the
ADI_LASTBUFFER_SUBMITTED
flag).
AG Access terminates the play operation upon delivering an
ADIEVN_PLAY_DONE
event (see
Section 6.5.3
, for termination reasons that may be included as part of the event).
Steps 2 and 3 above are typically performed multiple times.
Choose the appropriate function calls for your application:
To ...
Use...
Initiate a play operation in callback transfer mode
adiStartPlaying
Initiate a play operation in single transfer mode
adiPlayFromMemory
Initiate a play operation in asynchronous transfer mode
adiPlayAsync
Submit play buffer (asynchronous)
adiSubmitPlayBuffer
Terminate a play operation
adiStopPlaying
Adjust the playing volume
adiModifyPlayGain
Adjust the playing speed
adiModifyPlaySpeed
Return information about a play operation
adiGetPlayStatus
6.5.1 Voice Play Parameters
The
ADI_PLAY_PARMS
structure contains the following parameters, which modify play operations as noted:
DTMFabort-
Controls which DTMF tones abort a play operation.
gain-
Applies specific gain to the encoded audio.
maxspeed-
Dictates the maximum speed that will be used, which determines how much DSP processing power is allocated to the play operation. This parameter is ignored for encoding types for which speed modification is not supported. For more information about speed control, see
Section 6.5.7
.
speed
-
The initial speedup/slowdown factor applied to the encoded audio data. This parameter is ignored for encoding types for which speed modification is not supported.
6.5.2 Initiating a Play Operation
AG Access provides three functions to initiate playing voice data. The function used depends upon which data transfer method is selected, as listed below:
adiPlayFromMemory
-
The application submits a single memory buffer to AG Access.
adiStartPlaying
-
AG Access invokes an application-specified callback function when data is needed.
adiPlayAsync
-
AG Access generates a buffer request event when more data is needed. The application asynchronously submits play buffers in response.
In all three cases, AG Access returns
SUCCESS
if the "start playing" command is successfully sent to the AG board.
6.5.3 Terminating a Play Operation
The play operation on a port terminates when AG Access delivers an
ADIEVN_PLAY_DONE
event, regardless of the transfer method selected. The event
value
field contains the termination reason, which is one of the following.
CTA_REASON_FINISHED-
The application submitted a buffer with the
ADI_LASTBUFFER_SUBMITTED
flag and the buffer has finished playing.
CTA_REASON_RELEASED-
The call was released by either party.
CTA_REASON_DIGIT-
A DTMF digit specified in the abort mask was entered by the remote party.
CTA_REASON_STOPPED-
The application called
adiStopPlaying
to abort a play operation.
CTA_REASON_RECOGNITION-
The playing was aborted by the speech recognizer.
6.5.4 Playing Voice Data in Callback Mode
In callback mode, AG Access allocates a buffer and invokes an application-specified function to place voice data into it. You specify the callback function when a play operation is initiated with
adiStartPlaying
.
When AG Access requires data, it invokes the callback function, passing it a buffer to fill and the buffer size. The application's callback function reads data from a storage medium (e.g., a disk) into the buffer. The callback returns to AG Access the amount of data read and a flag indicating whether or not to terminate the play operation after the buffer is played.
In general, playing voice data using callback mode follows these steps:
The application invokes
adiStartPlaying
.
Note:
AG Access invokes the callback function from within the
adiStartPlaying
context to retrieve the initial buffer (i.e., before
adiStartPlaying
returns).
AG Access invokes the application's callback function when a buffer needs to be filled with voice data.
The application's callback function fills the buffer before returning.
At this point, if the application indicates that this is the last buffer (uses the
ADI_LASTBUFFER_SUBMITTED
flag) or if a termination condition has occurred, the play operation may terminate.
When playing completes, AG Access generates an
ADIEVN_PLAY_DONE
event.
Steps 2 and 3 are repeated until the
ADIEVN_PLAY_DONE
event is given to the application.
The application is not allowed to invoke AG Access functions while the callback function is executing.
The demonstration program
playrec
illustrates a play operation using callback mode.
6.5.5 Playing Voice Data in Asynchronous Mode
In asynchronous mode, the application transfers voice data from the host to the AG board by cooperatively exchanging commands and events with AG Access. These exchanges are depicted in the following diagram:
Figure 18. Voice Play Sequence
In general, transferring voice data asynchronously during a play operation follows these steps:
The application invokes
adiPlayAsync
.
AG Access sends an
ADIEVN_PLAY_BUFFER_REQ
event when a buffer is required.
The application invokes
adiSubmitPlayBuffer
in response to the
ADIEVN_PLAY_BUFFER_REQ
event.
When the play operation completes, AG Access generates an
ADIEVN_PLAY_DONE
event.
Steps 2 and 3 are repeated until the
ADIEVN_PLAY_DONE
event is given to the application.
Figure 19
is a state diagram depicting the complete life-cycle for a play operation in asynchronous transfer mode.
Figure 19. Voice Play State
The three states for asynchronous play transfer illustrated in
Figure 19
are:
Idle
-
The play operation is not active.
Active
-
When the application invokes
adiPlayAsync
, AG Access sends the initial buffer to the AG board and transitions to the Active state. The play state remains Active until one of the terminating conditions described in
Section 6.5.3
, occurs.
AG Access sends events and the application submits buffers while in this state as follows:
AG Access generates an
ADIEVN_PLAY_BUFFER_REQ
when more data is needed.
In response to AG Access, the application invokes
adiSubmitPlayBuffer
to continue playing. The application can terminate the play operation by setting the
ADI_LASTBUFFER_SUBMITTED
flag. This causes AG Access to generate an
ADIEVN_PLAY_DONE
event when the data already submitted has been played.
The application cannot invoke
adiSubmitPlayBuffer
unless AG Access has given it an
ADIEVN_PLAY_BUFFER_REQ
event. AG Access returns an
ADIERR_TOO_MANY_BUFFERS
error code when
adiSubmitPlayBuffer
is invoked without first receiving a buffer request event.
Stopping
-
The application can abort the play operation by invoking
adiStopPlaying
. AG Access will not accept any more play commands from the application while in the Stopping state. Any play functions invoked by the application result in AG Access returning an
CTAERR_INVALID_SEQUENCE
error code. When the
ADIEVN_PLAY_DONE
event is delivered to the application, the play state returns to Idle.
6.5.6 Controlling Gain During a Play Operation
The audio volume can be adjusted at play initiation by changing the default value of the play gain parameter stored in
ADI_PLAY_PARMS
. Volume can also be modified at any time while the play operation is active by calling
adiModifyPlayGain
. The default value of the gain is 0 dB (i.e., no gain). The gain may be set to any value in the range of -54db to +24db.
6.5.7 Controlling Speed During a Play Operation
To modify the speed at which the voice data is played, call
adiModifyPlaySpeed
during a currently active play operation. You can modify the playing speed for voice data that uses any of the following encodings:
ADI_ENCODE_NMS_16
ADI_ENCODE_NMS_24
ADI_ENCODE_NMS_32
ADI_ENCODE_NMS_64
ADI_ENCODE_OKI_24
ADI_ENCODE_OKI_32
If you invoke
adiModifyPlaySpeed
for a play operation with data in any other encoding format, the play operation will simply continue at its original speed.
To enable speed-up, increase the
maxspeed
play parameter stored in
ADI_PLAY_PARMS
from its default value of 100.
To use speed-up with NMS ADPCM encodings, replace
voice.dsp
in the
ag.cfg
file with
vox.dsp
and
voxr.dsp
.
When a play operation is started with a higher value of
maxspeed
, the necessary DSP resources are allocated to support increased speed. You can start a play operation with a fast speed (up to
maxspeed
) by changing the value of the
speed
parameter in the function call.
Note:
Starting a play operation with
maxspeed
greater than 100 requires additional DSP resources beyond those required for playing at normal speed. To determine whether your AG board(s) and configuration can support speed-up, see the
AG Runtime Configuration and Developer's Manual
.
(Page 6 of 8 in this chapter)
tech_support@nmss.com
Copyright © 1997, Natural MicroSystems, Inc. All rights reserved.