
psilobot.vercel.app/mandala/ The Raga Mandala - Sampler Edition is a web-based circular step sequencer and microtonal sampler interface. Operating at the intersection of traditional Indian classical music theory and modern browser DSP, it transforms linear step sequencing into a radial 6-ring, 16-step orbital grid driven by Web Audio API buffer resampling.Core DSP & Architecture Breakdown[ Local Audio File ] ──> [ FileReader ] ──> [ decodeAudioData ] ──> [ AudioBuffer Storage ] │ [ Circular Playhead ] ──> [ Radial Grid Trigger (Orbit x Step) ] ──────────────┤ ▼ [ Delay Echo (Dotted 8th) ] <── [ LP Filter (Biquad) ] <── [ ADSR Gain ] <── [ AudioBufferSourceNode ] │ │ (PlaybackRate Resampling) └──> [ Feedback Loop ] ───────────┴──> [ MediaStreamDestination ] ──> [ MediaRecorder (WebM) ] 1. Microtonal Resampling Engine (playNote)Unlike conventional samplers that rely on pitch-shifting algorithms or phase vocoders, Raga Mandala uses sample rate manipulation (source.playbackRate.setValueAtTime) relative to a $130.81\text{ Hz}$ root baseline ($C_3$).
$$\text{Tuned Frequency} = f_{\text{raga}} \times 2^{\left(\frac{\text{Transpose}}{12}\right)}$$$$\text{Playback Speed Ratio} = \frac{\text{Tuned Frequency}}{130.81\text{ Hz}}$$Scale Tunings: Pitch intervals are defined by fixed microtonal frequency arrays mapping directly to classical Ragas:Raga Bhairav: $[130.81, 138.59, 164.81, 174.61, 196.00, 207.65]\text{ Hz}$ (Features $D\flat$ and $A\flat$ interval drops).Raga Yaman: $[130.81, 146.83, 164.81, 185.00, 196.00, 220.00]\text{ Hz}$ (Features $F\sharp$ Lydian-style lift).Polyphonic Envelopes: Every triggered node instantiates a fresh AudioBufferSourceNode tied to an independent GainNode envelope (Attack, Decay, Release), allowing full polyphonic overlap without cutting off trailing note tails.2. Polar Coordinate Sequencing Grid (createMandala)The UI renders a 6-layer radial sequencer matrix ($6\text{ orbits} \times 16\text{ radial steps} = 96\text{ possible trigger nodes}$).Polar-to-Cartesian Mapping: Node DOM positions are calculated dynamically on initialization using trigonometric offsets:$$X = X_{\text{center}} + r_i \cdot \cos\left(\frac{2\pi \cdot j}{16} - \frac{\pi}{2}\right)$$$$Y = Y_{\text{center}} + r_i \cdot \sin\left(\frac{2\pi \cdot j}{16} - \frac{\pi}{2}\right)$$Polar Sweep Line: A single HTML division rotates $360^\circ$ relative to the current step ($22.5^\circ$ per step increments) to visually sync with the audio scheduler loop.3. Tempo-Synced Dynamic Echo & Master OutputBPM Delay Coupling: Delay time is continuously synced to tempo in real-time (delayTime = (60 / BPM) * 0.75), locking feedback repeats to a musical dotted-eighth note delay pattern.Stream Capturing: The audio output paths converge into a MediaStreamDestinationNode, allowing direct client-side recording to standard .webm container format via MediaRecorder.Key Technical SpecificationsFeatureImplementationPerformance / ParameterGrid Capacity96 Trigger Nodes6 Orbits (Pitch Rows) $\times$ 16 Angular StepsSynthesis MethodBuffer ResamplingVariable playbackRate targeting Raga frequenciesEnvelope GeneratorLinear / Exponential RampAttack ($1\text{ ms} - 200\text{ ms}$), Decay ($50\text{ ms} - 2\text{ s}$), Release ($100\text{ ms} - 5\text{ s}$)Filter StageLowpass (BiquadFilterNode)Cutoff frequency variable from $200\text{ Hz}$ to $12\text{ kHz}$Echo UnitFeedforward / Feedback LoopDotted 8th tempo-locked delay; feedback gain $0.0 - 0.7$Export CaptureClient-side MediaRecorderLossless WebM audio stream downloadEngineering Strengths & Optimization OpportunitiesStrengthsZero-Latency Microtonality: Re-tuning sample buffer playback via standard frequency ratio divisions avoids the computational overhead and artifacts of time-stretching processing algorithms.Generative Pattern Seeding (seedPattern): Algorithmic pattern generator calculates rhythmic probability intervals across orbits, providing instant generative musical ideas matching eastern scale modes.Hardware Acceleration: Mathematical layout generation runs once during pre-render, offloading step calculations during active playback loops.Recommended UpgradesBase Root Tuning Selector: The engine currently assumes all user-loaded samples are tuned to $C_3$ ($130.81\text{ Hz}$). Adding an explicit Root Key selector (e.g., $A$, $F\sharp$) would prevent sample playback from playing out-of-tune when loading non-$C$ samples.Sample Slicing Engine: Implementing custom start/end sample markers (bufferSource.start(time, offset, duration)) would transform the module from a simple pitch-transposer into a transient chop-sampler.