From c1ce9f1fc92b22aa1c553fe0ce53a05b4decc847 Mon Sep 17 00:00:00 2001 From: Andrea Martelloni Date: Mon, 8 Sep 2025 12:21:31 +0100 Subject: [PATCH] RL changes to integrate display --- MEMLNaut-PAF-CARL.ino | 18 +++++++------ PAFSynthAudioApp.hpp | 61 +++++++++++++++++++++++++++++++++++++++++++ src/memllib | 2 +- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/MEMLNaut-PAF-CARL.ino b/MEMLNaut-PAF-CARL.ino index 326c1a2..4b04c6f 100644 --- a/MEMLNaut-PAF-CARL.ino +++ b/MEMLNaut-PAF-CARL.ino @@ -12,8 +12,6 @@ #define APP_SRAM __not_in_flash("app") -// display APP_SRAM scr; - bool core1_disable_systick = true; bool core1_separate_stack = true; @@ -35,7 +33,8 @@ std::shared_ptr APP_SRAM RLInterface; std::shared_ptr APP_SRAM midi_interf; - +// Statically allocated, properly aligned storage in AUDIO_MEM for objects +alignas(PAFSynthAudioApp) char AUDIO_MEM audio_app_mem[sizeof(PAFSynthAudioApp)]; std::shared_ptr __scratch_y("audio") audio_app; // Inter-core communication @@ -89,7 +88,7 @@ void setup() // Setup interface with memory barrier protection WRITE_VOLATILE(interface_ready, true); // Bind interface after ensuring it's fully initialized - // RLInterface->bind_RL_interface(scr); + RLInterface->bind_RL_interface(); // Serial.println("Bound RL interface to MEMLNaut."); midi_interf = std::make_shared(); @@ -100,7 +99,7 @@ void setup() midi_interf->SetNoteCallback([RLInterface] (bool noteon, uint8_t note_number, uint8_t vel_value) { if (noteon) { uint8_t midimsg[2] = {note_number, vel_value }; - queue_try_add(&audio_app->qMIDINoteOn, &midimsg); + queue_try_add(&audio_app->qMIDINoteOn, &midimsg); } Serial.printf("MIDI Note %d: %d\n", note_number, vel_value); }); @@ -157,10 +156,13 @@ void setup1() // Create audio app with memory barrier protection { - auto temp_audio_app = std::make_shared(); + PAFSynthAudioApp* audio_raw = new (audio_app_mem) PAFSynthAudioApp(); + audio_raw->Setup(AudioDriver::GetSampleRate(), RLInterface); - temp_audio_app->Setup(AudioDriver::GetSampleRate(), RLInterface); - // temp_audio_app->Setup(AudioDriver::GetSampleRate(), dynamic_cast> (mlMode == IML ? interfaceIML : RLInterface)); + // shared_ptr with custom deleter calling only the destructor (control block still allocates) + auto audio_deleter = [](PAFSynthAudioApp* p) { if (p) p->~PAFSynthAudioApp(); }; + std::shared_ptr temp_audio_app(audio_raw, audio_deleter); + MEMORY_BARRIER(); audio_app = temp_audio_app; MEMORY_BARRIER(); diff --git a/PAFSynthAudioApp.hpp b/PAFSynthAudioApp.hpp index 8920325..b274891 100644 --- a/PAFSynthAudioApp.hpp +++ b/PAFSynthAudioApp.hpp @@ -27,6 +27,67 @@ public: stereosample_t __force_inline Process(const stereosample_t x) override; + float __force_inline ProcessLean() + { + float x1[1]; + + // const float trig = pulse.square(1); + + paf0.play(x1, 1, baseFreq, baseFreq + (paf0_cf * baseFreq), paf0_bw * baseFreq, paf0_vib, paf0_vfr, paf0_shift, 0); + float y = x1[0]; + + const float freq1 = baseFreq * detune; + + paf1.play(x1, 1, freq1, freq1 + (paf1_cf * freq1), paf1_bw * freq1, paf1_vib, paf1_vfr, paf1_shift, 1); + y += x1[0]; + + const float freq2 = freq1 * detune; + + paf2.play(x1, 1, freq2, freq2 + (paf2_cf * freq2), paf2_bw * freq2, paf2_vib, paf2_vfr, paf2_shift, 1); + y += x1[0]; + + #ifdef ARPEGGIATOR + const float ph = phasorOsc.phasor(1); + const bool euclidNewNote = euclidean(ph, 12, euclidN, 0, 0.1f); + if(zxdetect.onZX(euclidNewNote)) { + envamp=0.8f; + freqIndex++; + if(freqIndex >= nFREQs) { + freqIndex = 0; + } + baseFreq = frequencies[freqIndex]; + }else{ + // constexpr float envdec = 0.2f/9000.f; + envamp -= envdec; + if (envamp < 0.f) { + envamp = 0.f; + } + } + #else + if(newNote) { + newNote = false; + envamp=0.8f; + }else{ + // constexpr float envdec = 0.2f/9000.f; + envamp -= envdec; + if (envamp < 0.f) { + envamp = 0.f; + } + } + #endif) + y = y * envamp* envamp; + + #ifndef ARPEGGIATOR + y *= noteVel; + #endif + + float d1 = (dl1.play(y, 3500, 0.8f) * dl1mix); + // float d2 = (dl2.play(y, 15000, 0.8f) * dl2mix); + y = y + d1;// + d2; + frame++; + return y; + } + void Setup(float sample_rate, std::shared_ptr interface) override; void ProcessParams(const std::vector& params) override; diff --git a/src/memllib b/src/memllib index 5998f31..a85fab4 160000 --- a/src/memllib +++ b/src/memllib @@ -1 +1 @@ -Subproject commit 5998f312f887b60d13ce3437c0dca5cbf3df819b +Subproject commit a85fab44b44034098cec31285bfd68f4a041b33a