SPB Git

Repository Public

engine.rs 25.3 KB 666 lines rust

1//! ORIX Sonata2//! File: crates/sonata-runtime/src/engine.rs3//! Description: The engine: a real-time Processor (audio thread) and a Controller (any thread)4//! joined by lock-free queues. Transport, live control, metronome, hot swap with crossfade.5//!6//! Author: Simon-Pierre Boucher7//! Contact: contact@spboucher.ai89use crate::plan::{PreparedProgram, TapPoint, QUANTUM};10use crate::shared::{meter_slot, Shared, TransportState};11use crate::spsc::{channel, Consumer, Producer};12use sonata_dsp::core::DenormalGuard;13use sonata_ir::Strip;14use std::sync::atomic::Ordering::Relaxed;15use std::sync::{Arc, Mutex};1617/// Programs that may be loaded and not yet collected; `Controller::load` refuses beyond this.18const MAX_IN_FLIGHT: usize = 8;1920#[derive(Clone, Copy, Debug, PartialEq)]21pub struct EngineConfig {22    pub sample_rate: u32,23    /// Clamp the final output to [-1, 1]. On for a device, off for offline float rendering.24    pub hard_clip: bool,25    /// Measure the duration of every `process` call (two clock reads per callback).26    pub measure_timing: bool,27    /// Length of the hot-swap crossfade, seconds.28    pub crossfade_sec: f32,29    /// Capacity of the command queue.30    pub command_capacity: usize,31}3233impl EngineConfig {34    pub fn realtime(sample_rate: u32) -> EngineConfig {35        EngineConfig { sample_rate, hard_clip: true, measure_timing: true, crossfade_sec: 0.03, command_capacity: 4096 }36    }37    pub fn offline(sample_rate: u32) -> EngineConfig {38        EngineConfig { sample_rate, hard_clip: false, measure_timing: false, crossfade_sec: 0.03, command_capacity: 4096 }39    }40}4142enum Command {43    Play { count_in_bars: u32 },44    Pause,45    Stop,46    Seek(u64),47    Loop(Option<(u64, u64)>),48    Gain(Strip, Option<f32>),49    Pan(Strip, Option<f32>),50    Mute(Strip, Option<bool>),51    Solo(Strip, Option<bool>),52    EffectParam { strip: Strip, index: u32, param: u32, value: f32 },53    EffectMix { strip: Strip, index: u32, mix: f32 },54    EffectBypass { strip: Strip, index: u32, bypass: bool },55    InstrumentParam { track: u32, param: u32, value: f32 },56    NoteOn { track: u32, id: u64, pitch: f32, velocity: f32 },57    NoteOff { track: u32, id: u64 },58    Bend { track: u32, id: u64, semitones: f32 },59    Sustain { track: u32, down: bool },60    AllNotesOff,61    Panic,62    Metronome { enabled: bool, gain_db: f32 },63    Tap(TapPoint),64    Load(Box<PreparedProgram>),65    Unload,66}6768struct Click {69    phase: f32,70    inc: f32,71    env: f32,72    decay: f32,73}7475/// The audio-thread half of the engine. `process` is real-time safe: no allocation, lock, I/O or76/// logging. Everything it frees is handed back to the controller.77pub struct Processor {78    cfg: EngineConfig,79    shared: Arc<Shared>,80    cmds: Consumer<Command>,81    retired: Producer<Box<PreparedProgram>>,82    cur: Option<Box<PreparedProgram>>,83    fading: Option<Box<PreparedProgram>>,84    pending: Option<Box<PreparedProgram>>,85    fade_pos: usize,86    fade_len: usize,87    carry_l: [f32; QUANTUM],88    carry_r: [f32; QUANTUM],89    carry_len: usize,90    carry_pos: usize,91    state: TransportState,92    pos: u64,93    clock: u64,94    loop_range: Option<(u64, u64)>,95    count_in_left: u64,96    count_in_beat: u64,97    count_in_bar: u32,98    count_in_index: u64,99    metronome: bool,100    click_gain: f32,101    click: Click,102    tap: TapPoint,103    ms_l: f32,104    ms_r: f32,105}106107/// The control half of the engine. Usable from any thread; calls never block on the audio thread.108pub struct Controller {109    shared: Arc<Shared>,110    tx: Mutex<Producer<Command>>,111    rx: Mutex<(Consumer<Box<PreparedProgram>>, usize)>,112}113114/// Creates an engine. Give the [`Processor`] to the audio callback and keep the [`Controller`].115pub fn engine(cfg: EngineConfig) -> (Controller, Processor) {116    let shared = Arc::new(Shared::new(cfg.sample_rate));117    let (tx, cmds) = channel(cfg.command_capacity.max(64));118    let (retired, rx) = channel(MAX_IN_FLIGHT * 2);119    let fade_len = ((cfg.crossfade_sec.clamp(0.001, 1.0) * cfg.sample_rate as f32) as usize).max(QUANTUM);120    let proc_ = Processor {121        cfg,122        shared: shared.clone(),123        cmds,124        retired,125        cur: None,126        fading: None,127        pending: None,128        fade_pos: 0,129        fade_len,130        carry_l: [0.0; QUANTUM],131        carry_r: [0.0; QUANTUM],132        carry_len: 0,133        carry_pos: 0,134        state: TransportState::Stopped,135        pos: 0,136        clock: 0,137        loop_range: None,138        count_in_left: 0,139        count_in_beat: 1,140        count_in_bar: 4,141        count_in_index: 0,142        metronome: false,143        click_gain: 0.25,144        click: Click { phase: 0.0, inc: 0.0, env: 0.0, decay: 0.0 },145        tap: TapPoint::Master,146        ms_l: 0.0,147        ms_r: 0.0,148    };149    (Controller { shared, tx: Mutex::new(tx), rx: Mutex::new((rx, 0)) }, proc_)150}151152impl Controller {153    fn send(&self, c: Command) -> bool {154        let ok = self.tx.lock().map(|mut tx| tx.push(c).is_ok()).unwrap_or(false);155        if !ok {156            self.shared.dropped_commands.fetch_add(1, Relaxed);157        }158        ok159    }160161    /// Atomics describing the engine: transport, meters, scopes, timing, counters.162    pub fn shared(&self) -> &Arc<Shared> {163        &self.shared164    }165166    /// Hands a prepared program to the audio thread. It replaces the current one at the next167    /// chunk boundary with an equal-power crossfade, keeping the transport position and the live168    /// mixer overrides; notes sounding at that position are restarted in the new program.169    /// Returns the program when too many swaps are still in flight (call again later).170    pub fn load(&self, program: PreparedProgram) -> Result<(), Box<PreparedProgram>> {171        self.collect_garbage();172        let boxed = Box::new(program);173        if boxed.sample_rate() != self.shared.sample_rate() {174            return Err(boxed);175        }176        let Ok(mut rx) = self.rx.lock() else { return Err(boxed) };177        if rx.1 >= MAX_IN_FLIGHT {178            return Err(boxed);179        }180        let Ok(mut tx) = self.tx.lock() else { return Err(boxed) };181        match tx.push(Command::Load(boxed)) {182            Ok(()) => {183                rx.1 += 1;184                Ok(())185            }186            Err(Command::Load(b)) => Err(b),187            Err(_) => unreachable!(),188        }189    }190191    /// Removes the current program (fades it out); the engine then outputs silence.192    pub fn unload(&self) {193        self.send(Command::Unload);194    }195196    /// Frees programs the audio thread has retired. Called by `load`; call it periodically197    /// (for example from the meter timer) to release memory promptly. Returns how many were freed.198    pub fn collect_garbage(&self) -> usize {199        let Ok(mut rx) = self.rx.lock() else { return 0 };200        let mut n = 0;201        while let Some(p) = rx.0.pop() {202            drop(p);203            n += 1;204        }205        rx.1 = rx.1.saturating_sub(n);206        n207    }208209    pub fn play(&self) {210        self.send(Command::Play { count_in_bars: 0 });211    }212    /// Starts playback after `bars` bars of metronome clicks at the tempo and metre of the position.213    pub fn play_with_count_in(&self, bars: u32) {214        self.send(Command::Play { count_in_bars: bars.min(16) });215    }216    /// Stops the transport and keeps the position. Sounding notes are released.217    pub fn pause(&self) {218        self.send(Command::Pause);219    }220    /// Stops the transport and returns to the start (or the loop start). Sounding notes are released.221    pub fn stop(&self) {222        self.send(Command::Stop);223    }224    pub fn seek_samples(&self, sample: u64) {225        self.send(Command::Seek(sample));226    }227    pub fn seek_seconds(&self, seconds: f64) {228        self.send(Command::Seek(sonata_ir::seconds_to_samples(seconds, self.shared.sample_rate())));229    }230    /// Sets or clears the loop range `[start, end)` in samples. Ranges shorter than one quantum are ignored.231    pub fn set_loop(&self, range: Option<(u64, u64)>) {232        self.send(Command::Loop(range.filter(|(a, b)| *b >= *a + QUANTUM as u64)));233    }234    /// Overrides the fader of a strip in dB (`None` returns to the compiled value and its automation).235    pub fn set_gain_db(&self, strip: Strip, db: Option<f32>) {236        self.send(Command::Gain(strip, db));237    }238    pub fn set_pan(&self, strip: Strip, pan: Option<f32>) {239        self.send(Command::Pan(strip, pan));240    }241    pub fn set_mute(&self, strip: Strip, mute: Option<bool>) {242        self.send(Command::Mute(strip, mute));243    }244    pub fn set_solo(&self, track: Strip, solo: Option<bool>) {245        self.send(Command::Solo(track, solo));246    }247    /// Sets parameter `param` (index in the effect descriptor) of insert `index` of a strip.248    pub fn set_effect_param(&self, strip: Strip, index: u32, param: u32, value: f32) {249        self.send(Command::EffectParam { strip, index, param, value });250    }251    pub fn set_effect_mix(&self, strip: Strip, index: u32, mix: f32) {252        self.send(Command::EffectMix { strip, index, mix });253    }254    pub fn set_effect_bypass(&self, strip: Strip, index: u32, bypass: bool) {255        self.send(Command::EffectBypass { strip, index, bypass });256    }257    pub fn set_instrument_param(&self, track: u32, param: u32, value: f32) {258        self.send(Command::InstrumentParam { track, param, value });259    }260    /// Starts a live note on a track's instrument (MIDI keyboard, Instrument Lab audition).261    /// Works with the transport stopped. `id` must differ from compiled note ids; use ids with bit 63 set.262    pub fn note_on(&self, track: u32, id: u64, pitch: f32, velocity: f32) {263        self.send(Command::NoteOn { track, id, pitch, velocity });264    }265    pub fn note_off(&self, track: u32, id: u64) {266        self.send(Command::NoteOff { track, id });267    }268    pub fn pitch_bend(&self, track: u32, id: u64, semitones: f32) {269        self.send(Command::Bend { track, id, semitones });270    }271    pub fn sustain(&self, track: u32, down: bool) {272        self.send(Command::Sustain { track, down });273    }274    pub fn all_notes_off(&self) {275        self.send(Command::AllNotesOff);276    }277    /// Silences instruments, effects and delay lines at once.278    pub fn panic(&self) {279        self.send(Command::Panic);280    }281    pub fn set_metronome(&self, enabled: bool, gain_db: f32) {282        self.send(Command::Metronome { enabled, gain_db });283    }284    /// Selects what feeds `Shared::tap_scope`.285    pub fn set_tap(&self, tap: TapPoint) {286        self.send(Command::Tap(tap));287    }288}289290impl Processor {291    pub fn shared(&self) -> &Arc<Shared> {292        &self.shared293    }294295    fn retire(&mut self, p: Box<PreparedProgram>) {296        if let Err(p) = self.retired.push(p) {297            // Cannot happen while the controller bounds the programs in flight. Leaking is the only298            // real-time safe fallback: deallocating here could block the audio thread.299            std::mem::forget(p);300        }301    }302303    fn start_swap(&mut self, mut new: Box<PreparedProgram>) {304        new.set_tap(self.tap);305        if let Some(old) = self.cur.take() {306            new.adopt_overrides(&old);307            if self.state == TransportState::Playing {308                new.locate_chasing(self.pos);309            } else {310                new.locate(self.pos);311            }312            self.fading = Some(old);313            self.fade_pos = 0;314            self.shared.swapping.store(true, Relaxed);315        } else {316            new.locate(self.pos);317        }318        self.shared.end_sample.store(new.end_sample(), Relaxed);319        self.cur = Some(new);320        self.shared.generation.fetch_add(1, Relaxed);321    }322323    fn apply(&mut self, c: Command) {324        match c {325            Command::Play { count_in_bars } => {326                if self.state != TransportState::Playing {327                    if let (true, Some(p)) = (count_in_bars > 0, self.cur.as_ref()) {328                        let (beat, per_bar) = p.beat_at(self.pos);329                        self.count_in_beat = beat;330                        self.count_in_bar = per_bar;331                        self.count_in_left = beat * per_bar as u64 * count_in_bars as u64;332                        self.count_in_index = 0;333                        self.state = TransportState::CountIn;334                    } else {335                        self.state = TransportState::Playing;336                    }337                    let pos = self.pos;338                    if let Some(p) = self.cur.as_mut() {339                        p.locate(pos);340                    }341                }342            }343            Command::Pause => {344                self.state = TransportState::Paused;345                if let Some(p) = self.cur.as_mut() {346                    p.all_notes_off();347                }348            }349            Command::Stop => {350                self.state = TransportState::Stopped;351                self.pos = self.loop_range.map(|r| r.0).unwrap_or(0);352                let pos = self.pos;353                if let Some(p) = self.cur.as_mut() {354                    p.all_notes_off();355                    p.locate(pos);356                }357            }358            Command::Seek(s) => {359                self.pos = s;360                if let Some(p) = self.cur.as_mut() {361                    p.all_notes_off();362                    p.locate(s);363                }364                if let Some(p) = self.fading.as_mut() {365                    p.all_notes_off();366                    p.locate(s);367                }368            }369            Command::Loop(r) => self.loop_range = r,370            Command::Gain(s, v) => self.with_cur(|p| p.set_gain(s, v)),371            Command::Pan(s, v) => self.with_cur(|p| p.set_pan(s, v)),372            Command::Mute(s, v) => self.with_cur(|p| p.set_mute(s, v)),373            Command::Solo(s, v) => self.with_cur(|p| p.set_solo(s, v)),374            Command::EffectParam { strip, index, param, value } => self.with_cur(|p| p.set_effect_param(strip, index, param, value)),375            Command::EffectMix { strip, index, mix } => self.with_cur(|p| p.set_effect_mix(strip, index, mix)),376            Command::EffectBypass { strip, index, bypass } => self.with_cur(|p| p.set_effect_bypass(strip, index, bypass)),377            Command::InstrumentParam { track, param, value } => self.with_cur(|p| p.set_instrument_param(track, param, value)),378            Command::NoteOn { track, id, pitch, velocity } => self.with_cur(|p| p.live_note_on(track, id, pitch, velocity)),379            Command::NoteOff { track, id } => self.with_cur(|p| p.live_note_off(track, id)),380            Command::Bend { track, id, semitones } => self.with_cur(|p| p.live_bend(track, id, semitones)),381            Command::Sustain { track, down } => self.with_cur(|p| p.live_sustain(track, down)),382            Command::AllNotesOff => self.with_cur(|p| p.all_notes_off()),383            Command::Panic => {384                self.with_cur(|p| p.panic());385                if let Some(p) = self.fading.as_mut() {386                    p.panic();387                }388            }389            Command::Metronome { enabled, gain_db } => {390                self.metronome = enabled;391                if gain_db.is_finite() {392                    self.click_gain = 10f32.powf(gain_db.clamp(-60.0, 0.0) / 20.0);393                }394            }395            Command::Tap(t) => {396                self.tap = t;397                self.shared.tap_scope.clear();398                self.with_cur(|p| p.set_tap(t));399            }400            Command::Load(new) => {401                if self.fading.is_some() {402                    // A swap is in progress: keep only the newest candidate.403                    if let Some(older) = self.pending.replace(new) {404                        self.retire(older);405                    }406                } else {407                    self.start_swap(new);408                }409            }410            Command::Unload => {411                if let Some(p) = self.pending.take() {412                    self.retire(p);413                }414                if let Some(old) = self.cur.take() {415                    if let Some(f) = self.fading.replace(old) {416                        self.retire(f);417                    }418                    self.fade_pos = 0;419                    self.shared.swapping.store(true, Relaxed);420                }421                self.shared.end_sample.store(0, Relaxed);422            }423        }424    }425426    fn with_cur(&mut self, f: impl FnOnce(&mut PreparedProgram)) {427        if let Some(p) = self.cur.as_mut() {428            f(p);429        }430    }431432    fn trigger_click(&mut self, accent: bool) {433        let sr = self.cfg.sample_rate as f32;434        self.click = Click {435            phase: 0.0,436            inc: std::f32::consts::TAU * if accent { 1760.0 } else { 1175.0 } / sr,437            env: self.click_gain,438            decay: (-1.0 / (0.012 * sr)).exp(),439        };440    }441442    /// Renders the next chunk (at most [`QUANTUM`] frames) into the carry buffer and returns its length.443    fn render_chunk(&mut self) -> usize {444        while let Some(c) = self.cmds.pop() {445            self.apply(c);446        }447        let mut n = QUANTUM - (self.clock % QUANTUM as u64) as usize;448        let playing = self.state == TransportState::Playing;449        let counting = self.state == TransportState::CountIn;450        let pos = self.pos;451        if playing {452            let mut limit = u64::MAX;453            let metronome = self.metronome;454            let mut click = None;455            if let Some(p) = self.cur.as_mut() {456                limit = limit.min(p.next_boundary(pos));457                if metronome {458                    match p.next_beat(pos) {459                        Some((b, accent)) if b == pos => {460                            click = Some(accent);461                            if let Some((b2, _)) = p.next_beat(pos + 1) {462                                limit = limit.min(b2);463                            }464                        }465                        Some((b, _)) => limit = limit.min(b),466                        None => {}467                    }468                }469            }470            if let Some(accent) = click {471                self.trigger_click(accent);472            }473            if let Some(p) = self.fading.as_mut() {474                limit = limit.min(p.next_boundary(pos));475            }476            if let Some((_, end)) = self.loop_range.filter(|r| pos < r.1) {477                limit = limit.min(end);478            }479            n = n.min((limit - pos).min(QUANTUM as u64) as usize).max(1);480        } else if counting {481            let done = self.count_in_index;482            if done.is_multiple_of(self.count_in_beat) {483                self.trigger_click((done / self.count_in_beat).is_multiple_of(self.count_in_bar as u64));484            }485            let to_beat = self.count_in_beat - done % self.count_in_beat;486            n = n.min(to_beat.min(self.count_in_left).min(QUANTUM as u64) as usize).max(1);487        }488489        let (cl, cr) = (&mut self.carry_l[..n], &mut self.carry_r[..n]);490        match self.cur.as_mut() {491            Some(p) => {492                p.render(pos, n, playing, &self.shared);493                let (l, r) = p.output_chunk(n);494                cl.copy_from_slice(l);495                cr.copy_from_slice(r);496            }497            None => {498                cl.fill(0.0);499                cr.fill(0.0);500            }501        }502        if let Some(old) = self.fading.as_mut() {503            old.render(pos, n, playing, &self.shared);504            let (l, r) = old.output_chunk(n);505            let has_new = self.cur.is_some();506            for i in 0..n {507                let t = ((self.fade_pos + i + 1) as f32 / self.fade_len as f32).min(1.0) * std::f32::consts::FRAC_PI_2;508                let (go, gn) = (t.cos(), if has_new { t.sin() } else { 0.0 });509                cl[i] = cl[i] * gn + l[i] * go;510                cr[i] = cr[i] * gn + r[i] * go;511            }512            self.fade_pos += n;513            if self.fade_pos >= self.fade_len {514                if let Some(done) = self.fading.take() {515                    self.retire(done);516                }517                self.shared.swapping.store(false, Relaxed);518                if let Some(next) = self.pending.take() {519                    self.start_swap(next);520                }521            }522        }523524        // Metronome click (not part of the program: never rendered offline unless enabled).525        if self.click.env > 1e-5 {526            let (cl, cr) = (&mut self.carry_l[..n], &mut self.carry_r[..n]);527            for i in 0..n {528                let s = self.click.phase.sin() * self.click.env;529                self.click.phase += self.click.inc;530                self.click.env *= self.click.decay;531                cl[i] += s;532                cr[i] += s;533            }534            if self.click.phase > std::f32::consts::TAU * 64.0 {535                self.click.phase %= std::f32::consts::TAU;536            }537        }538539        // Final safety stage, meters and scope.540        let (cl, cr) = (&mut self.carry_l[..n], &mut self.carry_r[..n]);541        let (mut pk_l, mut pk_r, mut sq_l, mut sq_r, mut overs, mut bad) = (0.0f32, 0.0f32, 0.0f32, 0.0f32, 0u32, 0u64);542        let clip = self.cfg.hard_clip;543        for i in 0..n {544            let (mut a, mut b) = (cl[i], cr[i]);545            if !a.is_finite() {546                a = 0.0;547                bad += 1;548            }549            if !b.is_finite() {550                b = 0.0;551                bad += 1;552            }553            overs += (a.abs() >= 1.0 || b.abs() >= 1.0) as u32;554            if clip {555                a = a.clamp(-1.0, 1.0);556                b = b.clamp(-1.0, 1.0);557            }558            cl[i] = a;559            cr[i] = b;560            pk_l = pk_l.max(a.abs());561            pk_r = pk_r.max(b.abs());562            sq_l += a * a;563            sq_r += b * b;564        }565        if bad > 0 {566            self.shared.scrubbed.fetch_add(bad, Relaxed);567        }568        let keep = (-(n as f32) / (0.3 * self.cfg.sample_rate as f32)).exp();569        self.ms_l = self.ms_l * keep + (1.0 - keep) * sq_l / n as f32;570        self.ms_r = self.ms_r * keep + (1.0 - keep) * sq_r / n as f32;571        if self.ms_l < 1e-20 {572            self.ms_l = 0.0;573        }574        if self.ms_r < 1e-20 {575            self.ms_r = 0.0;576        }577        if let Some(slot) = meter_slot(Strip::Master) {578            self.shared.meter_write(slot, pk_l, pk_r, self.ms_l, self.ms_r, overs);579        }580        self.shared.master_scope.write(cl, cr);581        if !self.cur.as_ref().map(|p| p.has_tap()).unwrap_or(false) {582            self.shared.tap_scope.write(cl, cr);583        }584585        // Advance the transport.586        if playing {587            self.pos += n as u64;588            if let Some((start, end)) = self.loop_range {589                if self.pos == end {590                    self.pos = start;591                    if let Some(p) = self.cur.as_mut() {592                        p.all_notes_off();593                        p.locate(start);594                    }595                    if let Some(p) = self.fading.as_mut() {596                        p.all_notes_off();597                        p.locate(start);598                    }599                }600            }601        } else if counting {602            self.count_in_index += n as u64;603            self.count_in_left -= n as u64;604            if self.count_in_left == 0 {605                self.state = TransportState::Playing;606            }607        }608        self.clock += n as u64;609        self.carry_len = n;610        self.carry_pos = 0;611        let sh = &self.shared;612        sh.position.store(self.pos, Relaxed);613        sh.clock.store(self.clock, Relaxed);614        sh.state.store(self.state as u8, Relaxed);615        if let Some(p) = self.cur.as_ref() {616            sh.voices.store(p.active_voices() as u32, Relaxed);617            sh.limiter_reduction_db.store(p.limiter_reduction_db().to_bits(), Relaxed);618        } else {619            sh.voices.store(0, Relaxed);620        }621        n622    }623624    /// Fills `left` and `right` (equal lengths, any size) with the next frames of audio.625    /// Real-time safe. The result does not depend on how the caller slices time into blocks.626    pub fn process(&mut self, left: &mut [f32], right: &mut [f32]) {627        let _guard = DenormalGuard::new();628        let start = if self.cfg.measure_timing { Some(std::time::Instant::now()) } else { None };629        let total = left.len().min(right.len());630        let mut done = 0;631        while done < total {632            if self.carry_pos == self.carry_len {633                self.render_chunk();634            }635            let k = (self.carry_len - self.carry_pos).min(total - done);636            left[done..done + k].copy_from_slice(&self.carry_l[self.carry_pos..self.carry_pos + k]);637            right[done..done + k].copy_from_slice(&self.carry_r[self.carry_pos..self.carry_pos + k]);638            self.carry_pos += k;639            done += k;640        }641        if let Some(t) = start {642            let ns = t.elapsed().as_nanos() as u64;643            self.shared.timing.record(ns, total as u64 * 1_000_000_000 / self.cfg.sample_rate.max(1) as u64);644        }645    }646647    /// Offline interface: renders exactly one internal chunk and returns the master audio. Must not648    /// be mixed with `process` on the same processor (the carry buffer would be skipped).649    pub fn process_chunk(&mut self) -> (&[f32], &[f32]) {650        let _guard = DenormalGuard::new();651        let n = self.render_chunk();652        self.carry_pos = n;653        (&self.carry_l[..n], &self.carry_r[..n])654    }655656    /// Stem `index` of the current program for the chunk returned by the last `process_chunk`.657    pub fn stem_chunk(&self, index: usize) -> Option<(&[f32], &[f32])> {658        self.cur.as_ref().map(|p| p.stem_chunk(index, self.carry_len))659    }660661    /// Timeline position (samples) the next chunk starts at.662    pub fn position(&self) -> u64 {663        self.pos664    }665}666
Files main
Menu

Theme