Add panic logging test

This commit is contained in:
Ebu
2025-12-02 10:36:07 +01:00
parent 853b60e126
commit e170c0a99e
5 changed files with 54 additions and 7 deletions

15
Cargo.lock generated
View File

@@ -324,7 +324,10 @@ dependencies = [
name = "ebu-dsp"
version = "0.1.0"
dependencies = [
"crossbeam",
"log",
"nih_plug",
"simplelog",
]
[[package]]
@@ -336,6 +339,7 @@ dependencies = [
"ebu-dsp",
"femtovg",
"image",
"log",
"nih_plug",
"parking_lot",
"serde",
@@ -940,6 +944,17 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "simplelog"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0"
dependencies = [
"log",
"termcolor",
"time",
]
[[package]]
name = "slotmap"
version = "1.0.7"

View File

@@ -15,6 +15,7 @@ crossbeam = "0.8.4"
femtovg = "0.18.1"
serde = { version = "1.0.228", features = ["derive"] }
image = { version = "0.25.9", default-features = false, features = ["png"] }
log = "0.4.28"
[workspace]
members = ["ebu-dsp"]

View File

@@ -5,3 +5,6 @@ edition = "2024"
[dependencies]
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug", version = "0.0.0", default-features = false }
log = "0.4.28"
simplelog = "0.12.2"
crossbeam = "0.8.4"

View File

@@ -2,26 +2,28 @@ mod amplitude;
mod biquad;
mod comp;
mod decibel;
mod eq;
mod freq_split;
mod meter;
mod ring_buffer;
mod smoother;
mod traits;
mod eq;
use std::{
fmt::Debug,
ops::Add,
time::Duration,
fmt::Debug, ops::Add, panic, time::Duration
};
pub use amplitude::Amplitude;
pub use biquad::{BiquadFilter, BiquadFilterState, FilterMode, Slope};
pub use comp::{Compressor, CompressorState};
pub use freq_split::{FreqSplitter, FreqSplitterState};
pub use traits::{FloatFormatter, IntFormatter, Lerp, Processor};
use crossbeam::atomic::AtomicCell;
pub use decibel::Decibel;
pub use amplitude::Amplitude;
pub use eq::{Equalizer, EqualizerState};
pub use freq_split::{FreqSplitter, FreqSplitterState};
use log::{error, info};
use nih_plug::{nih_error, util::permit_alloc};
use simplelog::{CombinedLogger, Config, SimpleLogger, WriteLogger};
pub use traits::{FloatFormatter, IntFormatter, Lerp, Processor};
pub struct Rect<T> {
pub x: T,
@@ -196,3 +198,27 @@ pub fn rms<const N: usize>(sample_buffer: &RingBuffer<f64, N>, last_rms: f64) ->
last_rms.powf(2.0)
+ (1.0 / N as f64) * (sample_buffer[0].powf(2.0) - sample_buffer[N - 1].powf(2.0))
}
static LOGGER: AtomicCell<Option<Box<CombinedLogger>>> = AtomicCell::new(None);
pub fn init() {
permit_alloc(|| {
let log_file = std::fs::File::create("airfreshener.log").unwrap();
let term_log = SimpleLogger::new(log::LevelFilter::Debug, Config::default());
let file_log = WriteLogger::new(log::LevelFilter::Debug, Config::default(), log_file);
LOGGER.store(Some(simplelog::CombinedLogger::new(vec![
term_log, file_log,
])));
info!("Log check");
panic::set_hook(Box::new(|info| {
if let Some(str) = info.payload().downcast_ref::<String>() {
error!("Panic! {str}\n{:?}", info.location());
nih_error!("Panic! {str}\n{:?}", info.location());
}
else {
error!("Panic! No info provided.\n{:?}", info.location());
nih_error!("Panic! No info provided.\n{:?}", info.location());
}
}));
});
}

View File

@@ -99,6 +99,8 @@ impl Plugin for AirFreshener {
buffer_config: &BufferConfig,
_context: &mut impl InitContext<Self>,
) -> bool {
ebu_dsp::init();
let sample_rate = SampleRate(buffer_config.sample_rate as f64);
for _ in 0.._audio_io_layout
.main_input_channels