1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3
4<head>
5<LINK rel="stylesheet" type="text/css" href="../../CSS/revolution.css">
6<title>axvpb.pb.adpcmLoop</title>
7<META http-equiv="Content-Type" content="text/html; charset=utf-8">
8<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 6.5.0.0 for Windows">
9<META http-equiv="Content-Style-Type" content="text/css">
10</head>
11
12<body>
13
14<h1 align="left">axvpb.pb.adpcmLoop</h1>
15
16<h2>Syntax</h2>
17<dl><dd><pre class="construction">
18typedef struct _AXPBADPCMLOOP
19{
20    u16 loop_pred_scale;    // Predictor and scale
21    u16 loop_yn1;             // Log data (y[n - 1])
22    u16 loop_yn2;             // Log data (y[n - 2])
23
24} AXPBADPCMLOOP;
25</pre></dd></dl>
26
27<h2>Description</h2>
28<p>The ADPCM hardware decoder supports loop features that support looped ADPCM/PCM data.</p>
29
30<p>When you specify <code>AXPBADDR_LOOP_ON</code> for the <code>loopFlag</code> member of <code>axvpb.pb.addr(AXPBADDR structure)</code>, the loop feature is enabled for that voice.</p>
31
32<p>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 <code>loopAddressHi/Lo</code>. The ending address is specified by <code>endAddressHi/Lo</code>. Both are members of <code>axvpb.pb.addr</code>.</p>
33
34<p>In the case of ADPCM data:</p>
35
36<ol>
37<li>Loop and Loop Context<br>
38
39<p>The processing by the ADPCM hardware decoder proceeds while updating <code>axvpb.pb.adpcm(AXPBADPCM structure)</code> with the context for decoding, sample by sample.</p>
40
41<p>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.</p>
42
43<p>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 <CODE>axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure).</CODE></p>
44
45<p>The configuring and handling of loop context differs, depending on the way the ADPCM data is played.</p>
46<ul>
47<li>Playing looped ADPCM data</li>
48<li>Software streaming</li>
49</ul>
50
51<p></p>
52
53</li>
54
55<li>Playing looped ADPCM data<br>
56
57<p>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.</p>
58
59<p>The <code>axsimple</code> sample program uses this method. (Most of the sample programs use this method, but the processing is hidden inside the AX high-level library.)</p>
60
61<p>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 <code>DSPADPCM</code> structure). When the ADPCM data is to be played, the loop context is set to the <code>AXPBADPCMLOOP</code> structure, as shown below, and applied to the voice parameter block. (Alternately, it is directly set to the voice parameter block.)</p>
62
63<BLOCKQUOTE>
64<pre><CODE>
65DSPADPCM  *ps = (DSPADPCM*) (Pointer to ADPCM data)
66AXPBADPCMLOOP   adpcmloop;
67
68adpcmloop.loop_pred_scale = ps-&gt;lps;
69adpcmloop.loop_yn1        = ps-&gt;lyn1;
70adpcmloop.loop_yn2        = ps-&gt;lyn2;
71</CODE></pre>
72</BLOCKQUOTE>
73
74<p>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.</p>
75
76<p>In order to enable all of the loop context <code>axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure)</code> members, you must set the voice <SPAN class="argument">type</SPAN> <code>axvpb.pb.type</code> to <code>AX_PB_TYPE_NORMAL</code>.</p>
77
78</li>
79
80<li>Software streaming<br>
81
82<p>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.</p>
83
84<p>The sample program <code>axstream</code> uses this method.</p>
85
86<p><code>axstream</code> 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.</p>
87
88<p>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.</p>
89
90<BLOCKQUOTE>
91<pre><CODE>
92Loop start  =  Start of streaming buffer
93Loop end  =  End of streaming buffer
94</CODE></pre>
95</BLOCKQUOTE>
96
97<p>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 <code>axstream</code> sample program, the loop context is set every time the first half of the streaming buffer is overwritten with new data.</p>
98
99<p>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 (<code>yn1,yn2</code>) 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.</p>
100
101<p>In other words, for software streaming, you need to set the loop context as shown below with specific timing. (In the case of <code>axstream</code>, 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).</p>
102
103<BLOCKQUOTE>
104<pre><CODE>
105AXPBADPCMLOOP   adpcmloop;
106
107adpcmloop.loop_pred_scale = (u16)(*((u8*)(Start address of streaming buffer)));
108// no need to set loop_yn1 &amp; loop_yn2.
109</CODE></pre>
110</BLOCKQUOTE>
111
112<p>Along with this, you also need to set the voice <SPAN class="argument">type</SPAN> <code>axvpb.pb.type</code> to <code>AX_PB_TYPE_STREAM</code> so when the loop occurs, only the  loop context <code>axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure)</code>, predictor, and scale (<code>loop_pred_scale</code>) are allowed to be overwritten.</p>
113
114</li>
115
116<li>Software streaming of looped ADPCM data<br>
117
118<p>As mentioned above, for software streaming (as in the sample program <code>axstream</code>), the loop settings in the ADPCM data are ignored because the loop functionality is used for looping the streaming buffer.</p>
119
120<p>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.</p>
121
122<p>The <code>axstream2</code> sample program presents an example of the software streaming of looped ADPCM data. Review this sample if you are planning such an implementation.</p>
123
124</li>
125
126</ol>
127
128<p>There will be other times when 16-bit PCM or 8-bit PCM data is being played. If the decoder context  <code>axvpb.pb.adpcm(AXPBADPCM structure)</code> is set correctly for 16- or 8-bit PCM, then there should not be any problem even if a value such as loop context <code>axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure)</code> is set.</p>
129
130<p>If <code>axvpb.pb.adpcmLoop(AXPBADPCMLOOP structure)</code> members have changed, assert the <code>AX_SYNC_USER_ADPCMLOOP</code> bit in the <code>axvpb.sync</code> member.</p>
131
132<h2>See Also</h2>
133<p class="reference">
134<a href="../Voice_Parameter_Blocks/sync.html">axvpb.sync</a><BR> <a href="type.html">axvpb.pb.type</a><BR> <a href="AXPBADPCM_adpcm.html">axvpb.pb.adpcm</a><BR> <a href="AXPBADDR_addr.html">axvpb.pb.addr</a><BR> <a href="../Voice_Parameters/AXSetVoiceAdpcm.html">AXSetVoiceAdpcm</a>
135</p>
136
137<h2>Revision History</h2>
138<P>
1392009/05/11 Revised <B>Description</B>.<br>2006/03/01 Initial version.<BR>
140</P>
141
142<hr><p>CONFIDENTIAL</p></body>
143</html>
144