~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpg123_artsplugin/mpg123/decode.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

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
 *
 
7
 */
 
8
 
 
9
#include <stdlib.h>
 
10
#include <math.h>
 
11
#include <string.h>
 
12
 
 
13
#include "mpg123.h"
 
14
 
 
15
#define WRITE_SAMPLE(samples,sum,clip) \
 
16
  if( (sum) > REAL_PLUS_32767) { *(samples) = 0x7fff; (clip)++; } \
 
17
  else if( (sum) < REAL_MINUS_32768) { *(samples) = -0x8000; (clip)++; } \
 
18
  else { *(samples) = REAL_TO_SHORT(sum); }
 
19
 
 
20
int synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
 
21
{
 
22
  short samples_tmp[64];
 
23
  short *tmp1 = samples_tmp + channel;
 
24
  int i,ret;
 
25
  int pnt1=0;
 
26
 
 
27
  ret = synth_1to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1);
 
28
  samples += channel + *pnt;
 
29
 
 
30
  for(i=0;i<32;i++) {
 
31
    *samples = conv16to8[*tmp1>>AUSHIFT];
 
32
    samples += 2;
 
33
    tmp1 += 2;
 
34
  }
 
35
  *pnt += 64;
 
36
 
 
37
  return ret;
 
38
}
 
39
 
 
40
int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
41
{
 
42
  short samples_tmp[64];
 
43
  short *tmp1 = samples_tmp;
 
44
  int i,ret;
 
45
  int pnt1 = 0;
 
46
 
 
47
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
48
  samples += *pnt;
 
49
 
 
50
  for(i=0;i<32;i++) {
 
51
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
52
    tmp1 += 2;
 
53
  }
 
54
  *pnt += 32;
 
55
  
 
56
  return ret;
 
57
}
 
58
 
 
59
int synth_1to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
60
{
 
61
  short samples_tmp[64];
 
62
  short *tmp1 = samples_tmp;
 
63
  int i,ret;
 
64
  int pnt1 = 0;
 
65
 
 
66
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
67
  samples += *pnt;
 
68
 
 
69
  for(i=0;i<32;i++) {
 
70
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
71
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
72
    tmp1 += 2;
 
73
  }
 
74
  *pnt += 64;
 
75
 
 
76
  return ret;
 
77
}
 
78
 
 
79
int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
80
{
 
81
  short samples_tmp[64];
 
82
  short *tmp1 = samples_tmp;
 
83
  int i,ret;
 
84
  int pnt1 = 0;
 
85
 
 
86
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
87
  samples += *pnt;
 
88
 
 
89
  for(i=0;i<32;i++) {
 
90
    *( (short *)samples) = *tmp1;
 
91
    samples += 2;
 
92
    tmp1 += 2;
 
93
  }
 
94
  *pnt += 64;
 
95
 
 
96
  return ret;
 
97
}
 
98
 
 
99
 
 
100
int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
101
{
 
102
  int i,ret;
 
103
 
 
104
  ret = synth_1to1(bandPtr,0,samples,pnt);
 
105
  samples = samples + *pnt - 128;
 
106
 
 
107
  for(i=0;i<32;i++) {
 
108
    ((short *)samples)[1] = ((short *)samples)[0];
 
109
    samples+=4;
 
110
  }
 
111
 
 
112
  return ret;
 
113
}
 
114
 
 
115
 
 
116
int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
 
