Skip to content

Commit

Permalink
Revert "Trying to use the native _Complex"
Browse files Browse the repository at this point in the history
This reverts commit 6932d60.
  • Loading branch information
chris-hld committed Feb 6, 2024
1 parent 160f9b5 commit 93397b1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
16 changes: 8 additions & 8 deletions safpy/afstft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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))

Expand All @@ -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,
Expand Down
30 changes: 15 additions & 15 deletions safpy/decorrelator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -240,35 +240,35 @@ 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)

# 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)
Expand Down
2 changes: 1 addition & 1 deletion safpy/sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 25 additions & 10 deletions safpy_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -172,22 +187,22 @@
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);
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);
""")

Expand Down

0 comments on commit 93397b1

Please sign in to comment.