annotate mp3lib/layer1.c @ 33959:ef089a8affc6

Perform a wsHandleEvents() when playback ends. This fixes a redraw problem with the subwindow (video window) image that could appear twice (on a wrong position).
author ib
date Thu, 01 Sep 2011 19:14:11 +0000
parents 0ad2da052b2e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23464
diff changeset
1 /*
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23464
diff changeset
2 * Mpeg Layer-1 audio decoder
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
3 * --------------------------
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
4 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
5 * near unoptimzed ...
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
6 *
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23464
diff changeset
7 * may have a few bugs after last optimization ...
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
8 *
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
9 */
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
10
19265
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
11 /*
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
12 * Modified for use with MPlayer, for details see the changelog at
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
13 * http://svn.mplayerhq.hu/mplayer/trunk/
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
14 * $Id$
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
15 *
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
16 * The above-mentioned README file has the following to say about licensing:
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
17 *
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
18 * COPYING: you may use this source under LGPL terms!
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
19 */
f8d91df64bf1 Clarify licensing situation.
diego
parents: 18783
diff changeset
20
30167
347d152a5cfa Refactor real --> float #define to a typedef in a common header.
diego
parents: 29263
diff changeset
21 #include "mpg123.h"
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
22
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
23 static void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
24 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
25 unsigned int *ba=balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
26 unsigned int *sca = (unsigned int *) scale_index;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
27
15103
90670e48d270 Use proper parameter range in stereo test
henry
parents: 10468
diff changeset
28 if(fr->stereo == 2) {
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
29 int i;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
30 int jsbound = fr->jsbound;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23464
diff changeset
31 for (i=0;i<jsbound;i++) {
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
32 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
33 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
34 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
35 for (i=jsbound;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
36 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
37
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
38 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
39
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
40 for (i=0;i<jsbound;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
41 if ((*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
42 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
43 if ((*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
44 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
45 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
46 for (i=jsbound;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
47 if ((*ba++)) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
48 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
49 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
50 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
51 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
52 else {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
53 int i;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
54 for (i=0;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
55 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
56 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
57 for (i=0;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
58 if ((*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
59 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
60 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
61 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
62
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
63 static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
30990
0ad2da052b2e the great MPlayer tab removal: part I
diego
parents: 30633
diff changeset
64 unsigned int scale_index[2][SBLIMIT],struct frame *fr)
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
65 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
66 int i,n;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
67 int smpb[2*SBLIMIT]; /* values: 0-65535 */
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
68 int *sample;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
69 register unsigned int *ba;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
70 register unsigned int *sca = (unsigned int *) scale_index;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
71
15103
90670e48d270 Use proper parameter range in stereo test
henry
parents: 10468
diff changeset
72 if(fr->stereo == 2) {
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
73 int jsbound = fr->jsbound;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
74 register real *f0 = fraction[0];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
75 register real *f1 = fraction[1];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
76 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
77 for (sample=smpb,i=0;i<jsbound;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
78 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
79 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
80 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
81 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
82 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23464
diff changeset
83 for (i=jsbound;i<SBLIMIT;i++)
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
84 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
85 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
86
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
87 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
88 for (sample=smpb,i=0;i<jsbound;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
89 if((n=*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
90 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
91 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
92 *f0++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
93 if((n=*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
94 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
95 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
96 *f1++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
97 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
98 for (i=jsbound;i<SBLIMIT;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
99 if ((n=*ba++)) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
100 real samp = ( ((-1)<<n) + (*sample++) + 1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
101 *f0++ = samp * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
102 *f1++ = samp * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
103 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
104 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
105 *f0++ = *f1++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
106 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
107 for(i=fr->down_sample_sblimit;i<32;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
108 fraction[0][i] = fraction[1][i] = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
109 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
110 else {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
111 register real *f0 = fraction[0];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
112 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
113 for (sample=smpb,i=0;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
114 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
115 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
116 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
117 for (sample=smpb,i=0;i<SBLIMIT;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
118 if((n=*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
119 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
120 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
121 *f0++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
122 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
123 for(i=fr->down_sample_sblimit;i<32;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
124 fraction[0][i] = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
125 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
126 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
127
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
128 static int do_layer1(struct frame *fr,int single)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
129 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
130 int clip=0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
131 int i,stereo = fr->stereo;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
132 unsigned int balloc[2*SBLIMIT];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
133 unsigned int scale_index[2][SBLIMIT];
23464
1b1fdac4a68c Align output pointer so that we can use movaps instead of movups in dct64_sse;
zuxy
parents: 19265
diff changeset
134 DECLARE_ALIGNED(16, real, fraction[2][SBLIMIT]);
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
135 // int single = fr->single;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
136
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
137 // printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
138 // wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
139
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23464
diff changeset
140 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
141 (fr->mode_ext<<2)+4 : 32;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
142
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
143 if(stereo == 1 || single == 3)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
144 single = 0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
145
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
146 I_step_one(balloc,scale_index,fr);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
147
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
148 for (i=0;i<SCALE_BLOCK;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
149 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
150 I_step_two(fraction,balloc,scale_index,fr);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
151
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
152 if(single >= 0)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
153 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
154 clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
155 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
156 else {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
157 int p1 = pcm_point;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
158 clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
159 clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
160 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
161
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
162 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
163
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
164 return clip;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
165 }