1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! # mkaudiolibrary
//!
//! A Rust library for real-time audio signal processing, featuring analog modeling
//! through numeric functions and circuit simulation via Modified Nodal Analysis (MNA).
//!
//! ## Features
//!
//! - **Thread-safe buffers** - Concurrent access with `RwLock`-based locking
//! - **Analog modeling** - Asymmetric saturation for tube/tape-style harmonics
//! - **Circuit simulation** - Real-time MNA solver for reactive circuits
//! - **DSP primitives** - Convolution, compression, limiting, and delay
//! - **Audio file I/O** - WAV and AIFF format support with Buffer integration
//! - **Plugin system** - MKAU format for modular processing chains
//!
//! ## Quick Start
//!
//! ```ignore
//! use mkaudiolibrary::audiofile::{AudioFile, FileFormat};
//! use mkaudiolibrary::dsp::Compression;
//!
//! // Load an audio file
//! let mut audio = AudioFile::default();
//! audio.load("input.wav");
//!
//! // Convert to thread-safe buffers for processing
//! let buffers = audio.to_buffers();
//!
//! // Apply compression
//! let mut comp = Compression::new(audio.sample_rate() as f64);
//! comp.threshold = -12.0;
//! comp.ratio = 4.0;
//! for buffer in &buffers {
//! let output = mkaudiolibrary::buffer::Buffer::new(buffer.len());
//! comp.run(buffer, &output);
//! // ... use processed output
//! }
//!
//! // Save result
//! audio.save("output.wav", FileFormat::Wav);
//! ```
//!
//! ## Modules
//!
//! - [`buffer`] - Thread-safe audio buffers (`Buffer`, `PushBuffer`, `CircularBuffer`)
//! - [`dsp`] - Digital signal processing components
//! - [`audiofile`] - WAV/AIFF file loading and saving
//! - [`processor`] - MKAU plugin format and dynamic loading
//!
//! ## Thread Safety
//!
//! All buffer types use `Arc<RwLock<...>>` internally, enabling:
//! - Multiple concurrent readers
//! - Exclusive writer access
//! - Safe sharing across threads via `Clone`
//!
//! ```ignore
//! use mkaudiolibrary::buffer::Buffer;
//! use std::thread;
//!
//! let buffer = Buffer::<f64>::new(1024);
//! let buffer_clone = buffer.clone(); // Shares underlying data
//!
//! thread::spawn(move || {
//! let mut guard = buffer_clone.write();
//! guard[0] = 1.0;
//! });
//! ```
//!
//! ## DSP Processing Examples
//!
//! ### Saturation (Analog Modeling)
//!
//! ```ignore
//! use mkaudiolibrary::dsp::Saturation;
//! use mkaudiolibrary::buffer::Buffer;
//!
//! let sat = Saturation::new(10.0, 10.0, 1.0, 1.0, 0.0, false);
//! let input = Buffer::from_slice(&[0.0, 0.5, 1.0, -0.5, -1.0]);
//! let output = Buffer::new(5);
//! sat.run(&input, &output);
//! ```
//!
//! ### Circuit Simulation
//!
//! ```ignore
//! use mkaudiolibrary::dsp::{Circuit, Resistor, Capacitor};
//!
//! // RC lowpass filter: R=1kΩ, C=1µF, fc ≈ 159Hz
//! let mut circuit = Circuit::new(44100.0, 2);
//! circuit.add_component(Box::new(Resistor::new(1, 2, 1000.0)));
//! circuit.add_component(Box::new(Capacitor::new(2, 0, 1e-6)));
//! circuit.preprocess(10.0);
//!
//! let output = circuit.process(1.0, 2); // Input 1V, probe node 2
//! ```
//!
//! ### Dynamics Processing
//!
//! ```ignore
//! use mkaudiolibrary::dsp::{Compression, Limit};
//!
//! let mut compressor = Compression::new(44100.0);
//! compressor.threshold = -20.0; // dB
//! compressor.ratio = 4.0; // 4:1
//!
//! let mut limiter = Limit::new(44100.0);
//! limiter.ceiling = -0.1; // dB
//! ```
//!
//! ## License
//!
//! This library is dual-licensed:
//!
//! - **GPL-3.0** for open source projects
//! - **Commercial license** available for closed source usage
//!
//! For commercial licensing inquiries, contact: minjaekim@mkaudio.company
/// Thread-safe audio buffers for real-time concurrent processing.
///
/// Provides `Buffer`, `PushBuffer`, and `CircularBuffer` types with
/// `RwLock`-based locking for safe multi-threaded access.
/// Digital signal processing components for real-time audio.
///
/// Includes convolution, saturation, circuit simulation, compression,
/// limiting, and delay effects.
/// MKAU plugin format for modular audio processing chains.
///
/// Provides the `Processor` trait and dynamic plugin loading.
/// Audio file loading and saving for WAV and AIFF formats.
///
/// Supports 8/16/24/32-bit audio with normalized f64 sample representation.