10 {
11
12
13
14
15
16
17
18 short* sPtr = source;
19 int numBlocks = (samples + 13) / 14;
20
21 int nBits = 3;
22
23
24 double** bufferArray = stackalloc double*[8];
25 for (int z = 0; z < 8; z++)
26 {
27 bufferArray[z] = (double*) Marshal.AllocHGlobal(3 * 8);
28 }
29
30 double* buffer2 = stackalloc double[3];
31 short* sampleBuffer = (short*) Marshal.AllocHGlobal(0x7000);
32 short* chunkBuffer = stackalloc short[28];
33
34 for (int z = 0; z < 28; z++)
35 {
36 chunkBuffer[z] = 0;
37 }
38
39 double* sChunkBuffer = stackalloc double[3];
40 double* omgBuffer = stackalloc double[3];
41
42 double** pChannels = stackalloc double*[3];
43 for (int z = 0; z <= 2; z++)
44 {
45 pChannels[z] = (double*) Marshal.AllocHGlobal(3 * 8);
46 }
47
48 int* anotherBuffer = stackalloc int[3];
49
50 double** multiBuffer = (double**) Marshal.AllocHGlobal(numBlocks * 4 * 2);
51 int unused = 0;
52 int multiIndex = 0;
53
54 int blockSamples;
55 int temp;
56
57 float initValue = 0;
58 int lastUpdate = 0;
59 if (progress != null)
60 {
62 }
63
64 for (int x = samples; x > 0;)
65 {
66 if (x > 0x3800)
67 {
68 blockSamples = 0x3800;
69 x -= 0x3800;
70 }
71 else
72 {
73 blockSamples = x;
74 for (int z = 0; z < 14 && z + blockSamples < 0x3800; z++)
75 {
76 sampleBuffer[blockSamples + z] = 0;
77 }
78
79 x = 0;
80 }
81
82 short* tPtr = sampleBuffer;
83 for (int z = 0; z < blockSamples; z++)
84 {
85 *tPtr++ = *sPtr++;
86 }
87
88 for (int i = 0; i < blockSamples;)
89 {
90 for (int z = 0; z < 14; z++)
91 {
92 chunkBuffer[z] = chunkBuffer[z + 14];
93 }
94
95 for (int z = 0; z < 14; z++)
96 {
97 chunkBuffer[z + 14] = sampleBuffer[i++];
98 }
99
100 Something1(&chunkBuffer[14], sChunkBuffer);
101 if (Math.Abs(sChunkBuffer[0]) > 10.0)
102 {
103 Something2(&chunkBuffer[14], pChannels);
104 if (!Something3(pChannels, anotherBuffer, &temp))
105 {
106 Something4(pChannels, anotherBuffer, sChunkBuffer);
107 sChunkBuffer[0] = 1.0;
108 if (Something5(sChunkBuffer, omgBuffer) == 0)
109 {
110 multiBuffer[multiIndex] = (double*) Marshal.AllocHGlobal(3 * 8);
111 multiBuffer[multiIndex][0] = 1.0;
112 for (int z = 1; z <= 2; z++)
113 {
114 if (omgBuffer[z] >= 1.0)
115 {
116 omgBuffer[z] = 0.9999999999;
117 }
118
119 if (omgBuffer[z] <= -1.0)
120 {
121 omgBuffer[z] = -0.9999999999;
122 }
123 }
124
125 Something6(omgBuffer, multiBuffer[multiIndex]);
126 multiIndex++;
127 }
128 }
129 }
130
131 unused++;
132 }
133
134 if (progress != null)
135 {
136 lastUpdate += blockSamples;
137 if (lastUpdate % 0x3800 == 0)
138 {
140 }
141 }
142 }
143
144 progress?.
Update(initValue + samples);
145
146 sChunkBuffer[0] = 1.0;
147 for (int y = 1; y <= 2; y++)
148 {
149 sChunkBuffer[y] = 0.0;
150 }
151
152 for (int z = 0; z < multiIndex; z++)
153 {
154 Something7(multiBuffer[z], bufferArray[0]);
155 for (int y = 1; y <= 2; y++)
156 {
157 sChunkBuffer[y] = sChunkBuffer[y] + bufferArray[0][y];
158 }
159 }
160
161 for (int y = 1; y <= 2; y++)
162 {
163 sChunkBuffer[y] /= multiIndex;
164 }
165
166 double tmp;
167 Something8(sChunkBuffer, omgBuffer, bufferArray[0], &tmp);
168 for (int y = 1; y <= 2; y++)
169 {
170 if (omgBuffer[y] >= 1.0)
171 {
172 omgBuffer[y] = 0.9999999999;
173 }
174
175 if (omgBuffer[y] <= -1.0)
176 {
177 omgBuffer[y] = -0.9999999999;
178 }
179 }
180
181 Something6(omgBuffer, bufferArray[0]);
182
183 for (int w = 0; w < nBits;)
184 {
185
186 for (int z = 0; z <= 2; z++)
187 {
188 buffer2[z] = 0.0;
189 }
190
191 buffer2[1] = -1.0;
192 Something9(bufferArray, buffer2, 1 << w++, 0.01);
193
194 Something10(bufferArray, 1 << w, multiBuffer, multiIndex, 0.0);
195 }
196
197
198 for (int z = 0; z < 8; z++)
199 {
200 for (int y = 0; y < 2; y++)
201 {
202 double d = -bufferArray[z][y + 1] * 2048.0;
203 if (d > 0.0)
204 {
205 dest[(z << 1) + y] = d > 32767.0 ? (short) 32767 : (short) (d + 0.5);
206 }
207 else
208 {
209 dest[(z << 1) + y] = d < -32768.0 ? (short) -32768 : (short) (d - 0.5);
210 }
211 }
212 }
213
214
215 for (int i = 0; i < multiIndex; i++)
216 {
217 Marshal.FreeHGlobal((IntPtr) multiBuffer[i]);
218 }
219
220 Marshal.FreeHGlobal((IntPtr) multiBuffer);
221
222 for (int i = 0; i <= 2; i++)
223 {
224 Marshal.FreeHGlobal((IntPtr) pChannels[i]);
225 }
226
227 for (int i = 0; i < 8; i++)
228 {
229 Marshal.FreeHGlobal((IntPtr) bufferArray[i]);
230 }
231
232 Marshal.FreeHGlobal((IntPtr) sampleBuffer);
233
234
235 }