~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to decode_4to1.c

Tags: upstream-0.60
ImportĀ upstreamĀ versionĀ 0.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Mpeg Layer-1,2,3 audio decoder
3
 
 * ------------------------------
4
 
 * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
5
 
 * See also 'README'
6
 
 * version for slower machines .. decodes only every fourth sample
7
 
 * dunno why it sounds THIS annoying (maybe we should adapt the window?)
8
 
 * absolutely not optimized for this operation
9
 
 */
10
 
 
11
 
#include <stdlib.h>
12
 
#include <math.h>
13
 
#include <string.h>
14
 
 
15
 
#include "mpg123.h"
16
 
 
17
 
#define WRITE_SAMPLE(samples,sum,clip) \
18
 
  if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
19
 
  else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
20
 
  else { *(samples) = sum; }
21
 
 
22
 
int synth_4to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
23
 
{
24
 
  short samples_tmp[16];
25
 
  short *tmp1 = samples_tmp + channel;
26
 
  int i,ret;
27
 
  int pnt1 = 0;
28
 
 
29
 
  ret = synth_4to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1);
30
 
  samples += channel + *pnt;
31
 
 
32
 
  for(i=0;i<8;i++) {
33
 
    *samples = conv16to8[*tmp1>>AUSHIFT];
34
 
    samples += 2;
35
 
    tmp1 += 2;
36
 
  }
37
 
  *pnt += 16;
38
 
 
39
 
  return ret;
40
 
}
41
 
 
42
 
int synth_4to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
43
 
{
44
 
  short samples_tmp[16];
45
 
  short *tmp1 = samples_tmp;
46
 
  int i,ret;
47
 
  int pnt1 = 0;
48
 
 
49
 
  ret = synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
50
 
  samples += *pnt;
51
 
 
52
 
  for(i=0;i<8;i++) {
53
 
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
54
 
    tmp1 += 2;
55
 
  }
56
 
  *pnt += 8;
57
 
 
58
 
  return ret;
59
 
}
60
 
 
61
 
 
62
 
int synth_4to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
63
 
{
64
 
  short samples_tmp[16];
65
 
  short *tmp1 = samples_tmp;
66
 
  int i,ret;
67
 
  int pnt1 = 0;
68
 
 
69
 
  ret = synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
70
 
  samples += *pnt;
71
 
 
72
 
  for(i=0;i<8;i++) {
73
 
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
74
 
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
75
 
    tmp1 += 2;
76
 
  }
77
 
  *pnt += 16;
78
 
 
79
 
  return ret;
80
 
}
81
 
 
82
 
int synth_4to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
83
 
{
84
 
  short samples_tmp[16];
85
 
  short *tmp1 = samples_tmp;
86
 
  int i,ret;
87
 
  int pnt1 = 0;
88
 
 
89
 
  ret = synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
90
 
  samples += *pnt;
91
 
 
92
 
  for(i=0;i<8;i++) {
93
 
    *( (short *)samples) = *tmp1;
94
 
    samples += 2;
95
 
    tmp1 += 2;
96
 
  }
97
 
  *pnt += 16;
98
 
 
99
 
  return ret;
100
 
}
101
 
 
102
 
int synth_4to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
103
 
{
104
 
  int i,ret;
105
 
 
106
 
  ret = synth_4to1(bandPtr,0,samples,pnt);
107
 
  samples = samples + *pnt - 32;
108
 
 
109
 
  for(i=0;i<8;i++) {
110
 
    ((short *)samples)[1] = ((short *)samples)[0];
111
 
    samples+=4;
112
 
  }
113
 
 
114
 
  return ret;
115
 
}
116
 
 
117
 
int synth_4to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
118
 
