Moved AtomicFloat to synfx-dsp
This commit is contained in:
parent
db01caaac0
commit
4c5d832036
7 changed files with 13 additions and 131 deletions
|
@ -14,3 +14,5 @@ to the adjacent cells.
|
|||
chains on the hexagonal Matrix.
|
||||
* Feature: Added Scope DSP node and NodeConfigurator/Matrix API for retrieving
|
||||
the scope handles for access to it's capture buffers.
|
||||
* Feature: Added WBlockDSP visual programming language utilizing the `synfx-dsp-jit` crate.
|
||||
* Change: Moved DSP code over to `synfx-dsp` crate.
|
||||
|
|
|
@ -19,8 +19,8 @@ triple_buffer = "5.0.6"
|
|||
lazy_static = "1.4.0"
|
||||
hound = "3.4.0"
|
||||
synfx-dsp-jit = { path = "../synfx-dsp-jit", optional = true }
|
||||
synfx-dsp = "0.5.1"
|
||||
#synfx-dsp = { git = "https://github.com/WeirdConstructor/synfx-dsp" }
|
||||
#synfx-dsp = "0.5.1"
|
||||
synfx-dsp = { git = "https://github.com/WeirdConstructor/synfx-dsp" }
|
||||
|
||||
[dev-dependencies]
|
||||
num-complex = "0.2"
|
||||
|
|
|
@ -497,6 +497,8 @@ mod node_bosc;
|
|||
#[allow(non_upper_case_globals)]
|
||||
mod node_bowstri;
|
||||
#[allow(non_upper_case_globals)]
|
||||
mod node_code;
|
||||
#[allow(non_upper_case_globals)]
|
||||
mod node_comb;
|
||||
#[allow(non_upper_case_globals)]
|
||||
mod node_cqnt;
|
||||
|
@ -538,8 +540,6 @@ mod node_tseq;
|
|||
mod node_tslfo;
|
||||
#[allow(non_upper_case_globals)]
|
||||
mod node_vosc;
|
||||
#[allow(non_upper_case_globals)]
|
||||
mod node_code;
|
||||
|
||||
mod satom;
|
||||
pub mod tracker;
|
||||
|
@ -547,8 +547,8 @@ pub mod tracker;
|
|||
use crate::nodes::NodeAudioContext;
|
||||
use crate::nodes::NodeExecContext;
|
||||
|
||||
use crate::util::AtomicFloat;
|
||||
use std::sync::Arc;
|
||||
use synfx_dsp::AtomicFloat;
|
||||
|
||||
pub type LedPhaseVals<'a> = &'a [Arc<AtomicFloat>];
|
||||
|
||||
|
@ -564,7 +564,6 @@ use crate::fa_cqnt;
|
|||
use crate::fa_cqnt_omax;
|
||||
use crate::fa_cqnt_omin;
|
||||
use crate::fa_delay_mode;
|
||||
use synfx_dsp::fa_distort;
|
||||
use crate::fa_map_clip;
|
||||
use crate::fa_mux9_in_cnt;
|
||||
use crate::fa_noise_mode;
|
||||
|
@ -580,6 +579,7 @@ use crate::fa_smap_mode;
|
|||
use crate::fa_test_s;
|
||||
use crate::fa_tseq_cmode;
|
||||
use crate::fa_vosc_ovrsmpl;
|
||||
use synfx_dsp::fa_distort;
|
||||
|
||||
use node_ad::Ad;
|
||||
use node_allp::AllP;
|
||||
|
@ -587,6 +587,7 @@ use node_amp::Amp;
|
|||
use node_biqfilt::BiqFilt;
|
||||
use node_bosc::BOsc;
|
||||
use node_bowstri::BowStri;
|
||||
use node_code::Code;
|
||||
use node_comb::Comb;
|
||||
use node_cqnt::CQnt;
|
||||
use node_delay::Delay;
|
||||
|
@ -607,7 +608,6 @@ use node_sin::Sin;
|
|||
use node_smap::SMap;
|
||||
use node_test::Test;
|
||||
use node_tseq::TSeq;
|
||||
use node_code::Code;
|
||||
use node_tslfo::TsLFO;
|
||||
use node_vosc::VOsc;
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ use crate::dsp::tracker::{PatternData, Tracker};
|
|||
use crate::dsp::{node_factory, Node, NodeId, NodeInfo, ParamId, SAtom};
|
||||
use crate::monitor::{new_monitor_processor, MinMaxMonitorSamples, Monitor, MON_SIG_CNT};
|
||||
use crate::nodes::drop_thread::DropThread;
|
||||
use crate::util::AtomicFloat;
|
||||
#[cfg(feature = "synfx-dsp-jit")]
|
||||
use crate::wblockdsp::CodeEngine;
|
||||
use crate::SampleLibrary;
|
||||
|
@ -23,6 +22,7 @@ use ringbuf::{Producer, RingBuffer};
|
|||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use synfx_dsp::AtomicFloat;
|
||||
use triple_buffer::Output;
|
||||
|
||||
/// A NodeInstance describes the input/output/atom ports of a Node
|
||||
|
|
|
@ -8,7 +8,8 @@ use super::{
|
|||
};
|
||||
use crate::dsp::{Node, NodeContext, NodeId, MAX_BLOCK_SIZE};
|
||||
use crate::monitor::{MonitorBackend, MON_SIG_CNT};
|
||||
use crate::util::{AtomicFloat, Smoother};
|
||||
use crate::util::Smoother;
|
||||
use synfx_dsp::AtomicFloat;
|
||||
|
||||
use crate::log;
|
||||
use std::io::Write;
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
// See README.md and COPYING for details.
|
||||
|
||||
use crate::nodes::SCOPE_SAMPLES;
|
||||
use crate::util::{AtomicFloat, AtomicFloatPair};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use synfx_dsp::{AtomicFloat, AtomicFloatPair};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ScopeHandle {
|
||||
|
|
121
src/util.rs
121
src/util.rs
|
@ -2,8 +2,6 @@
|
|||
// This file is a part of HexoDSP. Released under GPL-3.0-or-later.
|
||||
// See README.md and COPYING for details.
|
||||
|
||||
use std::sync::atomic::{AtomicU32, AtomicU64, Ordering};
|
||||
|
||||
const SMOOTHING_TIME_MS: f32 = 10.0;
|
||||
|
||||
pub struct Smoother {
|
||||
|
@ -95,122 +93,3 @@ impl PerfTimer {
|
|||
self.i = std::time::Instant::now();
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation from vst-rs
|
||||
// https://github.com/RustAudio/vst-rs/blob/master/src/util/atomic_float.rs
|
||||
// Under MIT License
|
||||
// Copyright (c) 2015 Marko Mijalkovic
|
||||
pub struct AtomicFloat {
|
||||
atomic: AtomicU32,
|
||||
}
|
||||
|
||||
impl AtomicFloat {
|
||||
/// New atomic float with initial value `value`.
|
||||
pub fn new(value: f32) -> AtomicFloat {
|
||||
AtomicFloat { atomic: AtomicU32::new(value.to_bits()) }
|
||||
}
|
||||
|
||||
/// Get the current value of the atomic float.
|
||||
#[inline]
|
||||
pub fn get(&self) -> f32 {
|
||||
f32::from_bits(self.atomic.load(Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// Set the value of the atomic float to `value`.
|
||||
#[inline]
|
||||
pub fn set(&self, value: f32) {
|
||||
self.atomic.store(value.to_bits(), Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AtomicFloat {
|
||||
fn default() -> Self {
|
||||
AtomicFloat::new(0.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for AtomicFloat {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Debug::fmt(&self.get(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AtomicFloat {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(&self.get(), f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f32> for AtomicFloat {
|
||||
fn from(value: f32) -> Self {
|
||||
AtomicFloat::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AtomicFloat> for f32 {
|
||||
fn from(value: AtomicFloat) -> Self {
|
||||
value.get()
|
||||
}
|
||||
}
|
||||
|
||||
/// The AtomicFloatPair can store two `f32` numbers atomically.
|
||||
///
|
||||
/// This is useful for storing eg. min and max values of a sampled signal.
|
||||
pub struct AtomicFloatPair {
|
||||
atomic: AtomicU64,
|
||||
}
|
||||
|
||||
impl AtomicFloatPair {
|
||||
/// New atomic float with initial value `value`.
|
||||
pub fn new(v: (f32, f32)) -> AtomicFloatPair {
|
||||
AtomicFloatPair {
|
||||
atomic: AtomicU64::new(((v.0.to_bits() as u64) << 32) | (v.1.to_bits() as u64)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the current value of the atomic float.
|
||||
#[inline]
|
||||
pub fn get(&self) -> (f32, f32) {
|
||||
let v = self.atomic.load(Ordering::Relaxed);
|
||||
(f32::from_bits((v >> 32 & 0xFFFFFFFF) as u32), f32::from_bits((v & 0xFFFFFFFF) as u32))
|
||||
}
|
||||
|
||||
/// Set the value of the atomic float to `value`.
|
||||
#[inline]
|
||||
pub fn set(&self, v: (f32, f32)) {
|
||||
let v = ((v.0.to_bits() as u64) << 32) | (v.1.to_bits()) as u64;
|
||||
self.atomic.store(v, Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AtomicFloatPair {
|
||||
fn default() -> Self {
|
||||
AtomicFloatPair::new((0.0, 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for AtomicFloatPair {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let v = self.get();
|
||||
write!(f, "({}, {})", v.0, v.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AtomicFloatPair {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let v = self.get();
|
||||
write!(f, "({}, {})", v.0, v.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(f32, f32)> for AtomicFloatPair {
|
||||
fn from(value: (f32, f32)) -> Self {
|
||||
AtomicFloatPair::new((value.0, value.1))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AtomicFloatPair> for (f32, f32) {
|
||||
fn from(value: AtomicFloatPair) -> Self {
|
||||
value.get()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue