This commit is contained in:
chriskiefer 2025-05-02 14:57:46 +01:00
parent dd362158b7
commit f3a2dd9479

View file

@ -100,23 +100,19 @@ public:
void SaveInput(saving_mode_t mode) void SaveInput(saving_mode_t mode)
{ {
if (training_mode_ == TRAINING_MODE) { if (STORE_VALUE_MODE == mode) {
if (STORE_VALUE_MODE == mode) {
Serial.println("Move input to position..."); Serial.println("Move input to position...");
perform_inference_ = false; perform_inference_ = false;
} else { // STORE_POSITION_MODE } else { // STORE_POSITION_MODE
Serial.println("Creating example in this position."); Serial.println("Creating example in this position.");
// Save pair in the dataset // Save pair in the dataset
dataset_->Add(input_state_, output_state_); dataset_->Add(input_state_, output_state_);
perform_inference_ = true; perform_inference_ = true;
MLInference_(input_state_); MLInference_(input_state_);
}
} else {
Serial.println("Switch to training mode first.");
} }
} }
@ -125,8 +121,6 @@ public:
if (training_mode_ == TRAINING_MODE) { if (training_mode_ == TRAINING_MODE) {
Serial.println("Clearing dataset..."); Serial.println("Clearing dataset...");
dataset_->Clear(); dataset_->Clear();
} else {
Serial.println("Switch to training mode first.");
} }
} }
@ -136,8 +130,6 @@ public:
Serial.println("Randomising weights..."); Serial.println("Randomising weights...");
MLRandomise_(); MLRandomise_();
MLInference_(input_state_); MLInference_(input_state_);
} else {
Serial.println("Switch to training mode first.");
} }
} }
@ -284,22 +276,28 @@ protected:
} }
}; };
class SubtractiveSynthAudioApp : public AudioAppBase class AudioTestApp : public AudioAppBase
{ {
public: public:
static constexpr size_t kN_Params = 10; static constexpr size_t kN_Params = 10;
SubtractiveSynthAudioApp() : AudioAppBase() {} AudioTestApp() : AudioAppBase() {}
stereosample_t Process(const stereosample_t x) override stereosample_t Process(const stereosample_t x) override
{ {
float y = osc1.sawn(osc1freq); if (frame++ == 48000) {
y += osc2.sawn(osc2freq); frame = 0;
y += osc3.sawn(osc3freq); nSines++;
float lfo1val = (lfo1.triangle(lfo1freq) * lfo1depth); nSinesRcpr = 1.f/nSines;
svf.setParams(filter1freq * (1.f + lfo1val),filter1res); Serial.printf("N: %d\n", nSines);
y = svf.play(y, filterMix,1.0-filterMix,0,0); }
y *= 0.9f; float y = 0.f;
float freq=200;
for(size_t i=0; i < nSines; i++) {
y += oscs[i].sinebuf(freq);
freq+=10;
}
y *= nSinesRcpr;
stereosample_t ret { y, y }; stereosample_t ret { y, y };
return ret; return ret;
} }
@ -307,6 +305,7 @@ public:
void Setup(float sample_rate, std::shared_ptr<InterfaceBase> interface) override void Setup(float sample_rate, std::shared_ptr<InterfaceBase> interface) override
{ {
AudioAppBase::Setup(sample_rate, interface); AudioAppBase::Setup(sample_rate, interface);
oscs.resize(500);
// Additional setup code specific to FMSynthAudioApp // Additional setup code specific to FMSynthAudioApp
} }
@ -315,42 +314,16 @@ public:
// // Map parameters to the synth // // Map parameters to the synth
// synth_.mapParameters(params); // synth_.mapParameters(params);
// //Serial.print("Params processed."); // //Serial.print("Params processed.");
osc1freq = 50.f + (params[0] * 50.f);
osc2freq = osc1freq * (1.f + (params[1] * 0.1f));
osc3freq = osc1freq * (1.f + (params[2] * 0.5f));
filter1freq = 80.f + (params[3] * params[3] * 5000.f);
filter1res = (params[4] * 8.f);
lfo1freq = 0.1f + (params[5] * params[5] * 20.f);
lfo1depth = params[6] * 0.5f;
filterMix = params[7];
} }
protected: protected:
maxiOsc osc1; maxiOsc osc1;
maxiOsc osc2; std::vector<maxiOsc> oscs;
maxiOsc osc3; size_t frame=0;
maxiOsc lfo1; size_t nSines=1;
maxiOsc lfo2; float nSinesRcpr=1;
float osc1freq = 100;
float osc2freq = 101;
float osc3freq = 102;
float lfo1freq = 1;
float lfo1depth = 0.1;
maxiFilter filter1;
maxiSVF svf;
float filter1freq = 100;
float filter1res = 2.f;
float filterMix=1;
}; };
@ -359,7 +332,7 @@ protected:
// Global objects // Global objects
std::shared_ptr<IMLInterface> interface; std::shared_ptr<IMLInterface> interface;
std::shared_ptr<SubtractiveSynthAudioApp> audio_app; std::shared_ptr<AudioTestApp> audio_app;
// Inter-core communication // Inter-core communication
volatile bool core_0_ready = false; volatile bool core_0_ready = false;
@ -417,8 +390,7 @@ void bind_interface(std::shared_ptr<IMLInterface> interface)
}); });
MEMLNaut::Instance()->setRVGain1Callback([interface] (float value) { MEMLNaut::Instance()->setRVGain1Callback([interface] (float value) {
AudioDriver::setHeadphoneVolume(value); AudioDriver::setDACVolume(value);
Serial.println(value*4);
}); });
} }
@ -426,7 +398,7 @@ void bind_interface(std::shared_ptr<IMLInterface> interface)
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
//while (!Serial) {} while (!Serial) {}
Serial.println("Serial initialised."); Serial.println("Serial initialised.");
WRITE_VOLATILE(serial_ready, true); WRITE_VOLATILE(serial_ready, true);
@ -437,7 +409,7 @@ void setup()
// Setup interface with memory barrier protection // Setup interface with memory barrier protection
{ {
auto temp_interface = std::make_shared<IMLInterface>(); auto temp_interface = std::make_shared<IMLInterface>();
temp_interface->setup(kN_InputParams, SubtractiveSynthAudioApp::kN_Params); temp_interface->setup(kN_InputParams, AudioTestApp::kN_Params);
MEMORY_BARRIER(); MEMORY_BARRIER();
interface = temp_interface; interface = temp_interface;
MEMORY_BARRIER(); MEMORY_BARRIER();
@ -487,7 +459,7 @@ void setup1()
// Create audio app with memory barrier protection // Create audio app with memory barrier protection
{ {
auto temp_audio_app = std::make_shared<SubtractiveSynthAudioApp>(); auto temp_audio_app = std::make_shared<AudioTestApp>();
temp_audio_app->Setup(AudioDriver::GetSampleRate(), interface); temp_audio_app->Setup(AudioDriver::GetSampleRate(), interface);
MEMORY_BARRIER(); MEMORY_BARRIER();
audio_app = temp_audio_app; audio_app = temp_audio_app;