summaryrefslogtreecommitdiffstats
path: root/arm-wt-22k/lib_src/ARM-E_mastergain_gnu.s
blob: b4e905be79622936d24155227fa3224e361371fd (plain)
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
@***********************************************************
@ Function:    SynthMasterGain
@ Processor:   ARM-E
@ Description: Copies 32-bit synth output to 16-bit buffer
@              with saturated gain control
@              C-callable.
@
@ Usage: 
@	SynthMasterGain(
@			pInputBuffer
@			pOutputBuffer,
@			nGain,
@			nNumLoopSamples
@	);
@
@ Copyright Sonic Network Inc. 2004
@****************************************************************
@ Revision Control:
@   $Revision: 496 $
@   $Date: 2006-12-11 14:33:26 -0800 (Mon, 11 Dec 2006) $
@****************************************************************
@
@   where:
@	long *pInputBuffer
@	PASSED IN: r0
@
@	EAS_PCM *pOutputBuffer
@	PASSED IN: r1
@
@	short nGain
@	PASSED IN: r2
@
@	EAS_U16	nNumLoopSamples
@	PASSED IN: r3
@
@****************************************************************

	.include	"ARM_synth_constants_gnu.inc"

	.arm
	.text

	.func	SynthMasterGain
SynthMasterGain:

	.global	SynthMasterGain	@ allow other files to use this function
	




@ Stack frame
@ -----------
	.equ	RET_ADDR_SZ, 0			@return address
	.equ	REG_SAVE_SZ, 0			@save-on-entry registers saved
	.equ	FRAME_SZ, (8)			@local variables
	.equ	ARG_BLK_SZ, 0			@argument block

	.equ	PARAM_OFFSET, (ARG_BLK_SZ + FRAME_SZ + REG_SAVE_SZ + RET_ADDR_SZ)

@ Register usage
@ --------------
pnInputBuffer	.req	r0
pnOutputBuffer	.req	r1
nGain	.req	r2
nNumLoopSamples	.req	r3

	STMFD	sp!,{r4-r6,r14}					@Save any save-on-entry registers that are used

	LDR		r6, =0x7fff						@constant for saturation tests

loop:
	LDR		r4, [pnInputBuffer], #4			@fetch 1st output sample
	
	LDR		r5, [pnInputBuffer], #4			@fetch 2nd output sample

	SMULWB	r4, r4, nGain					@output = gain * input
	
	CMP		r4, r6							@check for positive saturation
	MOVGT	r4, r6							@saturate
	CMN		r4, r6							@check for negative saturation
	MVNLT	r4, r6							@saturate
	
	SMULWB	r5, r5, nGain					@output = gain * input
	
	STRH	r4, [pnOutputBuffer], #NEXT_OUTPUT_PCM	@save 1st output sample
	
	CMP		r5, r6							@check for positive saturation
	MOVGT	r5, r6							@saturate
	CMN		r5, r6							@check for negative saturation
	MVNLT	r5, r6							@saturate
	STRH	r5, [pnOutputBuffer], #NEXT_OUTPUT_PCM	@save 2nd output sample

	SUBS	nNumLoopSamples, nNumLoopSamples, #2
	BGT		loop

@
@ Return to calling function
@----------------------------------------------------------------

	LDMFD	sp!,{r4-r6, lr}				@ return to calling function
	BX		lr

@*****************************************************************************

	.endfunc		@ end of function/procedure

	.end		@ end of assembly code