Skip to content

Commit e0a4b2a

Browse files
committed
Align denoising arrays
1 parent a0c7024 commit e0a4b2a

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/denoise.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::api::FrameQueue;
2+
use crate::util::Aligned;
23
use crate::EncoderStatus;
34
use arrayvec::ArrayVec;
45
use ndarray::{Array3, ArrayView3, ArrayViewMut3};
@@ -8,7 +9,6 @@ use ndrustfft::{
89
use std::collections::{BTreeMap, VecDeque};
910
use std::f64::consts::PI;
1011
use std::iter::once;
11-
use std::marker::PhantomData;
1212
use std::mem::size_of;
1313
use std::ptr::copy_nonoverlapping;
1414
use std::sync::Arc;
@@ -43,10 +43,10 @@ where
4343
pad_dimensions: ArrayVec<(usize, usize), 3>,
4444
effective_heights: ArrayVec<usize, 3>,
4545

46-
hw: [f32; BLOCK_VOLUME],
47-
dftgc: [Complex<f32>; COMPLEX_COUNT],
46+
hw: Aligned<[f32; BLOCK_VOLUME]>,
47+
dftgc: Aligned<[Complex<f32>; COMPLEX_COUNT]>,
4848
fft: (R2cFftHandler<f32>, FftHandler<f32>, FftHandler<f32>),
49-
sigmas: [f32; CCNT2],
49+
sigmas: Aligned<[f32; CCNT2]>,
5050

5151
// This stores a copy of the unfiltered previous frame,
5252
// since in `frame_q` it will be filtered already.
@@ -55,8 +55,6 @@ where
5555
// code changes.
5656
frame_buffer: VecDeque<Arc<Frame<T>>>,
5757
pub(crate) cur_frameno: u64,
58-
59-
_t: PhantomData<T>,
6058
}
6159

6260
impl<T> DftDenoiser<T>
@@ -95,8 +93,8 @@ where
9593
effective_heights.push(e_h);
9694
}
9795

98-
let hw = Self::create_window();
99-
let mut dftgr = [0f32; BLOCK_VOLUME];
96+
let hw = Aligned::new(Self::create_window());
97+
let mut dftgr = Aligned::new([0f32; BLOCK_VOLUME]);
10098

10199
let fft = (
102100
R2cFftHandler::new(SB_SIZE),
@@ -111,7 +109,7 @@ where
111109
}
112110
let wscale = 1.0 / wscale;
113111

114-
let mut sigmas = [0f32; CCNT2];
112+
let mut sigmas = Aligned::new([0f32; CCNT2]);
115113
sigmas.fill(sigma / wscale);
116114

117115
let mut denoiser = DftDenoiser {
@@ -124,13 +122,12 @@ where
124122
hw,
125123
fft,
126124
sigmas,
127-
dftgc: [Complex::default(); COMPLEX_COUNT],
125+
dftgc: Aligned::new([Complex::default(); COMPLEX_COUNT]),
128126
frame_buffer: VecDeque::with_capacity(TB_MIDPOINT),
129127
cur_frameno: 0,
130-
_t: PhantomData::<T>::default(),
131128
};
132129

133-
let mut dftgc = [Complex::default(); COMPLEX_COUNT];
130+
let mut dftgc = Aligned::new([Complex::default(); COMPLEX_COUNT]);
134131
denoiser.real_to_complex_3d(&dftgr, &mut dftgc);
135132
denoiser.dftgc = dftgc;
136133

src/util/align.rs

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ impl<T> Aligned<T> {
4242
}
4343
}
4444

45+
impl<T> std::ops::Deref for Aligned<T> {
46+
type Target = T;
47+
48+
fn deref(&self) -> &T {
49+
&self.data
50+
}
51+
}
52+
53+
impl<T> std::ops::DerefMut for Aligned<T> {
54+
fn deref_mut(&mut self) -> &mut T {
55+
&mut self.data
56+
}
57+
}
58+
4559
/// An analog to a Box<[T]> where the underlying slice is aligned.
4660
/// Alignment is according to the architecture-specific SIMD constraints.
4761
pub struct AlignedBoxedSlice<T> {

0 commit comments

Comments
 (0)