Skip to content

Commit

Permalink
fixed fft and starting build stft
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellga committed Jul 14, 2024
1 parent a4eb974 commit f36132e
Show file tree
Hide file tree
Showing 23 changed files with 1,153 additions and 639 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"harmonium-fft",
"harmonium-resample",
"harmonium-window",
"harmonium-stft",
]

[workspace.dependencies]
Expand All @@ -23,6 +24,7 @@ harmonium-io = { path = "harmonium-io", default-features = false }
harmonium-fft = { path = "harmonium-fft", default-features = false }
harmonium-resample = { path = "harmonium-resample", default-features = false }
harmonium-window = { path = "harmonium-window", default-features = false }
harmonium-stft = { path = "harmonium-stft", default-features = false }

[profile.release]
opt-level = 3
Expand Down
9 changes: 7 additions & 2 deletions harmonium-core/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ where
where
Sh: Into<StrideShape<D>>,
{
let ndarray =
ArcArray::from_shape_vec(shape, v).map_err(|_| HError::OutOfSpecError("shape does not correspond to the number of elements in v or if the shape/strides would result in overflowing isize".to_string()))?;
let ndarray = ArcArray::from_shape_vec(shape, v).map_err(|_| {
HError::OutOfSpecError(
"shape does not correspond to the number of elements
in v or if the shape/strides would result in overflowing isize"
.to_string(),
)
})?;
Ok(HArray(ndarray))
}

Expand Down
15 changes: 7 additions & 8 deletions harmonium-core/src/audioop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ use crate::{
array::HArray,
errors::{HError, HResult},
};
use ndarray::{Axis, Dimension, Ix1, Ix2, IxDyn};
use ndarray::{Axis, Dimension, Ix0, Ix1, Ix2, IxDyn};
use num_traits::{Float, FloatConst, FromPrimitive};

pub trait AudioOp<T, D, U>
pub trait AudioOp<T, D>
where
T: Float + FloatConst + FromPrimitive,
D: Dimension,
U: Dimension,
{
fn nchannels(&self) -> usize;
fn nframes(&self) -> usize;
fn db_to_amplitude(&mut self, reference: T, power: T);
fn to_mono(&self) -> HResult<HArray<T, U>>;
fn to_mono(&self) -> HResult<HArray<T, D::Smaller>>;
}

pub enum Audio<'a, T>
Expand All @@ -26,7 +25,7 @@ where
Dyn(&'a HArray<T, IxDyn>),
}

impl<T> AudioOp<T, Ix1, Ix1> for HArray<T, Ix1>
impl<T> AudioOp<T, Ix1> for HArray<T, Ix1>
where
T: Float + FloatConst + FromPrimitive,
{
Expand All @@ -50,15 +49,15 @@ where
.mapv_inplace(|x| reference * a.powf(b * x).powf(power));
}

fn to_mono(&self) -> HResult<HArray<T, Ix1>> {
fn to_mono(&self) -> HResult<HArray<T, Ix0>> {
// To return an error is a design choice. This wasn't supposed to error.
Err(HError::OutOfSpecError(
"The length of the axis is zero.".into(),
))
}
}

impl<T> AudioOp<T, Ix2, Ix1> for HArray<T, Ix2>
impl<T> AudioOp<T, Ix2> for HArray<T, Ix2>
where
T: Float + FloatConst + FromPrimitive,
{
Expand Down Expand Up @@ -89,7 +88,7 @@ where
}
}

impl<T> AudioOp<T, IxDyn, IxDyn> for HArray<T, IxDyn>
impl<T> AudioOp<T, IxDyn> for HArray<T, IxDyn>
where
T: Float + FloatConst + FromPrimitive,
{
Expand Down
1 change: 0 additions & 1 deletion harmonium-fft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
harmonium-core = { workspace = true }
harmonium-io = { workspace = true }
rustfft = { workspace = true }
realfft = { workspace = true }
ndarray = { workspace = true }
Expand Down
Loading

0 comments on commit f36132e

Please sign in to comment.