1@*********************************************************** 2@ Function: SynthMasterGain 3@ Processor: ARM-E 4@ Description: Copies 32-bit synth output to 16-bit buffer 5@ with saturated gain control 6@ C-callable. 7@ 8@ Usage: 9@ SynthMasterGain( 10@ pInputBuffer 11@ pOutputBuffer, 12@ nGain, 13@ nNumLoopSamples 14@ ); 15@ 16@ Copyright Sonic Network Inc. 2004 17@**************************************************************** 18@ Revision Control: 19@ $Revision: 496 $ 20@ $Date: 2006-12-11 14:33:26 -0800 (Mon, 11 Dec 2006) $ 21@**************************************************************** 22@ 23@ where: 24@ long *pInputBuffer 25@ PASSED IN: r0 26@ 27@ EAS_PCM *pOutputBuffer 28@ PASSED IN: r1 29@ 30@ short nGain 31@ PASSED IN: r2 32@ 33@ EAS_U16 nNumLoopSamples 34@ PASSED IN: r3 35@ 36@**************************************************************** 37 38 #include "ARM_synth_constants_gnu.inc" 39 40 .arm 41 .text 42 43SynthMasterGain: 44 45 .global SynthMasterGain @ allow other files to use this function 46 47 48 49 50 51@ Stack frame 52@ ----------- 53 .equ RET_ADDR_SZ, 0 @return address 54 .equ REG_SAVE_SZ, 0 @save-on-entry registers saved 55 .equ FRAME_SZ, (8) @local variables 56 .equ ARG_BLK_SZ, 0 @argument block 57 58 .equ PARAM_OFFSET, (ARG_BLK_SZ + FRAME_SZ + REG_SAVE_SZ + RET_ADDR_SZ) 59 60@ Register usage 61@ -------------- 62pnInputBuffer .req r0 63pnOutputBuffer .req r1 64nGain .req r2 65nNumLoopSamples .req r3 66 67 STMFD sp!,{r4-r6,r14} @Save any save-on-entry registers that are used 68 69 LDR r6, =0x7fff @constant for saturation tests 70 71loop: 72 LDR r4, [pnInputBuffer], #4 @fetch 1st output sample 73 74 LDR r5, [pnInputBuffer], #4 @fetch 2nd output sample 75 76 SMULWB r4, r4, nGain @output = gain * input 77 78 CMP r4, r6 @check for positive saturation 79 MOVGT r4, r6 @saturate 80 CMN r4, r6 @check for negative saturation 81 MVNLT r4, r6 @saturate 82 83 SMULWB r5, r5, nGain @output = gain * input 84 85 STRH r4, [pnOutputBuffer], #NEXT_OUTPUT_PCM @save 1st output sample 86 87 CMP r5, r6 @check for positive saturation 88 MOVGT r5, r6 @saturate 89 CMN r5, r6 @check for negative saturation 90 MVNLT r5, r6 @saturate 91 STRH r5, [pnOutputBuffer], #NEXT_OUTPUT_PCM @save 2nd output sample 92 93 SUBS nNumLoopSamples, nNumLoopSamples, #2 94 BGT loop 95 96@ 97@ Return to calling function 98@---------------------------------------------------------------- 99 100 LDMFD sp!,{r4-r6, lr} @ return to calling function 101 BX lr 102 103@***************************************************************************** 104 105 .end @ end of assembly code 106 107