{
119
 
  static real buffs[2][2][0x110];
120
 
  static const int step = 2;
121
 
  static int bo = 1;
122
 
  short *samples = (short *) (out + *pnt);
123
 
 
124
 
  real *b0,(*buf)[0x110];
125
 
  int clip = 0; 
126
 
  int bo1;
127
 
 
128
 
  if(equalfile)
129
 
    do_equalizer(bandPtr,channel);
130
 
 
131
 
  if(!channel) {
132
 
    bo--;
133
 
    bo &= 0xf;
134
 
    buf = buffs[0];
135
 
  }
136
 
  else {
137
 
    samples++;
138
 
    buf = buffs[1];
139
 
  }
140
 
 
141
 
  if(bo & 0x1) {
142
 
    b0 = buf[0];
143
 
    bo1 = bo;
144
 
    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
145
 
  }
146
 
  else {
147
 
    b0 = buf[1];
148
 
    bo1 = bo+1;
149
 
    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
150
 
  }
151
 
 
152
 
  {
153
 
    register int j;
154
 
    real *window = decwin + 16 - bo1;
155
 
 
156
 
    for (j=4;j;j--,b0+=0x30,window+=0x70)
157
 
    {
158
 
      real sum;
159
 
      sum  = *window++ * *b0++;
160
 
      sum -= *window++ * *b0++;
161
 
      sum += *window++ * *b0++;
162
 
      sum -= *window++ * *b0++;
163
 
      sum += *window++ * *b0++;
164
 
      sum -= *window++ * *b0++;
165
 
      sum += *window++ * *b0++;
166
 
      sum -= *window++ * *b0++;
167
 
      sum += *window++ * *b0++;
168
 
      sum -= *window++ * *b0++;
169
 
      sum += *window++ * *b0++;
170
 
      sum -= *window++ * *b0++;
171
 
      sum += *window++ * *b0++;
172
 
      sum -= *window++ * *b0++;
173
 
      sum += *window++ * *b0++;
174
 
      sum -= *window++ * *b0++;
175
 
 
176
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
177
 
#if 0
178
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
179
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
180
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
181
 
#endif
182
 
    }
183
 
 
184
 
    {
185
 
      real sum;
186
 
      sum  = window[0x0] * b0[0x0];
187
 
      sum += window[0x2] * b0[0x2];
188
 
      sum += window[0x4] * b0[0x4];
189
 
      sum += window[0x6] * b0[0x6];
190
 
      sum += window[0x8] * b0[0x8];
191
 
      sum += window[0xA] * b0[0xA];
192
 
      sum += window[0xC] * b0[0xC];
193
 
      sum += window[0xE] * b0[0xE];
194
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
195
 
#if 0
196
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
197
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
198
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
199
 
#endif
200
 
      b0-=0x40,window-=0x80;
201
 
    }
202
 
    window += bo1<<1;
203
 
 
204
 
    for (j=3;j;j--,b0-=0x50,window-=0x70)
205
 
    {
206
 
      real sum;
207
 
      sum = -*(--window) * *b0++;
208
 
      sum -= *(--window) * *b0++;
209
 
      sum -= *(--window) * *b0++;
210
 
      sum -= *(--window) * *b0++;
211
 
      sum -= *(--window) * *b0++;
212
 
      sum -= *(--window) * *b0++;
213
 
      sum -= *(--window) * *b0++;
214
 
      sum -= *(--window) * *b0++;
215
 
      sum -= *(--window) * *b0++;
216
 
      sum -= *(--window) * *b0++;
217
 
      sum -= *(--window) * *b0++;
218
 
      sum -= *(--window) * *b0++;
219
 
      sum -= *(--window) * *b0++;
220
 
      sum -= *(--window) * *b0++;
221
 
      sum -= *(--window) * *b0++;
222
 
      sum -= *(--window) * *b0++;
223
 
 
224
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
225
 
#if 0
226
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
227
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
228
 
      WRITE_SAMPLE(samples,sum,clip); samples += step;
229
 
#endif
230
 
    }
231
 
  }
232
 
  
233
 
  *pnt += 32;
234
 
 
235
 
  return clip;
236
 
}
237
 
 
238