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

« back to all changes in this revision

Viewing changes to mpg123_artsplugin/mpg123/decode_2to1.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 by Michael Hipp, All rights reserved. See also 'README'
 
5
 * version for slower machines .. decodes only every second sample
 
6
 * sounds like 24000,22050 or 16000 kHz .. (depending on original sample freq.)
 
7
 *
 
8
 */
 
9
 
 
10
#include <stdlib.h>
 
11
#include <math.h>
 
12
#include <string.h>
 
13
 
 
14
#include "mpg123.h"
 
15
 
 
16
#define WRITE_SAMPLE(samples,sum,clip) \
 
17
  if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
 
18
  else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
 
19
  else { *(samples) = sum; }
 
20
 
 
21
int synth_2to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
 
22
{
 
23
  short samples_tmp[32];
 
24
  short *tmp1 = samples_tmp + channel;
 
25
  int i,ret;
 
26
  int pnt1 = 0;
 
27
 
 
28
  ret = synth_2to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1);
 
29
  samples += channel + *pnt;
 
30
 
 
31
  for(i=0;i<16;i++) {
 
32
    *samples = conv16to8[*tmp1>>AUSHIFT];
 
33
    samples += 2;
 
34
    tmp1 += 2;
 
35
  }
 
36
  *pnt += 32;
 
37
 
 
38
  return ret;
 
39
}
 
40
 
 
41
int synth_2to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
42
{
 
43
  short samples_tmp[32];
 
44
  short *tmp1 = samples_tmp;
 
45
  int i,ret;
 
46
  int pnt1 = 0;
 
47
 
 
48
  ret = synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
49
  samples += *pnt;
 
50
 
 
51
  for(i=0;i<16;i++) {
 
52
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
53
    tmp1 += 2;
 
54
  }
 
55
  *pnt += 16;
 
56
 
 
57
  return ret;
 
58
}
 
59
 
 
60
 
 
61
int synth_2to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
62
{
 
63
  short samples_tmp[32];
 
64
  short *tmp1 = samples_tmp;
 
65
  int i,ret;
 
66
  int pnt1 = 0;
 
67
 
 
68
  ret = synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
69
  samples += *pnt;
 
70
 
 
71
  for(i=0;i<16;i++) {
 
72
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
73
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
74
    tmp1 += 2;
 
75
  }
 
76
  *pnt += 32;
 
77
 
 
78
  return ret;
 
79
}
 
80
 
 
81
int synth_2to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
82
{
 
83
  short samples_tmp[32];
 
84
  short *tmp1 = samples_tmp;
 
85
  int i,ret;
 
86
  int pnt1=0;
 
87
 
 
88
  ret = synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
89
  samples += *pnt;
 
90
 
 
91
  for(i=0;i<16;i++) {
 
92
    *( (short *) samples) = *tmp1;
 
93
    samples += 2;
 
94
    tmp1 += 2;
 
95
  }
 
96
  *pnt += 32;
 
97
 
 
98
  return ret;
 
99
}
 
100
 
 
101
int synth_2to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
102
{
 
103
  int i,ret;
 
104
 
 
105
  ret = synth_2to1(bandPtr,0,samples,pnt);
 
106
  samples = samples + *pnt - 64;
 
107
 
 
108
  for(i=0;i<16;i++) {
 
109
    ((short *)samples)[1] = ((short *)samples)[0];
 
110
    samples+=4;
 
111
  }
 
112
  
 
113
  return ret;
 
114
}
 
115
 
 
116
int synth_2to1(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
    register int j;
 
155
    real *window = decwin + 16 - bo1;
 
156
 
 
157
    for (j=8;j;j--,b0+=0x10,window+=0x30)
 
158
    {
 
159
      real sum;
 
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
      sum -= *window++ * *b0++;
 
176
 
 
177
      WRITE_SAMPLE(samples,sum,clip); samples += step;
 
178
#if 0
 
179
      WRITE_SAMPLE(samples,sum,clip); samples += step;
 
180
#endif
 
181
    }
 
182
 
 
183
    {
 
184
      real sum;
 
185
      sum  = window[0x0] * b0[0x0];
 
186
      sum += window[0x2] * b0[0x2];
 
187
      sum += window[0x4] * b0[0x4];
 
188
      sum += window[0x6] * b0[0x6];
 
189
      sum += window[0x8] * b0[0x8];
 
190
      sum += window[0xA] * b0[0xA];
 
191
      sum += window[0xC] * b0[0xC];
 
192
      sum += window[0xE] * b0[0xE];
 
193
      WRITE_SAMPLE(samples,sum,clip); samples += step;
 
194
#if 0
 
195
      WRITE_SAMPLE(samples,sum,clip); samples += step;
 
196
#endif
 
197
      b0-=0x20,window-=0x40;
 
198
    }
 
199
    window += bo1<<1;
 
200
 
 
201
    for (j=7;j;j--,b0-=0x30,window-=0x30)
 
202
    {
 
203
      real sum;
 
204
      sum = -*(--window) * *b0++;
 
205
      sum -= *(--window) * *b0++;
 
206
      sum -= *(--window) * *b0++;
 
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
 
 
221
      WRITE_SAMPLE(samples,sum,clip); samples += step;
 
222
#if 0
 
223
      WRITE_SAMPLE(samples,sum,clip); samples += step;
 
224
#endif
 
225
    }
 
226
  }
 
227
 
 
228
  *pnt += 64;
 
229
 
 
230
  return clip;
 
231
}
 
232
 
 
233