Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 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) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
17
  else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
18
  else { *(samples) = sum; }
19
 
20
int synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples)
21
{
22
  short samples_tmp[64];
23
  short *tmp1 = samples_tmp + channel;
24
  int i,ret;
25
 
26
  samples += channel;
27
  ret = synth_1to1(bandPtr,channel,(unsigned char *) samples_tmp);
28
 
29
  for(i=0;i<32;i++) {
30
    *samples = conv16to8[*tmp1>>4];
31
    samples += 2;
32
    tmp1 += 2;
33
  }
34
 
35
  return ret;
36
}
37
 
38
int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples)
39
{
40
  short samples_tmp[64];
41
  short *tmp1 = samples_tmp;
42
  int i,ret;
43
 
44
  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp);
45
 
46
  for(i=0;i<32;i++) {
47
    *samples++ = conv16to8[*tmp1>>4];
48
    *samples++ = conv16to8[*tmp1>>4];
49
    tmp1 += 2;
50
  }
51
 
52
  return ret;
53
}
54
 
55
int synth_1to1_mono(real *bandPtr,unsigned char *samples)
56
{
57
  int i,ret = synth_1to1(bandPtr,0,samples);
58
  for(i=0;i<32;i++) {
59
    ((short *)samples)[1] = ((short *)samples)[0];
60
    samples+=4;
61
  }
62
  return ret;
63
}
64
 
65
 
66
int synth_1to1(real *bandPtr,int channel,unsigned char *out)
67
{
68
  static real buffs[2][2][0x110];
69
  static int bo = 1;
70
  short *samples = (short *) out;
71
 
72
  real *b0,(*buf)[0x110];
73
  int clip = 0;
74
  int bo1;
75
  static const int step = 2;
76
 
77
  if(!channel) {
78
    bo--;
79
    bo &= 0xf;
80
    buf = buffs[0];
81
  }
82
  else {
83
    samples++;
84
    buf = buffs[1];
85
  }
86
 
87
  if(bo & 0x1) {
88
    b0 = buf[0];
89
    bo1 = bo;
90
    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
91
  }
92
  else {
93
    b0 = buf[1];
94
    bo1 = bo+1;
95
    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
96
  }
97
 
98
 
99
  {
100
    register int j;
101
    real *window = decwin + 16 - bo1;
102
 
103
    for (j=16;j;j--,window+=0x10,samples+=step)
104
    {
105
      real sum;
106
      sum  = *window++ * *b0++;
107
      sum -= *window++ * *b0++;
108
      sum += *window++ * *b0++;
109
      sum -= *window++ * *b0++;
110
      sum += *window++ * *b0++;
111
      sum -= *window++ * *b0++;
112
      sum += *window++ * *b0++;
113
      sum -= *window++ * *b0++;
114
      sum += *window++ * *b0++;
115
      sum -= *window++ * *b0++;
116
      sum += *window++ * *b0++;
117
      sum -= *window++ * *b0++;
118
      sum += *window++ * *b0++;
119
      sum -= *window++ * *b0++;
120
      sum += *window++ * *b0++;
121
      sum -= *window++ * *b0++;
122
 
123
      WRITE_SAMPLE(samples,sum,clip);
124
    }
125
 
126
    {
127
      real sum;
128
      sum  = window[0x0] * b0[0x0];
129
      sum += window[0x2] * b0[0x2];
130
      sum += window[0x4] * b0[0x4];
131
      sum += window[0x6] * b0[0x6];
132
      sum += window[0x8] * b0[0x8];
133
      sum += window[0xA] * b0[0xA];
134
      sum += window[0xC] * b0[0xC];
135
      sum += window[0xE] * b0[0xE];
136
      WRITE_SAMPLE(samples,sum,clip);
137
      b0-=0x10,window-=0x20,samples+=step;
138
    }
139
    window += bo1<<1;
140
 
141
    for (j=15;j;j--,b0-=0x20,window-=0x10,samples+=step)
142
    {
143
      real sum;
144
      sum = -*(--window) * *b0++;
145
      sum -= *(--window) * *b0++;
146
      sum -= *(--window) * *b0++;
147
      sum -= *(--window) * *b0++;
148
      sum -= *(--window) * *b0++;
149
      sum -= *(--window) * *b0++;
150
      sum -= *(--window) * *b0++;
151
      sum -= *(--window) * *b0++;
152
      sum -= *(--window) * *b0++;
153
      sum -= *(--window) * *b0++;
154
      sum -= *(--window) * *b0++;
155
      sum -= *(--window) * *b0++;
156
      sum -= *(--window) * *b0++;
157
      sum -= *(--window) * *b0++;
158
      sum -= *(--window) * *b0++;
159
      sum -= *(--window) * *b0++;
160
 
161
      WRITE_SAMPLE(samples,sum,clip);
162
    }
163
  }
164
 
165
  return clip;
166
}
167
 
168