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
43	.func	SynthMasterGain
44SynthMasterGain:
45
46	.global	SynthMasterGain	@ allow other files to use this function
47
48
49
50
51
52@ Stack frame
53@ -----------
54	.equ	RET_ADDR_SZ, 0			@return address
55	.equ	REG_SAVE_SZ, 0			@save-on-entry registers saved
56	.equ	FRAME_SZ, (8)			@local variables
57	.equ	ARG_BLK_SZ, 0			@argument block
58
59	.equ	PARAM_OFFSET, (ARG_BLK_SZ + FRAME_SZ + REG_SAVE_SZ + RET_ADDR_SZ)
60
61@ Register usage
62@ --------------
63pnInputBuffer	.req	r0
64pnOutputBuffer	.req	r1
65nGain	.req	r2
66nNumLoopSamples	.req	r3
67
68	STMFD	sp!,{r4-r6,r14}					@Save any save-on-entry registers that are used
69
70	LDR		r6, =0x7fff						@constant for saturation tests
71
72loop:
73	LDR		r4, [pnInputBuffer], #4			@fetch 1st output sample
74
75	LDR		r5, [pnInputBuffer], #4			@fetch 2nd output sample
76
77	SMULWB	r4, r4, nGain					@output = gain * input
78
79	CMP		r4, r6							@check for positive saturation
80	MOVGT	r4, r6							@saturate
81	CMN		r4, r6							@check for negative saturation
82	MVNLT	r4, r6							@saturate
83
84	SMULWB	r5, r5, nGain					@output = gain * input
85
86	STRH	r4, [pnOutputBuffer], #NEXT_OUTPUT_PCM	@save 1st output sample
87
88	CMP		r5, r6							@check for positive saturation
89	MOVGT	r5, r6							@saturate
90	CMN		r5, r6							@check for negative saturation
91	MVNLT	r5, r6							@saturate
92	STRH	r5, [pnOutputBuffer], #NEXT_OUTPUT_PCM	@save 2nd output sample
93
94	SUBS	nNumLoopSamples, nNumLoopSamples, #2
95	BGT		loop
96
97@
98@ Return to calling function
99@----------------------------------------------------------------
100
101	LDMFD	sp!,{r4-r6, lr}				@ return to calling function
102	BX		lr
103
104@*****************************************************************************
105
106	.endfunc		@ end of function/procedure
107
108	.end		@ end of assembly code
109
110