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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
|
@ ScummVM Scumm Interpreter
@ Copyright (C) 2007 The ScummVM project
@
@ This program is free software@ you can redistribute it and/or
@ modify it under the terms of the GNU General Public License
@ as published by the Free Software Foundation@ either version 2
@ of the License, or (at your option) any later version.
@
@ This program is distributed in the hope that it will be useful,
@ but WITHOUT ANY WARRANTY@ without even the implied warranty of
@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ GNU General Public License for more details.
@
@ You should have received a copy of the GNU General Public License
@ along with this program@ if not, write to the Free Software
@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@
@ $URL: $
@ $Id: $
@
@ @author Robin Watts (robin@wss.co.uk)
@
@ This file, together with rate_arm.cpp, provides an ARM optimised version
@ of rate.cpp. The algorithm is essentially the same as that within rate.cpp
@ so to understand this file you should understand rate.cpp first.
.text
.global ARM_CopyRate_M
.global ARM_CopyRate_S
.global ARM_CopyRate_R
.global ARM_SimpleRate_M
.global ARM_SimpleRate_S
.global ARM_SimpleRate_R
.global ARM_LinearRate_M
.global ARM_LinearRate_S
.global ARM_LinearRate_R
ARM_CopyRate_M:
@ r0 = len
@ r1 = obuf
@ r2 = vol_l
@ r3 = vol_r
@ <> = ptr
LDR r12,[r13]
STMFD r13!,{r4-r7,r14}
MOV r14,#0 @ r14= 0
ORR r2, r2, r2, LSL #8 @ r2 = vol_l as 16 bits
ORR r3, r3, r3, LSL #8 @ r3 = vol_r as 16 bits
CopyRate_M_loop:
LDRSH r5, [r12], #2 @ r5 = tmp0 = tmp1 = *ptr++
LDRSH r6, [r1] @ r6 = obuf[0]
LDRSH r7, [r1, #2] @ r7 = obuf[1]
MUL r4, r2, r5 @ r4 = tmp0*vol_l
MUL r5, r3, r5 @ r5 = tmp1*vol_r
ADDS r6, r4, r6, LSL #16 @ r6 = obuf[0]<<16 + tmp0*vol_l
RSCVS r6, r14,#1<<31 @ Clamp r6
ADDS r7, r5, r7, LSL #16 @ r7 = obuf[1]<<16 + tmp1*vol_r
RSCVS r7, r14,#1<<31 @ Clamp r7
MOV r6, r6, LSR #16 @ Shift back to halfword
MOV r7, r7, LSR #16 @ Shift back to halfword
STRH r6, [r1], #2 @ Store output value
STRH r7, [r1], #2 @ Store output value
SUBS r0,r0,#1 @ len--
BGT CopyRate_M_loop @ and loop
LDMFD r13!,{r4-r7,PC}
ARM_CopyRate_S:
@ r0 = len
@ r1 = obuf
@ r2 = vol_l
@ r3 = vol_r
@ <> = ptr
LDR r12,[r13]
STMFD r13!,{r4-r7,r14}
MOV r14,#0 @ r14= 0
ORR r2, r2, r2, LSL #8 @ r2 = vol_l as 16 bits
ORR r3, r3, r3, LSL #8 @ r3 = vol_r as 16 bits
CopyRate_S_loop:
LDRSH r4, [r12],#2 @ r4 = tmp0 = *ptr++
LDRSH r5, [r12],#2 @ r5 = tmp1 = *ptr++
LDRSH r6, [r1] @ r6 = obuf[0]
LDRSH r7, [r1,#2] @ r7 = obuf[1]
MUL r4, r2, r4 @ r5 = tmp0*vol_l
MUL r5, r3, r5 @ r6 = tmp1*vol_r
ADDS r6, r4, r6, LSL #16 @ r6 = obuf[0]<<16 + tmp0*vol_l
RSCVS r6, r14,#1<<31 @ Clamp r6
ADDS r7, r5, r7, LSL #16 @ r7 = obuf[1]<<16 + tmp1*vol_r
RSCVS r7, r14,#1<<31 @ Clamp r7
MOV r6, r6, LSR #16 @ Shift back to halfword
MOV r7, r7, LSR #16 @ Shift back to halfword
STRH r6, [r1],#2 @ Store output value
STRH r7, [r1],#2 @ Store output value
SUBS r0,r0,#2 @ len -= 2
BGT CopyRate_S_loop @ and loop
LDMFD r13!,{r4-r7,PC}
ARM_CopyRate_R:
@ r0 = len
@ r1 = obuf
@ r2 = vol_l
@ r3 = vol_r
@ <> = ptr
LDR r12,[r13]
STMFD r13!,{r4-r7,r14}
MOV r14,#0 @ r14= 0
ORR r2, r2, r2, LSL #8 @ r2 = vol_l as 16 bits
ORR r3, r3, r3, LSL #8 @ r3 = vol_r as 16 bits
CopyRate_R_loop:
LDRSH r5, [r12],#2 @ r5 = tmp1 = *ptr++
LDRSH r4, [r12],#2 @ r4 = tmp0 = *ptr++
LDRSH r6, [r1] @ r6 = obuf[0]
LDRSH r7, [r1,#2] @ r7 = obuf[1]
MUL r4, r2, r4 @ r4 = tmp0*vol_l
MUL r5, r3, r5 @ r5 = tmp1*vol_r
ADDS r6, r4, r6, LSL #16 @ r6 = obuf[0]<<16 + tmp0*vol_l
RSCVS r6, r14,#1<<31 @ Clamp r6
ADDS r7, r5, r7, LSL #16 @ r7 = obuf[1]<<16 + tmp1*vol_r
RSCVS r7, r14,#1<<31 @ Clamp r7
MOV r6, r6, LSR #16 @ Shift back to halfword
MOV r7, r7, LSR #16 @ Shift back to halfword
STRH r6, [r1],#2 @ Store output value
STRH r7, [r1],#2 @ Store output value
SUBS r0,r0,#2 @ len -= 2
BGT CopyRate_R_loop @ and loop
LDMFD r13!,{r4-r7,PC}
ARM_SimpleRate_M:
@ r0 = AudioStream &input
@ r1 = input.readBuffer
@ r2 = input->sr
@ r3 = obuf
@ <> = osamp
@ <> = vol_l
@ <> = vol_r
MOV r12,r13
STMFD r13!,{r0-r2,r4-r8,r10-r11,r14}
LDMFD r12,{r11,r12,r14} @ r11= osamp
@ r12= vol_l
@ r14= vol_r
LDMIA r2,{r0,r1,r2,r8} @ r0 = inPtr
@ r1 = inLen
@ r2 = opos
@ r8 = opos_inc
CMP r11,#0 @ if (osamp <= 0)
BLE SimpleRate_M_end @ bale
MOV r10,#0
ORR r12,r12,r12,LSL #8 @ r12= vol_l as 16 bits
ORR r14,r14,r14,LSL #8 @ r14= vol_r as 16 bits
SimpleRate_M_loop:
SUBS r1, r1, #1 @ r1 = inLen -= 1
BLT SimpleRate_M_read
SUBS r2, r2, #1 @ r2 = opos--
ADDGE r0, r0, #2 @ if (r2 >= 0) { sr.inPtr++
BGE SimpleRate_M_loop @ and loop }
SimpleRate_M_read_return:
LDRSH r5, [r0],#2 @ r5 = tmp1 = *inPtr++
LDRSH r6, [r3] @ r6 = obuf[0]
LDRSH r7, [r3,#2] @ r7 = obuf[1]
ADD r2, r2, r8 @ r2 = opos += opos_inc
MUL r4, r12,r5 @ r4 = tmp0*vol_l
MUL r5, r14,r5 @ r5 = tmp1*vol_r
ADDS r6, r4, r6, LSL #16 @ r6 = obuf[0]<<16 + tmp0*vol_l
RSCVS r6, r10,#1<<31 @ Clamp r6
ADDS r7, r5, r7, LSL #16 @ r7 = obuf[1]<<16 + tmp1*vol_r
RSCVS r7, r10,#1<<31 @ Clamp r7
MOV r6, r6, LSR #16 @ Shift back to halfword
MOV r7, r7, LSR #16 @ Shift back to halfword
STRH r6, [r3],#2 @ Store output value
STRH r7, [r3],#2 @ Store output value
SUBS r11,r11,#1 @ len--
BGT SimpleRate_M_loop @ and loop
SimpleRate_M_end:
LDR r14,[r13,#8] @ r14 = sr
ADD r13,r13,#12 @ Skip over r0-r2 on stack
STMIA r14,{r0,r1,r2} @ Store back updated values
LDMFD r13!,{r4-r8,r10-r11,PC}
SimpleRate_M_read:
LDR r0, [r13,#4*2] @ r0 = sr
ADD r0, r0, #16 @ r0 = inPtr = inBuf
STMFD r13!,{r0,r2-r3,r12,r14}
MOV r1, r0 @ r1 = inBuf
LDR r0, [r13,#4*5] @ r0 = AudioStream & input
MOV r2, #512 @ r2 = ARRAYSIZE(inBuf)
@ Calling back into C++ here. WinCE is fairly easy about such things
@ but other OS are more awkward. r9 is preserved for Symbian, and
@ we have 3+8+5 = 16 things on the stack (an even number).
MOV r14,PC
LDR PC,[r13,#4*6] @ inLen = input.readBuffer(inBuf,512)
SUBS r1, r0, #1 @ r1 = inLen-1
LDMFD r13!,{r0,r2-r3,r12,r14}
BLT SimpleRate_M_end
SUBS r2, r2, #1 @ r2 = opos--
ADDGE r0, r0, #2 @ if (r2 >= 0) { sr.inPtr++
BGE SimpleRate_M_loop @ and loop }
B SimpleRate_M_read_return
ARM_SimpleRate_S:
@ r0 = AudioStream &input
@ r1 = input.readBuffer
@ r2 = input->sr
@ r3 = obuf
@ <> = osamp
@ <> = vol_l
@ <> = vol_r
MOV r12,r13
STMFD r13!,{r0-r2,r4-r8,r10-r11,r14}
LDMFD r12,{r11,r12,r14} @ r11= osamp
@ r12= vol_l
@ r14= vol_r
LDMIA r2,{r0,r1,r2,r8} @ r0 = inPtr
@ r1 = inLen
@ r2 = opos
@ r8 = opos_inc
CMP r11,#0 @ if (osamp <= 0)
BLE SimpleRate_S_end @ bale
MOV r10,#0
ORR r12,r12,r12,LSL #8 @ r12= vol_l as 16 bits
ORR r14,r14,r14,LSL #8 @ r14= vol_r as 16 bits
SimpleRate_S_loop:
SUBS r1, r1, #2 @ r1 = inLen -= 2
BLT SimpleRate_S_read
SUBS r2, r2, #1 @ r2 = opos--
ADDGE r0, r0, #4 @ if (r2 >= 0) { sr.inPtr += 2
BGE SimpleRate_S_loop @ and loop }
SimpleRate_S_read_return:
LDRSH r4, [r0],#2 @ r4 = tmp0 = *inPtr++
LDRSH r5, [r0],#2 @ r5 = tmp1 = *inPtr++
LDRSH r6, [r3] @ r6 = obuf[0]
LDRSH r7, [r3,#2] @ r7 = obuf[1]
ADD r2, r2, r8 @ r2 = opos += opos_inc
MUL r4, r12,r4 @ r5 = tmp0*vol_l
MUL r5, r14,r5 @ r6 = tmp1*vol_r
ADDS r6, r4, r6, LSL #16 @ r6 = obuf[0]<<16 + tmp0*vol_l
RSCVS r6, r10,#1<<31 @ Clamp r6
ADDS r7, r5, r7, LSL #16 @ r7 = obuf[1]<<16 + tmp1*vol_r
RSCVS r7, r10,#1<<31 @ Clamp r7
MOV r6, r6, LSR #16 @ Shift back to halfword
MOV r7, r7, LSR #16 @ Shift back to halfword
STRH r6, [r3],#2 @ Store output value
STRH r7, [r3],#2 @ Store output value
SUBS r11,r11,#1 @ osamp--
BGT SimpleRate_S_loop @ and loop
SimpleRate_S_end:
LDR r14,[r13,#8] @ r14 = sr
ADD r13,r13,#12 @ skip over r0-r2 on stack
STMIA r14,{r0,r1,r2} @ store back updated values
LDMFD r13!,{r4-r8,r10-r11,PC}
SimpleRate_S_read:
LDR r0, [r13,#4*2] @ r0 = sr
ADD r0, r0, #16 @ r0 = inPtr = inBuf
STMFD r13!,{r0,r2-r3,r12,r14}
MOV r1, r0 @ r1 = inBuf
LDR r0, [r13,#4*5] @ r0 = AudioStream & input
MOV r2, #512 @ r2 = ARRAYSIZE(inBuf)
@ Calling back into C++ here. WinCE is fairly easy about such things
@ but other OS are more awkward. r9 is preserved for Symbian, and
@ we have 3+8+5 = 16 things on the stack (an even number).
MOV r14,PC
LDR PC,[r13,#4*6] @ inLen = input.readBuffer(inBuf,512)
SUBS r1, r0, #2 @ r1 = inLen-2
LDMFD r13!,{r0,r2-r3,r12,r14}
BLT SimpleRate_S_end
SUBS r2, r2, #1 @ r2 = opos--
ADDGE r0, r0, #4 @ if (r2 >= 0) { sr.inPtr += 2
BGE SimpleRate_S_loop @ and loop }
B SimpleRate_S_read_return
ARM_SimpleRate_R:
@ r0 = AudioStream &input
@ r1 = input.readBuffer
@ r2 = input->sr
@ r3 = obuf
@ <> = osamp
@ <> = vol_l
@ <> = vol_r
MOV r12,r13
STMFD r13!,{r0-r2,r4-r8,r10-r11,r14}
LDMFD r12,{r11,r12,r14} @ r11= osamp
@ r12= vol_l
@ r14= vol_r
LDMIA r2,{r0,r1,r2,r8} @ r0 = inPtr
@ r1 = inLen
@ r2 = opos
@ r8 = opos_inc
CMP r11,#0 @ if (osamp <= 0)
BLE SimpleRate_R_end @ bale
MOV r10,#0
ORR r12,r12,r12,LSL #8 @ r12= vol_l as 16 bits
ORR r14,r14,r14,LSL #8 @ r14= vol_r as 16 bits
SimpleRate_R_loop:
SUBS r1, r1, #2 @ r1 = inLen -= 2
BLT SimpleRate_R_read
SUBS r2, r2, #1 @ r2 = opos--
ADDGE r0, r0, #4 @ if (r2 >= 0) { sr.inPtr += 2
BGE SimpleRate_R_loop @ and loop }
SimpleRate_R_read_return:
LDRSH r5, [r0],#2 @ r5 = tmp0 = *inPtr++
LDRSH r4, [r0],#2 @ r4 = tmp1 = *inPtr++
LDRSH r6, [r3] @ r6 = obuf[0]
LDRSH r7, [r3,#2] @ r7 = obuf[1]
ADD r2, r2, r8 @ r2 = opos += opos_inc
MUL r4, r12,r4 @ r5 = tmp0*vol_l
MUL r5, r14,r5 @ r6 = tmp1*vol_r
ADDS r6, r4, r6, LSL #16 @ r6 = obuf[0]<<16 + tmp0*vol_l
RSCVS r6, r10,#1<<31 @ Clamp r6
ADDS r7, r5, r7, LSL #16 @ r7 = obuf[1]<<16 + tmp1*vol_r
RSCVS r7, r10,#1<<31 @ Clamp r7
MOV r6, r6, LSR #16 @ Shift back to halfword
MOV r7, r7, LSR #16 @ Shift back to halfword
STRH r6, [r3],#2 @ Store output value
STRH r7, [r3],#2 @ Store output value
SUBS r11,r11,#1 @ osamp--
BGT SimpleRate_R_loop @ and loop
SimpleRate_R_end:
LDR r14,[r13,#8] @ r14 = sr
ADD r13,r13,#12 @ Skip over r0-r2 on stack
STMIA r14,{r0,r1,r2} @ Store back updated values
LDMFD r13!,{r4-r8,r10-r11,PC}
SimpleRate_R_read:
LDR r0, [r13,#4*2] @ r0 = sr
ADD r0, r0, #16 @ r0 = inPtr = inBuf
STMFD r13!,{r0,r2-r3,r12,r14}
MOV r1, r0 @ r1 = inBuf
LDR r0, [r13,#4*5] @ r0 = AudioStream & input
MOV r2, #512 @ r2 = ARRAYSIZE(inBuf)
@ Calling back into C++ here. WinCE is fairly easy about such things
@ but other OS are more awkward. r9 is preserved for Symbian, and
@ we have 3+8+5 = 16 things on the stack (an even number).
MOV r14,PC
LDR PC,[r13,#4*6] @ inLen = input.readBuffer(inBuf,512)
SUBS r1, r0, #2 @ r1 = inLen-2
LDMFD r13!,{r0,r2-r3,r12,r14}
BLT SimpleRate_R_end
SUBS r2, r2, #1 @ r2 = opos--
ADDGE r0, r0, #4 @ if (r2 >= 0) { sr.inPtr += 2
BGE SimpleRate_R_loop @ and loop }
B SimpleRate_R_read_return
ARM_LinearRate_M:
@ r0 = AudioStream &input
@ r1 = input.readBuffer
@ r2 = input->sr
@ r3 = obuf
@ <> = osamp
@ <> = vol_l
@ <> = vol_r
MOV r12,r13
STMFD r13!,{r0-r1,r4-r11,r14}
LDMFD r12,{r11,r12,r14} @ r11= osamp
@ r12= vol_l
@ r14= vol_r
LDMIA r2,{r0,r1,r8} @ r0 = inPtr
@ r1 = inLen
@ r8 = opos
CMP r11,#0 @ if (osamp <= 0)
BLE LinearRate_M_end @ bale
ORR r12,r12,r12,LSL #8 @ r12= vol_l as 16 bits
ORR r14,r14,r14,LSL #8 @ r14= vol_r as 16 bits
CMP r1,#0
BGT LinearRate_M_part2
@ part1 - read input samples
LinearRate_M_loop:
SUBS r1, r1, #1 @ r1 = inLen -= 1
BLT LinearRate_M_read
LinearRate_M_read_return:
LDR r10,[r2, #16] @ r10= icur[0,1]
LDRSH r5, [r0],#2 @ r5 = tmp1 = *inPtr++
SUBS r8, r8, #1 @ r8 = opos--
STR r10,[r2,#20] @ ilast[0,1] = icur[0,1]
STRH r5, [r2,#16] @ icur[0] = tmp1
BGE LinearRate_M_loop
@ part2 - form output samples
LinearRate_M_part2:
@ We are guaranteed that opos < 0 here
LDRSH r6, [r2,#20] @ r6 = ilast[0]
LDRSH r5, [r2,#16] @ r5 = icur[0]
LDRH r4, [r2,#24] @ r4 = opos_frac
LDR r10,[r2,#28] @ r10= opos_frac_inc
MOV r6, r6, LSL #16 @ r6 = ilast[0]<<16
SUB r5, r5, r6, ASR #16 @ r5 = icur[0] - ilast[0]
ADD r6, r6, #1<<15 @ r6 = ilast[0]+1<<(FRAC_BITS-1)
MLA r6, r4, r5, r6 @ r6 = (icur[0]-ilast[0])*opos_frac+ilast[0]
ADD r4, r4, r10 @ r4 = tmp = opos_frac+opos_inc_frac
STRH r4,[r2,#24] @ opos_frac &= 65535
ADD r8, r8, r4, LSR #16 @ opos += (tmp>>FRAC_BITS)
LDRSH r4, [r3] @ r4 = obuf[0]
LDRSH r5, [r3,#2] @ r5 = obuf[1]
MOV r6, r6, ASR #16 @ r6 = tmp0 = tmp1 >>= 16
MUL r7, r12,r6 @ r7 = tmp0*vol_l
MUL r6, r14,r6 @ r6 = tmp1*vol_r
ADDS r7, r7, r4, LSL #16 @ r7 = obuf[0]<<16 + tmp0*vol_l
MOV r4, #0
RSCVS r7, r4, #1<<31 @ Clamp r7
ADDS r6, r6, r5, LSL #16 @ r6 = obuf[1]<<16 + tmp1*vol_r
RSCVS r6, r4, #1<<31 @ Clamp r6
MOV r7, r7, LSR #16 @ Shift back to halfword
MOV r6, r6, LSR #16 @ Shift back to halfword
LDR r5, [r2,#12] @ r5 = opos_inc
STRH r7, [r3],#2 @ Store output value
STRH r6, [r3],#2 @ Store output value
SUBS r11, r11,#1 @ opos--
BLE LinearRate_M_end @ end if needed
ADDS r8, r8, r5 @ r8 = opos += opos_inc
BLT LinearRate_M_part2
B LinearRate_M_loop
LinearRate_M_end:
ADD r13,r13,#8
STMIA r2,{r0,r1,r8}
LDMFD r13!,{r4-r11,PC}
LinearRate_M_read:
ADD r0, r2, #32 @ r0 = inPtr = inBuf
STMFD r13!,{r0,r2-r3,r12,r14}
MOV r1, r0 @ r1 = inBuf
LDR r0, [r13,#4*5] @ r0 = AudioStream & input
MOV r2, #512 @ r2 = ARRAYSIZE(inBuf)
@ Calling back into C++ here. WinCE is fairly easy about such things
@ but other OS are more awkward. r9 is preserved for Symbian, and
@ we have 2+9+5 = 16 things on the stack (an even number).
MOV r14,PC
LDR PC,[r13,#4*6] @ inLen = input.readBuffer(inBuf,512)
SUBS r1, r0, #1 @ r1 = inLen-1
LDMFD r13!,{r0,r2-r3,r12,r14}
BLT LinearRate_M_end
B LinearRate_M_read_return
ARM_LinearRate_S:
@ r0 = AudioStream &input
@ r1 = input.readBuffer
@ r2 = input->sr
@ r3 = obuf
@ <> = osamp
@ <> = vol_l
@ <> = vol_r
MOV r12,r13
STMFD r13!,{r0-r1,r4-r11,r14}
LDMFD r12,{r11,r12,r14} @ r11= osamp
@ r12= vol_l
@ r14= vol_r
LDMIA r2,{r0,r1,r8} @ r0 = inPtr
@ r1 = inLen
@ r8 = opos
CMP r11,#0 @ if (osamp <= 0)
BLE LinearRate_S_end @ bale
ORR r12,r12,r12,LSL #8 @ r12= vol_l as 16 bits
ORR r14,r14,r14,LSL #8 @ r14= vol_r as 16 bits
CMP r1,#0
BGT LinearRate_S_part2
@ part1 - read input samples
LinearRate_S_loop:
SUBS r1, r1, #2 @ r1 = inLen -= 2
BLT LinearRate_S_read
LinearRate_S_read_return:
LDR r10,[r2, #16] @ r10= icur[0,1]
LDRSH r5, [r0],#2 @ r5 = tmp0 = *inPtr++
LDRSH r6, [r0],#2 @ r5 = tmp1 = *inPtr++
SUBS r8, r8, #1 @ r8 = opos--
STR r10,[r2,#20] @ ilast[0,1] = icur[0,1]
STRH r5, [r2,#16] @ icur[0] = tmp0
STRH r6, [r2,#16] @ icur[1] = tmp1
BGE LinearRate_S_loop
@ part2 - form output samples
LinearRate_S_part2:
@ We are guaranteed that opos < 0 here
LDRSH r6, [r2,#20] @ r6 = ilast[0]
LDRSH r5, [r2,#16] @ r5 = icur[0]
LDRH r4, [r2,#24] @ r4 = opos_frac
MOV r6, r6, LSL #16 @ r6 = ilast[0]<<16
SUB r5, r5, r6, ASR #16 @ r5 = icur[0] - ilast[0]
ADD r6, r6, #1<<15 @ r6 = ilast[0]+1<<(FRAC_BITS-1)
MLA r6, r4, r5, r6 @ r6 = (icur[0]-ilast[0])*opos_frac+ilast[0]
LDRSH r7, [r2,#22] @ r6 = ilast[1]
LDRSH r5, [r2,#18] @ r5 = icur[1]
LDR r10,[r2,#28] @ r10= opos_frac_inc
MOV r7, r7, LSL #16 @ r7 = ilast[1]<<16
SUB r5, r5, r7, ASR #16 @ r5 = icur[1] - ilast[1]
ADD r7, r7, #1<<15 @ r6 = ilast[1]+1<<(FRAC_BITS-1)
MLA r7, r4, r5, r7 @ r6 = (icur[1]-ilast[1])*opos_frac+ilast[1]
ADD r4, r4, r10 @ r4 = tmp = opos_frac+opos_inc_frac
STRH r4,[r2,#24] @ opos_frac &= 65535
ADD r8, r8, r4, LSR #16 @ opos += (tmp>>FRAC_BITS)
LDRSH r4, [r3] @ r4 = obuf[0]
LDRSH r5, [r3,#2] @ r5 = obuf[1]
MOV r7, r7, ASR #16 @ r7 = tmp0 >>= 16
MOV r6, r6, ASR #16 @ r6 = tmp1 >>= 16
MUL r7, r12,r7 @ r7 = tmp0*vol_l
MUL r6, r14,r6 @ r6 = tmp1*vol_r
ADDS r7, r7, r4, LSL #16 @ r7 = obuf[0]<<16 + tmp0*vol_l
MOV r4, #0
RSCVS r7, r4, #1<<31 @ Clamp r7
ADDS r6, r6, r5, LSL #16 @ r6 = obuf[1]<<16 + tmp1*vol_r
RSCVS r6, r4, #1<<31 @ Clamp r6
MOV r7, r7, LSR #16 @ Shift back to halfword
MOV r6, r6, LSR #16 @ Shift back to halfword
LDR r5, [r2,#12] @ r5 = opos_inc
STRH r7, [r3],#2 @ Store output value
STRH r6, [r3],#2 @ Store output value
SUBS r11, r11,#1 @ opos--
BLE LinearRate_S_end @ and loop
ADDS r8, r8, r5 @ r8 = opos += opos_inc
BLT LinearRate_S_part2
B LinearRate_S_loop
LinearRate_S_end:
ADD r13,r13,#8
STMIA r2,{r0,r1,r8}
LDMFD r13!,{r4-r11,PC}
LinearRate_S_read:
ADD r0, r2, #32 @ r0 = inPtr = inBuf
STMFD r13!,{r0,r2-r3,r12,r14}
MOV r1, r0 @ r1 = inBuf
LDR r0, [r13,#4*5] @ r0 = AudioStream & input
MOV r2, #512 @ r2 = ARRAYSIZE(inBuf)
@ Calling back into C++ here. WinCE is fairly easy about such things
@ but other OS are more awkward. r9 is preserved for Symbian, and
@ we have 2+9+5 = 16 things on the stack (an even number).
MOV r14,PC
LDR PC,[r13,#4*6] @ inLen = input.readBuffer(inBuf,512)
SUBS r1, r0, #2 @ r1 = inLen-2
LDMFD r13!,{r0,r2-r3,r12,r14}
BLT LinearRate_S_end
B LinearRate_S_read_return
ARM_LinearRate_R:
@ r0 = AudioStream &input
@ r1 = input.readBuffer
@ r2 = input->sr
@ r3 = obuf
@ <> = osamp
@ <> = vol_l
@ <> = vol_r
MOV r12,r13
STMFD r13!,{r0-r1,r4-r11,r14}
LDMFD r12,{r11,r12,r14} @ r11= osamp
@ r12= vol_l
@ r14= vol_r
LDMIA r2,{r0,r1,r8} @ r0 = inPtr
@ r1 = inLen
@ r8 = opos
CMP r11,#0 @ if (osamp <= 0)
BLE LinearRate_R_end @ bale
ORR r12,r12,r12,LSL #8 @ r12= vol_l as 16 bits
ORR r14,r14,r14,LSL #8 @ r14= vol_r as 16 bits
CMP r1,#0
BGT LinearRate_R_part2
@ part1 - read input samples
LinearRate_R_loop:
SUBS r1, r1, #2 @ r1 = inLen -= 2
BLT LinearRate_R_read
LinearRate_R_read_return:
LDR r10,[r2, #16] @ r10= icur[0,1]
LDRSH r5, [r0],#2 @ r5 = tmp0 = *inPtr++
LDRSH r6, [r0],#2 @ r5 = tmp1 = *inPtr++
SUBS r8, r8, #1 @ r8 = opos--
STR r10,[r2,#20] @ ilast[0,1] = icur[0,1]
STRH r5, [r2,#16] @ icur[0] = tmp0
STRH r6, [r2,#16] @ icur[1] = tmp1
BGE LinearRate_R_loop
@ part2 - form output samples
LinearRate_R_part2:
@ We are guaranteed that opos < 0 here
LDRSH r6, [r2,#20] @ r6 = ilast[0]
LDRSH r5, [r2,#16] @ r5 = icur[0]
LDRH r4, [r2,#24] @ r4 = opos_frac
MOV r6, r6, LSL #16 @ r6 = ilast[0]<<16
SUB r5, r5, r6, ASR #16 @ r5 = icur[0] - ilast[0]
ADD r6, r6, #1<<15 @ r6 = ilast[0]+1<<(FRAC_BITS-1)
MLA r6, r4, r5, r6 @ r6 = (icur[0]-ilast[0])*opos_frac+ilast[0]
LDRSH r7, [r2,#22] @ r6 = ilast[1]
LDRSH r5, [r2,#18] @ r5 = icur[1]
LDR r10,[r2,#28] @ r10= opos_frac_inc
MOV r7, r7, LSL #16 @ r7 = ilast[1]<<16
SUB r5, r5, r7, ASR #16 @ r5 = icur[1] - ilast[1]
ADD r7, r7, #1<<15 @ r6 = ilast[1]+1<<(FRAC_BITS-1)
MLA r7, r4, r5, r7 @ r6 = (icur[1]-ilast[1])*opos_frac+ilast[1]
ADD r4, r4, r10 @ r4 = tmp = opos_frac+opos_inc_frac
STRH r4,[r2,#24] @ opos_frac &= 65535
ADD r8, r8, r4, LSR #16 @ opos += (tmp>>FRAC_BITS)
LDRSH r4, [r3] @ r4 = obuf[0]
LDRSH r5, [r3,#2] @ r5 = obuf[1]
MOV r7, r7, ASR #16 @ r7 = tmp0 >>= 16
MOV r6, r6, ASR #16 @ r6 = tmp1 >>= 16
MUL r7, r12,r7 @ r7 = tmp0*vol_l
MUL r6, r14,r6 @ r6 = tmp1*vol_r
ADDS r7, r7, r4, LSL #16 @ r7 = obuf[0]<<16 + tmp0*vol_l
MOV r4, #0
RSCVS r7, r4, #1<<31 @ Clamp r7
ADDS r6, r6, r5, LSL #16 @ r6 = obuf[1]<<16 + tmp1*vol_r
RSCVS r6, r4, #1<<31 @ Clamp r6
MOV r7, r7, LSR #16 @ Shift back to halfword
MOV r6, r6, LSR #16 @ Shift back to halfword
LDR r5, [r2,#12] @ r5 = opos_inc
STRH r6, [r3],#2 @ Store output value
STRH r7, [r3],#2 @ Store output value
SUBS r11, r11,#1 @ opos--
BLE LinearRate_R_end @ and loop
ADDS r8, r8, r5 @ r8 = opos += opos_inc
BLT LinearRate_R_part2
B LinearRate_R_loop
LinearRate_R_end:
ADD r13,r13,#8
STMIA r2,{r0,r1,r8}
LDMFD r13!,{r4-r11,PC}
LinearRate_R_read:
ADD r0, r2, #32 @ r0 = inPtr = inBuf
STMFD r13!,{r0,r2-r3,r12,r14}
MOV r1, r0 @ r1 = inBuf
LDR r0, [r13,#4*5] @ r0 = AudioStream & input
MOV r2, #512 @ r2 = ARRAYSIZE(inBuf)
@ Calling back into C++ here. WinCE is fairly easy about such things
@ but other OS are more awkward. r9 is preserved for Symbian, and
@ we have 2+9+5 = 16 things on the stack (an even number).
MOV r14,PC
LDR PC,[r13,#4*6] @ inLen = input.readBuffer(inBuf,512)
SUBS r1, r0, #2 @ r1 = inLen-2
LDMFD r13!,{r0,r2-r3,r12,r14}
BLT LinearRate_R_end
B LinearRate_R_read_return
|