ReactOS  0.4.15-dev-439-g292f67a
layer1.c File Reference
#include "mpg123lib_intern.h"
#include "getbits.h"
#include "debug.h"
Include dependency graph for layer1.c:

Go to the source code of this file.

Macros

#define NEED_BITS(fr, num)
 
#define MINUS_SHIFT(n)   ( (int)(((unsigned int)-1)<<(n)) )
 

Functions

static int check_balloc (mpg123_handle *fr, unsigned int *balloc, unsigned int *end)
 
static int I_step_one (unsigned int balloc[], unsigned int scale_index[2][SBLIMIT], mpg123_handle *fr)
 
static int I_step_two (real fraction[2][SBLIMIT], unsigned int balloc[2 *SBLIMIT], unsigned int scale_index[2][SBLIMIT], mpg123_handle *fr)
 
int do_layer1 (mpg123_handle *fr)
 

Macro Definition Documentation

◆ MINUS_SHIFT

#define MINUS_SHIFT (   n)    ( (int)(((unsigned int)-1)<<(n)) )

Definition at line 116 of file layer1.c.

◆ NEED_BITS

#define NEED_BITS (   fr,
  num 
)
Value:
if((fr)->bits_avail < num) \
{ \
if(NOQUIET) \
error2("%u bits needed, %li available", num, (fr)->bits_avail); \
return -1; \
} \
GLuint GLuint num
Definition: glext.h:9618
#define NOQUIET

Definition at line 37 of file layer1.c.

Function Documentation

◆ check_balloc()

static int check_balloc ( mpg123_handle fr,
unsigned int balloc,
unsigned int end 
)
static

Definition at line 24 of file layer1.c.

25 {
26  unsigned int *ba;
27  for(ba=balloc; ba != end; ++ba)
28  if(*ba == 15)
29  {
30  if(NOQUIET) error("Illegal bit allocation value.");
31  return -1;
32  }
33 
34  return 0;
35 }
#define error(str)
Definition: mkdosfs.c:1605
GLuint GLuint end
Definition: gl.h:1545
#define NOQUIET

Referenced by I_step_one().

◆ do_layer1()

int do_layer1 ( mpg123_handle fr)

Definition at line 211 of file layer1.c.

212 {
213  int clip=0;
214  int i,stereo = fr->stereo;
215  unsigned int balloc[2*SBLIMIT];
216  unsigned int scale_index[2][SBLIMIT];
217  real (*fraction)[SBLIMIT] = fr->layer1.fraction; /* fraction[2][SBLIMIT] */
218  int single = fr->single;
219 
220  fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
221 
222  if(stereo == 1 || single == SINGLE_MIX) /* I don't see mixing handled here */
224 
225  if(I_step_one(balloc,scale_index,fr))
226  {
227  if(NOQUIET)
228  error("Aborting layer I decoding after step one.");
229  return clip;
230  }
231 
232  for(i=0;i<SCALE_BLOCK;i++)
233  {
234  if(I_step_two(fraction,balloc,scale_index,fr))
235  {
236  if(NOQUIET)
237  error("Aborting layer I decoding after step two.");
238  return clip;
239  }
240 
241  if(single != SINGLE_STEREO)
242  clip += (fr->synth_mono)(fraction[single], fr);
243  else
244  clip += (fr->synth_stereo)(fraction[0], fraction[1], fr);
245  }
246 
247  return clip;
248 }
static int I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT], mpg123_handle *fr)
Definition: layer1.c:45
#define error(str)
Definition: mkdosfs.c:1605
#define SCALE_BLOCK
#define SINGLE_STEREO
Definition: frame.h:188
#define SBLIMIT
_Tp _STLP_CALL real(const complex< _Tp > &__z)
Definition: _complex.h:727
float single
Definition: msinkaut.idl:29
static int I_step_two(real fraction[2][SBLIMIT], unsigned int balloc[2 *SBLIMIT], unsigned int scale_index[2][SBLIMIT], mpg123_handle *fr)
Definition: layer1.c:118
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SINGLE_LEFT
Definition: frame.h:189
func_synth_mono synth_mono
Definition: frame.h:182
struct mpg123_handle_struct::@3360 layer1
#define MPG_MD_JOINT_STEREO
#define NOQUIET
func_synth_stereo synth_stereo
Definition: frame.h:181
#define SINGLE_MIX
Definition: frame.h:191

◆ I_step_one()

static int I_step_one ( unsigned int  balloc[],
unsigned int  scale_index[2][SBLIMIT],
mpg123_handle fr 
)
static

Definition at line 45 of file layer1.c.

