Skip to content

Commit

Permalink
Finished adding window functions to interop facade.
Browse files Browse the repository at this point in the history
  • Loading branch information
liebharc committed Jan 3, 2016
1 parent 535b877 commit 2b9cd71
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/interop_facade/facade32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataVector32>) {
Expand Down Expand Up @@ -484,7 +486,6 @@ pub extern fn unapply_window32(vector: Box<DataVector32>, window: i32) -> Vector
convert_vec!(vector.unapply_window(window.as_ref()))
}


#[no_mangle]
pub extern fn windowed_fft32(vector: Box<DataVector32>, window: i32) -> VectorResult<DataVector32> {
let window = translate_to_window_function(window);
Expand All @@ -502,4 +503,47 @@ pub extern fn windowed_sifft32(vector: Box<DataVector32>, 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<f32> 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<DataVector32>, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult<DataVector32> {
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<DataVector32>, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult<DataVector32> {
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<DataVector32>, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult<DataVector32> {
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<DataVector32>, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult<DataVector32> {
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<DataVector32>, even_odd: i32, window: extern fn(*const c_void, usize, usize) -> f32, window_data: *const c_void) -> VectorResult<DataVector32> {
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))
}
76 changes: 76 additions & 0 deletions src/interop_facade/facade64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataVector64>) {
Expand Down Expand Up @@ -472,3 +474,77 @@ pub extern fn mirror64(vector: Box<DataVector64>, 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<DataVector64>, window: i32) -> VectorResult<DataVector64> {
let window = translate_to_window_function(window);
convert_vec!(vector.apply_window(window.as_ref()))
}

#[no_mangle]
pub extern fn unapply_window64(vector: Box<DataVector64>, window: i32) -> VectorResult<DataVector64> {
let window = translate_to_window_function(window);
convert_vec!(vector.unapply_window(window.as_ref()))
}

#[no_mangle]
pub extern fn windowed_fft64(vector: Box<DataVector64>, window: i32) -> VectorResult<DataVector64> {
let window = translate_to_window_function(window);
convert_vec!(vector.windowed_fft(window.as_ref()))
}

#[no_mangle]
pub extern fn windowed_ifft64(vector: Box<DataVector64>, window: i32) -> VectorResult<DataVector64> {
let window = translate_to_window_function(window);
convert_vec!(vector.windowed_ifft(window.as_ref()))
}

#[no_mangle]
pub extern fn windowed_sifft64(vector: Box<DataVector64>, even_odd: i32, window: i32) -> VectorResult<DataVector64> {
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<f64> 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<DataVector64>, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult<DataVector64> {
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<DataVector64>, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult<DataVector64> {
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<DataVector64>, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult<DataVector64> {
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<DataVector64>, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult<DataVector64> {
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<DataVector64>, even_odd: i32, window: extern fn(*const c_void, usize, usize) -> f64, window_data: *const c_void) -> VectorResult<DataVector64> {
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))
}

0 comments on commit 2b9cd71

Please sign in to comment.