-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio.cpp
More file actions
184 lines (164 loc) · 4.76 KB
/
audio.cpp
File metadata and controls
184 lines (164 loc) · 4.76 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <audio/Audio.h>
#ifdef LOOPER_USB_AUDIO
#include <audio/input_usb.h>
#include <audio/output_usb.h>
#endif
#ifdef LOOPER_OTG_AUDIO
#include <audio/input_otg.h>
#include <audio/output_otg.h>
#endif
#include "Looper.h"
#include "LooperVersion.h"
#include "apcKey25.h"
#include <circle/logger.h>
#include <circle/timer.h>
#ifdef LOOPER_LIVE_PITCH
#include "patches/RubberBandWrapper.h"
#endif
#define log_name "audio"
#if defined(LOOPER_USB_AUDIO) && defined(LOOPER_OTG_AUDIO)
#pragma message("compiling for LOOPER_USB_AUDIO + LOOPER_OTG_AUDIO")
#define USE_CS42448 0
#define USE_TEENSY_QUAD_SLAVE 0
#define USE_STANDARD_I2S 0
#define USE_USB_AUDIO 1
#define USE_OTG_AUDIO 1
#elif defined(LOOPER_USB_AUDIO)
#pragma message("compiling for LOOPER_USB_AUDIO")
#define USE_CS42448 0
#define USE_TEENSY_QUAD_SLAVE 0
#define USE_STANDARD_I2S 0
#define USE_USB_AUDIO 1
#define USE_OTG_AUDIO 0
#elif defined(LOOPER3)
#pragma message("compiling for LOOPER3")
#define USE_CS42448 0
#define USE_TEENSY_QUAD_SLAVE 1
#define USE_STANDARD_I2S 0
#define USE_USB_AUDIO 0
#define USE_OTG_AUDIO 0
#else
#pragma message("compiling for LOOPER2")
#define USE_CS42448 1
#define USE_TEENSY_QUAD_SLAVE 0
#define USE_STANDARD_I2S 0
#define USE_USB_AUDIO 0
#define USE_OTG_AUDIO 0
#endif
#define USE_WM8731 0
#define USE_STGL5000 0
#if USE_CS42448
#pragma message("Looper::audio.cpp using CS42448 (octo)")
AudioInputTDM input;
AudioOutputTDM output;
AudioControlCS42448 control;
#elif USE_WM8731
#pragma message("Looper::audio.cpp using WM8731")
#define WM8731_IS_I2S_MASTER 1
AudioInputI2S input;
AudioOutputI2S output;
#if WM8731_IS_I2S_MASTER
AudioControlWM8731 control;
#else
AudioControlWM8731Slave control;
#endif
#elif USE_STGL5000
#pragma message("Looper::audio.cpp using STGL5000")
AudioInputI2S input;
AudioOutputI2S output;
AudioControlSGTL5000 control;
#elif USE_TEENSY_QUAD_SLAVE
#pragma message("Looper::audio.cpp using TEENSY_QUAD_SLAVE")
AudioInputTeensyQuad input;
AudioOutputTeensyQuad output;
#elif USE_STANDARD_I2S
AudioInputI2S input;
AudioOutputI2S output;
#pragma message("Looper::audio.cpp using STANDARD I2S")
#elif USE_USB_AUDIO
AudioInputUSB input;
AudioOutputUSB output;
#pragma message("Looper::audio.cpp using USB AUDIO")
#endif
#if USE_OTG_AUDIO
AudioInputOTG otgIn;
AudioOutputOTG otgOut;
#endif
#ifdef LOOPER_LIVE_PITCH
RubberBandWrapper *pLivePitchWrapper = 0;
#endif
loopMachine *pTheLoopMachine = 0;
publicLoopMachine *pTheLooper = 0;
extern "C" void debug_blink(int n);
void setup()
{
debug_blink(1);
LOG("Looper " LOOPER_VERSION " starting at audio.cpp setup(%dx%d)",
LOOPER_NUM_TRACKS,
LOOPER_NUM_LAYERS);
debug_blink(1);
pTheLoopMachine = new loopMachine();
pTheLooper = (publicLoopMachine *) pTheLoopMachine;
debug_blink(1);
#ifdef LOOPER_LIVE_PITCH
pLivePitchWrapper = new RubberBandWrapper(AUDIO_SAMPLE_RATE, LOOPER_NUM_CHANNELS);
new AudioConnection(input, 0, *pLivePitchWrapper, 0);
new AudioConnection(input, 1, *pLivePitchWrapper, 1);
new AudioConnection(*pLivePitchWrapper, 0, *pTheLooper, 0);
new AudioConnection(*pLivePitchWrapper, 1, *pTheLooper, 1);
#else
new AudioConnection(input, 0, *pTheLooper, 0);
new AudioConnection(input, 1, *pTheLooper, 1);
#endif
new AudioConnection(*pTheLooper, 0, output, 0);
new AudioConnection(*pTheLooper, 1, output, 1);
debug_blink(1);
AudioSystem::initialize(200);
debug_blink(1);
#if USE_OTG_AUDIO
otgIn.start();
otgOut.start();
#endif
pTheLooper->setControl(LOOPER_CONTROL_OUTPUT_GAIN,0);
pTheLooper->setControl(LOOPER_CONTROL_INPUT_GAIN,0);
delay(100);
#if USE_WM8731
control.inputSelect(AUDIO_INPUT_LINEIN);
#endif
#if USE_STGL5000
control.setDefaults();
#endif
for (int i=LOOPER_CONTROL_THRU_VOLUME; i<=LOOPER_CONTROL_MIX_VOLUME; i++)
{
pTheLooper->setControl(i,pTheLooper->getControlDefault(i));
}
float default_out_val = pTheLooper->getControlDefault(LOOPER_CONTROL_OUTPUT_GAIN);
float default_in_val = pTheLooper->getControlDefault(LOOPER_CONTROL_INPUT_GAIN);
for (int j=0; j<20; j++)
{
u8 in_val = roundf(default_in_val * ((float)j)/20.00);
u8 out_val = roundf(default_out_val * ((float)j)/20.00);
pTheLooper->setControl(LOOPER_CONTROL_INPUT_GAIN,in_val);
delay(30);
pTheLooper->setControl(LOOPER_CONTROL_OUTPUT_GAIN,out_val);
delay(30);
}
new apcKey25();
LOG("aLooper::audio.cpp setup() finished",0);
}
void loop()
{
#ifdef LOOPER_LIVE_PITCH
if (pLivePitchWrapper && pTheAPC && pTheAPC->m_transposeLocked)
pLivePitchWrapper->updateRatios();
#endif
if (pTheLooper) {
logString_t *msg;
while ((msg = pTheLooper->getNextLogString()) != nullptr) {
CLogger::Get()->Write(msg->lname, LogNotice, *msg->string);
delete msg->string;
delete msg;
}
}
if (pTheAPC) pTheAPC->update();
}