117
{
 
118
  static real buffs[2][2][0x110];
 
119
  static const int step = 2;
 
120
  static int bo = 1;
 
121
  short *samples = (short *) (out+*pnt);
 
122
 
 
123
  real *b0,(*buf)[0x110];
 
124
  int clip = 0; 
 
125
  int bo1;
 
126
 
 
127
#ifndef NO_EQUALIZER
 
128
  if(param.enable_equalizer)
 
129
        do_equalizer(bandPtr,channel);
 
130
#endif
 
131
 
 
132
  if(!channel) {
 
133
    bo--;
 
134
    bo &= 0xf;
 
135
    buf = buffs[0];
 
136
  }
 
137
  else {
 
138
    samples++;
 
139
    buf = buffs[1];
 
140
  }
 
141
 
 
142
  if(bo & 0x1) {
 
143
    b0 = buf[0];
 
144
    bo1 = bo;
 
145
    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
 
146
  }
 
147
  else {
 
148
    b0 = buf[1];
 
149
    bo1 = bo+1;
 
150
    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
 
151
  }
 
152
 
 
153
 
 
154
  {
 
155
    register int j;
 
156
    real *window = decwin + 16 - bo1;
 
157
 
 
158
    for (j=16;j;j--,window+=0x10,samples+=step)
 
159
    {
 
160
      real sum;
 
161
      sum  = REAL_MUL(*window++, *b0++);
 
162
      sum -= REAL_MUL(*window++, *b0++);
 
163
      sum += REAL_MUL(*window++, *b0++);
 
164
      sum -= REAL_MUL(*window++, *b0++);
 
165
      sum += REAL_MUL(*window++, *b0++);
 
166
      sum -= REAL_MUL(*window++, *b0++);
 
167
      sum += REAL_MUL(*window++, *b0++);
 
168
      sum -= REAL_MUL(*window++, *b0++);
 
169
      sum += REAL_MUL(*window++, *b0++);
 
170
      sum -= REAL_MUL(*window++, *b0++);
 
171
      sum += REAL_MUL(*window++, *b0++);
 
172
      sum -= REAL_MUL(*window++, *b0++);
 
173
      sum += REAL_MUL(*window++, *b0++);
 
174
      sum -= REAL_MUL(*window++, *b0++);
 
175
      sum += REAL_MUL(*window++, *b0++);
 
176
      sum -= REAL_MUL(*window++, *b0++);
 
177
 
 
178
      WRITE_SAMPLE(samples,sum,clip);
 
179
    }
 
180
 
 
181
    {
 
182
      real sum;
 
183
      sum  = REAL_MUL(window[0x0], b0[0x0]);
 
184
      sum += REAL_MUL(window[0x2], b0[0x2]);
 
185
      sum += REAL_MUL(window[0x4], b0[0x4]);
 
186
      sum += REAL_MUL(window[0x6], b0[0x6]);
 
187
      sum += REAL_MUL(window[0x8], b0[0x8]);
 
188
      sum += REAL_MUL(window[0xA], b0[0xA]);
 
189
      sum += REAL_MUL(window[0xC], b0[0xC]);
 
190
      sum += REAL_MUL(window[0xE], b0[0xE]);
 
191
      WRITE_SAMPLE(samples,sum,clip);
 
192
      b0-=0x10,window-=0x20,samples+=step;
 
193
    }
 
194
    window += bo1<<1;
 
195
 
 
196
    for (j=15;j;j--,b0-=0x20,window-=0x10,samples+=step)
 
197
    {
 
198
      real sum;
 
199
      sum = -REAL_MUL(*(--window), *b0++);
 
200
      sum -= REAL_MUL(*(--window), *b0++);
 
201
      sum -= REAL_MUL(*(--window), *b0++);
 
202
      sum -= REAL_MUL(*(--window), *b0++);
 
203
      sum -= REAL_MUL(*(--window), *b0++);
 
204
      sum -= REAL_MUL(*(--window), *b0++);
 
205
      sum -= REAL_MUL(*(--window), *b0++);
 
206
      sum -= REAL_MUL(*(--window), *b0++);
 
207
      sum -= REAL_MUL(*(--window), *b0++);
 
208
      sum -= REAL_MUL(*(--window), *b0++);
 
209
      sum -= REAL_MUL(*(--window), *b0++);
 
210
      sum -= REAL_MUL(*(--window), *b0++);
 
211
      sum -= REAL_MUL(*(--window), *b0++);
 
212
      sum -= REAL_MUL(*(--window), *b0++);
 
213
      sum -= REAL_MUL(*(--window), *b0++);
 
214
      sum -= REAL_MUL(*(--window), *b0++);
 
215
 
 
216
      WRITE_SAMPLE(samples,sum,clip);
 
217
    }
 
218
  }
 
219
 
 
220
  *pnt += 128;
 
221
 
 
222
  return clip;
 
223
}