eas_chorusdata.h revision 7df30109963092559d3760c0661a020f9daf1030
1/*----------------------------------------------------------------------------
2 *
3 * File:
4 * eas_chorusdata.h
5 *
6 * Contents and purpose:
7 * Contains the prototypes for the Chorus effect.
8 *
9 *
10 * Copyright Sonic Network Inc. 2006
11
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 *      http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 *----------------------------------------------------------------------------
25 * Revision Control:
26 *   $Revision: 309 $
27 *   $Date: 2006-09-12 18:52:45 -0700 (Tue, 12 Sep 2006) $
28 *----------------------------------------------------------------------------
29*/
30
31#ifndef _EAS_CHORUS_H
32#define _EAS_CHORUS_H
33
34#include "eas_types.h"
35#include "eas_audioconst.h"
36
37//defines for chorus
38
39#define EAS_CHORUS_BYPASS_DEFAULT	1
40#define EAS_CHORUS_PRESET_DEFAULT	0
41#define EAS_CHORUS_RATE_DEFAULT		30
42#define EAS_CHORUS_DEPTH_DEFAULT	39
43#define EAS_CHORUS_LEVEL_DEFAULT	32767
44
45#define EAS_CHORUS_LEVEL_MIN		0
46#define EAS_CHORUS_LEVEL_MAX		32767
47
48#define EAS_CHORUS_RATE_MIN			10
49#define EAS_CHORUS_RATE_MAX			50
50
51#define EAS_CHORUS_DEPTH_MIN		15
52#define EAS_CHORUS_DEPTH_MAX		60
53
54#define CHORUS_SIZE_MS 20
55#define CHORUS_L_SIZE ((CHORUS_SIZE_MS*_OUTPUT_SAMPLE_RATE)/1000)
56#define CHORUS_R_SIZE CHORUS_L_SIZE
57#define CHORUS_SHAPE_SIZE 128
58#define CHORUS_DELAY_MS 10
59
60#define CHORUS_MAX_TYPE			4	// any Chorus numbers larger than this are invalid
61
62typedef struct
63{
64	EAS_I16				m_nRate;
65	EAS_I16				m_nDepth;
66	EAS_I16				m_nLevel;
67
68} S_CHORUS_PRESET;
69
70typedef struct
71{
72	S_CHORUS_PRESET		m_sPreset[CHORUS_MAX_TYPE];	//array of presets
73
74} S_CHORUS_PRESET_BANK;
75
76/* parameters for each Chorus */
77typedef struct
78{
79	EAS_I32 lfoLPhase;
80	EAS_I32 lfoRPhase;
81	EAS_I16 chorusIndexL;
82	EAS_I16 chorusIndexR;
83	EAS_U16 chorusTapPosition;
84
85	EAS_I16 m_nRate;
86	EAS_I16 m_nDepth;
87	EAS_I16 m_nLevel;
88
89	//delay lines used by the chorus, longer would sound better
90	EAS_PCM chorusDelayL[CHORUS_L_SIZE];
91	EAS_PCM chorusDelayR[CHORUS_R_SIZE];
92
93	EAS_BOOL	bypass;
94	EAS_I8		preset;
95
96	EAS_I16		m_nCurrentChorus;			// preset number for current Chorus
97	EAS_I16		m_nNextChorus;				// preset number for next Chorus
98
99	S_CHORUS_PRESET			pPreset;
100
101	S_CHORUS_PRESET_BANK	m_sPreset;
102
103} S_CHORUS_OBJECT;
104
105
106/*----------------------------------------------------------------------------
107 * WeightedTap()
108 *----------------------------------------------------------------------------
109 * Purpose: Does fractional array look-up using linear interpolation
110 *
111 * first convert indexDesired to actual desired index by taking into account indexReference
112 * then do linear interpolation between two actual samples using fractional part
113 *
114 * Inputs:
115 * array: pointer to array of signed 16 bit values, typically either PCM data or control data
116 * indexReference: the circular buffer relative offset
117 * indexDesired: the fractional index we are looking up (16 bits index + 16 bits fraction)
118 * indexLimit: the total size of the array, used to compute buffer wrap
119 *
120 * Outputs:
121 * Value from the input array, linearly interpolated between two actual data values
122 *
123 *----------------------------------------------------------------------------
124*/
125static EAS_I16 WeightedTap(const EAS_I16 *array, EAS_I16 indexReference, EAS_I32 indexDesired, EAS_I16 indexLimit);
126
127/*----------------------------------------------------------------------------
128 * ChorusReadInPresets()
129 *----------------------------------------------------------------------------
130 * Purpose: sets global Chorus preset bank to defaults
131 *
132 * Inputs:
133 *
134 * Outputs:
135 *
136 *----------------------------------------------------------------------------
137*/
138static EAS_RESULT ChorusReadInPresets(S_CHORUS_OBJECT *pChorusData);
139
140/*----------------------------------------------------------------------------
141 * ChorusUpdate
142 *----------------------------------------------------------------------------
143 * Purpose:
144 * Update the Chorus preset parameters as required
145 *
146 * Inputs:
147 *
148 * Outputs:
149 *
150 *
151 * Side Effects:
152 * - chorus paramters will be changed
153 * - m_nCurrentChorus := m_nNextChorus
154 *----------------------------------------------------------------------------
155*/
156static EAS_RESULT ChorusUpdate(S_CHORUS_OBJECT* pChorusData);
157
158#endif /* #ifndef _EAS_CHORUSDATA_H */
159
160
161