axvpb.pb.adpcmLoop

Syntax

typedef struct _AXPBADPCMLOOP
{
    u16 loop_pred_scale;    // Predictor and scale
    u16 loop_yn1;             // Log data (y[n - 1])
    u16 loop_yn2;             // Log data (y[n - 2])

} AXPBADPCMLOOP;

Description

The ADPCM hardware decoder supports loop features that support looped ADPCM/PCM data.

When you specify AXPBADDR_LOOP_ON for the loopFlag member of axvpb.pb.addr(AXPBADDR structure), the loop feature is enabled for that voice.

When loop functionality is enabled and the decoder pointer reaches the loop end, the ADPCM hardware decoder automatically returns the pointer to the start of the loop. The starting address is specified by loopAddressHi/Lo. The ending address is specified by endAddressHi/Lo. Both are members of axvpb.pb.addr.

In the case of ADPCM data:

  1. Loop and Loop Context

    The processing by the ADPCM hardware decoder proceeds while updating axvpb.pb.adpcm(AXPBADPCM structure) with the context for decoding, sample by sample.

    Because data contiguity is lost for the samples before and after the point where the loop occurs, the data may be decoded to inappropriate values if the context that is updated just before the loop point is used to decode the sample just after the loop point.

    To avoid this kind of inappropriate decoding, when a loop occurs the AX library automatically overwrites the decode context with the loop context specified by axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure).

    The configuring and handling of loop context differs, depending on the way the ADPCM data is played.

  2. Playing looped ADPCM data

    The normal playback method of the AX library. If the size of ADPCM data is sufficiently small and all of the data is placed in RAM during playback, then this is the method used.

    The axsimple sample program uses this method. (Most of the sample programs use this method, but the processing is hidden inside the AX high-level library.)

    When ADPCM data is created, the loop context is calculated based on the loop address specified to the argument of the DSPADPCM tool and then written to the output data header (the DSPADPCM structure). When the ADPCM data is to be played, the loop context is set to the AXPBADPCMLOOP structure, as shown below, and applied to the voice parameter block. (Alternately, it is directly set to the voice parameter block.)

    
    DSPADPCM  *ps = (DSPADPCM*) (Pointer to ADPCM data)
    AXPBADPCMLOOP   adpcmloop;
    
    adpcmloop.loop_pred_scale = ps->lps;
    adpcmloop.loop_yn1        = ps->lyn1;
    adpcmloop.loop_yn2        = ps->lyn2;
    

    For playback of looped ADPCM data, the loop context only needs to be set the one time when playback starts. This is because during playback the loop position and the loop context do not change.

    In order to enable all of the loop context axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure) members, you must set the voice type axvpb.pb.type to AX_PB_TYPE_NORMAL.

  3. Software streaming

    If the size of the ADPCM data is large and cannot all be placed in RAM during playback, this method plays it by dividing the data and reading it from where it is stored.

    The sample program axstream uses this method.

    axstream performs software streaming using the loop functionality of the ADPCM hardware decoder, but the loop-related settings are very different for the playback of looped ADPCM data.

    One difference is the loop addresses. For software streaming, the loop functionality is not used for the loop information inside the ADPCM data, but rather to loop the data in the streaming buffer. For this reason, the loop addresses are specified as shown below for software streaming.

    
    Loop start  =  Start of streaming buffer
    Loop end  =  End of streaming buffer
    

    Another difference is the loop context. For software streaming, the data in the streaming buffer is continuously overwritten as the playback of data proceeds. For this reason, when a loop from the end to the start of the streaming buffer occurs, the decoder must make use of the loop context for the newly overwritten data. In the axstream sample program, the loop context is set every time the first half of the streaming buffer is overwritten with new data.

    On the other hand, because of the size of the buffer the data in the loop from the end to the start of the streaming buffer is contiguous, even though there are start and end places for the loop. For this reason, when the loop occurs, the decoder context log data (yn1,yn2) does not need to be overwritten with loop context. Conversely, if the decoder context log data is overwritten by inappropriate values, after the loop occurs the data will not be decoded correctly.

    In other words, for software streaming, you need to set the loop context as shown below with specific timing. (In the case of axstream, set it every time the first half of the streaming buffer is overwritten with new data.) Then apply this timing to the voice parameter block (or directly set the voice parameter block).

    
    AXPBADPCMLOOP   adpcmloop;        
    
    adpcmloop.loop_pred_scale = (u16)(*((u8*)(Start address of streaming buffer)));
    // no need to set loop_yn1 & loop_yn2.
    

    Along with this, you also need to set the voice type axvpb.pb.type to AX_PB_TYPE_STREAM so when the loop occurs, only the loop context axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure), predictor, and scale (loop_pred_scale) are allowed to be overwritten.

  4. Software streaming of looped ADPCM data

    As mentioned above, for software streaming (as in the sample program axstream), the loop settings in the ADPCM data are ignored because the loop functionality is used for looping the streaming buffer.

    In order to stream the playback of looped ADPCM data, you must switch between the loop in the ADPCM data and the loop of the streaming buffer in accordance to the progression of playback. Furthermore, this switching must be performed with safe timing so the AX does not malfunction if the voice parameter block changes.

    The axstream2 sample program presents an example of the software streaming of looped ADPCM data. Review this sample if you are planning such an implementation.

There will be other times when 16-bit PCM or 8-bit PCM data is being played. If the decoder context axvpb.pb.adpcm(AXPBADPCM structure) is set correctly for 16- or 8-bit PCM, then there should not be any problem even if a value such as loop context axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure) is set.

If axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure) members have changed, assert the AX_SYNC_USER_ADPCMLOOP bit in the axvpb.sync member.

See Also

axvpb.sync
axvpb.pb.type
axvpb.pb.adpcm
axvpb.pb.addr
AXSetVoiceAdpcm

Revision History

2009/05/11 Revised Description.
2006/03/01 Initial version.


CONFIDENTIAL