blob: 47f6242a23d40b835fef323dd4b1623c2c5e0c00 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "AudioResampler"
18//#define LOG_NDEBUG 0
19
20#include <stdint.h>
21#include <stdlib.h>
22#include <sys/types.h>
23#include <cutils/log.h>
24#include <cutils/properties.h>
25#include "AudioResampler.h"
26#include "AudioResamplerSinc.h"
27#include "AudioResamplerCubic.h"
28
Jim Huang592a6d92011-04-06 14:19:29 +080029#ifdef __arm__
30#include <machine/cpu-features.h>
31#endif
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033namespace android {
34
Jim Huang592a6d92011-04-06 14:19:29 +080035#ifdef __ARM_HAVE_HALFWORD_MULTIPLY // optimized asm option
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 #define ASM_ARM_RESAMP1 // enable asm optimisation for ResamplerOrder1
Jim Huang592a6d92011-04-06 14:19:29 +080037#endif // __ARM_HAVE_HALFWORD_MULTIPLY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038// ----------------------------------------------------------------------------
39
40class AudioResamplerOrder1 : public AudioResampler {
41public:
42 AudioResamplerOrder1(int bitDepth, int inChannelCount, int32_t sampleRate) :
43 AudioResampler(bitDepth, inChannelCount, sampleRate), mX0L(0), mX0R(0) {
44 }
45 virtual void resample(int32_t* out, size_t outFrameCount,
46 AudioBufferProvider* provider);
47private:
48 // number of bits used in interpolation multiply - 15 bits avoids overflow
49 static const int kNumInterpBits = 15;
50
51 // bits to shift the phase fraction down to avoid overflow
52 static const int kPreInterpShift = kNumPhaseBits - kNumInterpBits;
53
54 void init() {}
55 void resampleMono16(int32_t* out, size_t outFrameCount,
56 AudioBufferProvider* provider);
57 void resampleStereo16(int32_t* out, size_t outFrameCount,
58 AudioBufferProvider* provider);
59#ifdef ASM_ARM_RESAMP1 // asm optimisation for ResamplerOrder1
60 void AsmMono16Loop(int16_t *in, int32_t* maxOutPt, int32_t maxInIdx,
61 size_t &outputIndex, int32_t* out, size_t &inputIndex, int32_t vl, int32_t vr,
62 uint32_t &phaseFraction, uint32_t phaseIncrement);
63 void AsmStereo16Loop(int16_t *in, int32_t* maxOutPt, int32_t maxInIdx,
64 size_t &outputIndex, int32_t* out, size_t &inputIndex, int32_t vl, int32_t vr,
65 uint32_t &phaseFraction, uint32_t phaseIncrement);
66#endif // ASM_ARM_RESAMP1
67
68 static inline int32_t Interp(int32_t x0, int32_t x1, uint32_t f) {
69 return x0 + (((x1 - x0) * (int32_t)(f >> kPreInterpShift)) >> kNumInterpBits);
70 }
71 static inline void Advance(size_t* index, uint32_t* frac, uint32_t inc) {
72 *frac += inc;
73 *index += (size_t)(*frac >> kNumPhaseBits);
74 *frac &= kPhaseMask;
75 }
76 int mX0L;
77 int mX0R;
78};
79
80// ----------------------------------------------------------------------------
81AudioResampler* AudioResampler::create(int bitDepth, int inChannelCount,
82 int32_t sampleRate, int quality) {
83
84 // can only create low quality resample now
85 AudioResampler* resampler;
86
87 char value[PROPERTY_VALUE_MAX];
88 if (property_get("af.resampler.quality", value, 0)) {
89 quality = atoi(value);
90 LOGD("forcing AudioResampler quality to %d", quality);
91 }
92
93 if (quality == DEFAULT)
94 quality = LOW_QUALITY;
95
96 switch (quality) {
97 default:
98 case LOW_QUALITY:
99 LOGV("Create linear Resampler");
100 resampler = new AudioResamplerOrder1(bitDepth, inChannelCount, sampleRate);
101 break;
102 case MED_QUALITY:
103 LOGV("Create cubic Resampler");
104 resampler = new AudioResamplerCubic(bitDepth, inChannelCount, sampleRate);
105 break;
106 case HIGH_QUALITY:
107 LOGV("Create sinc Resampler");
108 resampler = new AudioResamplerSinc(bitDepth, inChannelCount, sampleRate);
109 break;
110 }
111
112 // initialize resampler
113 resampler->init();
114 return resampler;
115}
116
117AudioResampler::AudioResampler(int bitDepth, int inChannelCount,
118 int32_t sampleRate) :
119 mBitDepth(bitDepth), mChannelCount(inChannelCount),
120 mSampleRate(sampleRate), mInSampleRate(sampleRate), mInputIndex(0),
Mike J. Chenc94519c2011-08-15 13:28:26 -0700121 mPhaseFraction(0), mLocalTimeFreq(0),
122 mPTS(AudioBufferProvider::kInvalidPTS) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 // sanity check on format
124 if ((bitDepth != 16) ||(inChannelCount < 1) || (inChannelCount > 2)) {
125 LOGE("Unsupported sample format, %d bits, %d channels", bitDepth,
126 inChannelCount);
127 // LOG_ASSERT(0);
128 }
129
130 // initialize common members
131 mVolume[0] = mVolume[1] = 0;
132 mBuffer.frameCount = 0;
133
134 // save format for quick lookup
135 if (inChannelCount == 1) {
136 mFormat = MONO_16_BIT;
137 } else {
138 mFormat = STEREO_16_BIT;
139 }
140}
141
142AudioResampler::~AudioResampler() {
143}
144
145void AudioResampler::setSampleRate(int32_t inSampleRate) {
146 mInSampleRate = inSampleRate;
147 mPhaseIncrement = (uint32_t)((kPhaseMultiplier * inSampleRate) / mSampleRate);
148}
149
150void AudioResampler::setVolume(int16_t left, int16_t right) {
151 // TODO: Implement anti-zipper filter
152 mVolume[0] = left;
153 mVolume[1] = right;
154}
155
Mike J. Chenc94519c2011-08-15 13:28:26 -0700156void AudioResampler::setLocalTimeFreq(uint64_t freq) {
157 mLocalTimeFreq = freq;
158}
159
160void AudioResampler::setPTS(int64_t pts) {
161 mPTS = pts;
162}
163
164int64_t AudioResampler::calculateOutputPTS(int outputFrameIndex) {
165
166 if (mPTS == AudioBufferProvider::kInvalidPTS) {
167 return AudioBufferProvider::kInvalidPTS;
168 } else {
169 return mPTS + ((outputFrameIndex * mLocalTimeFreq) / mSampleRate);
170 }
171}
172
Eric Laurent4bb21c42011-02-28 16:52:51 -0800173void AudioResampler::reset() {
174 mInputIndex = 0;
175 mPhaseFraction = 0;
176 mBuffer.frameCount = 0;
177}
178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179// ----------------------------------------------------------------------------
180
181void AudioResamplerOrder1::resample(int32_t* out, size_t outFrameCount,
182 AudioBufferProvider* provider) {
183
184 // should never happen, but we overflow if it does
185 // LOG_ASSERT(outFrameCount < 32767);
186
187 // select the appropriate resampler
188 switch (mChannelCount) {
189 case 1:
190 resampleMono16(out, outFrameCount, provider);
191 break;
192 case 2:
193 resampleStereo16(out, outFrameCount, provider);
194 break;
195 }
196}
197
198void AudioResamplerOrder1::resampleStereo16(int32_t* out, size_t outFrameCount,
199 AudioBufferProvider* provider) {
200
201 int32_t vl = mVolume[0];
202 int32_t vr = mVolume[1];
203
204 size_t inputIndex = mInputIndex;
205 uint32_t phaseFraction = mPhaseFraction;
206 uint32_t phaseIncrement = mPhaseIncrement;
207 size_t outputIndex = 0;
208 size_t outputSampleCount = outFrameCount * 2;
209 size_t inFrameCount = (outFrameCount*mInSampleRate)/mSampleRate;
210
211 // LOGE("starting resample %d frames, inputIndex=%d, phaseFraction=%d, phaseIncrement=%d\n",
212 // outFrameCount, inputIndex, phaseFraction, phaseIncrement);
213
214 while (outputIndex < outputSampleCount) {
215
216 // buffer is empty, fetch a new one
217 while (mBuffer.frameCount == 0) {
218 mBuffer.frameCount = inFrameCount;
Mike J. Chenc94519c2011-08-15 13:28:26 -0700219 provider->getNextBuffer(&mBuffer,
220 calculateOutputPTS(outputIndex / 2));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 if (mBuffer.raw == NULL) {
222 goto resampleStereo16_exit;
223 }
224
225 // LOGE("New buffer fetched: %d frames\n", mBuffer.frameCount);
226 if (mBuffer.frameCount > inputIndex) break;
227
228 inputIndex -= mBuffer.frameCount;
229 mX0L = mBuffer.i16[mBuffer.frameCount*2-2];
230 mX0R = mBuffer.i16[mBuffer.frameCount*2-1];
231 provider->releaseBuffer(&mBuffer);
232 // mBuffer.frameCount == 0 now so we reload a new buffer
233 }
234
235 int16_t *in = mBuffer.i16;
236
237 // handle boundary case
238 while (inputIndex == 0) {
239 // LOGE("boundary case\n");
240 out[outputIndex++] += vl * Interp(mX0L, in[0], phaseFraction);
241 out[outputIndex++] += vr * Interp(mX0R, in[1], phaseFraction);
242 Advance(&inputIndex, &phaseFraction, phaseIncrement);
243 if (outputIndex == outputSampleCount)
244 break;
245 }
246
247 // process input samples
248 // LOGE("general case\n");
249
250#ifdef ASM_ARM_RESAMP1 // asm optimisation for ResamplerOrder1
251 if (inputIndex + 2 < mBuffer.frameCount) {
252 int32_t* maxOutPt;
253 int32_t maxInIdx;
254
255 maxOutPt = out + (outputSampleCount - 2); // 2 because 2 frames per loop
256 maxInIdx = mBuffer.frameCount - 2;
257 AsmStereo16Loop(in, maxOutPt, maxInIdx, outputIndex, out, inputIndex, vl, vr,
258 phaseFraction, phaseIncrement);
259 }
260#endif // ASM_ARM_RESAMP1
261
262 while (outputIndex < outputSampleCount && inputIndex < mBuffer.frameCount) {
263 out[outputIndex++] += vl * Interp(in[inputIndex*2-2],
264 in[inputIndex*2], phaseFraction);
265 out[outputIndex++] += vr * Interp(in[inputIndex*2-1],
266 in[inputIndex*2+1], phaseFraction);
267 Advance(&inputIndex, &phaseFraction, phaseIncrement);
268 }
269
270 // LOGE("loop done - outputIndex=%d, inputIndex=%d\n", outputIndex, inputIndex);
271
272 // if done with buffer, save samples
273 if (inputIndex >= mBuffer.frameCount) {
274 inputIndex -= mBuffer.frameCount;
275
276 // LOGE("buffer done, new input index %d", inputIndex);
277
278 mX0L = mBuffer.i16[mBuffer.frameCount*2-2];
279 mX0R = mBuffer.i16[mBuffer.frameCount*2-1];
280 provider->releaseBuffer(&mBuffer);
281
282 // verify that the releaseBuffer resets the buffer frameCount
283 // LOG_ASSERT(mBuffer.frameCount == 0);
284 }
285 }
286
287 // LOGE("output buffer full - outputIndex=%d, inputIndex=%d\n", outputIndex, inputIndex);
288
289resampleStereo16_exit:
290 // save state
291 mInputIndex = inputIndex;
292 mPhaseFraction = phaseFraction;
293}
294
295void AudioResamplerOrder1::resampleMono16(int32_t* out, size_t outFrameCount,
296 AudioBufferProvider* provider) {
297
298 int32_t vl = mVolume[0];
299 int32_t vr = mVolume[1];
300
301 size_t inputIndex = mInputIndex;
302 uint32_t phaseFraction = mPhaseFraction;
303 uint32_t phaseIncrement = mPhaseIncrement;
304 size_t outputIndex = 0;
305 size_t outputSampleCount = outFrameCount * 2;
306 size_t inFrameCount = (outFrameCount*mInSampleRate)/mSampleRate;
307
308 // LOGE("starting resample %d frames, inputIndex=%d, phaseFraction=%d, phaseIncrement=%d\n",
309 // outFrameCount, inputIndex, phaseFraction, phaseIncrement);
310 while (outputIndex < outputSampleCount) {
311 // buffer is empty, fetch a new one
312 while (mBuffer.frameCount == 0) {
313 mBuffer.frameCount = inFrameCount;
Mike J. Chenc94519c2011-08-15 13:28:26 -0700314 provider->getNextBuffer(&mBuffer,
315 calculateOutputPTS(outputIndex / 2));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 if (mBuffer.raw == NULL) {
317 mInputIndex = inputIndex;
318 mPhaseFraction = phaseFraction;
319 goto resampleMono16_exit;
320 }
321 // LOGE("New buffer fetched: %d frames\n", mBuffer.frameCount);
322 if (mBuffer.frameCount > inputIndex) break;
323
324 inputIndex -= mBuffer.frameCount;
325 mX0L = mBuffer.i16[mBuffer.frameCount-1];
326 provider->releaseBuffer(&mBuffer);
327 // mBuffer.frameCount == 0 now so we reload a new buffer
328 }
329 int16_t *in = mBuffer.i16;
330
331 // handle boundary case
332 while (inputIndex == 0) {
333 // LOGE("boundary case\n");
334 int32_t sample = Interp(mX0L, in[0], phaseFraction);
335 out[outputIndex++] += vl * sample;
336 out[outputIndex++] += vr * sample;
337 Advance(&inputIndex, &phaseFraction, phaseIncrement);
338 if (outputIndex == outputSampleCount)
339 break;
340 }
341
342 // process input samples
343 // LOGE("general case\n");
344
345#ifdef ASM_ARM_RESAMP1 // asm optimisation for ResamplerOrder1
346 if (inputIndex + 2 < mBuffer.frameCount) {
347 int32_t* maxOutPt;
348 int32_t maxInIdx;
349
350 maxOutPt = out + (outputSampleCount - 2);
351 maxInIdx = (int32_t)mBuffer.frameCount - 2;
352 AsmMono16Loop(in, maxOutPt, maxInIdx, outputIndex, out, inputIndex, vl, vr,
353 phaseFraction, phaseIncrement);
354 }
355#endif // ASM_ARM_RESAMP1
356
357 while (outputIndex < outputSampleCount && inputIndex < mBuffer.frameCount) {
358 int32_t sample = Interp(in[inputIndex-1], in[inputIndex],
359 phaseFraction);
360 out[outputIndex++] += vl * sample;
361 out[outputIndex++] += vr * sample;
362 Advance(&inputIndex, &phaseFraction, phaseIncrement);
363 }
364
365
366 // LOGE("loop done - outputIndex=%d, inputIndex=%d\n", outputIndex, inputIndex);
367
368 // if done with buffer, save samples
369 if (inputIndex >= mBuffer.frameCount) {
370 inputIndex -= mBuffer.frameCount;
371
372 // LOGE("buffer done, new input index %d", inputIndex);
373
374 mX0L = mBuffer.i16[mBuffer.frameCount-1];
375 provider->releaseBuffer(&mBuffer);
376
377 // verify that the releaseBuffer resets the buffer frameCount
378 // LOG_ASSERT(mBuffer.frameCount == 0);
379 }
380 }
381
382 // LOGE("output buffer full - outputIndex=%d, inputIndex=%d\n", outputIndex, inputIndex);
383
384resampleMono16_exit:
385 // save state
386 mInputIndex = inputIndex;
387 mPhaseFraction = phaseFraction;
388}
389
390#ifdef ASM_ARM_RESAMP1 // asm optimisation for ResamplerOrder1
391
392/*******************************************************************
393*
394* AsmMono16Loop
395* asm optimized monotonic loop version; one loop is 2 frames
396* Input:
397* in : pointer on input samples
398* maxOutPt : pointer on first not filled
399* maxInIdx : index on first not used
400* outputIndex : pointer on current output index
401* out : pointer on output buffer
402* inputIndex : pointer on current input index
403* vl, vr : left and right gain
404* phaseFraction : pointer on current phase fraction
405* phaseIncrement
406* Ouput:
407* outputIndex :
408* out : updated buffer
409* inputIndex : index of next to use
410* phaseFraction : phase fraction for next interpolation
411*
412*******************************************************************/
413void AudioResamplerOrder1::AsmMono16Loop(int16_t *in, int32_t* maxOutPt, int32_t maxInIdx,
414 size_t &outputIndex, int32_t* out, size_t &inputIndex, int32_t vl, int32_t vr,
415 uint32_t &phaseFraction, uint32_t phaseIncrement)
416{
417#define MO_PARAM5 "36" // offset of parameter 5 (outputIndex)
418
419 asm(
420 "stmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n"
421 // get parameters
422 " ldr r6, [sp, #" MO_PARAM5 " + 20]\n" // &phaseFraction
423 " ldr r6, [r6]\n" // phaseFraction
424 " ldr r7, [sp, #" MO_PARAM5 " + 8]\n" // &inputIndex
425 " ldr r7, [r7]\n" // inputIndex
426 " ldr r8, [sp, #" MO_PARAM5 " + 4]\n" // out
427 " ldr r0, [sp, #" MO_PARAM5 " + 0]\n" // &outputIndex
428 " ldr r0, [r0]\n" // outputIndex
429 " add r8, r0, asl #2\n" // curOut
430 " ldr r9, [sp, #" MO_PARAM5 " + 24]\n" // phaseIncrement
431 " ldr r10, [sp, #" MO_PARAM5 " + 12]\n" // vl
432 " ldr r11, [sp, #" MO_PARAM5 " + 16]\n" // vr
433
434 // r0 pin, x0, Samp
435
436 // r1 in
437 // r2 maxOutPt
438 // r3 maxInIdx
439
440 // r4 x1, i1, i3, Out1
441 // r5 out0
442
443 // r6 frac
444 // r7 inputIndex
445 // r8 curOut
446
447 // r9 inc
448 // r10 vl
449 // r11 vr
450
451 // r12
452 // r13 sp
453 // r14
454
455 // the following loop works on 2 frames
456
Nick Kralevich80754d22011-09-16 13:14:16 -0700457 "1:\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 " cmp r8, r2\n" // curOut - maxCurOut
Nick Kralevich80754d22011-09-16 13:14:16 -0700459 " bcs 2f\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460
461#define MO_ONE_FRAME \
462 " add r0, r1, r7, asl #1\n" /* in + inputIndex */\
463 " ldrsh r4, [r0]\n" /* in[inputIndex] */\
464 " ldr r5, [r8]\n" /* out[outputIndex] */\
465 " ldrsh r0, [r0, #-2]\n" /* in[inputIndex-1] */\
466 " bic r6, r6, #0xC0000000\n" /* phaseFraction & ... */\
467 " sub r4, r4, r0\n" /* in[inputIndex] - in[inputIndex-1] */\
468 " mov r4, r4, lsl #2\n" /* <<2 */\
469 " smulwt r4, r4, r6\n" /* (x1-x0)*.. */\
470 " add r6, r6, r9\n" /* phaseFraction + phaseIncrement */\
471 " add r0, r0, r4\n" /* x0 - (..) */\
472 " mla r5, r0, r10, r5\n" /* vl*interp + out[] */\
473 " ldr r4, [r8, #4]\n" /* out[outputIndex+1] */\
474 " str r5, [r8], #4\n" /* out[outputIndex++] = ... */\
475 " mla r4, r0, r11, r4\n" /* vr*interp + out[] */\
476 " add r7, r7, r6, lsr #30\n" /* inputIndex + phaseFraction>>30 */\
477 " str r4, [r8], #4\n" /* out[outputIndex++] = ... */
478
479 MO_ONE_FRAME // frame 1
480 MO_ONE_FRAME // frame 2
481
482 " cmp r7, r3\n" // inputIndex - maxInIdx
Nick Kralevich80754d22011-09-16 13:14:16 -0700483 " bcc 1b\n"
484 "2:\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485
486 " bic r6, r6, #0xC0000000\n" // phaseFraction & ...
487 // save modified values
488 " ldr r0, [sp, #" MO_PARAM5 " + 20]\n" // &phaseFraction
489 " str r6, [r0]\n" // phaseFraction
490 " ldr r0, [sp, #" MO_PARAM5 " + 8]\n" // &inputIndex
491 " str r7, [r0]\n" // inputIndex
492 " ldr r0, [sp, #" MO_PARAM5 " + 4]\n" // out
493 " sub r8, r0\n" // curOut - out
494 " asr r8, #2\n" // new outputIndex
495 " ldr r0, [sp, #" MO_PARAM5 " + 0]\n" // &outputIndex
496 " str r8, [r0]\n" // save outputIndex
497
498 " ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, pc}\n"
499 );
500}
501
502/*******************************************************************
503*
504* AsmStereo16Loop
505* asm optimized stereo loop version; one loop is 2 frames
506* Input:
507* in : pointer on input samples
508* maxOutPt : pointer on first not filled
509* maxInIdx : index on first not used
510* outputIndex : pointer on current output index
511* out : pointer on output buffer
512* inputIndex : pointer on current input index
513* vl, vr : left and right gain
514* phaseFraction : pointer on current phase fraction
515* phaseIncrement
516* Ouput:
517* outputIndex :
518* out : updated buffer
519* inputIndex : index of next to use
520* phaseFraction : phase fraction for next interpolation
521*
522*******************************************************************/
523void AudioResamplerOrder1::AsmStereo16Loop(int16_t *in, int32_t* maxOutPt, int32_t maxInIdx,
524 size_t &outputIndex, int32_t* out, size_t &inputIndex, int32_t vl, int32_t vr,
525 uint32_t &phaseFraction, uint32_t phaseIncrement)
526{
527#define ST_PARAM5 "40" // offset of parameter 5 (outputIndex)
528 asm(
529 "stmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}\n"
530 // get parameters
531 " ldr r6, [sp, #" ST_PARAM5 " + 20]\n" // &phaseFraction
532 " ldr r6, [r6]\n" // phaseFraction
533 " ldr r7, [sp, #" ST_PARAM5 " + 8]\n" // &inputIndex
534 " ldr r7, [r7]\n" // inputIndex
535 " ldr r8, [sp, #" ST_PARAM5 " + 4]\n" // out
536 " ldr r0, [sp, #" ST_PARAM5 " + 0]\n" // &outputIndex
537 " ldr r0, [r0]\n" // outputIndex
538 " add r8, r0, asl #2\n" // curOut
539 " ldr r9, [sp, #" ST_PARAM5 " + 24]\n" // phaseIncrement
540 " ldr r10, [sp, #" ST_PARAM5 " + 12]\n" // vl
541 " ldr r11, [sp, #" ST_PARAM5 " + 16]\n" // vr
542
543 // r0 pin, x0, Samp
544
545 // r1 in
546 // r2 maxOutPt
547 // r3 maxInIdx
548
549 // r4 x1, i1, i3, out1
550 // r5 out0
551
552 // r6 frac
553 // r7 inputIndex
554 // r8 curOut
555
556 // r9 inc
557 // r10 vl
558 // r11 vr
559
560 // r12 temporary
561 // r13 sp
562 // r14
563
Nick Kralevich80754d22011-09-16 13:14:16 -0700564 "3:\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 " cmp r8, r2\n" // curOut - maxCurOut
Nick Kralevich80754d22011-09-16 13:14:16 -0700566 " bcs 4f\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567
568#define ST_ONE_FRAME \
569 " bic r6, r6, #0xC0000000\n" /* phaseFraction & ... */\
570\
571 " add r0, r1, r7, asl #2\n" /* in + 2*inputIndex */\
572\
573 " ldrsh r4, [r0]\n" /* in[2*inputIndex] */\
574 " ldr r5, [r8]\n" /* out[outputIndex] */\
575 " ldrsh r12, [r0, #-4]\n" /* in[2*inputIndex-2] */\
576 " sub r4, r4, r12\n" /* in[2*InputIndex] - in[2*InputIndex-2] */\
577 " mov r4, r4, lsl #2\n" /* <<2 */\
578 " smulwt r4, r4, r6\n" /* (x1-x0)*.. */\
579 " add r12, r12, r4\n" /* x0 - (..) */\
580 " mla r5, r12, r10, r5\n" /* vl*interp + out[] */\
581 " ldr r4, [r8, #4]\n" /* out[outputIndex+1] */\
582 " str r5, [r8], #4\n" /* out[outputIndex++] = ... */\
583\
584 " ldrsh r12, [r0, #+2]\n" /* in[2*inputIndex+1] */\
585 " ldrsh r0, [r0, #-2]\n" /* in[2*inputIndex-1] */\
586 " sub r12, r12, r0\n" /* in[2*InputIndex] - in[2*InputIndex-2] */\
587 " mov r12, r12, lsl #2\n" /* <<2 */\
588 " smulwt r12, r12, r6\n" /* (x1-x0)*.. */\
589 " add r12, r0, r12\n" /* x0 - (..) */\
590 " mla r4, r12, r11, r4\n" /* vr*interp + out[] */\
591 " str r4, [r8], #4\n" /* out[outputIndex++] = ... */\
592\
593 " add r6, r6, r9\n" /* phaseFraction + phaseIncrement */\
594 " add r7, r7, r6, lsr #30\n" /* inputIndex + phaseFraction>>30 */
595
596 ST_ONE_FRAME // frame 1
597 ST_ONE_FRAME // frame 1
598
599 " cmp r7, r3\n" // inputIndex - maxInIdx
Nick Kralevich80754d22011-09-16 13:14:16 -0700600 " bcc 3b\n"
601 "4:\n"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602
603 " bic r6, r6, #0xC0000000\n" // phaseFraction & ...
604 // save modified values
605 " ldr r0, [sp, #" ST_PARAM5 " + 20]\n" // &phaseFraction
606 " str r6, [r0]\n" // phaseFraction
607 " ldr r0, [sp, #" ST_PARAM5 " + 8]\n" // &inputIndex
608 " str r7, [r0]\n" // inputIndex
609 " ldr r0, [sp, #" ST_PARAM5 " + 4]\n" // out
610 " sub r8, r0\n" // curOut - out
611 " asr r8, #2\n" // new outputIndex
612 " ldr r0, [sp, #" ST_PARAM5 " + 0]\n" // &outputIndex
613 " str r8, [r0]\n" // save outputIndex
614
615 " ldmfd sp!, {r4, r5, r6, r7, r8, r9, r10, r11, r12, pc}\n"
616 );
617}
618
619#endif // ASM_ARM_RESAMP1
620
621
622// ----------------------------------------------------------------------------
623}
624; // namespace android