diff --git a/src/interop_facade/facade32.rs b/src/interop_facade/facade32.rs index 75a44a3ce..e32c3f16c 100644 --- a/src/interop_facade/facade32.rs +++ b/src/interop_facade/facade32.rs @@ -9,8 +9,10 @@ use vector_types:: { FrequencyDomainOperations, DataVector32, Statistics}; +use window_functions::WindowFunction; use num::complex::Complex32; use std::slice; +use std::os::raw::c_void; #[no_mangle] pub extern fn delete_vector32(vector: Box) { @@ -484,7 +486,6 @@ pub extern fn unapply_window32(vector: Box, window: i32) -> Vector convert_vec!(vector.unapply_window(window.as_ref())) } - #[no_mangle] pub extern fn windowed_fft32(vector: Box, window: i32) -> VectorResult { let window = translate_to_window_function(window); @@ -502,4 +503,47 @@ pub extern fn windowed_sifft32(vector: Box, even_odd: i32, window: let even_odd = translate_to_even_odd(even_odd); let window = translate_to_window_function(window); convert_vec!(vector.windowed_sifft(even_odd, window.as_ref())) +} + +struct ForeignWindowFunction { + window_function: extern fn(*const c_void, usize, usize) -> f32, + window_data: *const c_void +} + +impl WindowFunction for ForeignWindowFunction { + fn window(&self, idx: usize, points: usize) -> f32 { + let fun = self.window_function; + fun(self.window_data, idx, points) + } +} + +#[no_mangle] +pub extern fn apply_custom_window32(vector: Box, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.apply_window(&window)) +} + +#[no_mangle] +pub extern fn unapply_custom_window32(vector: Box, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.unapply_window(&window)) +} + +#[no_mangle] +pub extern fn windowed_custom_fft32(vector: Box, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.windowed_fft(&window)) +} + +#[no_mangle] +pub extern fn windowed_custom_ifft32(vector: Box, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.windowed_ifft(&window)) +} + +#[no_mangle] +pub extern fn windowed_custom_sifft32(vector: Box, even_odd: i32, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult { + let even_odd = translate_to_even_odd(even_odd); + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.windowed_sifft(even_odd, &window)) } \ No newline at end of file diff --git a/src/interop_facade/facade64.rs b/src/interop_facade/facade64.rs index abcdecdd5..255344ef0 100644 --- a/src/interop_facade/facade64.rs +++ b/src/interop_facade/facade64.rs @@ -10,8 +10,10 @@ use vector_types:: { FrequencyDomainOperations, DataVector64, Statistics}; +use window_functions::WindowFunction; use num::complex::Complex64; use std::slice; +use std::os::raw::c_void; #[no_mangle] pub extern fn delete_vector64(vector: Box) { @@ -472,3 +474,77 @@ pub extern fn mirror64(vector: Box, even_odd: i32) -> VectorResult let even_odd = translate_to_even_odd(even_odd); convert_vec!(vector.mirror(even_odd)) } + +#[no_mangle] +pub extern fn apply_window64(vector: Box, window: i32) -> VectorResult { + let window = translate_to_window_function(window); + convert_vec!(vector.apply_window(window.as_ref())) +} + +#[no_mangle] +pub extern fn unapply_window64(vector: Box, window: i32) -> VectorResult { + let window = translate_to_window_function(window); + convert_vec!(vector.unapply_window(window.as_ref())) +} + +#[no_mangle] +pub extern fn windowed_fft64(vector: Box, window: i32) -> VectorResult { + let window = translate_to_window_function(window); + convert_vec!(vector.windowed_fft(window.as_ref())) +} + +#[no_mangle] +pub extern fn windowed_ifft64(vector: Box, window: i32) -> VectorResult { + let window = translate_to_window_function(window); + convert_vec!(vector.windowed_ifft(window.as_ref())) +} + +#[no_mangle] +pub extern fn windowed_sifft64(vector: Box, even_odd: i32, window: i32) -> VectorResult { + let even_odd = translate_to_even_odd(even_odd); + let window = translate_to_window_function(window); + convert_vec!(vector.windowed_sifft(even_odd, window.as_ref())) +} + +struct ForeignWindowFunction { + window_function: extern fn(*const c_void, usize, usize) -> f64, + window_data: *const c_void +} + +impl WindowFunction for ForeignWindowFunction { + fn window(&self, idx: usize, points: usize) -> f64 { + let fun = self.window_function; + fun(self.window_data, idx, points) + } +} + +#[no_mangle] +pub extern fn apply_custom_window64(vector: Box, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.apply_window(&window)) +} + +#[no_mangle] +pub extern fn unapply_custom_window64(vector: Box, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.unapply_window(&window)) +} + +#[no_mangle] +pub extern fn windowed_custom_fft64(vector: Box, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.windowed_fft(&window)) +} + +#[no_mangle] +pub extern fn windowed_custom_ifft64(vector: Box, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult { + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.windowed_ifft(&window)) +} + +#[no_mangle] +pub extern fn windowed_custom_sifft64(vector: Box, even_odd: i32, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult { + let even_odd = translate_to_even_odd(even_odd); + let window = ForeignWindowFunction { window_function: window, window_data: window_data }; + convert_vec!(vector.windowed_sifft(even_odd, &window)) +}