Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / libzmpeg3 / audio / layer2.C
1 /*
2  * most other tables are calculated on program start (which is (of course)
3  * not ISO-conform) .. 
4  * Layer-3 huffman table is in huffman.h
5  */
6
7 #include "../libzmpeg3.h"
8
9 static zaudio_t::imdct_al_table_t alloc_0[] = {
10   {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
11   {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
12   {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
13   {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
14   {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
15   {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
16   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
17   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
18   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
19   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
20   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
21   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
22   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
23   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
24   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
25   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
26   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
27   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
28   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
29   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
30   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
31   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
32   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
33   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
34   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
35   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
36   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
37   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
38   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
39   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
40   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
41   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
42   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
43   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
44   {2,0},{5,3},{7,5},{16,-32767},
45   {2,0},{5,3},{7,5},{16,-32767},
46   {2,0},{5,3},{7,5},{16,-32767},
47   {2,0},{5,3},{7,5},{16,-32767}
48 };
49
50 static zaudio_t::imdct_al_table_t alloc_1[] = {
51   {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
52   {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
53   {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
54   {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
55   {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
56   {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
57   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
58   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
59   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
60   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
61   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
62   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
63   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
64   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
65   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
66   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
67   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
68   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
69   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
70   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
71   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
72   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
73   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
74   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
75   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
76   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
77   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
78   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
79   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
80   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
81   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
82   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
83   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
84   {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
85   {2,0},{5,3},{7,5},{16,-32767},
86   {2,0},{5,3},{7,5},{16,-32767},
87   {2,0},{5,3},{7,5},{16,-32767},
88   {2,0},{5,3},{7,5},{16,-32767},
89   {2,0},{5,3},{7,5},{16,-32767},
90   {2,0},{5,3},{7,5},{16,-32767},
91   {2,0},{5,3},{7,5},{16,-32767}
92 };
93
94 static zaudio_t::imdct_al_table_t alloc_2[] = {
95   {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
96   {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
97   {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
98   {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
99   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
100   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
101   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
102   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
103   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
104   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}
105 };
106
107 static zaudio_t::imdct_al_table_t alloc_3[] = {
108   {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
109   {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
110   {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
111   {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
112   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
113   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
114   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
115   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
116   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
117   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
118   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
119   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
120   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
121   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}
122 };
123
124 static zaudio_t::imdct_al_table_t alloc_4[] = {
125   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
126   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
127   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
128   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
129   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
130   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
131   {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
132   {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
133   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
134   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
135   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
136   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
137   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
138   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
139   {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
140   {2,0},{5,3},{7,5},{10,9},
141   {2,0},{5,3},{7,5},{10,9},
142   {2,0},{5,3},{7,5},{10,9},
143   {2,0},{5,3},{7,5},{10,9},
144   {2,0},{5,3},{7,5},{10,9},
145   {2,0},{5,3},{7,5},{10,9},
146   {2,0},{5,3},{7,5},{10,9},
147   {2,0},{5,3},{7,5},{10,9},
148   {2,0},{5,3},{7,5},{10,9},
149   {2,0},{5,3},{7,5},{10,9},
150   {2,0},{5,3},{7,5},{10,9},
151   {2,0},{5,3},{7,5},{10,9},
152   {2,0},{5,3},{7,5},{10,9},
153   {2,0},{5,3},{7,5},{10,9},
154   {2,0},{5,3},{7,5},{10,9},
155   {2,0},{5,3},{7,5},{10,9},
156   {2,0},{5,3},{7,5},{10,9},
157   {2,0},{5,3},{7,5},{10,9},
158   {2,0},{5,3},{7,5},{10,9}
159 };
160
161 int zaudio_decoder_layer_t::
162 select_table()
163 {
164   static int translate[3][2][16] = {
165     {{ 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0},
166      { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0}},
167     {{ 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0},
168      { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0}},
169     {{ 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0},
170      { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0}}
171   };
172   int table, sblim;
173   static imdct_al_table_t *tables[5] = {
174     alloc_0, alloc_1, alloc_2, alloc_3, alloc_4
175   };
176   static int sblims[5] = {27, 30, 8, 12, 30};
177
178   if( lsf )
179     table = 4;
180   else
181     table = translate[sampling_frequency_code][2 - channels][bitrate_index];
182   sblim = sblims[table];
183
184   alloc = tables[table];
185   II_sblimit = sblim;
186   return 0;
187 }
188
189 int zaudio_decoder_layer_t::
190 step_one(uint8_t *bit_alloc, int *scale)
191 {
192   int stereo = channels - 1;
193   int sblimit = II_sblimit;
194   int sblimit2 = II_sblimit << stereo;
195   imdct_al_table_t *alloc1 = alloc;
196   int i, result = 0;
197   uint8_t *scfsi_buf = layer2_scfsi_buf;
198   uint8_t *scfsi, *bita;
199   uint8_t *bita_end = bit_alloc + 64;
200   int sc, step;
201
202   bita = bit_alloc;
203   if( stereo ) {
204     /* Stereo */
205     for( i=jsbound; --i>=0 && bita < bita_end-2; alloc1+=(1<<step) ) {
206       *bita++ = (char)stream->get_bits(step = alloc1->bits);
207       *bita++ = (char)stream->get_bits(step);
208     }
209     for( i=sblimit-jsbound; --i>=0 && bita < bita_end-2; alloc1+=(1<<step)) {
210       bita[0] = (char)stream->get_bits(step = alloc1->bits);
211       bita[1] = bita[0];
212       bita += 2;
213     }
214     bita = bit_alloc;
215     scfsi = scfsi_buf;
216     for( i=sblimit2; --i>=0 ; )
217       if( *bita++ )
218         *scfsi++ = (char)stream->get_bits(2);
219   }
220   else {
221     /* mono */
222     for( i=sblimit; --i>=0 ; alloc1+=(1<<step) )
223       *bita++ = (char)stream->get_bits(step = alloc1->bits);
224       bita = bit_alloc;
225       scfsi = scfsi_buf;
226       for( i=sblimit; --i>=0 ; )
227         if( *bita++ )
228           *scfsi++ = (char)stream->get_bits(2);
229   }
230
231   bita = bit_alloc;
232   scfsi = scfsi_buf;
233   for( i=sblimit2; --i>=0; ) {
234     if( *bita++ ) switch(*scfsi++) {
235     case 0: 
236       *scale++ = stream->get_bits(6);
237       *scale++ = stream->get_bits(6);
238       *scale++ = stream->get_bits(6);
239       break;
240     case 1 : 
241       *scale++ = sc = stream->get_bits(6);
242       *scale++ = sc;
243       *scale++ = stream->get_bits(6);
244       break;
245     case 2: 
246       *scale++ = sc = stream->get_bits(6);
247       *scale++ = sc;
248       *scale++ = sc;
249       break;
250     default:              /* case 3 */
251       *scale++ = stream->get_bits(6);
252       *scale++ = sc = stream->get_bits(6);
253       *scale++ = sc;
254       break;
255     }
256   }
257   return result;
258 }
259
260 int zaudio_decoder_layer_t::
261 step_two(uint8_t *bit_alloc, float fraction[2][4][SBLIMIT], int *scale, int x1)
262 {
263   int i, j, k, ba, result = 0;
264   int sblimit = II_sblimit;
265   imdct_al_table_t *alloc2, *alloc1 = alloc;
266   uint8_t *bita = bit_alloc;
267   int d1, step;
268
269   for( i=0; i<jsbound; ++i, alloc1+=(1<<step) ) {
270     step = alloc1->bits;
271     for( j=0; j<channels; ++j ) {
272       if( (ba=*bita++) != 0 ) {
273         k = (alloc2 = alloc1 + ba)->bits;
274         if( (d1 = alloc2->d) < 0 ) {
275           float cm = muls[k][scale[x1]];
276           fraction[j][0][i] = ((float)((int)stream->get_bits(k) + d1)) * cm;
277           fraction[j][1][i] = ((float)((int)stream->get_bits(k) + d1)) * cm;
278           fraction[j][2][i] = ((float)((int)stream->get_bits(k) + d1)) * cm;
279         }
280         else {
281           static int *table[] = 
282             {0, 0, 0, grp_3tab, 0, grp_5tab, 0, 0, 0, grp_9tab};
283           uint32_t idx, *tab, m = scale[x1];
284           idx = (uint32_t)stream->get_bits(k);
285           tab = (uint32_t*)(table[d1] + idx + idx + idx);
286           fraction[j][0][i] = muls[*tab++][m];
287           fraction[j][1][i] = muls[*tab++][m];
288           fraction[j][2][i] = muls[*tab][m];  
289         }
290         scale += 3;
291       }
292       else
293         fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
294     }
295   }
296
297   for( i=jsbound; i<sblimit; ++i, alloc1+=(1<<step) ) {
298     step = alloc1->bits;
299     /* channel 1 and channel 2 bitalloc are the same */
300     ++bita;    
301     if( (ba=*bita++) != 0 ) {
302       k= (alloc2 = alloc1+ba)->bits;
303       if( (d1 = alloc2->d) < 0 ) {
304         float cm = muls[k][scale[x1 + 3]];
305         fraction[1][0][i] = (fraction[0][0][i] = (float)((int)stream->get_bits(k) + d1)) * cm;
306         fraction[1][1][i] = (fraction[0][1][i] = (float)((int)stream->get_bits(k) + d1)) * cm;
307         fraction[1][2][i] = (fraction[0][2][i] = (float)((int)stream->get_bits(k) + d1)) * cm;
308         cm = muls[k][scale[x1]];
309         fraction[0][0][i] *= cm; 
310         fraction[0][1][i] *= cm; 
311         fraction[0][2][i] *= cm;
312       }
313       else {
314         static int *table[] = {0, 0, 0, grp_3tab, 0, grp_5tab, 0, 0, 0, grp_9tab};
315         uint8_t idx, *tab, m1, m2;
316         m1 = scale[x1]; 
317         m2 = scale[x1+3];
318         idx = (uint8_t)stream->get_bits(k);
319         tab = (uint8_t*)(table[d1] + idx + idx + idx);
320         fraction[0][0][i] = muls[*tab][m1]; 
321         fraction[1][0][i] = muls[*tab++][m2];
322         fraction[0][1][i] = muls[*tab][m1]; 
323         fraction[1][1][i] = muls[*tab++][m2];
324         fraction[0][2][i] = muls[*tab][m1]; 
325         fraction[1][2][i] = muls[*tab][m2];
326       }
327       scale += 6;
328     }
329     else {
330       fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
331       fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
332     }
333 /* 
334    should we use individual scalefac for channel 2 or
335    is the current way the right one , where we just copy channel 1 to
336    channel 2 ?? 
337    The current 'strange' thing is, that we throw away the scalefac
338    values for the second channel ...!!
339 -> changed .. now we use the scalefac values of channel one !! 
340 */
341   }
342
343   if( sblimit > (int)SBLIMIT ) sblimit = SBLIMIT;
344   for( i=sblimit; i < (int)SBLIMIT; ++i )
345     for( j=0; j < channels; ++j )
346       fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
347
348   return result;
349 }
350
351 int zaudio_decoder_layer_t::
352 do_layer2(uint8_t *zframe, int zframe_size, float **zoutput, int render)
353 {
354   int i, j, result = 0;
355   float fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
356   uint8_t bit_alloc[64];
357   int scale[192];
358   int zsingle = single;
359   int output_position = 0;
360 //zmsg("1\n");
361   zframe += 4;
362   /* Set up bitstream to use buffer */
363   stream->use_ptr(zframe);
364   if( error_protection )
365     stream->get_bits(16);
366
367   select_table();
368
369   jsbound = (mode == md_JOINT_STEREO) ?
370     (mode_ext << 2) + 4 : II_sblimit;
371
372   if( channels == 1 || zsingle == 3 )
373     zsingle = 0;
374
375   result |= step_one(bit_alloc, scale);
376
377   for( i=0; i < (int)SCALE_BLOCK && !result; ++i ) {
378     result |= step_two(bit_alloc, fraction, scale, i >> 2);
379     for( j=0; j < 3; ++j ) {
380       if( zsingle >= 0 ) {
381         /* Monaural */
382         if( render )
383           synth_stereo(fraction[0][j], 0, zoutput[0], &output_position);
384         else
385           output_position += 32;
386       }
387       else {
388         /* Stereo */
389         int p1 = output_position;
390         if( render ) {
391 //zmsg(" 3\n");
392           synth_stereo(fraction[0][j], 0, zoutput[0], &p1);
393 //zmsg(" 4\n");
394           synth_stereo(fraction[1][j], 1, zoutput[1], &output_position);
395 //zmsg(" 5\n");
396         }
397         else
398           output_position += 32;
399       }
400     }
401   }
402
403   return output_position;
404 }
405