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

« back to all changes in this revision

Viewing changes to mpg123_artsplugin/mpg123/layer1.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 audio decoder 
 
3
 * --------------------------
 
4
 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
 
5
 * near unoptimzed ...
 
6
 *
 
7
 * may have a few bugs after last optimization ... 
 
8
 *
 
9
 */
 
10
 
 
11
#include "mpg123.h"
 
12
 
 
13
#include "getbits.h"
 
14
 
 
15
void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
 
16
{
 
17
  unsigned int *ba=balloc;
 
18
  unsigned int *sca = (unsigned int *) scale_index;
 
19
 
 
20
  if(fr->stereo) {
 
21
    int i;
 
22
    int jsbound = fr->jsbound;
 
23
    for (i=0;i<jsbound;i++) { 
 
24
      *ba++ = getbits(&bsi,4);
 
25
      *ba++ = getbits(&bsi,4);
 
26
    }
 
27
    for (i=jsbound;i<SBLIMIT;i++)
 
28
      *ba++ = getbits(&bsi,4);
 
29
 
 
30
    ba = balloc;
 
31
 
 
32
    for (i=0;i<jsbound;i++) {
 
33
      if ((*ba++))
 
34
        *sca++ = getbits(&bsi,6);
 
35
      if ((*ba++))
 
36
        *sca++ = getbits(&bsi,6);
 
37
    }
 
38
    for (i=jsbound;i<SBLIMIT;i++)
 
39
      if ((*ba++)) {
 
40
        *sca++ =  getbits(&bsi,6);
 
41
        *sca++ =  getbits(&bsi,6);
 
42
      }
 
43
  }
 
44
  else {
 
45
    int i;
 
46
    for (i=0;i<SBLIMIT;i++)
 
47
      *ba++ = getbits(&bsi,4);
 
48
    ba = balloc;
 
49
    for (i=0;i<SBLIMIT;i++)
 
50
      if ((*ba++))
 
51
        *sca++ = getbits(&bsi,6);
 
52
  }
 
53
}
 
54
 
 
55
void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
 
56
        unsigned int scale_index[2][SBLIMIT],struct frame *fr)
 
57
{
 
58
  int i,n;
 
59
  int smpb[2*SBLIMIT]; /* values: 0-65535 */
 
60
  int *sample;
 
61
  register unsigned int *ba;
 
62
  register unsigned int *sca = (unsigned int *) scale_index;
 
63
 
 
64
  if(fr->stereo) {
 
65
    int jsbound = fr->jsbound;
 
66
    register real *f0 = fraction[0];
 
67
    register real *f1 = fraction[1];
 
68
    ba = balloc;
 
69
    for (sample=smpb,i=0;i<jsbound;i++)  {
 
70
      if ((n = *ba++))
 
71
        *sample++ = getbits(&bsi,n+1);
 
72
      if ((n = *ba++))
 
73
        *sample++ = getbits(&bsi,n+1);
 
74
    }
 
75
    for (i=jsbound;i<SBLIMIT;i++) 
 
76
      if ((n = *ba++))
 
77
        *sample++ = getbits(&bsi,n+1);
 
78
 
 
79
    ba = balloc;
 
80
    for (sample=smpb,i=0;i<jsbound;i++) {
 
81
      if((n=*ba++))
 
82
        *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
 
83
      else
 
84
        *f0++ = 0.0;
 
85
      if((n=*ba++))
 
86
        *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
 
87
      else
 
88
        *f1++ = 0.0;
 
89
    }
 
90
    for (i=jsbound;i<SBLIMIT;i++) {
 
91
      if ((n=*ba++)) {
 
92
        real samp = ( ((-1)<<n) + (*sample++) + 1);
 
93
        *f0++ = samp * muls[n+1][*sca++];
 
94
        *f1++ = samp * muls[n+1][*sca++];
 
95
      }
 
96
      else
 
97
        *f0++ = *f1++ = 0.0;
 
98
    }
 
99
    for(i=fr->down_sample_sblimit;i<32;i++)
 
100
      fraction[0][i] = fraction[1][i] = 0.0;
 
101
  }
 
102
  else {
 
103
    register real *f0 = fraction[0];
 
104
    ba = balloc;
 
105
    for (sample=smpb,i=0;i<SBLIMIT;i++)
 
106
      if ((n = *ba++))
 
107
        *sample++ = getbits(&bsi,n+1);
 
108
    ba = balloc;
 
109
    for (sample=smpb,i=0;i<SBLIMIT;i++) {
 
110
      if((n=*ba++))
 
111
        *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
 
112
      else
 
113
        *f0++ = 0.0;
 
114
    }
 
115
    for(i=fr->down_sample_sblimit;i<32;i++)
 
116
      fraction[0][i] = 0.0;
 
117
  }
 
118
}
 
119
 
 
120
int do_layer1(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_struct *ai)
 
121
{
 
122
  int clip=0;
 
123
  int i,stereo = fr->stereo;
 
124
  unsigned int balloc[2*SBLIMIT];
 
125
  unsigned int scale_index[2][SBLIMIT];
 
126
  real fraction[2][SBLIMIT];
 
127
  int single = fr->single;
 
128
 
 
129
  fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
 
130
 
 
131
  if(stereo == 1 || single == 3)
 
132
    single = 0;
 
133
 
 
134
  I_step_one(balloc,scale_index,fr);
 
135
 
 
136
  for (i=0;i<SCALE_BLOCK;i++)
 
137
  {
 
138
    I_step_two(fraction,balloc,scale_index,fr);
 
139
 
 
140
    if(single >= 0)
 
141
    {
 
142
      clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
 
143
    }
 
144
    else {
 
145
        int p1 = pcm_point;
 
146
        clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
 
147
        clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
 
148
    }
 
149
 
 
150
    if(pcm_point >= audiobufsize)
 
151
      audio_flush(outmode,ai);
 
152
  }
 
153
 
 
154
  return clip;
 
155
}
 
156
 
 
157