Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.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++ ) *scfsi++ = (char)stream->get_bits(2);
228   }
229
230   bita = bit_alloc;
231   scfsi = scfsi_buf;
232   for( i=sblimit2; --i>=0; ) {
233     if( *bita++ ) switch(*scfsi++) {
234     case 0: 
235       *scale++ = stream->get_bits(6);
236       *scale++ = stream->get_bits(6);
237       *scale++ = stream->get_bits(6);
238       break;
239     case 1 : 
240       *scale++ = sc = stream->get_bits(6);
241       *scale++ = sc;
242       *scale++ = stream->get_bits(6);
243       break;
244     case 2: 
245       *scale++ = sc = stream->get_bits(6);
246       *scale++ = sc;
247       *scale++ = sc;
248       break;
249     default:              /* case 3 */
250       *scale++ = stream->get_bits(6);
251       *scale++ = sc = stream->get_bits(6);
252       *scale++ = sc;
253       break;
254     }
255   }
256   return result;
257 }
258
259 int zaudio_decoder_layer_t::
260 step_two(uint8_t *bit_alloc, float fraction[2][4][SBLIMIT], int *scale, int x1)
261 {
262   int i, j, k, ba, result = 0;
263   int sblimit = II_sblimit;
264   imdct_al_table_t *alloc2, *alloc1 = alloc;
265   uint8_t *bita = bit_alloc;
266   int d1, step;
267
268   for( i=0; i<jsbound; ++i, alloc1+=(1<<step) ) {
269     step = alloc1->bits;
270     for( j=0; j<channels; ++j ) {
271       if( (ba=*bita++) != 0 ) {
272         k = (alloc2 = alloc1 + ba)->bits;
273         if( (d1 = alloc2->d) < 0 ) {
274           float cm = muls[k][scale[x1]];
275           fraction[j][0][i] = ((float)((int)stream->get_bits(k) + d1)) * cm;
276           fraction[j][1][i] = ((float)((int)stream->get_bits(k) + d1)) * cm;
277           fraction[j][2][i] = ((float)((int)stream->get_bits(k) + d1)) * cm;
278         }
279         else {
280           static int *table[] = 
281             {0, 0, 0, grp_3tab, 0, grp_5tab, 0, 0, 0, grp_9tab};
282           uint32_t idx, *tab, m = scale[x1];
283           idx = (uint32_t)stream->get_bits(k);
284           tab = (uint32_t*)(table[d1] + idx + idx + idx);
285           fraction[j][0][i] = muls[*tab++][m];
286           fraction[j][1][i] = muls[*tab++][m];
287           fraction[j][2][i] = muls[*tab][m];  
288         }
289         scale += 3;
290       }
291       else
292         fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
293     }
294   }
295
296   for( i=jsbound; i<sblimit; ++i, alloc1+=(1<<step) ) {
297     step = alloc1->bits;
298     /* channel 1 and channel 2 bitalloc are the same */
299     ++bita;    
300     if( (ba=*bita++) != 0 ) {
301       k= (alloc2 = alloc1+ba)->bits;
302       if( (d1 = alloc2->d) < 0 ) {
303         float cm = muls[k][scale[x1 + 3]];
304         fraction[1][0][i] = (fraction[0][0][i] = (float)((int)stream->get_bits(k) + d1)) * cm;
305         fraction[1][1][i] = (fraction[0][1][i] = (float)((int)stream->get_bits(k) + d1)) * cm;
306         fraction[1][2][i] = (fraction[0][2][i] = (float)((int)stream->get_bits(k) + d1)) * cm;
307         cm = muls[k][scale[x1]];
308         fraction[0][0][i] *= cm; 
309         fraction[0][1][i] *= cm; 
310         fraction[0][2][i] *= cm;
311       }
312       else {
313         static int *table[] = {0, 0, 0, grp_3tab, 0, grp_5tab, 0, 0, 0, grp_9tab};
314         uint8_t idx, *tab, m1, m2;
315         m1 = scale[x1]; 
316         m2 = scale[x1+3];
317         idx = (uint8_t)stream->get_bits(k);
318         tab = (uint8_t*)(table[d1] + idx + idx + idx);
319         fraction[0][0][i] = muls[*tab][m1]; 
320         fraction[1][0][i] = muls[*tab++][m2];
321         fraction[0][1][i] = muls[*tab][m1]; 
322         fraction[1][1][i] = muls[*tab++][m2];
323         fraction[0][2][i] = muls[*tab][m1]; 
324         fraction[1][2][i] = muls[*tab][m2];
325       }
326       scale += 6;
327     }
328     else {
329       fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
330       fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
331     }
332 /* 
333    should we use individual scalefac for channel 2 or
334    is the current way the right one , where we just copy channel 1 to
335    channel 2 ?? 
336    The current 'strange' thing is, that we throw away the scalefac
337    values for the second channel ...!!
338 -> changed .. now we use the scalefac values of channel one !! 
339 */
340   }
341
342   if( sblimit > (int)SBLIMIT ) sblimit = SBLIMIT;
343   for( i=sblimit; i < (int)SBLIMIT; ++i )
344     for( j=0; j < channels; ++j )
345       fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
346
347   return result;
348 }
349
350 int zaudio_decoder_layer_t::
351 do_layer2(uint8_t *zframe, int zframe_size, float **zoutput, int render)
352 {
353   int i, j, result = 0;
354   float fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
355   uint8_t bit_alloc[64];
356   int scale[192];
357   int zsingle = single;
358   int output_position = 0;
359 //zmsg("1\n");
360   zframe += 4;
361   /* Set up bitstream to use buffer */
362   stream->use_ptr(zframe);
363   if( error_protection )
364     stream->get_bits(16);
365
366   select_table();
367
368   jsbound = (mode == md_JOINT_STEREO) ?
369     (mode_ext << 2) + 4 : II_sblimit;
370
371   if( channels == 1 || zsingle == 3 )
372     zsingle = 0;
373
374   result |= step_one(bit_alloc, scale);
375
376   for( i=0; i < (int)SCALE_BLOCK && !result; ++i ) {
377     result |= step_two(bit_alloc, fraction, scale, i >> 2);
378     for( j=0; j < 3; ++j ) {
379       if( zsingle >= 0 ) {
380         /* Monaural */
381         if( render )
382           synth_stereo(fraction[0][j], 0, zoutput[0], &output_position);
383         else
384           output_position += 32;
385       }
386       else {
387         /* Stereo */
388         int p1 = output_position;
389         if( render ) {
390 //zmsg(" 3\n");
391           synth_stereo(fraction[0][j], 0, zoutput[0], &p1);
392 //zmsg(" 4\n");
393           synth_stereo(fraction[1][j], 1, zoutput[1], &output_position);
394 //zmsg(" 5\n");
395         }
396         else
397           output_position += 32;
398       }
399     }
400   }
401
402   return output_position;
403 }
404