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

« back to all changes in this revision

Viewing changes to src/decode.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        decode.c: decoding samples...
 
3
 
 
4
        copyright 1995-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
 
5
        see COPYING and AUTHORS files in distribution or http://mpg123.de
 
6
        initially written by Michael Hipp
 
7
*/
 
8
 
 
9
#include <stdlib.h>
 
10
#include <math.h>
 
11
#include <string.h>
 
12
 
 
13
#include "config.h"
 
14
#include "mpg123.h"
 
15
 
 
16
#define WRITE_SAMPLE(samples,sum,clip) \
 
17
  if( (sum) > REAL_PLUS_32767) { *(samples) = 0x7fff; (clip)++; } \
 
18
  else if( (sum) < REAL_MINUS_32768) { *(samples) = -0x8000; (clip)++; } \
 
19
  else { *(samples) = REAL_TO_SHORT(sum); }
 
20
 
 
21
int synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
 
22
{
 
23
  short samples_tmp[64];
 
24
  short *tmp1 = samples_tmp + channel;
 
25
  int i,ret;
 
26
  int pnt1=0;
 
27
 
 
28
  ret = synth_1to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1);
 
29
  samples += channel + *pnt;
 
30
 
 
31
  for(i=0;i<32;i++) {
 
32
    *samples = conv16to8[*tmp1>>AUSHIFT];
 
33
    samples += 2;
 
34
    tmp1 += 2;
 
35
  }
 
36
  *pnt += 64;
 
37
 
 
38
  return ret;
 
39
}
 
40
 
 
41
int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
42
{
 
43
  short samples_tmp[64];
 
44
  short *tmp1 = samples_tmp;
 
45
  int i,ret;
 
46
  int pnt1 = 0;
 
47
 
 
48
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
49
  samples += *pnt;
 
50
 
 
51
  for(i=0;i<32;i++) {
 
52
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
53
    tmp1 += 2;
 
54
  }
 
55
  *pnt += 32;
 
56
  
 
57
  return ret;
 
58
}
 
59
 
 
60
int synth_1to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
61
{
 
62
  short samples_tmp[64];
 
63
  short *tmp1 = samples_tmp;
 
64
  int i,ret;
 
65
  int pnt1 = 0;
 
66
 
 
67
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
68
  samples += *pnt;
 
69
 
 
70
  for(i=0;i<32;i++) {
 
71
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
72
    *samples++ = conv16to8[*tmp1>>AUSHIFT];
 
73
    tmp1 += 2;
 
74
  }
 
75
  *pnt += 64;
 
76
 
 
77
  return ret;
 
78
}
 
79
 
 
80
int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
 
81
{
 
82
  short samples_tmp[64];
 
83
  short *tmp1 = samples_tmp;
 
84
  int i,ret;
 
85
  int pnt1 = 0;
 
86
 
 
87
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
 
88
  samples += *pnt;
 
89
 
 
90
  for(i=0;i<32;i++) {
 
91
    *( (short *)samples) = *tmp1;
 
92
    samples += 2;
 
93
    tmp1 += 2;
 
94
  }
 
95
  *pnt += 64;
 
96
 
 
97
  return ret;
 
98
}
 
99
 
 
100
 
 
101
int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
102
{
 
103
  int i,ret;
 
104
 
 
105
  ret = synth_1to1(bandPtr,0,samples,pnt);
 
106
  samples = samples + *pnt - 128;
 
107
 
 
108
  for(i=0;i<32;i++) {
 
109
    ((short *)samples)[1] = ((short *)samples)[0];
 
110
    samples+=4;
 
111
  }
 
112
 
 
113
  return ret;
 
114
}
 
115
 
 
116
 
 
117
int synth_1to1(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(have_eq_settings)
 
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
  {
 
154
    register int j;
 
155
    real *window = decwin + 16 - bo1;
 
156
 
 
157
    for (j=16;j;j--,window+=0x10,samples+=step)
 
158
    {
 
159
      real sum;
 
160
      sum  = REAL_MUL(*window++, *b0++);
 
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
 
 
177
      WRITE_SAMPLE(samples,sum,clip);
 
178
    }
 
179
 
 
180
    {
 
181
      real sum;
 
182
      sum  = REAL_MUL(window[0x0], b0[0x0]);
 
183
      sum += REAL_MUL(window[0x2], b0[0x2]);
 
184
      sum += REAL_MUL(window[0x4], b0[0x4]);
 
185
      sum += REAL_MUL(window[0x6], b0[0x6]);
 
186
      sum += REAL_MUL(window[0x8], b0[0x8]);
 
187
      sum += REAL_MUL(window[0xA], b0[0xA]);
 
188
      sum += REAL_MUL(window[0xC], b0[0xC]);
 
189
      sum += REAL_MUL(window[0xE], b0[0xE]);
 
190
      WRITE_SAMPLE(samples,sum,clip);
 
191
      b0-=0x10,window-=0x20,samples+=step;
 
192
    }
 
193
    window += bo1<<1;
 
194
 
 
195
    for (j=15;j;j--,b0-=0x20,window-=0x10,samples+=step)
 
196
    {
 
197
      real sum;
 
198
      sum = -REAL_MUL(*(--window), *b0++);
 
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
 
 
215
      WRITE_SAMPLE(samples,sum,clip);
 
216
    }
 
217
  }
 
218
 
 
219
  *pnt += 128;
 
220
 
 
221
  return clip;
 
222
}