User | Revision | Line number | New contents of line |
faker |
0:8e3468376286
|
1
|
/*****************************************************/
|
faker |
0:8e3468376286
|
2
|
/* MBED MULTI EFFECTOR */
|
faker |
0:8e3468376286
|
3
|
/* */
|
faker |
0:8e3468376286
|
4
|
/* */
|
faker |
0:8e3468376286
|
5
|
/*****************************************************/
|
faker |
0:8e3468376286
|
6
|
|
faker |
0:8e3468376286
|
7
|
#include "mbed.h"
|
faker |
0:8e3468376286
|
8
|
#include "TextLCD.h"
|
faker |
0:8e3468376286
|
9
|
#include "R_Sw_Check.h"
|
faker |
0:8e3468376286
|
10
|
#include "Distotion_Unit.h"
|
faker |
0:8e3468376286
|
11
|
|
faker |
0:8e3468376286
|
12
|
Ticker sampling;
|
faker |
0:8e3468376286
|
13
|
AnalogIn Ain(p17);
|
faker |
0:8e3468376286
|
14
|
AnalogOut Aout(p18);
|
faker |
0:8e3468376286
|
15
|
TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3)
|
faker |
0:8e3468376286
|
16
|
DigitalIn Rsw0A(p5);
|
faker |
0:8e3468376286
|
17
|
DigitalIn Rsw0B(p6);
|
faker |
0:8e3468376286
|
18
|
DigitalIn Rsw1A(p7);
|
faker |
0:8e3468376286
|
19
|
DigitalIn Rsw1B(p8);
|
faker |
0:8e3468376286
|
20
|
DigitalIn Rsw2A(p9);
|
faker |
0:8e3468376286
|
21
|
DigitalIn Rsw2B(p10);
|
faker |
0:8e3468376286
|
22
|
DigitalIn Rsw3A(p11);
|
faker |
0:8e3468376286
|
23
|
DigitalIn Rsw3B(p12);
|
faker |
0:8e3468376286
|
24
|
|
faker |
0:8e3468376286
|
25
|
/*******************************/
|
faker |
0:8e3468376286
|
26
|
/* For Test Signal */
|
faker |
0:8e3468376286
|
27
|
/*******************************/
|
faker |
0:8e3468376286
|
28
|
#define TEST_SIGNAL_ENABLE (0) // 1 : Internal SinWave for Debug
|
faker |
0:8e3468376286
|
29
|
#define TEST_SIGNAL_FREQ (1000.0) // Frequency [Hz]
|
faker |
0:8e3468376286
|
30
|
#define TEST_SIGNAL_AMP (30000.0) // Amplitude
|
faker |
0:8e3468376286
|
31
|
#define PAI (3.14159)
|
faker |
0:8e3468376286
|
32
|
|
faker |
0:8e3468376286
|
33
|
/*******************************/
|
faker |
0:8e3468376286
|
34
|
/* For ADC & DAC Setting */
|
faker |
0:8e3468376286
|
35
|
/*******************************/
|
faker |
0:8e3468376286
|
36
|
#define SAMPLING_TIME (25.0) // ADC Sampling Rate [us]
|
faker |
0:8e3468376286
|
37
|
|
faker |
0:8e3468376286
|
38
|
volatile unsigned int *g_usiAd0cr, *g_usiAd0dr2; // ADC Reg
|
faker |
0:8e3468376286
|
39
|
unsigned int *g_usiDacr; // DAC Reg
|
faker |
0:8e3468376286
|
40
|
unsigned int g_usiFinalOut;
|
faker |
0:8e3468376286
|
41
|
int g_ssBuff[10];
|
faker |
0:8e3468376286
|
42
|
float g_fTestWaveT;
|
faker |
0:8e3468376286
|
43
|
|
faker |
0:8e3468376286
|
44
|
/*******************************/
|
faker |
0:8e3468376286
|
45
|
/* Effect Process */
|
faker |
0:8e3468376286
|
46
|
/*******************************/
|
faker |
0:8e3468376286
|
47
|
void effectProcess() {
|
faker |
0:8e3468376286
|
48
|
// Line Out
|
faker |
0:8e3468376286
|
49
|
*g_usiDacr = g_usiFinalOut;
|
faker |
0:8e3468376286
|
50
|
// ADC Start
|
faker |
0:8e3468376286
|
51
|
*g_usiAd0cr = 0x01200204;
|
faker |
0:8e3468376286
|
52
|
|
faker |
0:8e3468376286
|
53
|
#if (TEST_SIGNAL_ENABLE == 1) // Test Signal Sin Wave
|
faker |
0:8e3468376286
|
54
|
g_ssBuff[0] = TEST_SIGNAL_AMP * sin(g_fTestWaveT);
|
faker |
0:8e3468376286
|
55
|
g_fTestWaveT = g_fTestWaveT + 2.0 * PAI * SAMPLING_TIME * TEST_SIGNAL_FREQ / 1e6;
|
faker |
0:8e3468376286
|
56
|
if (g_fTestWaveT >= (2.0 * PAI))g_fTestWaveT = 0;
|
faker |
0:8e3468376286
|
57
|
#endif
|
faker |
0:8e3468376286
|
58
|
|
faker |
0:8e3468376286
|
59
|
//
|
faker |
0:8e3468376286
|
60
|
// Effect Func();
|
faker |
0:8e3468376286
|
61
|
//
|
faker |
0:8e3468376286
|
62
|
|
faker |
0:8e3468376286
|
63
|
g_ssBuff[1] = distotion(g_ssBuff[0]);
|
faker |
0:8e3468376286
|
64
|
|
faker |
0:8e3468376286
|
65
|
//
|
faker |
0:8e3468376286
|
66
|
// Effect Func();
|
faker |
0:8e3468376286
|
67
|
//
|
faker |
0:8e3468376286
|
68
|
|
faker |
0:8e3468376286
|
69
|
#if (TEST_SIGNAL_ENABLE == 0)
|
faker |
0:8e3468376286
|
70
|
while (1) {
|
faker |
0:8e3468376286
|
71
|
if ((*g_usiAd0dr2 & 0x80000000) != 0)break; // ADC Done ?
|
faker |
0:8e3468376286
|
72
|
}
|
faker |
0:8e3468376286
|
73
|
g_ssBuff[0] = (int)(*g_usiAd0dr2 & 0x0000FFF0) - 32768;
|
faker |
0:8e3468376286
|
74
|
#endif
|
faker |
0:8e3468376286
|
75
|
|
faker |
0:8e3468376286
|
76
|
g_usiFinalOut = 0x00010000 | (g_ssBuff[1] + 32768);
|
faker |
0:8e3468376286
|
77
|
}
|
faker |
0:8e3468376286
|
78
|
|
faker |
0:8e3468376286
|
79
|
|
faker |
0:8e3468376286
|
80
|
/*******************************/
|
faker |
0:8e3468376286
|
81
|
/* MAIN */
|
faker |
0:8e3468376286
|
82
|
/*******************************/
|
faker |
0:8e3468376286
|
83
|
int main() {
|
faker |
0:8e3468376286
|
84
|
|
faker |
0:8e3468376286
|
85
|
int iParamSwPol[4];
|
faker |
0:8e3468376286
|
86
|
|
faker |
0:8e3468376286
|
87
|
// LCD INIT
|
faker |
0:8e3468376286
|
88
|
lcd.cls();
|
faker |
0:8e3468376286
|
89
|
lcd.locate(0,0);
|
faker |
0:8e3468376286
|
90
|
lcd.printf("Dist Mode Type %d", g_distMode);
|
faker |
0:8e3468376286
|
91
|
lcd.locate(0,1);
|
faker |
0:8e3468376286
|
92
|
lcd.printf("Input Gain %4.1f", g_inputGain);
|
faker |
0:8e3468376286
|
93
|
lcd.locate(0,2);
|
faker |
0:8e3468376286
|
94
|
lcd.printf("Clip Level %6d", g_clipLevel);
|
faker |
0:8e3468376286
|
95
|
lcd.locate(0,3);
|
faker |
0:8e3468376286
|
96
|
lcd.printf("Output Gain %4.1f", g_outputGain);
|
faker |
0:8e3468376286
|
97
|
|
faker |
0:8e3468376286
|
98
|
// ADC & DAC SETTING
|
faker |
0:8e3468376286
|
99
|
g_usiAd0cr = (unsigned int*)0x40034000;
|
faker |
0:8e3468376286
|
100
|
g_usiAd0dr2 = (unsigned int*)0x40034018;
|
faker |
0:8e3468376286
|
101
|
g_usiDacr = (unsigned int*)0x4008C000;
|
faker |
0:8e3468376286
|
102
|
|
faker |
0:8e3468376286
|
103
|
// SAMPLING TIMER START
|
faker |
0:8e3468376286
|
104
|
sampling.attach_us(&effectProcess, SAMPLING_TIME);
|
faker |
0:8e3468376286
|
105
|
|
faker |
0:8e3468376286
|
106
|
|
faker |
0:8e3468376286
|
107
|
while (1) {
|
faker |
0:8e3468376286
|
108
|
|
faker |
0:8e3468376286
|
109
|
//
|
faker |
0:8e3468376286
|
110
|
// Parameter Setting Func
|
faker |
0:8e3468376286
|
111
|
//
|
faker |
0:8e3468376286
|
112
|
|
faker |
0:8e3468376286
|
113
|
switch(ucRotarySwPol(Rsw0A, Rsw0B, Rsw1A, Rsw1B, Rsw2A, Rsw2B, Rsw3A, Rsw3B, iParamSwPol)){
|
faker |
0:8e3468376286
|
114
|
case 0: g_distMode = g_distMode + iParamSwPol[0];
|
faker |
0:8e3468376286
|
115
|
if(g_distMode <= 0)g_distMode = 3;
|
faker |
0:8e3468376286
|
116
|
if(g_distMode > 3)g_distMode = 1;
|
faker |
0:8e3468376286
|
117
|
lcd.locate(0,0);
|
faker |
0:8e3468376286
|
118
|
lcd.printf(" ");
|
faker |
0:8e3468376286
|
119
|
lcd.locate(0,0);
|
faker |
0:8e3468376286
|
120
|
lcd.printf("Dist Mode Type %d", g_distMode);
|
faker |
0:8e3468376286
|
121
|
break;
|
faker |
0:8e3468376286
|
122
|
case 1: g_inputGain = g_inputGain + 0.5 * iParamSwPol[1];
|
faker |
0:8e3468376286
|
123
|
lcd.locate(0,1);
|
faker |
0:8e3468376286
|
124
|
lcd.printf(" ");
|
faker |
0:8e3468376286
|
125
|
lcd.locate(0,1);
|
faker |
0:8e3468376286
|
126
|
lcd.printf("Input Gain %4.1f", g_inputGain);
|
faker |
0:8e3468376286
|
127
|
break;
|
faker |
0:8e3468376286
|
128
|
case 2: g_clipLevel = g_clipLevel + 1000 * iParamSwPol[2];
|
faker |
0:8e3468376286
|
129
|
lcd.locate(0,2);
|
faker |
0:8e3468376286
|
130
|
lcd.printf(" ");
|
faker |
0:8e3468376286
|
131
|
lcd.locate(0,2);
|
faker |
0:8e3468376286
|
132
|
lcd.printf("Clip Level %6d", g_clipLevel);
|
faker |
0:8e3468376286
|
133
|
break;
|
faker |
0:8e3468376286
|
134
|
case 3: g_outputGain = g_outputGain + 0.5 * iParamSwPol[3];
|
faker |
0:8e3468376286
|
135
|
lcd.locate(0,3);
|
faker |
0:8e3468376286
|
136
|
lcd.printf(" ");
|
faker |
0:8e3468376286
|
137
|
lcd.locate(0,3);
|
faker |
0:8e3468376286
|
138
|
lcd.printf("Output Gain %4.1f", g_outputGain);
|
faker |
0:8e3468376286
|
139
|
break;
|
faker |
0:8e3468376286
|
140
|
default:break;
|
faker |
0:8e3468376286
|
141
|
}
|
faker |
0:8e3468376286
|
142
|
|
faker |
0:8e3468376286
|
143
|
//
|
faker |
0:8e3468376286
|
144
|
// Parameter Setting Func
|
faker |
0:8e3468376286
|
145
|
//
|
faker |
0:8e3468376286
|
146
|
|
faker |
0:8e3468376286
|
147
|
}
|
faker |
0:8e3468376286
|
148
|
}
|
faker |
0:8e3468376286
|
149
|
|