46 {
47  unsigned int *ba=balloc;
48  unsigned int *sca = (unsigned int *) scale_index;
49 
50  if(fr->stereo == 2)
51  {
52  int i;
53  int jsbound = fr->jsbound;
54  unsigned int needbits = jsbound*2*4 + (SBLIMIT-jsbound)*4;
55 
56  NEED_BITS(fr, needbits);
57  needbits = 0;
58  for(i=0;i<jsbound;i++)
59  {
60  ba[0] = getbits_fast(fr, 4);
61  ba[1] = getbits_fast(fr, 4);
62  needbits += ((ba[0]?1:0)+(ba[1]?1:0))*6;
63  ba+=2;
64  }
65  for(i=jsbound;i<SBLIMIT;i++)
66  {
67  *ba = getbits_fast(fr, 4);
68  needbits += (*ba?1:0)*12;
69  ++ba;
70  }
71 
72  if(check_balloc(fr, balloc, ba)) return -1;
73 
74  ba = balloc;
75  NEED_BITS(fr, needbits)
76  for(i=0;i<jsbound;i++)
77  {
78  if ((*ba++))
79  *sca++ = getbits_fast(fr, 6);
80  if ((*ba++))
81  *sca++ = getbits_fast(fr, 6);
82  }
83  for (i=jsbound;i<SBLIMIT;i++) if((*ba++))
84  {
85  *sca++ = getbits_fast(fr, 6);
86  *sca++ = getbits_fast(fr, 6);
87  }
88  }
89  else
90  {
91  int i;
92  unsigned int needbits = SBLIMIT*4;
93 
94  NEED_BITS(fr, needbits)
95  needbits = 0;
96  for(i=0;i<SBLIMIT;i++)
97  {
98  *ba = getbits_fast(fr, 4);
99  needbits += (*ba?1:0)*6;
100  ++ba;
101  }
102 
103  if(check_balloc(fr, balloc, ba)) return -1;
104 
105  ba = balloc;
106  NEED_BITS(fr, needbits)
107  for (i=0;i<SBLIMIT;i++)
108  if ((*ba++))
109  *sca++ = getbits_fast(fr, 6);
110  }
111 
112  return 0;
113 }
#define SBLIMIT
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define NEED_BITS(fr, num)
Definition: layer1.c:37
#define getbits_fast(fr, nob)
Definition: getbits.h:89
static int check_balloc(mpg123_handle *fr, unsigned int *balloc, unsigned int *end)
Definition: layer1.c:24

Referenced by do_layer1().

◆ I_step_two()

static int I_step_two ( real  fraction[2][SBLIMIT],
unsigned int  balloc[2 *SBLIMIT],
unsigned int  scale_index[2][SBLIMIT],
mpg123_handle fr 
)
static

Definition at line 118 of file layer1.c.

119 {
120  int i,n;
121  int smpb[2*SBLIMIT]; /* values: 0-65535 */
122  int *sample;
123  register unsigned int *ba;
124  register unsigned int *sca = (unsigned int *) scale_index;
125 
126  if(fr->stereo == 2)
127  {
128  unsigned int needbits = 0;
129  int jsbound = fr->jsbound;
130  register real *f0 = fraction[0];
131  register real *f1 = fraction[1];
132 
133  ba = balloc;
134  for(sample=smpb,i=0;i<jsbound;i++)
135  {
136  if((n=*ba++))
137  needbits += n+1;
138  if((n=*ba++))
139  needbits += n+1;
140  }
141  for(i=jsbound;i<SBLIMIT;i++)
142  if((n = *ba++))
143  needbits += n+1;
144  NEED_BITS(fr, needbits)
145 
146  ba = balloc;
147  for(sample=smpb,i=0;i<jsbound;i++)
148  {
149  if((n = *ba++)) *sample++ = getbits(fr, n+1);
150 
151  if((n = *ba++)) *sample++ = getbits(fr, n+1);
152  }
153  for(i=jsbound;i<SBLIMIT;i++)
154  if((n = *ba++))
155  *sample++ = getbits(fr, n+1);
156 
157  ba = balloc;
158  for(sample=smpb,i=0;i<jsbound;i++)
159  {
160  if((n=*ba++))
161  *f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1), fr->muls[n+1][*sca++]);
162  else *f0++ = DOUBLE_TO_REAL(0.0);
163 
164  if((n=*ba++))
165  *f1++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1), fr->muls[n+1][*sca++]);
166  else *f1++ = DOUBLE_TO_REAL(0.0);
167  }
168  for(i=jsbound;i<SBLIMIT;i++)
169  {
170  if((n=*ba++))
171  {
172  real samp = DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1);
173  *f0++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]);
174  *f1++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]);
175  }
176  else *f0++ = *f1++ = DOUBLE_TO_REAL(0.0);
177  }
178  for(i=fr->down_sample_sblimit;i<32;i++)
179  fraction[0][i] = fraction[1][i] = 0.0;
180  }
181  else
182  {
183  unsigned int needbits = 0;
184  register real *f0 = fraction[0];
185 
186  ba = balloc;
187  for(sample=smpb,i=0;i<SBLIMIT;i++)
188  if((n = *ba++))
189  needbits += n+1;
190  NEED_BITS(fr, needbits);
191 
192  ba = balloc;
193  for(sample=smpb,i=0;i<SBLIMIT;i++)
194  if ((n = *ba++))
195  *sample++ = getbits(fr, n+1);
196 
197 
198  ba = balloc;
199  for(sample=smpb,i=0;i<SBLIMIT;i++)
200  {
201  if((n=*ba++))
202  *f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15(MINUS_SHIFT(n) + (*sample++) + 1), fr->muls[n+1][*sca++]);
203  else *f0++ = DOUBLE_TO_REAL(0.0);
204  }
205  for(i=fr->down_sample_sblimit;i<32;i++)
206  fraction[0][i] = DOUBLE_TO_REAL(0.0);
207  }
208  return 0;
209 }
#define MINUS_SHIFT(n)
Definition: layer1.c:116
#define DOUBLE_TO_REAL(x)
#define SBLIMIT
GLdouble n
Definition: glext.h:7729
_Tp _STLP_CALL real(const complex< _Tp > &__z)
Definition: _complex.h:727
int down_sample_sblimit
Definition: frame.h:194
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
real muls[27][64]
Definition: frame.h:145
static unsigned int getbits(mpg123_handle *fr, int number_of_bits)
Definition: getbits.h:32
#define NEED_BITS(fr, num)
Definition: layer1.c:37
#define REAL_MUL_SCALE_LAYER12(x, y)
#define f1(x, y, z)
Definition: sha1.c:30
#define DOUBLE_TO_REAL_15(x)

Referenced by do_layer1().