Add a permit_alloc function
Since assert_no_alloc also hides panic messages which can make debugging more difficult: https://github.com/Windfisch/rust-assert-no-alloc/issues/4
This commit is contained in:
parent
592a908132
commit
0fa394247f
1 changed files with 14 additions and 0 deletions
14
src/util.rs
14
src/util.rs
|
@ -7,6 +7,20 @@ pub use stft::StftHelper;
|
||||||
|
|
||||||
pub const MINUS_INFINITY_DB: f32 = -100.0;
|
pub const MINUS_INFINITY_DB: f32 = -100.0;
|
||||||
|
|
||||||
|
/// Temporarily allow allocations within `func` if NIH-plug was configured with the
|
||||||
|
/// `assert_process_allocs` feature.
|
||||||
|
#[cfg(all(debug_assertions, feature = "assert_process_allocs"))]
|
||||||
|
pub fn permit_alloc<T, F: FnOnce() -> T>(func: F) -> T {
|
||||||
|
assert_no_alloc::permit_alloc(func)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Temporarily allow allocations within `func` if NIH-plug was configured with the
|
||||||
|
/// `assert_process_allocs` feature.
|
||||||
|
#[cfg(not(all(debug_assertions, feature = "assert_process_allocs")))]
|
||||||
|
pub fn permit_alloc<T, F: FnOnce() -> T>(func: F) -> T {
|
||||||
|
func
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert decibels to a voltage gain ratio, treating anything below -100 dB as minus infinity.
|
/// Convert decibels to a voltage gain ratio, treating anything below -100 dB as minus infinity.
|
||||||
pub fn db_to_gain(dbs: f32) -> f32 {
|
pub fn db_to_gain(dbs: f32) -> f32 {
|
||||||
if dbs > MINUS_INFINITY_DB {
|
if dbs > MINUS_INFINITY_DB {
|
||||||
|
|
Loading…
Add table
Reference in a new issue