Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX DJ9// File : Packages/ORIXDJCore/Sources/ORIXDSP/Effects/Noise.swift10// Description : Noise sweep: band-pass filtered white noise added to the11// input (wet = input + noise).12// Module : ORIXDSP13// Repository : https://git.spboucher.ai/orix-dj14// Created : 2026-11-2115// Last Modified : 2026-11-2116//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author : Simon-Pierre Boucher22// Position : Professor of Finance23// Institution : Université du Québec en Outaouais (UQO)24// Department : Département des sciences administratives25// Organization : SP Boucher26//27// Website : https://spboucher.ai28// Git : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General : info@spboucher.ai35// Professional : contact@spboucher.ai36// Direct : simon@spboucher.ai37// Research : research@spboucher.ai38// Development : dev@spboucher.ai39// Support : support@spboucher.ai40// Security/Admin : admin@spboucher.ai41// Notifications : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification : Public68// Distribution : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License : None specified (no license file in this repository)82// Maintainer : Simon-Pierre Boucher83// Technical Contact: dev@spboucher.ai84//85// =============================================================================86// END OF SP BOUCHER SOURCE HEADER87// =============================================================================8889import Foundation9091/// Independent noise per channel through a smoothed constant-peak-gain band-pass. A narrower band is therefore quieter,92/// which keeps a resonant sweep from jumping in level.93public final class NoiseEffect: EffectUnit, @unchecked Sendable {94 private var generatorL = NoiseGenerator(seed: 0x1234_5678), generatorR = NoiseGenerator(seed: 0x9E37_79B9)95 private var filter: SmoothedSVF96 private var level: OnePoleSmoother9798 public init(sampleRate: Double) {99 let d = EffectCatalog.descriptor(.noise)100 filter = SmoothedSVF(mode: .bandpass, frequency: d.params[1].defaultValue, q: d.params[2].defaultValue, sampleRate: Float(sampleRate))101 level = OnePoleSmoother(timeConstantMS: 20, sampleRate: Float(sampleRate))102 super.init(kind: .noise, sampleRate: sampleRate)103 parameterChanged(0); level.snap(level.target)104 }105106 public override func parameterChanged(_ index: Int) {107 if index == 0 { level.target = dbToLinear(values[0]) } else { filter.set(frequency: values[1], q: values[2]) }108 }109110 public override func reset() { filter.reset() }111112 public override func processWet(_ l: UnsafeMutablePointer<Float>, _ r: UnsafeMutablePointer<Float>, _ n: Int) {113 var f = filter, lv = level, gl = generatorL, gr = generatorR, i = 0114 while i < n {115 let c = min(SmoothedSVF.chunk, n - i)116 f.prepare(c)117 for k in i ..< i + c {118 let g = lv.next()119 let (nl, nr) = f.tick(gl.next(), gr.next())120 l[k] += nl * g; r[k] += nr * g121 }122 i += c123 }124 filter = f; level = lv; generatorL = gl; generatorR = gr125 }126}127