Skip to content

Commit c365ede

Browse files
uklotzdeorottier
authored andcommitted
Update MSRV to 1.70 and remove lazy_static and once_cell
1 parent 826b5b8 commit c365ede

File tree

8 files changed

+38
-37
lines changed

8 files changed

+38
-37
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ keywords = ["web-audio-api", "audio", "sound", "dsp"]
1010
license = "MIT"
1111
categories = ["multimedia::audio"]
1212
exclude = ["/samples", "/showcase", "/.github"]
13+
rust-version = "1.70"
1314

1415
[dependencies]
1516
arc-swap = "1.6"
@@ -22,10 +23,8 @@ dasp_sample = "0.11"
2223
float_eq = "1.0"
2324
hound = "3.5"
2425
hrtf = "0.8"
25-
lazy_static = "1.4"
2626
log = "0.4"
2727
num-complex = "0.4"
28-
once_cell = "1.10"
2928
realfft = "3.0"
3029
rubato = "0.14"
3130
rustc-hash = "1.1"

src/node/audio_buffer_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use once_cell::sync::OnceCell;
1+
use std::cell::OnceCell;
22
use std::sync::atomic::{AtomicBool, Ordering};
33
use std::sync::Arc;
44

src/node/mod.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
//! The AudioNode interface and concrete types
22
use std::f32::consts::PI;
33
use std::sync::atomic::{AtomicU32, AtomicUsize, Ordering};
4-
use std::sync::Arc;
4+
use std::sync::{Arc, OnceLock};
55

66
use crate::context::{AudioContextRegistration, ConcreteBaseAudioContext};
77
use crate::events::{ErrorEvent, EventHandler, EventPayload, EventType};
88
use crate::render::{AudioParamValues, AudioProcessor, AudioRenderQuantum, RenderScope};
99
use crate::AudioBufferIter;
1010
use crate::Event;
1111

12-
use lazy_static::lazy_static;
13-
1412
mod analyser;
1513
pub use analyser::*;
1614
mod audio_buffer_source;
@@ -58,14 +56,14 @@ pub(crate) const TABLE_LENGTH_BY_4_USIZE: usize = TABLE_LENGTH_USIZE / 4;
5856
pub(crate) const TABLE_LENGTH_F32: f32 = TABLE_LENGTH_USIZE as f32;
5957
pub(crate) const TABLE_LENGTH_BY_4_F32: f32 = TABLE_LENGTH_BY_4_USIZE as f32;
6058

61-
// Compute one period sine wavetable of size TABLE_LENGTH
62-
lazy_static! {
63-
pub(crate) static ref SINETABLE: Vec<f32> = {
64-
let table: Vec<f32> = (0..TABLE_LENGTH_USIZE)
59+
pub(crate) fn sine_table() -> &'static [f32] {
60+
static INSTANCE: OnceLock<Vec<f32>> = OnceLock::new();
61+
INSTANCE.get_or_init(|| {
62+
// Compute one period sine wavetable of size TABLE_LENGTH
63+
(0..TABLE_LENGTH_USIZE)
6564
.map(|x| ((x as f32) * 2.0 * PI * (1. / (TABLE_LENGTH_F32))).sin())
66-
.collect();
67-
table
68-
};
65+
.collect()
66+
})
6967
}
7068

7169
/// How channels must be matched between the node's inputs and outputs.

