diff --git a/safpy/afstft.py b/safpy/afstft.py index ab5d5c2..9e35801 100644 --- a/safpy/afstft.py +++ b/safpy/afstft.py @@ -188,7 +188,7 @@ def forward(self, in_frame_td): lib.afSTFT_forward_flat(self._afstft_phandle[0], ffi.from_buffer("float *", in_frame_td), framesize, - ffi.from_buffer("float _Complex *", data_fd)) + ffi.from_buffer("float_complex *", data_fd)) return data_fd def backward(self, in_frame_fd): @@ -224,7 +224,7 @@ def backward(self, in_frame_fd): data_td = np.empty((num_ch_out, framesize), dtype=np.float32) lib.afSTFT_backward_flat(self._afstft_phandle[0], - ffi.from_buffer("float _Complex *", + ffi.from_buffer("float_complex *", in_frame_fd), framesize, ffi.from_buffer("float *", data_td)) @@ -249,16 +249,16 @@ def forward_nd(self, in_frame_td): data_td_ptr[idx_ch] = ffi.from_buffer("float *", in_frame_td[idx_ch, :]) - data_fd_ptr = ffi.cast("float _Complex ***", + data_fd_ptr = ffi.cast("float_complex ***", lib.malloc3d(num_bands, num_ch_in, num_hops, - ffi.sizeof("float _Complex"))) + ffi.sizeof("float_complex"))) lib.afSTFT_forward(self._afstft_phandle[0], data_td_ptr, framesize, data_fd_ptr) # unpack data_fd = np.reshape(np.frombuffer(ffi.buffer(data_fd_ptr[0][0], num_bands*num_ch_in*num_hops * - ffi.sizeof("float _Complex")), + ffi.sizeof("float_complex")), dtype=np.complex64), (num_bands, num_ch_in, num_hops)) @@ -277,13 +277,13 @@ def backward_nd(self, in_frame_fd): num_bands = self.num_bands # populate - data_fd_ptr = ffi.cast("float _Complex ***", + data_fd_ptr = ffi.cast("float_complex ***", lib.malloc2d(num_bands, num_ch_out, - ffi.sizeof("float _Complex*"))) + ffi.sizeof("float_complex*"))) for idx_band in range(num_bands): for idx_ch in range(num_ch_out): data_fd_ptr[idx_band][idx_ch] = \ - ffi.from_buffer("float _Complex *", + ffi.from_buffer("float_complex *", in_frame_fd[idx_band, idx_ch, :]) data_td_ptr = ffi.cast("float **", lib.malloc2d(num_ch_out, framesize, diff --git a/safpy/decorrelator.py b/safpy/decorrelator.py index f605756..71a6fe0 100644 --- a/safpy/decorrelator.py +++ b/safpy/decorrelator.py @@ -140,25 +140,25 @@ def apply(self, in_frame_fd): num_t_slots = in_frame_fd.shape[2] # populate - data_in_ptr = ffi.cast("float _Complex ***", + data_in_ptr = ffi.cast("float_complex ***", lib.malloc2d(num_bands, num_ch, - ffi.sizeof("float _Complex *"))) + ffi.sizeof("float_complex *"))) for idx_band in range(num_bands): for idx_ch in range(num_ch): data_in_ptr[idx_band][idx_ch] = \ - ffi.from_buffer("float _Complex *", + ffi.from_buffer("float_complex *", in_frame_fd[idx_band, idx_ch, :]) - data_out_ptr = ffi.cast("float _Complex ***", + data_out_ptr = ffi.cast("float_complex ***", lib.malloc3d(num_bands, num_ch, num_t_slots, - ffi.sizeof("float _Complex *"))) + ffi.sizeof("float_complex *"))) lib.latticeDecorrelator_apply(self._decorrelator_phandle[0], data_in_ptr, num_t_slots, data_out_ptr) # unpack data_out = np.reshape(np.frombuffer(ffi.buffer(data_out_ptr[0][0], num_bands*num_ch*num_t_slots * - ffi.sizeof("float _Complex")), + ffi.sizeof("float_complex")), dtype=np.complex64), (num_bands, num_ch, num_t_slots)) @@ -240,22 +240,22 @@ def apply(self, in_frame_fd, alpha=0.95, beta=0.995): num_t_slots = in_frame_fd.shape[2] # populate - data_in_ptr = ffi.cast("float _Complex ***", + data_in_ptr = ffi.cast("float_complex ***", lib.malloc2d(num_bands, num_ch, - ffi.sizeof("float _Complex *"))) + ffi.sizeof("float_complex *"))) for idx_band in range(num_bands): for idx_ch in range(num_ch): data_in_ptr[idx_band][idx_ch] = \ - ffi.from_buffer("float _Complex *", + ffi.from_buffer("float_complex *", in_frame_fd[idx_band, idx_ch, :]) - data_res_ptr = ffi.cast("float _Complex ***", + data_res_ptr = ffi.cast("float_complex ***", lib.malloc3d(num_bands, num_ch, num_t_slots, - ffi.sizeof("float _Complex *"))) + ffi.sizeof("float_complex *"))) - data_trs_ptr = ffi.cast("float _Complex ***", + data_trs_ptr = ffi.cast("float_complex ***", lib.malloc3d(num_bands, num_ch, num_t_slots, - ffi.sizeof("float _Complex *"))) + ffi.sizeof("float_complex *"))) lib.transientDucker_apply(self._ducker_phandle[0], data_in_ptr, num_t_slots, alpha, beta, data_res_ptr, data_trs_ptr) @@ -263,12 +263,12 @@ def apply(self, in_frame_fd, alpha=0.95, beta=0.995): # unpack data_res = np.reshape(np.frombuffer(ffi.buffer(data_res_ptr[0][0], num_bands*num_ch*num_t_slots * - ffi.sizeof("float _Complex")), + ffi.sizeof("float_complex")), dtype=np.complex64), (num_bands, num_ch, num_t_slots)) data_trs = np.reshape(np.frombuffer(ffi.buffer(data_trs_ptr[0][0], num_bands*num_ch*num_t_slots * - ffi.sizeof("float _Complex")), + ffi.sizeof("float_complex")), dtype=np.complex64), (num_bands, num_ch, num_t_slots)) lib.free(data_in_ptr) diff --git a/safpy/sh.py b/safpy/sh.py index 5f9de77..ce216d8 100644 --- a/safpy/sh.py +++ b/safpy/sh.py @@ -109,5 +109,5 @@ def getSHcomplex(order, dirs): nDirs = np.shape(dirs)[0] Y = np.empty(((order+1)**2, nDirs), dtype=np.complex64) lib.getSHcomplex(order, ffi.from_buffer("float *", dirs), - nDirs, ffi.from_buffer("float _Complex *", Y)) + nDirs, ffi.from_buffer("float_complex *", Y)) return Y diff --git a/safpy_build.py b/safpy_build.py index 55c3473..94f84c1 100644 --- a/safpy_build.py +++ b/safpy_build.py @@ -36,6 +36,21 @@ """) +if sys.platform != "win32": + ffibuilder.cdef(""" + + typedef float _Complex float_complex; + typedef double _Complex double_complex; + + """) +else: + ffibuilder.cdef(""" + + typedef _Fcomplex float_complex; + typedef _Dcomplex double_complex; + + """) + ffibuilder.cdef(""" typedef enum _AFSTFT_FDDATA_FORMAT{ @@ -98,7 +113,7 @@ float* dirs_rad, int nDirs, /* Output Arguments */ - float _Complex* Y); + float_complex* Y); void generateVBAPgainTable3D(/* Input arguments */ float* ls_dirs_deg, @@ -137,20 +152,20 @@ void afSTFT_forward(void * const hSTFT, float** dataTD, int framesize, - float _Complex*** dataFD); + float_complex*** dataFD); void afSTFT_backward(void * const hSTFT, - float _Complex*** dataFD, + float_complex*** dataFD, int framesize, float** dataTD); void afSTFT_forward_flat(void * const hSTFT, float* dataTD, int framesize, - float _Complex* dataFD); + float_complex* dataFD); void afSTFT_backward_flat(void * const hSTFT, - float _Complex* dataFD, + float_complex* dataFD, int framesize, float* dataTD); @@ -172,9 +187,9 @@ void latticeDecorrelator_reset(void * hDecor); void latticeDecorrelator_apply(void * hDecor, - float _Complex *** inFrame, + float_complex *** inFrame, int nTimeSlots, - float _Complex *** decorFrame); + float_complex *** decorFrame); void transientDucker_create(void ** phDucker, int nCH, int nBands); @@ -182,12 +197,12 @@ void transientDucker_destroy(void ** phDucker); void transientDucker_apply(void * hDucker, - float _Complex *** inFrame, + float_complex *** inFrame, int nTimeSlots, float alpha, float beta, - float _Complex *** residualFrame, - float _Complex *** transientFrame); + float_complex *** residualFrame, + float_complex *** transientFrame); """)