Repository navigation
Expand file tree
/
Copy pathTracker.cpp
More file actions
245 lines (209 loc) · 6.82 KB
/
Copy pathTracker.cpp
File metadata and controls
245 lines (209 loc) · 6.82 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include "Platform.h"
#include "Profiler.h"
#include "TrackerImpl.h"
#include "mtWavetableEnvelopes.h"
#include "core/interface.h"
#include "elapsedMillis.h"
#include "fileManager.h"
#include "mtAudioEngine.h"
#include "mtAudioExport.h"
#include "mtConfig.h"
#include "mtHardware.h"
#include "mtMidi.h"
#include "mtPadsBacklight.h"
#include "mtSequencer.h"
#include "mtSleep.h"
#include "mtSliceDetector.h"
#include "mods.h" // MT:
#include "lockupRecorder.h" // MT:
#include "songloop.h" // MT:
#include <cr_section_macros.h>
//----------------------------------- EXTERNAL RAM CONFIGURATION --------------------------------
// clang-format off
__attribute__((section(".sample_memory"), used)) int16_t externalRamSampleMemory[SAMPLE_MEMORY_SIZE / 2];
__attribute__((section(".delay_memory"), used)) int16_t externalRamDelayBuff[DELAY_MEMORY_SIZE / 2];
__attribute__((section(".reverb_memory"), used)) uint16_t externalRamReverbBuff[REVERB_MEMORY_SIZE / 2];
__attribute__((section(".scratch_memory"), aligned(32), used)) uint8_t externalRamScratchBuff[SHARED_SCRATCH_MEMORY_SIZE];
// clang-format on
int16_t* externalRamEffectsBuff = externalRamSampleMemory + (EDIT_BUFF_OFFSET / 2);
int16_t* externalRamSampleMemoryBegin = externalRamSampleMemory;
//--------------------------------------------------------------------------------------------------------------
static TrackerImpl instance;
extern void onPowerButtonChange(int value);
extern void onSDCardSlotChange(bool state);
void startDisplay(Platform* platform)
{
[[maybe_unused]] bool powerButtonState = platform->getPowerButtonState();
display.begin(platform->getDisplayDriver(), platform->getTimer());
#ifdef PLATFORM_IMX
// delay to hide white screen before driver initialize the screen
platform->getTimer()->delay(200);
#endif
#ifdef TRACKER_MINI
// only in release build mode (always start device immediately in debug mode)
#if !defined(DEBUG) && !defined(FORCED_AUTOSTART)
if (platform->readForceStartUp() == false &&
(!powerButtonState || platform->getBattery()->isEmpty()))
{
Battery* battery = platform->getBattery();
display.showBatteryScreen(
battery->isEmpty(), battery->getCharging(), battery->getLevel(), battery->getVoltage());
platform->getTimer()->delay(100);
display.turnOn();
display.showBatteryScreen(
battery->isEmpty(), battery->getCharging(), battery->getLevel(), battery->getVoltage());
platform->getTimer()->delay(2000);
platform->setPowerMode(false);
}
#endif
#endif
display.turnOn();
}
Tracker* Tracker::getInstance()
{
return &instance;
}
TrackerImpl* TrackerImpl::getInstance()
{
return &instance;
}
Platform* TrackerImpl::getPlatform()
{
return platform;
}
#ifdef FEATURE_SYNTH
Synth& TrackerImpl::getSynth()
{
return synth;
}
#endif
const char* Tracker::getVersion()
{
return "1.0";
}
void TrackerImpl::init(Platform* platform)
{
this->platform = platform;
initWavetableEnvelopes();
Timer* timer = getPlatform()->getTimer();
elapsedMicros::init(timer);
elapsedMillis::init(timer);
elapsedMicrosAudio::init(timer);
elapsedMillisAudio::init(timer);
#ifdef PLATFORM_IMX
AudioStream::setUsbAudio(platform->getUsbAudio());
#endif
midiInit(platform->getUartMidi(), platform->getUsbMidi());
platform->setPowerButtonCallback(onPowerButtonChange);
platform->getFileSystem()->setMountEventCallback(onSDCardSlotChange);
#ifdef FEATURE_SYNTH
synth.init(platform, [this]() { return sequencer.getCurrentTempo(); });
engine.init(platform, &synth);
#else
engine.init(platform, nullptr);
#endif
sequencer.init();
sequencer.setCrcCalculator(platform->getCrcCalculator());
padsBacklight.init(500, platform->getLeds());
exporter.init(platform->getFileSystem());
Profiler::getInstance()->init();
newFileManager.setCrcCalculator(platform->getCrcCalculator());
initConfig(platform);
// UI init at the end
#ifdef FEATURE_SYNTH
mtInterface.begin(platform, &synth);
#else
mtInterface.begin(platform, nullptr);
#endif
bool stereoSampleMode = false;
#ifdef PLATFORM_IMX
stereoSampleMode = true;
#endif
#ifdef FEATURE_SYNTH
newFileManager.init(platform->getFileSystem(), &synth, stereoSampleMode);
#else
newFileManager.init(platform->getFileSystem(), nullptr, stereoSampleMode);
#endif
#if MT_MODS // MT: global mod switches from mods.cfg
mods::init(platform->getFileSystem());
#endif
interfaceGlobals.devMode = platform->getFileSystem()->exists("/.develop");
#if defined(PLATFORM_IMX) && defined(ENABLE_DEV_CONSOLE)
if (interfaceGlobals.devMode)
{
// The serial port carries the log and the development console.
Usb* usb = platform->getUsb();
usb->setClassState(Usb::ClassType::kSerial, true);
usb->reset();
}
#endif
}
void TrackerImpl::update()
{
if (lowPower.getLowPowerState() == shutdownStateSleep)
{
return;
}
engine.updateSdStream();
display.update();
engine.updateSdStream();
padsBacklight.update();
exporter.update();
sliceDetector.update();
newFileManager.update();
mtInterface.update();
#if MT_HAS_SONGLOOP // MT: Song Loop: the next pattern on time in Performance
if (mods::on(mods::Mod::songloop))
{
mods::songloop::tick(mods::songloop::ceSide());
}
#endif
engine.updateSdStream();
sequencer.update();
#if MT_MODS // MT: the mods' main-loop work
mods::update();
#endif
#if MT_LOCKUP_RECORDER // MT: diagnostic builds
mods::lockup::update();
#endif
}
void TrackerImpl::updateAudioBuffers(void* left, void* right, int length)
{
if (AudioStream::renderMode)
{
return;
}
#if MT_LOCKUP_RECORDER // MT: diagnostic builds
mods::lockup::audioStart();
#endif
if (platform != nullptr)
{
midiSetAudioBlockStartUs(platform->getTimer()->micros());
}
Profiler::getInstance()->startMeasuringAudio();
midiUpdate();
// Exact hardware I2S sample rate:
// - IMX (Tracker+ and Tracker Mini): PLL4 = 24 MHz * (37 + 15168/24000) / 2 / 4 / 10 / 256 = 44100.0 Hz
// - MK66 (Original Tracker): F_CPU = 180 MHz * 16 / 255 / 256 = 44117.6470588 Hz
#ifdef PLATFORM_IMX
static constexpr float kAudioSampleRate = 44100.0f;
#else
static constexpr float kAudioSampleRate = 44117.6470588f;
#endif
float updateIntervalSeconds = length / kAudioSampleRate;
sequencer.tick(updateIntervalSeconds);
engine.update();
engine.updateAudioBuffers(left, right, length);
Profiler::getInstance()->stopMeasuringAudio();
#if MT_LOCKUP_RECORDER // MT: diagnostic builds
mods::lockup::audioStop();
#endif
}
void TrackerImpl::updateInputAudioBuffers(void* dataI2s, void* dataUsb, int length)
{
engine.updateInputAudioBuffers(dataI2s, dataUsb, length);
}
void (*TrackerImpl::getStartDisplayFunc())(Platform*)
{
return startDisplay;
}