src/node/oscillator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::render::{AudioParamValues, AudioProcessor, AudioRenderQuantum, Render
99
use crate::RENDER_QUANTUM_SIZE;
1010

1111
use super::{
12-
AudioNode, AudioScheduledSourceNode, ChannelConfig, ChannelConfigOptions, SINETABLE,
12+
sine_table, AudioNode, AudioScheduledSourceNode, ChannelConfig, ChannelConfigOptions,
1313
TABLE_LENGTH_USIZE,
1414
};
1515

@@ -467,7 +467,8 @@ impl OscillatorRenderer {
467467

468468
// linear interpolation into lookup table
469469
let k = (position - floored) as f32;
470-
SINETABLE[prev_index].mul_add(1. - k, SINETABLE[next_index] * k)
470+
let sine_table = sine_table();
471+
sine_table[prev_index].mul_add(1. - k, sine_table[next_index] * k)
471472
}
472473

473474
#[inline]

src/node/stereo_panner.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::param::{AudioParam, AudioParamDescriptor};
44
use crate::render::{AudioParamValues, AudioProcessor, AudioRenderQuantum, RenderScope};
55

66
use super::{
7-
AudioNode, ChannelConfig, ChannelConfigOptions, ChannelCountMode, ChannelInterpretation,
8-
SINETABLE, TABLE_LENGTH_BY_4_F32, TABLE_LENGTH_BY_4_USIZE,
7+
sine_table, AudioNode, ChannelConfig, ChannelConfigOptions, ChannelCountMode,
8+
ChannelInterpretation, TABLE_LENGTH_BY_4_F32, TABLE_LENGTH_BY_4_USIZE,
99
};
1010

1111
/// Options for constructing a [`StereoPannerOptions`]
@@ -71,8 +71,10 @@ fn assert_valid_channel_count_mode(mode: ChannelCountMode) {
7171
#[inline(always)]
7272
fn get_stereo_gains(x: f32) -> [f32; 2] {
7373
let idx = (x * TABLE_LENGTH_BY_4_F32) as usize;
74-
let gain_left = SINETABLE[idx + TABLE_LENGTH_BY_4_USIZE];
75-
let gain_right = SINETABLE[idx];
74+
75+
let sine_table = sine_table();
76+
let gain_left = sine_table[idx + TABLE_LENGTH_BY_4_USIZE];
77+
let gain_right = sine_table[idx];
7678

7779
[gain_left, gain_right]
7880
}

src/node/waveshaper.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use std::sync::{
2-
atomic::{AtomicU32, Ordering},
3-
Arc,
1+
use std::{
2+
cell::OnceCell,
3+
sync::{
4+
atomic::{AtomicU32, Ordering},
5+
Arc,
6+
},
47
};
58

69
use crossbeam_channel::{Receiver, Sender};
7-
use once_cell::sync::OnceCell;
810
use rubato::{FftFixedInOut, Resampler as _};
911

1012
use crate::{

src/param.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::node::{
1010
use crate::render::{AudioParamValues, AudioProcessor, AudioRenderQuantum, RenderScope};
1111
use crate::{AtomicF32, RENDER_QUANTUM_SIZE};
1212

13-
use once_cell::sync::OnceCell;
13+
use std::sync::OnceLock;
1414

1515
/// For SetTargetAtTime event, that theoretically cannot end, if the diff between
1616
/// the current value and the target is below this threshold, the value is set
@@ -221,8 +221,8 @@ impl AudioNode for AudioParam {
221221
&self.registration
222222
}
223223

224-
fn channel_config(&self) -> &ChannelConfig {
225-
static INSTANCE: OnceCell<ChannelConfig> = OnceCell::new();
224+
fn channel_config(&self) -> &'static ChannelConfig {
225+
static INSTANCE: OnceLock<ChannelConfig> = OnceLock::new();
226226
INSTANCE.get_or_init(|| {
227227
ChannelConfigOptions {
228228
count: 1,

src/spatial.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::node::{
99
use crate::param::{AudioParam, AudioParamDescriptor, AudioParamRaw, AutomationRate};
1010
use crate::render::{AudioParamValues, AudioProcessor, AudioRenderQuantum, RenderScope};
1111

12-
use lazy_static::lazy_static;
1312
use std::f32::consts::PI;
13+
use std::sync::OnceLock;
1414

1515
/// AudioParam settings for the cartesian coordinates
1616
pub(crate) const PARAM_OPTS: AudioParamDescriptor = AudioParamDescriptor {
@@ -81,22 +81,21 @@ pub(crate) struct AudioListenerNode {
8181
fields: AudioListener,
8282
}
8383

84-
lazy_static! {
85-
static ref AUDIO_LISTENER_CHANNEL_CONFIG: ChannelConfig = ChannelConfigOptions {
86-
count: 1,
87-
count_mode: ChannelCountMode::Explicit,
88-
interpretation: ChannelInterpretation::Discrete,
89-
}
90-
.into();
91-
}
92-
9384
impl AudioNode for AudioListenerNode {
9485
fn registration(&self) -> &AudioContextRegistration {
9586
&self.registration
9687
}
9788

9889
fn channel_config(&self) -> &ChannelConfig {
99-
&AUDIO_LISTENER_CHANNEL_CONFIG
90+
static INSTANCE: OnceLock<ChannelConfig> = OnceLock::new();
91+
INSTANCE.get_or_init(|| {
92+
ChannelConfigOptions {
93+
count: 1,
94+
count_mode: ChannelCountMode::Explicit,
95+
interpretation: ChannelInterpretation::Discrete,
96+
}
97+
.into()
98+
})
10099
}
101100

102101
fn number_of_inputs(&self) -> usize {

0 commit comments

Comments
 (0)