audio_master/audio_master/
audio_master.rs

1use std::{
2    cell::RefCell,
3    marker::PhantomData,
4    rc::Rc,
5    sync::{Arc, RwLock},
6};
7
8use fxhash::{FxHashMap, FxHashSet};
9use num_traits::Float;
10use rustfft::{FftPlanner, num_complex::Complex};
11
12use crate::{
13    audio_buffer::{AudioBuffer, AudioBufferInterleaved, AudioChannelLayout},
14    audio_math::AudioFilter,
15    backend::{AudioHost, Device, RawAudioStream},
16    float_type::FloatType,
17    resampler::{Resampler, ResamplerQuality},
18};
19
20/// Represents the state of an audio effect after processing or parameter operations.
21/// This enum is used to indicate success or various error conditions in audio effect handling.
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum AudioEffectState {
24    /// Processing completed successfully.
25    ProcessOk,
26    /// An error occurred during processing.
27    ProcessError,
28    /// The specified parameter does not exist.
29    ParamNoEntry,
30    // ParamOutOfRange, // Commented out in original; potentially for future use.
31    /// The provided string parameter value is invalid, with the error message.
32    ParamStrInvalid(String),
33    /// The effect operation was successful.
34    EffectOk,
35    /// Failed to reset the effect.
36    EffectResetFailed,
37    /// An effect with the same name already exists.
38    EffectAlreadyExists,
39    /// The specified effect does not exist.
40    EffectNoEntry,
41}
42
43/// Represents the value of an effect parameter, supporting various numeric and string types.
44#[derive(Debug, Clone)]
45pub enum EffectParamValue<'a> {
46    U8(u8),
47    U16(u16),
48    U32(u32),
49    U64(u64),
50    I8(i8),
51    I16(i16),
52    I32(i32),
53    I64(i64),
54    F32(f32),
55    F64(f64),
56    Str(&'a str),
57}
58
59/// Represents the type of an effect parameter, used for type checking and validation.
60#[derive(Debug, Clone, Copy, PartialEq, Eq)]
61pub enum EffectParamType {
62    U8,
63    U16,
64    U32,
65    U64,
66    I8,
67    I16,
68    I32,
69    I64,
70    F32,
71    F64,
72    Str,
73}
74
75/// Represents the state of an audio stream after processing.
76/// This indicates whether the stream processed normally or encountered issues.
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub enum AudioStreamState {
79    /// Stream processing was successful.
80    Ok,
81    /// An internal error occurred; input buffer is filled with zeros.
82    Err,
83    /// The stream is silent; input buffer is filled with zeros.
84    Silence,
85    /// Other error condition with a descriptive message; input buffer is filled with zeros.
86    Other(String),
87}
88
89/// Volume metrics, clipping information, and FFT analysis data.
90#[derive(Debug, Clone)]
91pub struct AudioAnalysis {
92    /// Name or identifier for this analysis.
93    pub name: String,
94    /// Average volume in decibels.
95    pub avg_volume_db: f32,
96    /// Number of clipping occurrences.
97    pub clippings: usize,
98    /// Ratio of clipping in the signal.
99    pub clipping_ratio: f32,
100    /// FFT analysis data as a vector of floats.
101    pub analysis: Vec<f32>,
102}
103
104/// Alias for parameter property descriptions.
105/// This is an array of tuples, each containing a parameter name and its type.
106/// The const generic `N` specifies the number of parameters.
107pub type ParamPropDesk<'a, const N: usize> = [(&'a str, EffectParamType); N];
108
109/// Trait for implementing audio effects.
110/// NOTE: Parameter names are validated against `ParamPropDesk`, so no additional name checks are needed.
111pub trait AudioEffectTrait<T: FloatType> {
112    /// Main processing function for the effect.
113    /// Applies the effect to the input audio buffer.
114    /// Returns the state after processing.
115    fn process(&mut self, input: &mut AudioBuffer<T>) -> AudioEffectState;
116
117    /// Retrieves the value of a parameter by name.
118    /// Returns the parameter value or an error state if not found.
119    fn get_param(&mut self, name: &str) -> Result<EffectParamValue, AudioEffectState>;
120
121    /// Sets the value of a parameter by name.
122    /// Returns the state after setting the parameter.
123    fn set_param(&mut self, name: &str, value: EffectParamValue) -> AudioEffectState;
124
125    /// Resets the effect to its initial state.
126    /// Returns the state after reset.
127    fn reset(&mut self) -> AudioEffectState;
128
129    /// Sets the sample rate for the effect.
130    /// This may be used to adjust internal calculations based on sample rate.
131    fn set_sample_rate(&mut self, sample_rate: f32);
132}
133
134#[derive(Debug, Clone)]
135pub struct AudioStreamContext {
136    /// Timestamp of the current stream position in seconds.
137    pub timestamp: f64,
138    /// Sample rate in Hz.
139    pub sample_rate: u32,
140}
141
142/// Trait for feeders that provide audio data to streams.
143/// Implementors process input buffers based on the provided context.
144pub trait AudioStreamFeederTrait<T: FloatType + Float> {
145    /// Processes the input audio buffer using the given context.
146    /// Returns the state of the stream after processing.
147    fn process(
148        &mut self,
149        context: &AudioStreamContext,
150        input: &mut AudioBuffer<T>,
151    ) -> AudioStreamState;
152}
153
154/// Public API trait for audio effects.
155/// NOTE: Uses raw pointers internally for reference exposure; not read/write secured for get_name() and get_params().
156pub trait AudioEffectImpl<T: FloatType + Float>: Sized {
157    /// Creates a new audio effect with the given name, parameter properties, and processor.
158    /// The const generic `N` specifies the number of parameters.
159    fn new<const N: usize>(
160        name: &str,
161        param_props: ParamPropDesk<N>,
162        proc: Box<dyn AudioEffectTrait<T>>,
163    ) -> AudioEffect<T>;
164
165    /// Gets the name of the effect.
166    fn get_name(&self) -> &str;
167
168    /// Gets a reference to the map of all parameters and their types.
169    fn get_params(&self) -> &FxHashMap<String, EffectParamType>;
170
171    /// Sets a parameter by name.
172    /// Returns the state after setting.
173    fn set_param(&mut self, name: &str, value: EffectParamValue) -> AudioEffectState;
174
175    /// Gets a parameter value by name.
176    /// Returns the value or an error state.
177    fn get_param(&self, name: &str) -> Result<EffectParamValue, AudioEffectState>;
178
179    /// Enables or disables the input filter before processing.
180    fn use_filter_in(&mut self, use_filter: bool);
181
182    /// Enables or disables the output filter after processing.
183    fn use_filter_out(&mut self, use_filter: bool);
184
185    /// Checks if the input filter is enabled.
186    fn is_using_filter_in(&self) -> bool;
187    /// Checks if the output filter is enabled.
188    fn is_using_filter_out(&self) -> bool;
189
190    /// Sets the mix level (clamped between 0.0 and 1.0).
191    fn set_mix(&mut self, new_mix: f32);
192
193    /// Gets the current mix level.
194    fn get_mix(&self) -> f32;
195
196    /// Sets the low-cut frequency for the input filter (clamped between 10.0 and 22050.0 Hz).
197    fn set_low_cut_in(&mut self, cut: f32);
198
199    /// Gets the low-cut frequency for the input filter.
200    fn get_low_cut_in(&self) -> f32;
201
202    /// Sets the high-cut frequency for the input filter (clamped between 10.0 and 22050.0 Hz).
203    fn set_high_cut_in(&mut self, cut: f32);
204
205    /// Gets the high-cut frequency for the input filter.
206    fn get_high_cut_in(&self) -> f32;
207
208    /// Sets the low-cut frequency for the output filter (clamped between 10.0 and 22050.0 Hz).
209    fn set_low_cut_out(&mut self, cut: f32);
210
211    /// Gets the low-cut frequency for the output filter.
212    fn get_low_cut_out(&self) -> f32;
213
214    /// Sets the high-cut frequency for the output filter (clamped between 10.0 and 22050.0 Hz).
215    fn set_high_cut_out(&mut self, cut: f32);
216
217    /// Gets the high-cut frequency for the output filter.
218    fn get_high_cut_out(&self) -> f32;
219}
220
221/// Public API trait for audio processors.
222/// This manages a sequence of effects and global processing settings.
223pub trait AudioProcessorImpl<T: FloatType + Float>: Sized {
224    /// Creates a new audio processor with the given sample rate and buffer size.
225    fn new(sample_rate: f32, buffer_size: usize) -> AudioProcessor<T>;
226
227    /// Sets the global mix level (clamped between 0.0 and 1.0).
228    fn set_mix(&mut self, mix: f32);
229
230    /// Gets the global mix level.
231    fn get_mix(&self) -> f32;
232
233    /// Enables or disables the global filter.
234    fn use_filter(&mut self, use_filter: bool);
235    /// Checks if the global filter is enabled.
236    fn is_using_filter(&self) -> bool;
237
238    /// Sets the low-cut frequency for the global filter (clamped between 10.0 and 22050.0 Hz).
239    fn set_low_cut(&mut self, low_cut: f32);
240
241    /// Gets the low-cut frequency for the global filter.
242    fn get_low_cut(&self) -> f32;
243
244    /// Sets the high-cut frequency for the global filter (clamped between 10.0 and 22050.0 Hz).
245    fn set_high_cut(&mut self, high_cut: f32);
246
247    /// Gets the high-cut frequency for the global filter.
248    fn get_high_cut(&self) -> f32;
249
250    /// Sets the sample rate for the processor and updates all effects.
251    /// Clamped between 1000.0 and 192000.0 Hz.
252    fn set_sample_rate(&mut self, sample_rate: f32);
253
254    /// Gets the current sample rate.
255    fn get_sample_rate(&self) -> f32;
256
257    /// Adds an effect to the processor.
258    /// Returns `EffectAlreadyExists` if an effect with the same name is present.
259    fn add_effect(&mut self, effect: AudioEffect<T>) -> AudioEffectState;
260
261    /// Removes an effect by name.
262    /// Returns the removed effect or `EffectNoEntry` if not found.
263    fn remove_effect(&mut self, name: &str) -> Result<AudioEffect<T>, AudioEffectState>;
264
265    /// Moves an effect from one position to another in the processing sequence.
266    fn move_effect(&mut self, from: usize, to: usize);
267
268    /// Gets a clone of the effect by name.
269    /// Returns `EffectNoEntry` if not found.
270    fn get_effect(&self, name: &str) -> Result<AudioEffect<T>, AudioEffectState>;
271
272    /// Connects an analyzer to the processor for audio analysis.
273    fn connect_analyser(&mut self, anal: Rc<RefCell<AudioAnalyser<T>>>);
274
275    /// Disconnects and returns the connected analyzer, if any.
276    fn disconnect_analyser(&mut self) -> Option<Rc<RefCell<AudioAnalyser<T>>>>;
277}
278
279/// Settings for creating an audio stream, including sample rate and channel layout.
280#[derive(Debug, Clone)]
281pub struct AudioStreamSettings {
282    /// Sample rate in Hz.
283    pub sample_rate: u32,
284    /// Channel layout.
285    pub channel_layout: AudioChannelLayout,
286}
287
288/// Error types for the audio master system.
289#[derive(Debug, Clone, PartialEq, PartialOrd)]
290pub enum AudioMasterError {
291    /// No audio device is available.
292    NoDeviceAvailable,
293    /// The stream has not been initialized.
294    StreamNotInitialized,
295    /// Internal error with a descriptive message.
296    Internal(String),
297}
298
299/// Public API trait for the audio master, which manages devices and streams.
300pub trait AudioMasterImpl {
301    /// Creates a new audio master with default settings.
302    fn new() -> AudioMaster;
303    /// Creates a new audio master with a specified buffer size.
304    fn new_with_buffer_size(buffer_size: usize) -> AudioMaster;
305    /// Creates a new audio master with a specified frame rate (FPS).
306    fn new_with_fps(fps: usize) -> AudioMaster;
307
308    /// Stops the main system audio stream.
309    fn stop_sys_stream(&mut self) -> Result<(), AudioMasterError>;
310
311    /// Starts the main system audio stream.
312    fn start_sys_stream(&mut self) -> Result<(), AudioMasterError>;
313
314    /// Attempts to initialize the audio stream.
315    fn try_to_initialize_stream(&mut self) -> Result<(), AudioMasterError>;
316    /// Gets a list of available audio devices.
317    fn devices(&self) -> Vec<Device>;
318    /// Gets the currently selected device, if any.
319    fn get_current_device(&self) -> Option<Device>;
320
321    /// Changes the current audio device by ID.
322    fn change_device(&self, device_id: usize) -> Result<(), AudioMasterError>;
323
324    /// Creates a new f32 audio stream with the given settings and feeder.
325    fn create_stream_f32(
326        &mut self,
327        settings: &AudioStreamSettings,
328        feeder: Box<dyn AudioStreamFeederTrait<f32>>,
329    ) -> AudioStream<f32>;
330    /// Creates a new f64 audio stream with the given settings and feeder.
331    fn create_stream_f64(
332        &mut self,
333        settings: &AudioStreamSettings,
334        feeder: Box<dyn AudioStreamFeederTrait<f64>>,
335    ) -> AudioStream<f64>;
336}
337
338/// Public API trait for audio streams.
339/// This manages stream properties like volume, speed, and filtering.
340pub trait AudioStreamImpl<T: FloatType + Float> {
341    /// Enables or disables normalization.
342    fn use_normalization(&mut self, norm: bool);
343    /// Checks if normalization is enabled.
344    fn is_using_normalization(&self) -> bool;
345
346    /// Gets the current timestamp in seconds.
347    fn get_timestamp(&self) -> f64;
348
349    /// Gets the resampler quality.
350    fn get_resample_quality(&self) -> ResamplerQuality;
351    /// Sets the resampler quality.
352    fn set_resample_quality(&mut self, quality: ResamplerQuality);
353
354    /// Gets the playback speed (clamped between 0.2 and 8.0).
355    fn get_speed(&self) -> f32;
356    /// Sets the playback speed (clamped between 0.2 and 8.0).
357    fn set_speed(&mut self, speed: f32);
358
359    /// Gets the volume level.
360    fn get_volume(&self) -> f32;
361
362    /// Sets the volume level (clamped between 0.0 and 1.0).
363    fn set_volume(&self, volume: f32);
364
365    /// Enables or disables the filter.
366    fn use_filter(&mut self, filter: bool);
367    /// Checks if the filter is enabled.
368    fn is_using_filter(&self) -> bool;
369
370    /// Gets the low-cut frequency.
371    fn get_low_cut(&self) -> f32;
372    /// Sets the low-cut frequency (clamped between 10.0 and 22050.0 Hz).
373    fn set_low_cut(&mut self, low_cut: f32);
374
375    /// Gets the high-cut frequency.
376    fn get_high_cut(&self) -> f32;
377
378    /// Sets the high-cut frequency (clamped between 10.0 and 22050.0 Hz).
379    fn set_high_cut(&mut self, high_cut: f32);
380
381    /// Gets the sample rate.
382    fn get_sample_rate(&self) -> f32;
383
384    /// Sets the sample rate (clamped between 1000.0 and 192000.0 Hz).
385    fn set_sample_rate(&mut self, sample_rate: f32);
386
387    /// Gets the channel layout.
388    fn get_channel_layout(&self) -> AudioChannelLayout;
389    /// Sets the channel layout.
390    fn set_channel_layout(&mut self, layout: AudioChannelLayout);
391
392    /// Gets a clone of the shared processor.
393    fn get_processor(&self) -> AudioProcessor<T>;
394
395    /// Resumes the stream if paused.
396    fn resume(&mut self);
397    /// Pauses the stream.
398    fn pause(&mut self);
399}
400
401/// Shared pointer to an audio effect, using Arc<RwLock> for thread-safe access.
402#[derive(Clone)]
403pub struct AudioEffect<T: FloatType + Float> {
404    /// Inner effect data, wrapped in Arc<RwLock> for shared mutable access.
405    pub(super) inner: Arc<RwLock<AudioEffectInner<T>>>,
406}
407
408/// Shared pointer to the audio master.
409#[derive(Clone)]
410pub struct AudioMaster {
411    pub(super) inner: Arc<RwLock<AudioMasterInner>>,
412}
413
414/// Shared pointer to an audio stream.
415/// NOTE: This is a virtual in-runtime object, not a system-level stream.
416#[derive(Clone)]
417pub struct AudioStream<T: FloatType + Float> {
418    pub(super) inner: Arc<RwLock<AudioStreamInner<T>>>,
419}
420
421/// Shared pointer to an audio processor.
422#[derive(Clone)]
423pub struct AudioProcessor<T: FloatType + Float> {
424    /// Inner processor data, wrapped in Arc<RwLock> for shared mutable access.
425    pub(super) inner: Arc<RwLock<AudioProcessorInner<T>>>,
426}
427
428pub trait AudioProcessorPrivateImpl<T: FloatType + Float>: Sized {
429    /// Main processing function that applies effects to the input buffer.
430    fn process(&mut self, input: &mut AudioBuffer<T>) -> AudioEffectState;
431
432    /// Sets the sample rate for all effects in the processor.
433    fn set_effects_sample_rate(&mut self, sample_rate: f32);
434
435    /// Starts an analysis sequence with the given analyzer and size.
436    fn anal_start_sequence(anal: &Option<Rc<RefCell<AudioAnalyser<T>>>>, size: usize);
437    /// Ends an analysis sequence with the given analyzer.
438    fn anal_end_sequence(anal: &Option<Rc<RefCell<AudioAnalyser<T>>>>);
439    /// Analyzes the next node in the sequence.
440    fn analyze_next_node(
441        anal: &Option<Rc<RefCell<AudioAnalyser<T>>>>,
442        name: &str,
443        input: &AudioBuffer<T>,
444    );
445
446    /// Sets the buffer size for the processor.
447    fn set_buffer_size(&mut self, new_len: usize);
448}
449
450pub trait AudioStreamPrivateImpl<T: FloatType + Float>: Sized {
451    /// Factory method to create a new stream inner with feeder, sample rate, and channel layout.
452    fn factory(
453        feeder: Box<dyn AudioStreamFeederTrait<T>>,
454        sample_rate: u32,
455        channel_layout: AudioChannelLayout,
456    ) -> Self;
457
458    /// Processes the input buffer.
459    fn process(&mut self, input: &mut AudioBuffer<T>);
460    /// Performs pre-processing steps.
461    fn pre_process(&mut self);
462    /// Performs post-processing on the input buffer.
463    fn post_process(&mut self, input: &mut AudioBuffer<T>);
464
465    /// Clears internal buffers.
466    fn clear_buffers(&mut self);
467    /// Sets the buffer size for the stream.
468    fn set_buffer_size(&mut self, new_buff_size: usize);
469}
470
471pub trait AudioEffectPrivateImpl<T: FloatType + Float>: Sized {
472    /// Processes the input buffer with the effect.
473    fn process(&mut self, input: &mut AudioBuffer<T>) -> AudioEffectState;
474    /// Sets the sample rate for the effect.
475    fn set_sample_rate(&mut self, sample_rate: f32);
476    /// Resizes internal buffers to the new length.
477    fn resize(&mut self, new_len: usize);
478}
479
480pub trait AudioAnalyserPrivateImpl<T: FloatType>: Sized {
481    /// Resizes internal buffers to the new length.
482    fn resize(&mut self, new_len: usize);
483    /// Calculates volume and clipping metrics.
484    fn calc_volume_and_clippings(&mut self);
485    /// Performs the analysis.
486    fn analyze(&mut self);
487
488    /// Starts an analysis sequence with the given size.
489    fn start_sequence(&mut self, size: usize);
490    /// Ends an analysis sequence.
491    fn end_sequence(&mut self);
492    /// Processes the next node in the analysis sequence.
493    fn process_next_node(&mut self, name: &str, input: &AudioBuffer<T>);
494}
495
496pub trait AudioAnalysisPrivateImpl: Sized {
497    fn new(len: usize) -> AudioAnalysis;
498}
499
500/// Feeder for the main audio stream.
501#[derive(Clone)]
502pub struct MainStreamFeeder<T> {
503    /// Shared reference to the audio master inner.
504    pub(super) master: Arc<RwLock<AudioMasterInner>>,
505    /// Phantom data for type parameter T.
506    pub(super) _phantom: PhantomData<T>,
507}
508
509/// Struct representing a parameter property.
510#[derive(Debug, Clone)]
511pub struct ParamProp {
512    /// Name of the parameter.
513    pub(super) name: String,
514    /// Type of the parameter.
515    pub(super) _type: EffectParamType,
516}
517
518pub trait AudioMasterPrivateImpl: Sized {
519    /// Factory method to create a new master inner with host, device, buffer size, and frame rate.
520    fn factory(
521        host: AudioHost,
522        device: Device,
523        buffer_size: Option<usize>,
524        frame_rate: Option<usize>,
525    ) -> Arc<RwLock<Self>>;
526    /// Attempts to create a default master with optional buffer size and frame rate.
527    fn try_to_create_default(
528        buffer_size: Option<usize>,
529        frame_rate: Option<usize>,
530    ) -> Option<Arc<RwLock<Self>>>;
531}
532
533pub struct AudioMasterInner {
534    /// The audio host backend.
535    pub(super) host: AudioHost,
536    /// Currently selected device.
537    pub(super) current_device: Option<Device>,
538    /// List of f32 streams with their buffers.
539    pub(super) streams_f32: Vec<(AudioBuffer<f32>, Arc<RwLock<AudioStreamInner<f32>>>)>,
540    /// List of f64 streams with their buffers.
541    pub(super) streams_f64: Vec<(AudioBuffer<f64>, Arc<RwLock<AudioStreamInner<f64>>>)>,
542    /// Main raw audio stream.
543    pub(super) main_stream: Option<RawAudioStream<f32>>,
544}
545
546pub struct AudioStreamInner<T: FloatType + Float> {
547    /// The feeder providing audio data.
548    pub(super) feeder: Box<dyn AudioStreamFeederTrait<T>>,
549    /// Current sample rate.
550    pub(super) sample_rate: f32,
551    /// Playback speed factor.
552    pub(super) speed: f32,
553    /// Volume level.
554    pub(super) volume: f32,
555    /// Resampling factor.
556    pub(super) resample_factor: f64,
557
558    /// Channel layout.
559    pub(super) channel_layout: AudioChannelLayout,
560    /// Resampled interleaved buffer.
561    pub(super) buffer_resampled: AudioBufferInterleaved<T>,
562    /// Interleaved buffer.
563    pub(super) buffer: AudioBufferInterleaved<T>,
564    /// Callback buffer.
565    pub(super) cb_buffer: AudioBuffer<T>,
566    /// Position in the resampled buffer.
567    pub(super) resampled_buffer_pos: usize,
568    /// Length of the resampled buffer.
569    pub(super) resampled_buffer_len: usize,
570
571    /// Flag for using filter.
572    pub(super) use_filter: bool,
573    /// Flag for using normalization.
574    pub(super) use_normalization: bool,
575    /// Flag for using processor.
576    pub(super) use_processor: bool,
577
578    /// Associated processor.
579    pub(super) processor: AudioProcessor<T>,
580    /// Audio filter.
581    pub(super) filter: AudioFilter<T>,
582
583    /// Resampler instance.
584    pub(super) resampler: Resampler<T>,
585    /// Current timestamp.
586    pub(super) timestamp: f64,
587    /// Flag indicating if the stream is paused.
588    pub(super) is_paused: bool,
589}
590
591pub struct AudioEffectInner<T: FloatType + Float> {
592    /// Name of the effect.
593    pub(super) name: String,
594    /// Map of parameters and their types.
595    pub(super) params: FxHashMap<String, EffectParamType>,
596    /// The effect processor trait object.
597    pub(super) processor: Box<dyn AudioEffectTrait<T>>,
598    /// Internal buffer.
599    pub(super) buffer: AudioBuffer<T>,
600    /// Mix level.
601    pub(super) mix: f32,
602
603    /// Current sample rate (for getter).
604    pub(super) sample_rate: f32,
605
606    /// Input filter.
607    pub(super) filter_in: AudioFilter<T>,
608    /// Output filter.
609    pub(super) filter_out: AudioFilter<T>,
610    /// Flag for using input filter.
611    pub(super) use_filter_in: bool,
612    /// Flag for using output filter.
613    pub(super) use_filter_out: bool,
614
615    /// If true, mutes the input signal but allows output.
616    pub(super) is_muffled: bool,
617}
618
619pub struct AudioProcessorInner<T: FloatType + Float> {
620    /// Set of effect names for quick lookup.
621    pub(super) effects: FxHashSet<String>,
622    /// Sequence of effects to apply.
623    pub(super) effects_seq: Vec<AudioEffect<T>>,
624    /// Internal buffer.
625    pub(super) buffer: AudioBuffer<T>,
626    /// Optional analyzer.
627    pub(super) analyser: Option<Rc<RefCell<AudioAnalyser<T>>>>,
628    /// Global filter.
629    pub(super) filter: AudioFilter<T>,
630    /// Flag for using the global filter.
631    pub(super) use_filter: bool,
632
633    /// Current sample rate.
634    pub(super) sample_rate: f32,
635    /// Global mix level.
636    pub(super) mix: f32,
637}
638
639pub struct AudioAnalyser<T: FloatType> {
640    /// FFT planner for f32.
641    pub(super) planner: FftPlanner<f32>,
642    /// Signal data as complex numbers.
643    pub(super) signal: Vec<Complex<f32>>,
644    /// Mixed audio data.
645    pub(super) mixed: Vec<T>,
646    /// List of analyses.
647    pub(super) anals: Vec<AudioAnalysis>,
648    /// User callback for analysis results.
649    pub(super) user_cb: Box<dyn FnMut(&[AudioAnalysis]) + 'static>,
650    /// Size of the analysis sequence.
651    pub(super) seq_size: usize,
652    /// Current index in the sequence.
653    pub(super) seq_index: usize,
654    /// Flag indicating if the sequence has started.
655    pub(super) seq_started: bool,
656}