Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions engine/builtin_fx/SonKuSpatialProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor,
bool acceptsMidi() const override {return false;}
bool producesMidi() const override {return false;}
bool isMidiEffect() const override {return false;}
double getTailLengthSeconds() const override {return 0.;}
double getTailLengthSeconds() const override {
return accepted_.ambienceAmount>0.f?0.78:
accepted_.roomAmount>0.f?0.25:0.;
}
int getNumPrograms() override {return 1;}
int getCurrentProgram() override {return 0;}
void setCurrentProgram(int) override {}
Expand Down Expand Up @@ -80,30 +83,40 @@ class SonKuSpatialProcessor final : public juce::AudioProcessor,
void getStateInformation(juce::MemoryBlock& dest) override {
juce::MemoryOutputStream out(dest,false);
out.writeInt(0x534F4E4B); // SONK
out.writeInt(1);
out.writeInt(2); // v1 sessions remain readable; v2 adds SPACE
out.writeFloat(accepted_.startAzimuthDegrees);
out.writeFloat(accepted_.revolutionSeconds);
out.writeFloat(accepted_.stereoSpreadDegrees);
out.writeFloat(accepted_.spatialMix);
out.writeFloat(accepted_.outputTrim);
out.writeByte(accepted_.moving?1:0);
out.writeByte(accepted_.clockwise?1:0);
out.writeFloat(accepted_.roomAmount);
out.writeFloat(accepted_.ambienceAmount);
}
bool restoreUnpublishedState(const void* data,int size) {
if(published_||!data||size!=30||!queue_.empty()||!complete_.empty())return false;
if(published_||!data||(size!=30&&size!=38)||
!queue_.empty()||!complete_.empty())return false;
juce::MemoryInputStream in(data,static_cast<std::size_t>(size),false);
if(in.readInt()!=0x534F4E4B||in.readInt()!=1)return false;
if(in.readInt()!=0x534F4E4B)return false;
const int version=in.readInt();
if((version==1&&size!=30)||(version==2&&size!=38)||
(version!=1&&version!=2))return false;
armix::sonku::Settings next{};
next.startAzimuthDegrees=in.readFloat();
next.revolutionSeconds=in.readFloat();
next.stereoSpreadDegrees=in.readFloat();
next.spatialMix=in.readFloat();
next.outputTrim=in.readFloat();
const int moving=in.readByte(),clockwise=in.readByte();
if(moving>1||clockwise>1||!in.isExhausted())return false;
if(moving>1||clockwise>1)return false;
next.moving=moving!=0;
next.clockwise=clockwise!=0;
if(!armix::sonku::valid(next))return false;
if(version==2) {
next.roomAmount=in.readFloat();
next.ambienceAmount=in.readFloat();
}
if(!in.isExhausted()||!armix::sonku::valid(next))return false;
if(ready_&&!core_.setSettings(next))return false;
accepted_=next;
return true;
Expand Down
17 changes: 13 additions & 4 deletions engine/builtin_fx/sonku/SonKuEarlyReflections.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ class SonKuEarlyReflections final {
lowpass_.fill(0.f);
for(auto& paths:tap_)for(auto& p:paths)p=Tap{};
write_=0;untilGeometry_=0;primed_=false;
amount_=0.f;
activeFrames_=0;amount_=0.f;
}
// Deliberately experimental and OFF by default. Legacy 8/8 direction
// baseline stays bit-identical. A/B is set on an unpublished/offline core
// until headphone, CPU and device gates approve native publication.
bool setAmount(float value) noexcept {
if(!std::isfinite(value)||value<0.f||value>1.f)return false;
if(amountTarget_==0.f&&amount_==0.f&&value>0.f)reset();
// O(1) activation: never clear the 2x8192 history on an audio
// callback. Mask all reads until they belong to this activation.
if(amountTarget_==0.f&&amount_==0.f&&value>0.f) {
lowpass_.fill(0.f);
for(auto& paths:tap_)for(auto& p:paths)p=Tap{};
write_=0;untilGeometry_=0;primed_=false;activeFrames_=0;
}
amountTarget_=value;
return true;
}
Expand Down Expand Up @@ -127,6 +133,7 @@ class SonKuEarlyReflections final {
}
}
write_=(write_+1)&(ringFrames-1);
if(activeFrames_<ringFrames)++activeFrames_;
--untilGeometry_;
// Preserve the headroom of the native direct path: no artificial
// direction-dependent boost at FRONT or REAR.
Expand All @@ -147,7 +154,9 @@ class SonKuEarlyReflections final {
const float fract=bounded-static_cast<float>(integer);
const int i0=(write_-integer)&(ringFrames-1);
const int i1=(i0-1)&(ringFrames-1);
return history_[source][i0]*(1.f-fract)+history_[source][i1]*fract;
const float newer=activeFrames_>=integer ?history_[source][i0]:0.f;
const float older=activeFrames_>integer ?history_[source][i1]:0.f;
return newer*(1.f-fract)+older*fract;
}
void updateGeometry(double azimuth,float spread) noexcept {
constexpr float pi=3.14159265358979323846f;
Expand Down Expand Up @@ -210,7 +219,7 @@ class SonKuEarlyReflections final {
std::array<float,sourceCount> lowpass_{};
float rate_=0.f,delaySlew_=0.f,gainSlew_=0.f,amountSlew_=0.f;
float amount_=0.f,amountTarget_=0.f;
int write_=0,untilGeometry_=0;
int write_=0,untilGeometry_=0,activeFrames_=0;
SonKuRoomShape shape_=SonKuRoomShape::Rectangular;
SonKuRoomGeometry geometry_{};
bool custom_=false,ready_=false,primed_=false;
Expand Down
56 changes: 48 additions & 8 deletions engine/builtin_fx/sonku/SonKuMusicalReverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,32 @@
// reflections; no source-following stereo pan is imposed on the reverb tail.
// These listening-test presets are OFF in the shipping JUCE editor.
namespace armix::sonku {
enum class SonKuReverbPreset : std::uint8_t { StudioGlue=0, AiryChamber=1 };
enum class SonKuReverbPreset : std::uint8_t {
StudioGlue=0, AiryChamber=1, SpaciousChamber=2, LargeAuditorium=3
};
// Control-side room scale policy: explicit, predictable candidates rather
// than making RT60 linearly proportional to room dimensions (which sounds
// unnaturally hollow and rings). No physically calibrated hall claim.
struct SonKuRoomAmbience {
SonKuReverbPreset preset=SonKuReverbPreset::StudioGlue;
float wet=0.f;
};
inline SonKuRoomAmbience musicalAmbienceForRoom(
float widthMeters,float depthMeters,float distanceMeters) noexcept {
if(!std::isfinite(widthMeters)||!std::isfinite(depthMeters)||
!std::isfinite(distanceMeters)||widthMeters<5.f||
depthMeters<5.f||widthMeters>40.f||depthMeters>40.f||
distanceMeters<1.6f||distanceMeters>10.f||
2.f*(distanceMeters+.5f)>std::min(widthMeters,depthMeters))
return {}; // Safe OFF, not an unbounded wet impulse.
const float span=std::sqrt(widthMeters*depthMeters);
const float distanceScale=std::clamp(1.6f/distanceMeters,.16f,1.f);
// Smaller distant-source input must not suddenly exaggerate late tails.
const float wet=.26f+.12f*std::sqrt(distanceScale);
if(span<10.f)return {SonKuReverbPreset::StudioGlue,wet};
if(span<20.f)return {SonKuReverbPreset::SpaciousChamber,wet};
return {SonKuReverbPreset::LargeAuditorium,wet};
}

class SonKuMusicalReverb final {
public:
Expand All @@ -35,19 +60,25 @@ class SonKuMusicalReverb final {
void reset() noexcept {
for(auto& line:memory_)line.fill(0.f);
lowpass_.fill(0.f);
write_=0;amount_=0.f;
write_=0;activeFrames_=0;amount_=0.f;
// The target amount is a CONTROL-side setting and survives resetting
// host transport/processor so the same program can restart cleanly.
}
bool setAmount(float amount) noexcept {
if(!std::isfinite(amount) || amount<0.f || amount>1.f)return false;
if(amount_==0.f && amountTarget_==0.f && amount>0.f)reset();
// O(1) safe realtime rearm: no 128KiB ring clear. Delayed
// reads are masked until new post-rearm samples fill their tap.
if(amount_==0.f && amountTarget_==0.f && amount>0.f) {
lowpass_.fill(0.f);write_=0;activeFrames_=0;
}
amountTarget_=amount;
return true;
}
bool setPreset(SonKuReverbPreset value) noexcept {
if(value!=SonKuReverbPreset::StudioGlue &&
value!=SonKuReverbPreset::AiryChamber)return false;
value!=SonKuReverbPreset::AiryChamber &&
value!=SonKuReverbPreset::SpaciousChamber &&
value!=SonKuReverbPreset::LargeAuditorium)return false;
// Preset updates calculate RT60 coefficients. Never use this setter
// on an active realtime callback; native host doesn't expose it yet.
if(active())return false;
Expand All @@ -67,7 +98,8 @@ class SonKuMusicalReverb final {
std::array<float,lineCount> y{},mix{};
for(int i=0;i<lineCount;++i){
const int index=(write_-delay_[i])&(ringFrames-1);
const float sample=memory_[i][index];
const float sample=activeFrames_>=delay_[i]?
memory_[i][index]:0.f;
lowpass_[i]+=dampCoeff_*(sample-lowpass_[i]);
y[i]=sample;
mix[i]=lowpass_[i]*gain_[i];
Expand Down Expand Up @@ -96,6 +128,7 @@ class SonKuMusicalReverb final {
(mid*inMid[i]+side*inSide[i]);
}
write_=(write_+1)&(ringFrames-1);
if(activeFrames_<ringFrames)++activeFrames_;
amount_+=slew_*(amountTarget_-amount_);
if(std::abs(amount_-amountTarget_)<1.e-5f)amount_=amountTarget_;
// Wet-only. The KEMAR direct field and physical reflections retain
Expand All @@ -109,8 +142,15 @@ class SonKuMusicalReverb final {
// First late energy arrives ~44 ms: behind earliest image reflections.
constexpr std::array<int,lineCount> lengths{
2111,2339,2579,2803,3079,3319,3593,3929};
const float rt60=preset_==SonKuReverbPreset::StudioGlue?.78f:1.28f;
const float cutoff=preset_==SonKuReverbPreset::StudioGlue?5900.f:7000.f;
// Musical tuning, not volume-derived Sabine RT60. Prepared once,
// never recomputed per sample; original two presets remain identical.
float rt60=0.78f,cutoff=5900.f;
switch(preset_) {
case SonKuReverbPreset::StudioGlue: break;
case SonKuReverbPreset::AiryChamber: rt60=1.28f;cutoff=7000.f;break;
case SonKuReverbPreset::SpaciousChamber: rt60=1.65f;cutoff=5400.f;break;
case SonKuReverbPreset::LargeAuditorium: rt60=2.20f;cutoff=4700.f;break;
}
constexpr float pi=3.14159265358979323846f;
dampCoeff_=1.f-std::exp(-2.f*pi*cutoff/sampleRate_);
for(int i=0;i<lineCount;++i){
Expand All @@ -127,7 +167,7 @@ class SonKuMusicalReverb final {
std::array<int,lineCount> delay_{};
float sampleRate_=48000.f,dampCoeff_=0.f,slew_=0.f;
float amount_=0.f,amountTarget_=0.f;
int write_=0;
int write_=0,activeFrames_=0;
SonKuReverbPreset preset_=SonKuReverbPreset::StudioGlue;
bool ready_=false;
};
Expand Down
19 changes: 18 additions & 1 deletion engine/builtin_fx/sonku/SonKuSpatialCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct Settings {
float outputTrim = 0.75f; // avoid summing two uncorrelated emitters at unity
bool moving = true;
bool clockwise = true;
float roomAmount = 0.f; // default native ROOM OFF
float ambienceAmount = 0.f; // default native late FDN OFF
};
inline bool valid(const Settings& s) noexcept {
return std::isfinite(s.startAzimuthDegrees) &&
Expand All @@ -30,7 +32,9 @@ inline bool valid(const Settings& s) noexcept {
std::isfinite(s.stereoSpreadDegrees) && s.stereoSpreadDegrees>=0.f &&
s.stereoSpreadDegrees<=180.f &&
std::isfinite(s.spatialMix) && s.spatialMix>=0.f && s.spatialMix<=1.f &&
std::isfinite(s.outputTrim) && s.outputTrim>=0.f && s.outputTrim<=1.f;
std::isfinite(s.outputTrim) && s.outputTrim>=0.f && s.outputTrim<=1.f &&
std::isfinite(s.roomAmount) && s.roomAmount>=0.f && s.roomAmount<=1.f &&
std::isfinite(s.ambienceAmount) && s.ambienceAmount>=0.f && s.ambienceAmount<=1.f;
}
inline double wrapDegrees(double degrees) noexcept {
degrees=std::fmod(degrees,360.0);
Expand Down Expand Up @@ -75,6 +79,19 @@ class SonKuSpatialCore final {
if(!s.moving || !settings_.moving ||
s.startAzimuthDegrees!=settings_.startAzimuthDegrees)
degrees_=wrapDegrees(s.startAzimuthDegrees);
// Room geometry is the approved Square for the native SPACE
// controls. Custom offline M3 geometry is not altered by these
// native parameters. Both wet setters are O(1), including rearm.
// Do not overwrite already-configured offline acoustic trials
// merely because legacy motion settings are re-sent. Changes are
// strictly native-param deltas; old settings had both amounts OFF.
if(s.roomAmount!=settings_.roomAmount) {
if(s.roomAmount>0.f && !room_.active() &&
!room_.setShape(SonKuRoomShape::Square))return false;
if(!room_.setAmount(s.roomAmount))return false;
}
if(s.ambienceAmount!=settings_.ambienceAmount &&
!reverb_.setAmount(s.ambienceAmount))return false;
settings_=s;
remaining_=0;
return true;
Expand Down
12 changes: 12 additions & 0 deletions site/preview-v2/assets/mixer-fx-rack.css
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,18 @@
.mx-sonku .sk-rotary:focus-within .sk-dial-cap{outline:1px solid #87d5e6;outline-offset:2px}
.mx-sonku .sk-rotary output{font-size:11px;font-weight:600;letter-spacing:.2px;
font-variant-numeric:tabular-nums;color:#dcf3f7}
.mx-sonku .sk-space{display:grid;gap:5px;padding:8px 9px 7px;
border:1px solid rgba(120,172,189,.28);border-radius:7px;
background:linear-gradient(155deg,rgba(9,27,38,.72),rgba(19,47,60,.50))}
.mx-sonku .sk-space-head{display:flex;align-items:center;justify-content:space-between;
font-size:9px;letter-spacing:1.15px;color:#d0ecf3;font-weight:600}
.mx-sonku .sk-space-head span:last-child{font-size:8px;letter-spacing:.45px;
color:#8baebd;font-weight:400}
.mx-sonku .sk-controls label.sk-space-row{display:grid;grid-template-columns:75px minmax(0,1fr) 36px;
gap:7px;align-items:center;font-size:9px;letter-spacing:0;color:#bcd6df}
.mx-sonku .sk-space-row input{grid-column:auto!important;width:100%!important;
height:14px!important;margin:0!important;accent-color:#73cddd}
.mx-sonku .sk-space-row output{text-align:right;font-size:9px}
.mx-sonku .sk-guide{font-size:9px;line-height:1.42;color:#91b2c2;
border-top:1px solid rgba(113,157,173,.24);padding-top:9px;letter-spacing:.1px}
.mx-sonku .sk-status{background:linear-gradient(#142836,#0c1a27);
Expand Down
22 changes: 21 additions & 1 deletion site/preview-v2/assets/mixer-native-sonku.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"use strict";
const ID="armix.builtin.8d-sonku.v1";
const defaults=()=>({startAzimuthDegrees:0,revolutionSeconds:12,
stereoSpreadDegrees:60,spatialMix:1,outputTrim:.75,moving:true,clockwise:true});
stereoSpreadDegrees:60,spatialMix:1,outputTrim:.75,moving:true,clockwise:true,
roomAmount:0,ambienceAmount:0});
const valid=s=>s && Number.isFinite(s.startAzimuthDegrees) &&
Math.abs(s.startAzimuthDegrees)<=360 &&
Number.isFinite(s.revolutionSeconds)&&s.revolutionSeconds>=.5&&s.revolutionSeconds<=120 &&
Number.isFinite(s.stereoSpreadDegrees)&&s.stereoSpreadDegrees>=0&&s.stereoSpreadDegrees<=180 &&
Number.isFinite(s.spatialMix)&&s.spatialMix>=0&&s.spatialMix<=1 &&
Number.isFinite(s.outputTrim)&&s.outputTrim>=0&&s.outputTrim<=1 &&
Number.isFinite(s.roomAmount)&&s.roomAmount>=0&&s.roomAmount<=1 &&
Number.isFinite(s.ambienceAmount)&&s.ambienceAmount>=0&&s.ambienceAmount<=1 &&
typeof s.moving==="boolean"&&typeof s.clockwise==="boolean";
const backend=()=>window.__JUCE__?.backend;
const native=()=>typeof backend()?.emitEvent==="function";
Expand Down Expand Up @@ -104,6 +107,10 @@ root.innerHTML=[
'<label class="sk-rotary"><span class="sk-param-name">SPREAD</span><span class="sk-dial"><span class="sk-dial-track"></span><span class="sk-dial-cap"><span class="sk-dial-needle"></span></span><input id="skSpread" type="range" min="0" max="180" step="1" value="60" title="Drag up/down, arrow keys or double-click to reset"/></span><output id="skSpreadValue">60°</output></label>',
'<label class="sk-rotary"><span class="sk-param-name">SPATIAL MIX</span><span class="sk-dial"><span class="sk-dial-track"></span><span class="sk-dial-cap"><span class="sk-dial-needle"></span></span><input id="skMix" type="range" min="0" max="100" step="1" value="100" title="Drag up/down, arrow keys or double-click to reset"/></span><output id="skMixValue">100%</output></label>',
'<label class="sk-rotary"><span class="sk-param-name">OUTPUT TRIM</span><span class="sk-dial"><span class="sk-dial-track"></span><span class="sk-dial-cap"><span class="sk-dial-needle"></span></span><input id="skTrim" type="range" min="0" max="100" step="1" value="75" title="Drag up/down, arrow keys or double-click to reset"/></span><output id="skTrimValue">75%</output></label>',
'</div><div class="sk-space" role="group" aria-label="Room ambience">',
'<div class="sk-space-head"><span>SPACE</span><span>SQUARE ROOM · NATIVE PCM</span></div>',
'<label class="sk-space-row" for="skRoom"><span>Reflections</span><input id="skRoom" type="range" min="0" max="100" value="0" step="1"/><output id="skRoomValue">OFF</output></label>',
'<label class="sk-space-row" for="skAmbience"><span>Ambience</span><input id="skAmbience" type="range" min="0" max="100" value="0" step="1"/><output id="skAmbienceValue">OFF</output></label>',
'</div><div class="sk-guide">Drag the two monitors on the orbit · knobs: vertical drag, double-click to reset</div>',
'</aside></div>',
'<footer class="sk-status"><span id="skMode">VISUAL PREVIEW</span><span id="skHint" role="status">No browser audio</span></footer>'
Expand Down Expand Up @@ -142,6 +149,11 @@ function render(){
dial.style.setProperty("--sk-sweep",(p*270).toFixed(2)+"deg");
dial.style.setProperty("--sk-needle",(-135+p*270).toFixed(2)+"deg");
}
for(const [id,value,out] of [["skRoom",s.roomAmount,"skRoomValue"],
["skAmbience",s.ambienceAmount,"skAmbienceValue"]]){
$(id).value=String(Math.round(value*100));
$(out).textContent=value===0?"OFF":Math.round(value*100)+"%";
}
const liveMotion=s.moving&&current&&!pending?observed:
s.startAzimuthDegrees;
const phase=native()&&s.moving&&current&&!pending&&observedAt?
Expand Down Expand Up @@ -229,6 +241,14 @@ $("skClose").addEventListener("click",()=>{root.hidden=true;current=null;
if(clock!==null){clearInterval(clock);clock=null;}});
$("skMotion").addEventListener("click",()=>send({...draft,moving:!draft.moving}));
$("skDirection").addEventListener("click",()=>send({...draft,clockwise:!draft.clockwise}));
for(const [id,key] of [["skRoom","roomAmount"],["skAmbience","ambienceAmount"]]) {
const el=$(id);
el.addEventListener("input",()=>{
const value=Number(el.value)/100;
if(Number.isFinite(value)){draft={...draft,[key]:value};render();}
});
el.addEventListener("change",()=>send({...draft,[key]:Number(el.value)/100}));
}
for(const [id,key,convert] of [
["skSpeed","revolutionSeconds",v=>v],
["skSpread","stereoSpreadDegrees",v=>v],
Expand Down
Loading
Loading