1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
Index: apps/codecs/libwma/wmadec.h
===================================================================
--- apps/codecs/libwma/wmadec.h	(revision 27586)
+++ apps/codecs/libwma/wmadec.h	(working copy)
@@ -166,6 +166,5 @@
 int wma_decode_superframe_init(WMADecodeContext* s,
                                const uint8_t *buf, int buf_size);
 int wma_decode_superframe_frame(WMADecodeContext* s,
-                                int32_t *samples,
                                 const uint8_t *buf, int buf_size);
 #endif
Index: apps/codecs/libwma/wmadeci.c
===================================================================
--- apps/codecs/libwma/wmadeci.c	(revision 27586)
+++ apps/codecs/libwma/wmadeci.c	(working copy)
@@ -768,7 +768,7 @@

 /* return 0 if OK. return 1 if last block of frame. return -1 if
    unrecorrable error. */
-static int wma_decode_block(WMADecodeContext *s, int32_t *scratch_buffer)
+static int wma_decode_block(WMADecodeContext *s)
 {
     int n, v, a, ch, code, bsize;
     int coef_nb_bits, total_gain;
@@ -1236,20 +1236,22 @@
     }

     for(ch = 0; ch < s->nb_channels; ++ch)
-    {
+    { 
+		/* BLOCK_MAX_SIZE is 2048 (samples) and MAX_CHANNELS is 2. */
+    	static uint32_t scratch_buf[BLOCK_MAX_SIZE * MAX_CHANNELS] IBSS_ATTR;
         if (s->channel_coded[ch])
         {
             int n4, index;

             n4 = s->block_len >>1;

-            ff_imdct_calc( (s->frame_len_bits - bsize + 1),
-                          (int32_t*)scratch_buffer,
+            ff_imdct_calc((s->frame_len_bits - bsize + 1),
+                          scratch_buf,
                           (*(s->coefs))[ch]);

             /* add in the frame */
             index = (s->frame_len / 2) + s->block_pos - n4;
-            wma_window(s, scratch_buffer, &((*s->frame_out)[ch][index]));
+            wma_window(s, scratch_buf, &((*s->frame_out)[ch][index]));



@@ -1257,7 +1259,7 @@
                channel if it is not coded */
             if (s->ms_stereo && !s->channel_coded[1])
             {
-                wma_window(s, scratch_buffer, &((*s->frame_out)[1][index]));
+                wma_window(s, scratch_buf, &((*s->frame_out)[1][index]));
             }
         }
     }
@@ -1276,11 +1278,9 @@
 }

 /* decode a frame of frame_len samples */
-static int wma_decode_frame(WMADecodeContext *s, int32_t *samples)
+static int wma_decode_frame(WMADecodeContext *s)
 {
-    int ret, i, n, ch, incr;
-    int32_t *ptr;
-    fixed32 *iptr;
+    int ret;

     /* read each block */
     s->block_num = 0;
@@ -1289,7 +1289,7 @@

     for(;;)
     {
-        ret = wma_decode_block(s, samples);
+        ret = wma_decode_block(s);
         if (ret < 0)
         {

@@ -1301,25 +1301,7 @@
             break;
         }
     }
-
-    /* return frame with full 30-bit precision */
-    n = s->frame_len;
-    incr = s->nb_channels;
-    for(ch = 0; ch < s->nb_channels; ++ch)
-    {
-        ptr = samples + ch;
-        iptr = &((*s->frame_out)[ch][0]);
-
-        for (i=0;i<n;++i)
-        {
-            *ptr = (*iptr++);
-            ptr += incr;
-        }
-
-        memmove(&((*s->frame_out)[ch][0]), &((*s->frame_out)[ch][s->frame_len]),
-            s->frame_len * sizeof(fixed32));
-    }
-
+    
     return 0;
 }

@@ -1364,13 +1346,18 @@
 */

 int wma_decode_superframe_frame(WMADecodeContext* s,
-                                int32_t* samples, /*output*/
                                 const uint8_t *buf,  /*input*/
                                 int buf_size)
 {
-    int pos, len;
+    int pos, len, ch;
     uint8_t *q;
     int done = 0;
+    
+    for(ch = 0; ch < s->nb_channels; ch++)
+		memmove(&((*s->frame_out)[ch][0]), 
+		        &((*s->frame_out)[ch][s->frame_len]),
+				s->frame_len * sizeof(fixed32));
+    
     if ((s->use_bit_reservoir) && (s->current_frame == 0))
     {
         if (s->last_superframe_len > 0)
@@ -1402,7 +1389,7 @@

             /* this frame is stored in the last superframe and in the
                current one */
-            if (wma_decode_frame(s, samples) < 0)
+            if (wma_decode_frame(s) < 0)
             {
                 goto fail;
             }
@@ -1422,7 +1409,7 @@
     /* If we haven't decoded a frame yet, do it now */
     if (!done)
         {
-            if (wma_decode_frame(s, samples) < 0)
+            if (wma_decode_frame(s) < 0)
             {
                 goto fail;
             }
Index: apps/codecs/wma.c
===================================================================
--- apps/codecs/wma.c	(revision 27586)
+++ apps/codecs/wma.c	(working copy)
@@ -25,12 +25,6 @@

 CODEC_HEADER

-/* The output buffer containing the decoded samples (channels 0 and 1)
-   BLOCK_MAX_SIZE is 2048 (samples) and MAX_CHANNELS is 2.
- */
-
-static uint32_t decoded[BLOCK_MAX_SIZE * MAX_CHANNELS] IBSS_ATTR;
-
 /* NOTE: WMADecodeContext is 120152 bytes (on x86) */
 static WMADecodeContext wmadec;

@@ -100,7 +94,7 @@
     resume_offset = 0;
     ci->configure(DSP_SWITCH_FREQUENCY, wfx.rate);
     ci->configure(DSP_SET_STEREO_MODE, wfx.channels == 1 ?
-                  STEREO_MONO : STEREO_INTERLEAVED);
+                  STEREO_MONO : STEREO_NONINTERLEAVED);
     codec_set_replaygain(ci->id3);

     /* The main decoding loop */
@@ -157,7 +151,6 @@
             for (i=0; i < wmadec.nb_frames; i++)
             {
                 wmares = wma_decode_superframe_frame(&wmadec,
-                                                     decoded,
                                                      audiobuf, audiobufsize);

                 ci->yield ();
@@ -173,7 +166,7 @@
                         goto new_packet;
                     }
                 } else if (wmares > 0) {
-                    ci->pcmbuf_insert(decoded, NULL, wmares);
+                    ci->pcmbuf_insert(wmadec.frame_out[0], wmadec.frame_out[1], wmares);
                     elapsedtime += (wmares*10)/(wfx.rate/100);
                     ci->set_elapsed(elapsedtime);
                 }