summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/splay/synth_Std.cpp
blob: 6ea1d027785540fe91754d311c57820faa6ff32f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
  std synth implementation
  Copyright (C) 2001  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */



#include "synthesis.h"



#include "dct64.cpp"

#include <iostream>

using namespace std;

inline void Synthesis::computebuffer_Std(REAL *fraction,
					 REAL buffer[2][CALCBUFFERSIZE]) {
  REAL *out1,*out2;
  out1=buffer[currentcalcbuffer]+calcbufferoffset;
  out2=buffer[currentcalcbuffer^1]+calcbufferoffset;
  dct64(out1,out2,fraction);
}


#define SAVE putraw(r);
#define OS  r=*vp * *dp++
#define XX  vp+=15;r+=*vp * *dp++
#define OP  r+=*--vp * *dp++


inline void Synthesis::generatesingle_Std(void) {
  int i;
  register REAL r, *vp;
  register const REAL *dp;

  i=32;
  dp=filter;
  vp=calcbuffer[LS][currentcalcbuffer]+calcbufferoffset; 
// actual_v+actual_write_pos;

  switch (calcbufferoffset)
  {
    case  0:for(;i;i--,vp+=15){
              OS;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  1:for(;i;i--,vp+=15){
	      OS;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  2:for(;i;i--,vp+=15){
              OS;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  3:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  4:for(;i;i--,vp+=15){
              OS;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  5:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  6:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  7:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  8:for(;i;i--,vp+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case  9:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;
	      SAVE;}break;
    case 10:for(;i;i--,vp+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;
	      SAVE;}break;
    case 11:for(;i;i--,vp+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;
	      SAVE;}break;
    case 12:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;
	      SAVE;}break;
    case 13:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;
	      SAVE;}break;
    case 14:for(;i;i--,vp+=15){
	      OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;
	      SAVE;}break;
    case 15:for(;i;i--,vp+=31){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
	      SAVE;}break;
  }
}

#undef OS
#undef XX
#undef OP
#undef SAVE


#define SAVE putraw(r1); putraw(r2);

#define OS r1=*vp1 * *dp; \
           r2=*vp2 * *dp++ 
#define XX vp1+=15;r1+=*vp1 * *dp; \
           vp2+=15;r2+=*vp2 * *dp++
#define OP r1+=*--vp1 * *dp; \
           r2+=*--vp2 * *dp++

/*
inline void Synthesis::generate_old(void)
{
  int i;
  REAL r1,r2;
  register REAL *vp1,*vp2;
  register const REAL *dp;

  dp=filter;
  vp1=calcbuffer[LS][currentcalcbuffer]+calcbufferoffset;
  vp2=calcbuffer[RS][currentcalcbuffer]+calcbufferoffset;
// actual_v+actual_write_pos;

  i=32;
  switch (calcbufferoffset)
  {
    case  0:for(;i;i--,vp1+=15,vp2+=15){
              OS;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  1:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  2:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  3:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  4:for(;i;i--,vp1+=15,vp2+=15){
             OS;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  5:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  6:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  7:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  8:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
    case  9:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;
              SAVE;}break;
    case 10:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;
              SAVE;}break;
    case 11:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;
              SAVE;}break;
    case 12:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;
              SAVE;}break;
    case 13:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;
              SAVE;}break;
    case 14:for(;i;i--,vp1+=15,vp2+=15){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;
              SAVE;}break;
    case 15:for(;i;i--,vp1+=31,vp2+=31){
              OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;
              SAVE;}break;
  }
}
*/
#undef OS
#undef XX
#undef OP
#undef SAVE

#include "op.h"
#define SAVE putraw(r1); putraw(r2);

inline void Synthesis::generate_Std(void)
{
  int i;
  REAL r1,r2;

  register REAL *vp1;
  register const REAL *dp;

  dp=filter;
  vp1=calcbuffer[LS][currentcalcbuffer]+calcbufferoffset;
  // we calculate cp2 from vp1 because they are both
  // in the same array. code was:
  // register REAL* vp2
  //vp2=calcbuffer[RS][currentcalcbuffer]+calcbufferoffset;

  i=32;
  switch (calcbufferoffset)
  {
    case  0:for(;i;i--,OP_END_1(15,14)){
              OS;XX1;XX2;OP14;
	      SAVE;}break;
    case  1:for(;i;i--,OP_END_1(15,13)){
              OS;OP;OP_END_2(1);XX2;OP13;
	      SAVE;}break;
    case  2:for(;i;i--,OP_END_1(15,12)){
              OS;OP2;OP_END_2(2);XX2;OP12;
	      SAVE;}break;
    case  3:for(;i;i--,OP_END_1(15,11)){ 
              OS;OP3;OP_END_2(3);XX2;OP11;
	      SAVE;}break;
    case  4:for(;i;i--,OP_END_1(15,10)){
              OS;OP4;OP_END_2(4);XX2;OP10;
	      SAVE;}break;
    case  5:for(;i;i--,OP_END_1(15,9)){
              OS;OP5;OP_END_2(5);XX2;OP9;
	      SAVE;}break;
    case  6:for(;i;i--,OP_END_1(15,8)){
              OS;OP6;OP_END_2(6);XX2;OP8;
	      SAVE;}break;
    case  7:for(;i;i--,OP_END_1(15,7)){
              OS;OP7;OP_END_2(7);XX2;OP7;
	      SAVE;}break;
    case  8:for(;i;i--,OP_END_1(15,6)){
              OS;OP8;OP_END_2(8);XX2;OP6;
	      SAVE;}break;
    case  9:for(;i;i--,OP_END_1(15,5)){
              OS;OP9;OP_END_2(9);XX2;OP5;
	      SAVE;}break;
    case 10:for(;i;i--,OP_END_1(15,4)){
              OS;OP10;OP_END_2(10);XX2;OP4;
	      SAVE;}break;
    case 11:for(;i;i--,OP_END_1(15,3)){
              OS;OP11;OP_END_2(11);XX2;OP3;
	      SAVE;}break;
    case 12:for(;i;i--,OP_END_1(15,2)){
              OS;OP12;OP_END_2(12);XX2;OP2;
	      SAVE;}break;
    case 13:for(;i;i--,OP_END_1(15,1)){
              OS;OP13;OP_END_2(13);XX2;OP;
	      SAVE;}break;
    case 14:for(;i;i--,vp1+=15){
	      OS;OP14;OP_END_2(14);XX2;
	      SAVE;}break;
    case 15:for(;i;i--,OP_END_1(31,15)){
              OS;OP15;
	      SAVE;}break;
  }
}
#undef OP_END_1
#undef OP_END_2
#undef OP
#undef OP1
#undef OP2
#undef OP3
#undef OP4
#undef OP5
#undef OP6
#undef OP7
#undef OP8
#undef OP9
#undef OP10
#undef OP11
#undef OP12
#undef OP13
#undef OP14
#undef OP15
#undef OS
#undef XX1
#undef XX2
#undef SCHEDULE
#undef SCHEDULE1
#undef SCHEDULE2
#undef SAVE

void Synthesis::synth_Std(int lOutputStereo,REAL *fractionL,REAL *fractionR) {
  switch(lOutputStereo) {
  case true:
    computebuffer_Std(fractionL,calcbuffer[LS]);
    computebuffer_Std(fractionR,calcbuffer[RS]);
    generate_Std();
    nextOffset();
    break;
  case false:
    computebuffer_Std(fractionL,calcbuffer[LS]);
    generatesingle_Std();
    nextOffset();
    break;
  default:
    cout << "unknown lOutputStereo in Synthesis::synth_Std"<<endl;
    exit(0);
  }
}


void Synthesis::synthMP3_Std(int lOutputStereo,
			     REAL hout [2][SSLIMIT][SBLIMIT]) {
  int ss;
  switch(lOutputStereo) {
  case true:
    for(ss=0;ss<SSLIMIT;ss++) {
      computebuffer_Std(hout[LS][ss],calcbuffer[LS]);
      computebuffer_Std(hout[RS][ss],calcbuffer[RS]);
      generate_Std();
      nextOffset();
    }
    break;
  case false:
    for(ss=0;ss<SSLIMIT;ss++) {
      computebuffer_Std(hout[LS][ss],calcbuffer[LS]);
      generatesingle_Std();
      nextOffset();
    }
    break;
  default:
    cout << "unknown lOutputStereo in Synthesis::synth_Std"<<endl;
    exit(0);
  }
}