diff --git a/dereverbrate/CMakeLists.txt b/dereverbrate/CMakeLists.txt new file mode 100644 index 0000000..d356f7f --- /dev/null +++ b/dereverbrate/CMakeLists.txt @@ -0,0 +1,129 @@ +#cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 2.8) +project(dereverbrate) + +set(CMAKE_CXX_STANDARD 14) + +set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) + +include_directories(./) + + + + +##add_subdirectory(dereveb_c) +#add_subdirectory(waves) +# +#add_executable(dereverbrate_test main.cpp) +#target_link_libraries(dereverbrate_test +# #${LIBRARY_OUTPUT_PATH}/libinverse.a +# #${LIBRARY_OUTPUT_PATH}/libdereverb.a +# ${LIBRARY_OUTPUT_PATH}/libwaves.a +# ) + + + +####多个文件夹,一个cmakelist.txt + +#########文件夹1 +#include_directories(./dereveb_c) +#include_directories(/usr/local/opt/libomp/include/) #for omp.h +## 源文件 +#file(GLOB DEREVEB_C_SRC ./dereveb_c/*.cpp) + +#########文件夹2 +###头文件 +include_directories(./inverse) +###源文件 +file(GLOB INVERSE_SRC ./inverse/*.cpp) + +#########文件夹3 +include_directories(./waves/inc) +AUX_SOURCE_DIRECTORY(./waves/src DIR_WAVES_SRCS) +#add_library(waves ${DIR_WAVES_SRCS}) + + +#########文件夹4 +#set(CMAKE_C_COMPILER "/usr/bin/gcc") #这里写你的gcc路径 +#set(CMAKE_CXX_COMPILER "/usr/bin/g++") #这里写你的g++路径 +set(OPENMP_LIBRARIES "/usr/local/opt/libomp/lib") #这里写你的libomp路径, 通过brew安装的默认地址 +set(OPENMP_INCLUDES "/usr/local/opt/libomp/include")#这里写你的libomp路径 +OPTION (USE_OpenMP "Use OpenMP to enamble " ON) + +if(APPLE AND USE_OpenMP) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + set(OpenMP_C "${CMAKE_C_COMPILER}") + set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -lomp -Wno-unused-command-line-argument") + #注意以上需要增加-Xpreprocessor 以及不能直接-llibomp 在这里不需要前缀lib只需要-lomp即可,下面相似的地方也是同个道理 + set(OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5") + set(OpenMP_libomp_LIBRARY ${OpenMP_C_LIB_NAMES}) + set(OpenMP_libgomp_LIBRARY ${OpenMP_C_LIB_NAMES}) + set(OpenMP_libiomp5_LIBRARY ${OpenMP_C_LIB_NAMES}) + endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(OpenMP_CXX "${CMAKE_CXX_COMPILER}") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -lomp -Wno-unused-command-line-argument") + set(OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5") + set(OpenMP_libomp_LIBRARY ${OpenMP_CXX_LIB_NAMES}) + set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES}) + set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES}) + endif() +endif() + +if(USE_OpenMP) + find_package(OpenMP REQUIRED) +endif(USE_OpenMP) + +if (OPENMP_FOUND) + include_directories("${OPENMP_INCLUDES}") + link_directories("${OPENMP_LIBRARIES}") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") +endif(OPENMP_FOUND) + + +include_directories(./dereveb_c) +#include_directories(/usr/local/opt/libomp/include/) #for omp.h +# 源文件 +file(GLOB DEREVEB_C_SRC ./dereveb_c/*.cpp) + + +add_executable(dereverbrate_test main.cpp + ${DEREVEB_C_SRC} + ${DIR_WAVES_SRCS} + ${INVERSE_SRC} + ) + +#set(LIBRARY_OMP_PATH /usr/local/opt/libomp/lib) +#target_link_libraries(dereverbrate_test +# ${LIBRARY_OMP_PATH}/libinverse.a) + + + + + + + + + + + +#######单个子库编译###### +#add_subdirectory(inverse) +#add_executable(dereverbrate_test main.cpp) +#target_link_libraries(dereverbrate_test +# ${LIBRARY_OUTPUT_PATH}/libinverse.a +# ) + + + + +#######一个文件编译#### +####头文件 +#include_directories(./inverse) +# +####源文件 +#file(GLOB INVERSE_SRC ./inverse/*.cpp) +# +#add_executable(dereverbrate_test main.cpp ${INVERSE_SRC}) +# diff --git a/dereverbrate/audio/._stalbans_a_mono.wav b/dereverbrate/audio/._stalbans_a_mono.wav new file mode 100644 index 0000000..48d1245 Binary files /dev/null and b/dereverbrate/audio/._stalbans_a_mono.wav differ diff --git a/dereverbrate/audio/stalbans_a_mono.wav b/dereverbrate/audio/stalbans_a_mono.wav new file mode 100644 index 0000000..76822cf Binary files /dev/null and b/dereverbrate/audio/stalbans_a_mono.wav differ diff --git a/dereverbrate/audio/stalbans_a_mono_16bit.pkf b/dereverbrate/audio/stalbans_a_mono_16bit.pkf new file mode 100644 index 0000000..c7a0497 Binary files /dev/null and b/dereverbrate/audio/stalbans_a_mono_16bit.pkf differ diff --git a/dereverbrate/audio/stalbans_a_mono_16bit.wav b/dereverbrate/audio/stalbans_a_mono_16bit.wav new file mode 100644 index 0000000..b629360 Binary files /dev/null and b/dereverbrate/audio/stalbans_a_mono_16bit.wav differ diff --git a/dereverbrate/dereveb_c/.gitignore b/dereverbrate/dereveb_c/.gitignore new file mode 100644 index 0000000..9c66351 --- /dev/null +++ b/dereverbrate/dereveb_c/.gitignore @@ -0,0 +1,22 @@ +*.asv +*.m~ +*.mex* +*.o +*.obj +*.dll +*.so +*.dylib +*.a +*.lib +*.exe +*.map +*.rsp +*.tmw +*.mat +sil/ +interface/_coder_*_info.* +coderassumptions/ +target/ +build/ +debug/ +*.slxc diff --git a/dereverbrate/dereveb_c/FFTImplementationCallback.cpp b/dereverbrate/dereveb_c/FFTImplementationCallback.cpp new file mode 100644 index 0000000..c8eed23 --- /dev/null +++ b/dereverbrate/dereveb_c/FFTImplementationCallback.cpp @@ -0,0 +1,968 @@ +// +// File: FFTImplementationCallback.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "FFTImplementationCallback.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : const ::coder::array &x +// int xoffInit +// ::coder::array &y +// int nrowsx +// int nRows +// int nfft +// const ::coder::array &wwc +// const ::coder::array &costab +// const ::coder::array &sintab +// const ::coder::array &costabinv +// const ::coder::array &sintabinv +// Return Type : void +// +namespace coder { +namespace internal { +void FFTImplementationCallback::doHalfLengthBluestein( + const ::coder::array &x, int xoffInit, + ::coder::array &y, int nrowsx, int nRows, int nfft, + const ::coder::array &wwc, + const ::coder::array &costab, + const ::coder::array &sintab, + const ::coder::array &costabinv, + const ::coder::array &sintabinv) +{ + array fv; + array fy; + array reconVar1; + array reconVar2; + array ytmp; + array b_costab; + array b_sintab; + array costab1q; + array hcostabinv; + array hsintab; + array hsintabinv; + array wrapIndex; + double b_temp_re_tmp; + double re_tmp; + double temp_im; + double temp_re; + double twid_im; + double twid_re; + double z_tmp; + int hnRows; + int i; + int iDelta2; + int ihi; + int istart; + int j; + int ju; + int k; + int nRowsD2; + int nd2; + int temp_re_tmp; + boolean_T tst; + hnRows = nRows / 2; + ytmp.set_size(hnRows); + if (hnRows > nrowsx) { + ytmp.set_size(hnRows); + for (iDelta2 = 0; iDelta2 < hnRows; iDelta2++) { + ytmp[iDelta2].re = 0.0; + ytmp[iDelta2].im = 0.0; + } + } + if ((x.size(0) & 1) == 0) { + tst = true; + ihi = x.size(0); + } else if (x.size(0) >= nRows) { + tst = true; + ihi = nRows; + } else { + tst = false; + ihi = x.size(0) - 1; + } + if (ihi > nRows) { + ihi = nRows; + } + nd2 = nRows << 1; + temp_im = 6.2831853071795862 / static_cast(nd2); + j = nd2 / 2 / 2; + costab1q.set_size(1, j + 1); + costab1q[0] = 1.0; + nd2 = j / 2 - 1; + for (k = 0; k <= nd2; k++) { + costab1q[k + 1] = std::cos(temp_im * (static_cast(k) + 1.0)); + } + iDelta2 = nd2 + 2; + nd2 = j - 1; + for (k = iDelta2; k <= nd2; k++) { + costab1q[k] = std::sin(temp_im * static_cast(j - k)); + } + costab1q[j] = 0.0; + j = costab1q.size(1) - 1; + nd2 = (costab1q.size(1) - 1) << 1; + b_costab.set_size(1, nd2 + 1); + b_sintab.set_size(1, nd2 + 1); + b_costab[0] = 1.0; + b_sintab[0] = 0.0; + for (k = 0; k < j; k++) { + b_costab[k + 1] = costab1q[k + 1]; + b_sintab[k + 1] = -costab1q[(j - k) - 1]; + } + iDelta2 = costab1q.size(1); + for (k = iDelta2; k <= nd2; k++) { + b_costab[k] = -costab1q[nd2 - k]; + b_sintab[k] = -costab1q[k - j]; + } + nd2 = costab.size(1) / 2; + costab1q.set_size(1, nd2); + hsintab.set_size(1, nd2); + hcostabinv.set_size(1, nd2); + hsintabinv.set_size(1, nd2); + for (i = 0; i < nd2; i++) { + iDelta2 = ((i + 1) << 1) - 2; + costab1q[i] = costab[iDelta2]; + hsintab[i] = sintab[iDelta2]; + hcostabinv[i] = costabinv[iDelta2]; + hsintabinv[i] = sintabinv[iDelta2]; + } + reconVar1.set_size(hnRows); + reconVar2.set_size(hnRows); + wrapIndex.set_size(1, hnRows); + for (i = 0; i < hnRows; i++) { + iDelta2 = i << 1; + temp_im = b_sintab[iDelta2]; + temp_re = b_costab[iDelta2]; + reconVar1[i].re = temp_im + 1.0; + reconVar1[i].im = -temp_re; + reconVar2[i].re = 1.0 - temp_im; + reconVar2[i].im = temp_re; + if (i + 1 != 1) { + wrapIndex[i] = (hnRows - i) + 1; + } else { + wrapIndex[0] = 1; + } + } + z_tmp = static_cast(ihi) / 2.0; + iDelta2 = static_cast(z_tmp); + for (ju = 0; ju < iDelta2; ju++) { + temp_re_tmp = (hnRows + ju) - 1; + temp_re = wwc[temp_re_tmp].re; + temp_im = wwc[temp_re_tmp].im; + nd2 = xoffInit + (ju << 1); + twid_re = x[nd2]; + twid_im = x[nd2 + 1]; + ytmp[ju].re = temp_re * twid_re + temp_im * twid_im; + ytmp[ju].im = temp_re * twid_im - temp_im * twid_re; + } + if (!tst) { + temp_re_tmp = (hnRows + static_cast(z_tmp)) - 1; + temp_re = wwc[temp_re_tmp].re; + temp_im = wwc[temp_re_tmp].im; + twid_re = x[xoffInit + (static_cast(z_tmp) << 1)]; + ytmp[static_cast(z_tmp)].re = temp_re * twid_re + temp_im * 0.0; + ytmp[static_cast(z_tmp)].im = temp_re * 0.0 - temp_im * twid_re; + if (static_cast(z_tmp) + 2 <= hnRows) { + iDelta2 = static_cast(static_cast(ihi) / 2.0) + 2; + for (i = iDelta2; i <= hnRows; i++) { + ytmp[i - 1].re = 0.0; + ytmp[i - 1].im = 0.0; + } + } + } else if (static_cast(z_tmp) + 1 <= hnRows) { + iDelta2 = static_cast(static_cast(ihi) / 2.0) + 1; + for (i = iDelta2; i <= hnRows; i++) { + ytmp[i - 1].re = 0.0; + ytmp[i - 1].im = 0.0; + } + } + z_tmp = static_cast(nfft) / 2.0; + nd2 = static_cast(z_tmp); + fy.set_size(nd2); + if (static_cast(z_tmp) > ytmp.size(0)) { + fy.set_size(nd2); + for (iDelta2 = 0; iDelta2 < nd2; iDelta2++) { + fy[iDelta2].re = 0.0; + fy[iDelta2].im = 0.0; + } + } + ihi = ytmp.size(0); + istart = static_cast(z_tmp); + if (ihi <= istart) { + istart = ihi; + } + iDelta2 = static_cast(z_tmp) - 2; + nRowsD2 = static_cast(z_tmp) / 2; + k = nRowsD2 / 2; + nd2 = 0; + ju = 0; + for (i = 0; i <= istart - 2; i++) { + fy[nd2] = ytmp[i]; + j = static_cast(z_tmp); + tst = true; + while (tst) { + j >>= 1; + ju ^= j; + tst = ((ju & j) == 0); + } + nd2 = ju; + } + fy[nd2] = ytmp[istart - 1]; + if (static_cast(z_tmp) > 1) { + for (i = 0; i <= iDelta2; i += 2) { + b_temp_re_tmp = fy[i + 1].re; + temp_re = fy[i + 1].im; + re_tmp = fy[i].re; + twid_re = fy[i].im; + fy[i + 1].re = re_tmp - b_temp_re_tmp; + fy[i + 1].im = twid_re - temp_re; + fy[i].re = re_tmp + b_temp_re_tmp; + fy[i].im = twid_re + temp_re; + } + } + nd2 = 2; + iDelta2 = 4; + ju = ((k - 1) << 2) + 1; + while (k > 0) { + for (i = 0; i < ju; i += iDelta2) { + temp_re_tmp = i + nd2; + temp_re = fy[temp_re_tmp].re; + temp_im = fy[temp_re_tmp].im; + fy[temp_re_tmp].re = fy[i].re - temp_re; + fy[temp_re_tmp].im = fy[i].im - temp_im; + fy[i].re = fy[i].re + temp_re; + fy[i].im = fy[i].im + temp_im; + } + istart = 1; + for (j = k; j < nRowsD2; j += k) { + twid_re = costab1q[j]; + twid_im = hsintab[j]; + i = istart; + ihi = istart + ju; + while (i < ihi) { + temp_re_tmp = i + nd2; + b_temp_re_tmp = fy[temp_re_tmp].im; + temp_im = fy[temp_re_tmp].re; + temp_re = twid_re * temp_im - twid_im * b_temp_re_tmp; + temp_im = twid_re * b_temp_re_tmp + twid_im * temp_im; + fy[temp_re_tmp].re = fy[i].re - temp_re; + fy[temp_re_tmp].im = fy[i].im - temp_im; + fy[i].re = fy[i].re + temp_re; + fy[i].im = fy[i].im + temp_im; + i += iDelta2; + } + istart++; + } + k /= 2; + nd2 = iDelta2; + iDelta2 += iDelta2; + ju -= nd2; + } + FFTImplementationCallback::r2br_r2dit_trig_impl(wwc, static_cast(z_tmp), + costab1q, hsintab, fv); + nd2 = fy.size(0); + for (iDelta2 = 0; iDelta2 < nd2; iDelta2++) { + re_tmp = fy[iDelta2].re; + twid_im = fv[iDelta2].im; + temp_im = fy[iDelta2].im; + temp_re = fv[iDelta2].re; + fy[iDelta2].re = re_tmp * temp_re - temp_im * twid_im; + fy[iDelta2].im = re_tmp * twid_im + temp_im * temp_re; + } + FFTImplementationCallback::r2br_r2dit_trig_impl(fy, static_cast(z_tmp), + hcostabinv, hsintabinv, fv); + if (fv.size(0) > 1) { + temp_im = 1.0 / static_cast(fv.size(0)); + nd2 = fv.size(0); + for (iDelta2 = 0; iDelta2 < nd2; iDelta2++) { + fv[iDelta2].re = temp_im * fv[iDelta2].re; + fv[iDelta2].im = temp_im * fv[iDelta2].im; + } + } + iDelta2 = wwc.size(0); + for (k = hnRows; k <= iDelta2; k++) { + temp_im = wwc[k - 1].re; + temp_re = fv[k - 1].im; + twid_re = wwc[k - 1].im; + twid_im = fv[k - 1].re; + nd2 = k - hnRows; + ytmp[nd2].re = temp_im * twid_im + twid_re * temp_re; + ytmp[nd2].im = temp_im * temp_re - twid_re * twid_im; + } + for (i = 0; i < hnRows; i++) { + double ytmp_re_tmp; + iDelta2 = wrapIndex[i]; + temp_im = ytmp[i].re; + temp_re = reconVar1[i].im; + twid_re = ytmp[i].im; + twid_im = reconVar1[i].re; + re_tmp = ytmp[iDelta2 - 1].re; + b_temp_re_tmp = -ytmp[iDelta2 - 1].im; + z_tmp = reconVar2[i].im; + ytmp_re_tmp = reconVar2[i].re; + y[i].re = 0.5 * ((temp_im * twid_im - twid_re * temp_re) + + (re_tmp * ytmp_re_tmp - b_temp_re_tmp * z_tmp)); + y[i].im = 0.5 * ((temp_im * temp_re + twid_re * twid_im) + + (re_tmp * z_tmp + b_temp_re_tmp * ytmp_re_tmp)); + iDelta2 = hnRows + i; + y[iDelta2].re = 0.5 * ((temp_im * ytmp_re_tmp - twid_re * z_tmp) + + (re_tmp * twid_im - b_temp_re_tmp * temp_re)); + y[iDelta2].im = 0.5 * ((temp_im * z_tmp + twid_re * ytmp_re_tmp) + + (re_tmp * temp_re + b_temp_re_tmp * twid_im)); + } +} + +// +// Arguments : const ::coder::array &x +// int xoffInit +// ::coder::array &y +// int unsigned_nRows +// const ::coder::array &costab +// const ::coder::array &sintab +// Return Type : void +// +void FFTImplementationCallback::doHalfLengthRadix2( + const ::coder::array &x, int xoffInit, + ::coder::array &y, int unsigned_nRows, + const ::coder::array &costab, + const ::coder::array &sintab) +{ + array reconVar1; + array reconVar2; + array hcostab; + array hsintab; + array wrapIndex; + array bitrevIndex; + double b_y_re_tmp; + double c_y_re_tmp; + double d_y_re_tmp; + double temp2_im; + double temp2_re; + double temp_im; + double temp_im_tmp; + double temp_re; + double temp_re_tmp; + double y_re_tmp; + double z_tmp; + int hszCostab; + int i; + int istart; + int iy; + int j; + int ju; + int k; + int nRows; + int nRowsD2; + int nRowsM2; + boolean_T tst; + nRows = unsigned_nRows / 2; + j = y.size(0); + if (j > nRows) { + j = nRows; + } + nRowsM2 = nRows - 2; + nRowsD2 = nRows / 2; + k = nRowsD2 / 2; + hszCostab = costab.size(1) / 2; + hcostab.set_size(1, hszCostab); + hsintab.set_size(1, hszCostab); + for (i = 0; i < hszCostab; i++) { + iy = ((i + 1) << 1) - 2; + hcostab[i] = costab[iy]; + hsintab[i] = sintab[iy]; + } + reconVar1.set_size(nRows); + reconVar2.set_size(nRows); + wrapIndex.set_size(1, nRows); + for (i = 0; i < nRows; i++) { + temp_re = sintab[i]; + temp2_re = costab[i]; + reconVar1[i].re = temp_re + 1.0; + reconVar1[i].im = -temp2_re; + reconVar2[i].re = 1.0 - temp_re; + reconVar2[i].im = temp2_re; + if (i + 1 != 1) { + wrapIndex[i] = (nRows - i) + 1; + } else { + wrapIndex[0] = 1; + } + } + z_tmp = static_cast(unsigned_nRows) / 2.0; + ju = 0; + iy = 1; + hszCostab = static_cast(z_tmp); + bitrevIndex.set_size(hszCostab); + for (istart = 0; istart < hszCostab; istart++) { + bitrevIndex[istart] = 0; + } + for (istart = 0; istart <= j - 2; istart++) { + bitrevIndex[istart] = iy; + hszCostab = static_cast(z_tmp); + tst = true; + while (tst) { + hszCostab >>= 1; + ju ^= hszCostab; + tst = ((ju & hszCostab) == 0); + } + iy = ju + 1; + } + bitrevIndex[j - 1] = iy; + if ((x.size(0) & 1) == 0) { + tst = true; + j = x.size(0); + } else if (x.size(0) >= unsigned_nRows) { + tst = true; + j = unsigned_nRows; + } else { + tst = false; + j = x.size(0) - 1; + } + if (j > unsigned_nRows) { + j = unsigned_nRows; + } + temp_re = static_cast(j) / 2.0; + istart = static_cast(temp_re); + for (i = 0; i < istart; i++) { + iy = xoffInit + (i << 1); + y[bitrevIndex[i] - 1].re = x[iy]; + y[bitrevIndex[i] - 1].im = x[iy + 1]; + } + if (!tst) { + istart = bitrevIndex[static_cast(temp_re)] - 1; + y[istart].re = x[xoffInit + (static_cast(temp_re) << 1)]; + y[istart].im = 0.0; + } + if (nRows > 1) { + for (i = 0; i <= nRowsM2; i += 2) { + temp_re_tmp = y[i + 1].re; + temp_im_tmp = y[i + 1].im; + y[i + 1].re = y[i].re - temp_re_tmp; + y[i + 1].im = y[i].im - y[i + 1].im; + y[i].re = y[i].re + temp_re_tmp; + y[i].im = y[i].im + temp_im_tmp; + } + } + hszCostab = 2; + iy = 4; + ju = ((k - 1) << 2) + 1; + while (k > 0) { + for (i = 0; i < ju; i += iy) { + nRowsM2 = i + hszCostab; + temp_re = y[nRowsM2].re; + temp_im = y[nRowsM2].im; + y[nRowsM2].re = y[i].re - temp_re; + y[nRowsM2].im = y[i].im - temp_im; + y[i].re = y[i].re + temp_re; + y[i].im = y[i].im + temp_im; + } + istart = 1; + for (j = k; j < nRowsD2; j += k) { + temp2_re = hcostab[j]; + temp2_im = hsintab[j]; + i = istart; + nRows = istart + ju; + while (i < nRows) { + nRowsM2 = i + hszCostab; + temp_re_tmp = y[nRowsM2].im; + y_re_tmp = y[nRowsM2].re; + temp_re = temp2_re * y_re_tmp - temp2_im * temp_re_tmp; + temp_im = temp2_re * temp_re_tmp + temp2_im * y_re_tmp; + y[nRowsM2].re = y[i].re - temp_re; + y[nRowsM2].im = y[i].im - temp_im; + y[i].re = y[i].re + temp_re; + y[i].im = y[i].im + temp_im; + i += iy; + } + istart++; + } + k /= 2; + hszCostab = iy; + iy += iy; + ju -= hszCostab; + } + hszCostab = static_cast(z_tmp) / 2; + temp_re_tmp = y[0].re; + temp_im_tmp = y[0].im; + y[0].re = + 0.5 * ((temp_re_tmp * reconVar1[0].re - temp_im_tmp * reconVar1[0].im) + + (temp_re_tmp * reconVar2[0].re - -temp_im_tmp * reconVar2[0].im)); + y[0].im = + 0.5 * ((temp_re_tmp * reconVar1[0].im + temp_im_tmp * reconVar1[0].re) + + (temp_re_tmp * reconVar2[0].im + -temp_im_tmp * reconVar2[0].re)); + y[static_cast(z_tmp)].re = + 0.5 * ((temp_re_tmp * reconVar2[0].re - temp_im_tmp * reconVar2[0].im) + + (temp_re_tmp * reconVar1[0].re - -temp_im_tmp * reconVar1[0].im)); + y[static_cast(z_tmp)].im = + 0.5 * ((temp_re_tmp * reconVar2[0].im + temp_im_tmp * reconVar2[0].re) + + (temp_re_tmp * reconVar1[0].im + -temp_im_tmp * reconVar1[0].re)); + for (i = 2; i <= hszCostab; i++) { + double temp2_im_tmp; + temp_re_tmp = y[i - 1].re; + temp_im_tmp = y[i - 1].im; + istart = wrapIndex[i - 1]; + temp2_im = y[istart - 1].re; + temp2_im_tmp = y[istart - 1].im; + y_re_tmp = reconVar1[i - 1].im; + b_y_re_tmp = reconVar1[i - 1].re; + c_y_re_tmp = reconVar2[i - 1].im; + d_y_re_tmp = reconVar2[i - 1].re; + y[i - 1].re = 0.5 * ((temp_re_tmp * b_y_re_tmp - temp_im_tmp * y_re_tmp) + + (temp2_im * d_y_re_tmp - -temp2_im_tmp * c_y_re_tmp)); + y[i - 1].im = 0.5 * ((temp_re_tmp * y_re_tmp + temp_im_tmp * b_y_re_tmp) + + (temp2_im * c_y_re_tmp + -temp2_im_tmp * d_y_re_tmp)); + iy = (static_cast(z_tmp) + i) - 1; + y[iy].re = 0.5 * ((temp_re_tmp * d_y_re_tmp - temp_im_tmp * c_y_re_tmp) + + (temp2_im * b_y_re_tmp - -temp2_im_tmp * y_re_tmp)); + y[iy].im = 0.5 * ((temp_re_tmp * c_y_re_tmp + temp_im_tmp * d_y_re_tmp) + + (temp2_im * y_re_tmp + -temp2_im_tmp * b_y_re_tmp)); + temp_im = reconVar1[istart - 1].im; + temp_re = reconVar1[istart - 1].re; + y_re_tmp = reconVar2[istart - 1].im; + temp2_re = reconVar2[istart - 1].re; + y[istart - 1].re = + 0.5 * ((temp2_im * temp_re - temp2_im_tmp * temp_im) + + (temp_re_tmp * temp2_re - -temp_im_tmp * y_re_tmp)); + y[istart - 1].im = + 0.5 * ((temp2_im * temp_im + temp2_im_tmp * temp_re) + + (temp_re_tmp * y_re_tmp + -temp_im_tmp * temp2_re)); + istart = (istart + static_cast(z_tmp)) - 1; + y[istart].re = 0.5 * ((temp2_im * temp2_re - temp2_im_tmp * y_re_tmp) + + (temp_re_tmp * temp_re - -temp_im_tmp * temp_im)); + y[istart].im = 0.5 * ((temp2_im * y_re_tmp + temp2_im_tmp * temp2_re) + + (temp_re_tmp * temp_im + -temp_im_tmp * temp_re)); + } + temp_re_tmp = y[hszCostab].re; + temp_im_tmp = y[hszCostab].im; + y_re_tmp = reconVar1[hszCostab].im; + b_y_re_tmp = reconVar1[hszCostab].re; + c_y_re_tmp = reconVar2[hszCostab].im; + d_y_re_tmp = reconVar2[hszCostab].re; + temp_re = temp_re_tmp * d_y_re_tmp; + temp2_re = temp_re_tmp * b_y_re_tmp; + y[hszCostab].re = 0.5 * ((temp2_re - temp_im_tmp * y_re_tmp) + + (temp_re - -temp_im_tmp * c_y_re_tmp)); + temp2_im = temp_re_tmp * c_y_re_tmp; + temp_im = temp_re_tmp * y_re_tmp; + y[hszCostab].im = 0.5 * ((temp_im + temp_im_tmp * b_y_re_tmp) + + (temp2_im + -temp_im_tmp * d_y_re_tmp)); + istart = static_cast(z_tmp) + hszCostab; + y[istart].re = 0.5 * ((temp_re - temp_im_tmp * c_y_re_tmp) + + (temp2_re - -temp_im_tmp * y_re_tmp)); + y[istart].im = 0.5 * ((temp2_im + temp_im_tmp * d_y_re_tmp) + + (temp_im + -temp_im_tmp * b_y_re_tmp)); +} + +// +// Arguments : const ::coder::array &x +// int n2blue +// int nfft +// const ::coder::array &costab +// const ::coder::array &sintab +// const ::coder::array &sintabinv +// ::coder::array &y +// Return Type : void +// +void FFTImplementationCallback::dobluesteinfft( + const ::coder::array &x, int n2blue, int nfft, + const ::coder::array &costab, + const ::coder::array &sintab, + const ::coder::array &sintabinv, ::coder::array &y) +{ + array b_fv; + array fv; + array r; + array wwc; + double b_re_tmp; + double c_re_tmp; + double d_re_tmp; + double re_tmp; + int b_k; + int b_y; + int i; + int i1; + int minNrowsNx; + int nInt2m1; + int u0; + int xoff; + if ((nfft & 1) == 0) { + int k; + int nInt2; + int nRows; + int rt; + nRows = nfft / 2; + nInt2m1 = (nRows + nRows) - 1; + wwc.set_size(nInt2m1); + rt = 0; + wwc[nRows - 1].re = 1.0; + wwc[nRows - 1].im = 0.0; + nInt2 = nRows << 1; + for (k = 0; k <= nRows - 2; k++) { + double nt_im; + double nt_re; + b_y = ((k + 1) << 1) - 1; + if (nInt2 - rt <= b_y) { + rt += b_y - nInt2; + } else { + rt += b_y; + } + nt_im = -3.1415926535897931 * static_cast(rt) / + static_cast(nRows); + if (nt_im == 0.0) { + nt_re = 1.0; + nt_im = 0.0; + } else { + nt_re = std::cos(nt_im); + nt_im = std::sin(nt_im); + } + i = (nRows - k) - 2; + wwc[i].re = nt_re; + wwc[i].im = -nt_im; + } + i = nInt2m1 - 1; + for (k = i; k >= nRows; k--) { + wwc[k] = wwc[(nInt2m1 - k) - 1]; + } + } else { + int k; + int nInt2; + int rt; + nInt2m1 = (nfft + nfft) - 1; + wwc.set_size(nInt2m1); + rt = 0; + wwc[nfft - 1].re = 1.0; + wwc[nfft - 1].im = 0.0; + nInt2 = nfft << 1; + for (k = 0; k <= nfft - 2; k++) { + double nt_im; + double nt_re; + b_y = ((k + 1) << 1) - 1; + if (nInt2 - rt <= b_y) { + rt += b_y - nInt2; + } else { + rt += b_y; + } + nt_im = -3.1415926535897931 * static_cast(rt) / + static_cast(nfft); + if (nt_im == 0.0) { + nt_re = 1.0; + nt_im = 0.0; + } else { + nt_re = std::cos(nt_im); + nt_im = std::sin(nt_im); + } + i = (nfft - k) - 2; + wwc[i].re = nt_re; + wwc[i].im = -nt_im; + } + i = nInt2m1 - 1; + for (k = i; k >= nfft; k--) { + wwc[k] = wwc[(nInt2m1 - k) - 1]; + } + } + nInt2m1 = x.size(0); + y.set_size(nfft, x.size(1)); + if (nfft > x.size(0)) { + y.set_size(nfft, x.size(1)); + b_y = nfft * x.size(1); + for (i = 0; i < b_y; i++) { + y[i].re = 0.0; + y[i].im = 0.0; + } + } + b_y = x.size(1) - 1; +#pragma omp parallel for num_threads(omp_get_max_threads()) private( \ + fv, b_fv, r, xoff, i1, minNrowsNx, u0, b_k, re_tmp, b_re_tmp, c_re_tmp, \ + d_re_tmp) + + for (int chan = 0; chan <= b_y; chan++) { + xoff = chan * nInt2m1; + r.set_size(nfft); + if (nfft > x.size(0)) { + r.set_size(nfft); + for (i1 = 0; i1 < nfft; i1++) { + r[i1].re = 0.0; + r[i1].im = 0.0; + } + } + if ((n2blue != 1) && ((nfft & 1) == 0)) { + FFTImplementationCallback::doHalfLengthBluestein( + x, xoff, r, x.size(0), nfft, n2blue, wwc, costab, sintab, costab, + sintabinv); + } else { + minNrowsNx = x.size(0); + if (nfft <= minNrowsNx) { + minNrowsNx = nfft; + } + for (b_k = 0; b_k < minNrowsNx; b_k++) { + u0 = (nfft + b_k) - 1; + i1 = xoff + b_k; + r[b_k].re = wwc[u0].re * x[i1]; + r[b_k].im = wwc[u0].im * -x[i1]; + } + i1 = minNrowsNx + 1; + for (b_k = i1; b_k <= nfft; b_k++) { + r[b_k - 1].re = 0.0; + r[b_k - 1].im = 0.0; + } + FFTImplementationCallback::r2br_r2dit_trig_impl(r, n2blue, costab, sintab, + b_fv); + FFTImplementationCallback::r2br_r2dit_trig_impl(wwc, n2blue, costab, + sintab, fv); + fv.set_size(b_fv.size(0)); + u0 = b_fv.size(0); + for (i1 = 0; i1 < u0; i1++) { + re_tmp = b_fv[i1].re; + b_re_tmp = fv[i1].im; + c_re_tmp = b_fv[i1].im; + d_re_tmp = fv[i1].re; + fv[i1].re = re_tmp * d_re_tmp - c_re_tmp * b_re_tmp; + fv[i1].im = re_tmp * b_re_tmp + c_re_tmp * d_re_tmp; + } + FFTImplementationCallback::r2br_r2dit_trig_impl(fv, n2blue, costab, + sintabinv, b_fv); + if (b_fv.size(0) > 1) { + re_tmp = 1.0 / static_cast(b_fv.size(0)); + u0 = b_fv.size(0); + for (i1 = 0; i1 < u0; i1++) { + b_fv[i1].re = re_tmp * b_fv[i1].re; + b_fv[i1].im = re_tmp * b_fv[i1].im; + } + } + i1 = wwc.size(0); + for (b_k = nfft; b_k <= i1; b_k++) { + re_tmp = wwc[b_k - 1].re; + b_re_tmp = b_fv[b_k - 1].im; + c_re_tmp = wwc[b_k - 1].im; + d_re_tmp = b_fv[b_k - 1].re; + u0 = b_k - nfft; + r[u0].re = re_tmp * d_re_tmp + c_re_tmp * b_re_tmp; + r[u0].im = re_tmp * b_re_tmp - c_re_tmp * d_re_tmp; + } + } + u0 = r.size(0); + for (i1 = 0; i1 < u0; i1++) { + y[i1 + y.size(0) * chan] = r[i1]; + } + } +} + +// +// Arguments : int nfft +// boolean_T useRadix2 +// int *n2blue +// int *nRows +// Return Type : void +// +void FFTImplementationCallback::get_algo_sizes(int nfft, boolean_T useRadix2, + int *n2blue, int *nRows) +{ + *n2blue = 1; + if (useRadix2) { + *nRows = nfft; + } else { + if (nfft > 0) { + int n; + int pmax; + n = (nfft + nfft) - 1; + pmax = 31; + if (n <= 1) { + pmax = 0; + } else { + int pmin; + boolean_T exitg1; + pmin = 0; + exitg1 = false; + while ((!exitg1) && (pmax - pmin > 1)) { + int k; + int pow2p; + k = (pmin + pmax) >> 1; + pow2p = 1 << k; + if (pow2p == n) { + pmax = k; + exitg1 = true; + } else if (pow2p > n) { + pmax = k; + } else { + pmin = k; + } + } + } + *n2blue = 1 << pmax; + } + *nRows = *n2blue; + } +} + +// +// Arguments : const ::coder::array &x +// int n1_unsigned +// const ::coder::array &costab +// const ::coder::array &sintab +// ::coder::array &y +// Return Type : void +// +void FFTImplementationCallback::r2br_r2dit_trig( + const ::coder::array &x, int n1_unsigned, + const ::coder::array &costab, + const ::coder::array &sintab, ::coder::array &y) +{ + array r; + int i1; + int loop_ub; + int nrows; + int xoff; + nrows = x.size(0); + y.set_size(n1_unsigned, x.size(1)); + if (n1_unsigned > x.size(0)) { + y.set_size(n1_unsigned, x.size(1)); + loop_ub = n1_unsigned * x.size(1); + for (int i{0}; i < loop_ub; i++) { + y[i].re = 0.0; + y[i].im = 0.0; + } + } + loop_ub = x.size(1) - 1; +#pragma omp parallel for num_threads(omp_get_max_threads()) private(r, xoff, i1) + + for (int chan = 0; chan <= loop_ub; chan++) { + xoff = chan * nrows; + r.set_size(n1_unsigned); + if (n1_unsigned > x.size(0)) { + r.set_size(n1_unsigned); + for (i1 = 0; i1 < n1_unsigned; i1++) { + r[i1].re = 0.0; + r[i1].im = 0.0; + } + } + FFTImplementationCallback::doHalfLengthRadix2(x, xoff, r, n1_unsigned, + costab, sintab); + xoff = r.size(0); + for (i1 = 0; i1 < xoff; i1++) { + y[i1 + y.size(0) * chan] = r[i1]; + } + } +} + +// +// Arguments : const ::coder::array &x +// int unsigned_nRows +// const ::coder::array &costab +// const ::coder::array &sintab +// ::coder::array &y +// Return Type : void +// +void FFTImplementationCallback::r2br_r2dit_trig_impl( + const ::coder::array &x, int unsigned_nRows, + const ::coder::array &costab, + const ::coder::array &sintab, ::coder::array &y) +{ + double temp_im; + double temp_re; + double temp_re_tmp; + double twid_re; + int i; + int iDelta2; + int iheight; + int iy; + int ju; + int k; + int nRowsD2; + y.set_size(unsigned_nRows); + if (unsigned_nRows > x.size(0)) { + y.set_size(unsigned_nRows); + for (iy = 0; iy < unsigned_nRows; iy++) { + y[iy].re = 0.0; + y[iy].im = 0.0; + } + } + iDelta2 = x.size(0); + if (iDelta2 > unsigned_nRows) { + iDelta2 = unsigned_nRows; + } + iheight = unsigned_nRows - 2; + nRowsD2 = unsigned_nRows / 2; + k = nRowsD2 / 2; + iy = 0; + ju = 0; + for (i = 0; i <= iDelta2 - 2; i++) { + boolean_T tst; + y[iy] = x[i]; + iy = unsigned_nRows; + tst = true; + while (tst) { + iy >>= 1; + ju ^= iy; + tst = ((ju & iy) == 0); + } + iy = ju; + } + y[iy] = x[iDelta2 - 1]; + if (unsigned_nRows > 1) { + for (i = 0; i <= iheight; i += 2) { + temp_re_tmp = y[i + 1].re; + temp_im = y[i + 1].im; + temp_re = y[i].re; + twid_re = y[i].im; + y[i + 1].re = temp_re - temp_re_tmp; + y[i + 1].im = twid_re - temp_im; + y[i].re = temp_re + temp_re_tmp; + y[i].im = twid_re + temp_im; + } + } + iy = 2; + iDelta2 = 4; + iheight = ((k - 1) << 2) + 1; + while (k > 0) { + int b_temp_re_tmp; + for (i = 0; i < iheight; i += iDelta2) { + b_temp_re_tmp = i + iy; + temp_re = y[b_temp_re_tmp].re; + temp_im = y[b_temp_re_tmp].im; + y[b_temp_re_tmp].re = y[i].re - temp_re; + y[b_temp_re_tmp].im = y[i].im - temp_im; + y[i].re = y[i].re + temp_re; + y[i].im = y[i].im + temp_im; + } + ju = 1; + for (int j{k}; j < nRowsD2; j += k) { + double twid_im; + int ihi; + twid_re = costab[j]; + twid_im = sintab[j]; + i = ju; + ihi = ju + iheight; + while (i < ihi) { + b_temp_re_tmp = i + iy; + temp_re_tmp = y[b_temp_re_tmp].im; + temp_im = y[b_temp_re_tmp].re; + temp_re = twid_re * temp_im - twid_im * temp_re_tmp; + temp_im = twid_re * temp_re_tmp + twid_im * temp_im; + y[b_temp_re_tmp].re = y[i].re - temp_re; + y[b_temp_re_tmp].im = y[i].im - temp_im; + y[i].re = y[i].re + temp_re; + y[i].im = y[i].im + temp_im; + i += iDelta2; + } + ju++; + } + k /= 2; + iy = iDelta2; + iDelta2 += iDelta2; + iheight -= iy; + } +} + +} // namespace internal +} // namespace coder + +// +// File trailer for FFTImplementationCallback.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/FFTImplementationCallback.h b/dereverbrate/dereveb_c/FFTImplementationCallback.h new file mode 100644 index 0000000..57e16b2 --- /dev/null +++ b/dereverbrate/dereveb_c/FFTImplementationCallback.h @@ -0,0 +1,65 @@ +// +// File: FFTImplementationCallback.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef FFTIMPLEMENTATIONCALLBACK_H +#define FFTIMPLEMENTATIONCALLBACK_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Type Definitions +namespace coder { +namespace internal { +class FFTImplementationCallback { +public: + static void get_algo_sizes(int nfft, boolean_T useRadix2, int *n2blue, + int *nRows); + static void r2br_r2dit_trig(const ::coder::array &x, + int n1_unsigned, + const ::coder::array &costab, + const ::coder::array &sintab, + ::coder::array &y); + static void dobluesteinfft(const ::coder::array &x, int n2blue, + int nfft, const ::coder::array &costab, + const ::coder::array &sintab, + const ::coder::array &sintabinv, + ::coder::array &y); + static void r2br_r2dit_trig_impl(const ::coder::array &x, + int unsigned_nRows, + const ::coder::array &costab, + const ::coder::array &sintab, + ::coder::array &y); + +protected: + static void doHalfLengthRadix2(const ::coder::array &x, + int xoffInit, ::coder::array &y, + int unsigned_nRows, + const ::coder::array &costab, + const ::coder::array &sintab); + static void + doHalfLengthBluestein(const ::coder::array &x, int xoffInit, + ::coder::array &y, int nrowsx, int nRows, + int nfft, const ::coder::array &wwc, + const ::coder::array &costab, + const ::coder::array &sintab, + const ::coder::array &costabinv, + const ::coder::array &sintabinv); +}; + +} // namespace internal +} // namespace coder + +#endif +// +// File trailer for FFTImplementationCallback.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/_clang-format b/dereverbrate/dereveb_c/_clang-format new file mode 100644 index 0000000..55a16f7 --- /dev/null +++ b/dereverbrate/dereveb_c/_clang-format @@ -0,0 +1,27 @@ +BasedOnStyle: LLVM +Language: Cpp +IndentWidth: 2 +ColumnLimit: 80 +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +CommentPragmas: '^(Return Type|Arguments)\s*' +DeriveLineEnding : true +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + SplitEmptyFunction: true + SplitEmptyRecord: true diff --git a/dereverbrate/dereveb_c/cat.cpp b/dereverbrate/dereveb_c/cat.cpp new file mode 100644 index 0000000..5adeaff --- /dev/null +++ b/dereverbrate/dereveb_c/cat.cpp @@ -0,0 +1,62 @@ +// +// File: cat.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "cat.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +// +// Arguments : coder::array &x +// const coder::array &r1 +// const coder::array &inputFramePower +// const coder::array &M +// Return Type : void +// +void binary_expand_op(coder::array &x, + const coder::array &r1, + const coder::array &inputFramePower, + const coder::array &M) +{ + coder::array r; + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + if (inputFramePower.size(0) == 1) { + i = r1.size(0); + } else { + i = inputFramePower.size(0); + } + r.set_size(i); + stride_0_0 = (r1.size(0) != 1); + stride_1_0 = (inputFramePower.size(0) != 1); + if (inputFramePower.size(0) == 1) { + loop_ub = r1.size(0); + } else { + loop_ub = inputFramePower.size(0); + } + for (i = 0; i < loop_ub; i++) { + r[i] = 1.0 - r1[i * stride_0_0] / inputFramePower[i * stride_1_0]; + } + x.set_size(r.size(0), 2); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + x[i] = r[i]; + } + loop_ub = M.size(0); + for (i = 0; i < loop_ub; i++) { + x[i + x.size(0)] = 0.0; + } +} + +// +// File trailer for cat.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/cat.h b/dereverbrate/dereveb_c/cat.h new file mode 100644 index 0000000..c86f21e --- /dev/null +++ b/dereverbrate/dereveb_c/cat.h @@ -0,0 +1,29 @@ +// +// File: cat.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef CAT_H +#define CAT_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +void binary_expand_op(coder::array &x, + const coder::array &r1, + const coder::array &inputFramePower, + const coder::array &M); + +#endif +// +// File trailer for cat.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/codedescriptor.dmr b/dereverbrate/dereveb_c/codedescriptor.dmr new file mode 100644 index 0000000..ca55916 Binary files /dev/null and b/dereverbrate/dereveb_c/codedescriptor.dmr differ diff --git a/dereverbrate/dereveb_c/coder_array.h b/dereverbrate/dereveb_c/coder_array.h new file mode 100644 index 0000000..f9ec234 --- /dev/null +++ b/dereverbrate/dereveb_c/coder_array.h @@ -0,0 +1,786 @@ +/* Copyright 2019 The Mathworks, Inc. */ +/* Copied from + * fullfile(matlabroot,'extern','include','coder','coder_array','coder_array_rtw_cpp11.h') */ + +#ifndef _mw_coder_array_cpp11_h +#define _mw_coder_array_cpp11_h + +// Usage: +// +// coder::array: T base type of data, N number of dimensions +// +// coder::array() +// : default constructor +// coder::array(coder::array const &) +// : copy constructor (always make a deep copy of other array) +// coder::array(T const *data, SizeType const *sz) +// : Set data with sizes of this array. +// : (Data is not copied, data is not deleted) +// coder::array::operator = (coder coder::array &) +// : Assign into this array; +// : delete its previous contents (if owning the data.) +// set(T const *data, SizeType sz1, SizeType sz2, ...) +// : Set data with dimensions. +// : (Data is not copied, data is not deleted) +// set_size(SizeType sz1, SizeType sz2, ...) +// : Set sizes of array. Reallocate memory of data if needed. +// bool is_owner() : Return true if the data is owned by the class. +// void set_owner(b) : Set if the data is owned by the class. +// SizeType capacity() : How many entries are reserved by memory allocation. +// reshape( SizeType sz1, SizeType sz2, ...) +// : Reshape array to a different ND shape. Do not copy the data. +// : The number of elements must not be changed (numel()==sz1*sz2*...) +// : Return the array with possibly new number of dimensions. +// clear() : Reset array to be empty. +// SizeType numel() : Return the number of elements. +// operator [] (SizeType index) : Extract element at linear index (0 based.) +// size(SizeType dimension) : Size of array of the provided dimension. +// SizeType * size() : Return the pointer to all the sizes of this array. +// SizeType index(SizeType i1, SizeType i2, ...) +// : Compute the linear index from ND index (i1,i2,...) +// at(SizeType i1, SizeType i2, ...) : The element at index (i1,i2,...) + +#include +#include +#include +#include +#include + +#ifndef INT32_T +#include "rtwtypes.h" +#endif + +namespace coder { + +#ifndef CODER_ARRAY_NEW_DELETE +#define CODER_ARRAY_NEW_DELETE +#define CODER_NEW(T, N) new T[N] +#define CODER_DELETE(P) delete[](P) +#endif + +#ifndef CODER_ARRAY_SIZE_TYPE_DEFINED +using SizeType = int; +#endif + +namespace std = ::std; + +namespace detail { + +#ifndef CODER_ARRAY_DATA_PTR_DEFINED +template +class data_ptr { + public: + using value_type = T; + using size_type = SZ; + + data_ptr() + : data_(nullptr) + , size_(0) + , capacity_(0) + , owner_(false) { + } + data_ptr(T* _data, SZ _sz) + : data_(_data) + , size_(_sz) + , capacity_(_sz) + , owner_(false) { + } + + data_ptr(data_ptr const& _other) + : data_(_other.owner_ ? nullptr : _other.data_) + , size_(_other.owner_ ? 0 : _other.size_) + , capacity_(_other.owner_ ? 0 : _other.capacity_) + , owner_(_other.owner_) { + if (owner_) { + resize(_other.size_); + (void)std::copy(_other.data_, _other.data_ + size_, data_); + } + } + + ~data_ptr() { + if (owner_) { + CODER_DELETE(data_); + } + } + SZ capacity() const { + return capacity_; + } + void reserve(SZ _n) { + if (_n > capacity_) { + T* const new_data{CODER_NEW(T, _n)}; + (void)std::copy(data_, data_ + size_, new_data); + if (owner_) { + CODER_DELETE(data_); + } + data_ = new_data; + capacity_ = _n; + owner_ = true; + } + } + void resize(SZ _n) { + reserve(_n); + size_ = _n; + } + + private: + // Prohibit use of assignment operator to prevent subtle bugs + void operator=(data_ptr const& _other); + + public: + void set(T* _data, SZ _sz) { + if (owner_) { + CODER_DELETE(data_); + } + data_ = _data; + size_ = _sz; + owner_ = false; + capacity_ = size_; + } + + void copy(T const* const _data, SZ _size) { + if (data_ == _data) { + size_ = _size; + return; + } + if (owner_) { + CODER_DELETE(data_); + } + data_ = CODER_NEW(T, _size); + owner_ = true; + size_ = _size; + capacity_ = size_; + (void)std::copy(_data, _data + _size, data_); + } + + void copy(data_ptr const& _other) { + copy(_other.data_, _other.size_); + } + + operator T*() { + return &data_[0]; + } + + operator T const *() const { + return &data_[0]; + } + + T& operator[](SZ _index) { + return data_[_index]; + } + T const& operator[](SZ _index) const { + return data_[_index]; + } + + T* operator->() { + return data_; + } + + T const* operator->() const { + return data_; + } + + bool is_null() const { + return data_ == nullptr; + } + + void clear() { + if (owner_) { + CODER_DELETE(data_); + } + data_ = nullptr; + size_ = 0; + capacity_ = 0; + owner_ = false; + } + + bool is_owner() const { + return owner_; + } + + void set_owner(bool _b) { + owner_ = _b; + } + + private: + T* data_; + SZ size_; + SZ capacity_; + bool owner_; +}; +#endif + +} // namespace detail + +// Implementing the random access iterator class so coder::array can be +// used in STL iterators. +template +class array_iterator : public std::iterator { + public: + array_iterator() + : arr_(nullptr) + , i_(0) { + } + array_iterator(array_iterator const& other) + : arr_(other.arr_) + , i_(other.i_) { + } + ~array_iterator() { + } + typename T::value_type& operator*() const { + return (*arr_)[i_]; + } + typename T::value_type* operator->() const { + return &(*arr_)[i_]; + } + typename T::value_type& operator[](typename T::size_type _di) const { + return (*arr_)[i_ + _di]; + } + array_iterator& operator++() { + ++i_; + return *this; + } + array_iterator& operator--() { + --i_; + return *this; + } + array_iterator operator++(int) { + array_iterator cp{*this}; + ++i_; + return cp; + } + array_iterator operator--(int) { + array_iterator cp{*this}; + --i_; + return cp; + } + array_iterator& operator=(array_iterator const& _other) { + this->i_ = _other.i_; + return *this; + } + bool operator==(array_iterator const& _other) const { + return i_ == _other.i_; + } + bool operator!=(array_iterator const& _other) const { + return i_ != _other.i_; + } + bool operator<(array_iterator const& _other) const { + return i_ < _other.i_; + } + bool operator>(array_iterator const& _other) const { + return i_ > _other.i_; + } + bool operator<=(array_iterator const& _other) const { + return i_ <= _other.i_; + } + bool operator>=(array_iterator const& _other) const { + return i_ >= _other.i_; + } + array_iterator operator+(typename T::size_type _add) const { + array_iterator cp{*this}; + cp.i_ += _add; + return cp; + } + array_iterator& operator+=(typename T::size_type _add) { + this->i_ += _add; + return *this; + } + array_iterator operator-(typename T::size_type _subtract) const { + array_iterator cp{*this}; + cp.i_ -= _subtract; + return cp; + } + array_iterator& operator-=(typename T::size_type _subtract) { + this->i_ -= _subtract; + return *this; + } + typename T::size_type operator-(array_iterator const& _other) const { + return static_cast(this->i_ - _other.i_); + } + + array_iterator(T* _arr, typename T::size_type _i) + : arr_(_arr) + , i_(_i) { + } + + private: + T* arr_; + typename T::size_type i_; +}; + +// Const version of the array iterator. +template +class const_array_iterator : public std::iterator { + public: + const_array_iterator() + : arr_(nullptr) + , i_(0) { + } + const_array_iterator(const_array_iterator const& other) + : arr_(other.arr_) + , i_(other.i_) { + } + ~const_array_iterator() { + } + typename T::value_type const& operator*() const { + return (*arr_)[i_]; + } + typename T::value_type const* operator->() const { + return &(*arr_)[i_]; + } + typename T::value_type const& operator[](typename T::size_type _di) const { + return (*arr_)[i_ + _di]; + } + const_array_iterator& operator++() { + ++i_; + return *this; + } + const_array_iterator& operator--() { + --i_; + return *this; + } + const_array_iterator operator++(int) { + const_array_iterator copy{*this}; + ++i_; + return copy; + } + const_array_iterator operator--(int) { + const_array_iterator copy{*this}; + --i_; + return copy; + } + const_array_iterator& operator=(const_array_iterator const& _other) { + this->i_ = _other.i_; + return *this; + } + bool operator==(const_array_iterator const& _other) const { + return i_ == _other.i_; + } + bool operator!=(const_array_iterator const& _other) const { + return i_ != _other.i_; + } + bool operator<(const_array_iterator const& _other) const { + return i_ < _other.i_; + } + bool operator>(const_array_iterator const& _other) const { + return i_ > _other.i_; + } + bool operator<=(const_array_iterator const& _other) const { + return i_ <= _other.i_; + } + bool operator>=(const_array_iterator const& _other) const { + return i_ >= _other.i_; + } + const_array_iterator operator+(typename T::size_type _add) const { + const_array_iterator cp{*this}; + cp.i_ += _add; + return cp; + } + const_array_iterator& operator+=(typename T::size_type _add) { + this->i_ += _add; + return *this; + } + const_array_iterator operator-(typename T::size_type _subtract) const { + const_array_iterator cp{*this}; + cp.i_ -= _subtract; + return cp; + } + + const_array_iterator& operator-=(typename T::size_type _subtract) { + this->i_ -= _subtract; + return *this; + } + + typename T::size_type operator-(const_array_iterator const& _other) const { + return static_cast(this->i_ - _other.i_); + } + + const_array_iterator(T const* _arr, typename T::size_type _i) + : arr_(_arr) + , i_(_i) { + } + + private: + T const* arr_; + typename T::size_type i_; + typename T::size_type n_; +}; + +namespace detail { + +// detail::numel: Compile-time product of the given size vector of length N. +template +class numel { + public: + template + static SZ compute(SZ _size[]) { + return _size[N - 1] * numel::compute(_size); + } +}; +template <> +class numel<0> { + public: + template + static SZ compute(SZ[]) { + return 1; + } +}; + +// Compute the product for a set of numeric arguments: product(10, 20, 30, ...) => +// 10*20*30*... +template +struct product_i { + static SZ compute(First _f, Rest... _rest) { + return _f * product_i::compute(_rest...); + } +}; +template +struct product_i { + static SZ compute(Last _l) { + return _l; + } +}; + +template +SZ product(Args... args) { + return product_i::compute(args...); +} + +// Compute flat index from (column-major) ND size vector and a list of indices. +template +class index_nd { + public: + template + static SZ compute(SZ const _size[], SZ const _indices[]) { + SZ const weight{numel::compute(_size)}; + return weight * _indices[I - 1] + index_nd::compute(_size, _indices); + } +}; + +template <> +class index_nd<0> { + public: + template + static SZ compute(SZ[], SZ[]) { + return 0; + } +}; + +template +struct match_dimensions {}; + +template <> +struct match_dimensions { + static void check() { + } +}; + +} // namespace detail + +// Base class for code::array. SZ is the type used for sizes (currently int32_t.) +// Overloading up to 10 dimensions (not using variadic templates to +// stay compatible with C++98.) +template +class array_base { + public: + using value_type = T; + using size_type = SZ; + + array_base() { + (void)::memset(size_, 0, sizeof(SZ) * N); + } + + array_base(T* _data, SZ const* _sz) + : data_(_data, coder::detail::numel::compute(_sz)) { + (void)std::copy(_sz, _sz + N, size_); + } + + array_base& operator=(array_base const& _other) { + data_.copy(_other.data_); + (void)std::copy(_other.size_, _other.size_ + N, size_); + return *this; + } + + template + void set(T* _data, Dims... dims) { + coder::detail::match_dimensions::check(); + data_.set(_data, coder::detail::product(dims...)); + set_size_i<0>(dims...); + } + + bool is_owner() const { + return data_.is_owner(); + } + + void set_owner(bool b) { + data_.set_owner(b); + } + + SZ capacity() const { + return data_.capacity(); + } + + private: + template + void set_size_i(First f, Rest... rest) { + size_[_i] = f; + set_size_i<_i + 1, Rest...>(rest...); + } + template + void set_size_i(Last l) { + size_[_i] = l; + } + + public: + template + void set_size(Dims... dims) { + coder::detail::match_dimensions::check(); + set_size_i<0>(dims...); + ensureCapacity(numel()); + } + + template + array_base reshape_n(SZ const (&_ns)[N1]) const { + array_base reshaped{const_cast(&data_[0]), _ns}; + return reshaped; + } + + template + array_base(sizeof...(Dims))> reshape(Dims... dims) const { + SZ const ns[]{static_cast(dims)...}; + return reshape_n(ns); + } + + T& operator[](SZ _index) { + return data_[_index]; + } + + T const& operator[](SZ _index) const { + return data_[_index]; + } + + void clear() { + data_.clear(); + } + + T* data() { + return data_; + } + + T const* data() const { + return data_; + } + + SZ const* size() const { + return &size_[0]; + } + + SZ size(SZ _index) const { + return size_[_index]; + } + + SZ numel() const { + return coder::detail::numel::compute(size_); + } + + template + SZ index(Dims... _dims) const { + coder::detail::match_dimensions::check(); + SZ const indices[]{static_cast(_dims)...}; + return coder::detail::index_nd(sizeof...(_dims))>::compute(size_, indices); + } + + template + T& at(Dims... _i) { + coder::detail::match_dimensions::check(); + return data_[index(_i...)]; + } + + template + T const& at(Dims... _i) const { + coder::detail::match_dimensions::check(); + return data_[index(_i...)]; + } + + array_iterator > begin() { + return array_iterator >(this, 0); + } + array_iterator > end() { + return array_iterator >(this, this->numel()); + } + const_array_iterator > begin() const { + return const_array_iterator >(this, 0); + } + const_array_iterator > end() const { + return const_array_iterator >(this, this->numel()); + } + + protected: + coder::detail::data_ptr data_; + SZ size_[N]; + + private: + void ensureCapacity(SZ _newNumel) { + if (_newNumel > data_.capacity()) { + SZ i{data_.capacity()}; + if (i < 16) { + i = 16; + } + + while (i < _newNumel) { + if (i > 1073741823) { + i = MAX_int32_T; + } else { + i *= 2; + } + } + data_.reserve(i); + } + data_.resize(_newNumel); + } +}; + +// The standard coder::array class with base type and number of dimensions. +template +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : Base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + array(T* _data, SizeType const* _sz) + : Base(_data, _sz) { + } +}; + +// Specialize on char_T (row vector) for better support on strings. +template <> +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : array_base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + + array(std::string const& _str) { + operator=(_str); + } + + array(char_T const* const _str) { + operator=(_str); + } + + array(std::vector const& _vec) { + SizeType const n{static_cast(_vec.size())}; + set_size(1, n); + data_.copy(&_vec[0], n); + } + + array& operator=(std::string const& _str) { + SizeType const n{static_cast(_str.size())}; + set_size(1, n); + data_.copy(_str.c_str(), n); + return *this; + } + + array& operator=(char_T const* const _str) { + SizeType const n{static_cast(strlen(_str))}; + set_size(1, n); + data_.copy(_str, n); + return *this; + } + + operator std::string() const { + return std::string(static_cast(&(*this)[0]), static_cast(size(1))); + } +}; + +// Specialize on 2 dimensions for better support interactions with +// std::vector and row vectors. +template +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : Base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + array(std::vector const& _vec) { + operator=(_vec); + } + + array& operator=(std::vector const& _vec) { + SizeType n{static_cast(_vec.size())}; + Base::set_size(1, n); + Base::data_.copy(&_vec[0], n); + return *this; + } + + operator std::vector() const { + T const* p{&Base::data_[0]}; + return std::vector(p, p + Base::numel()); + } +}; + +// Specialize on 1 dimension for better support with std::vector and +// column vectors. +template +class array : public array_base { + private: + using Base = array_base; + + public: + array() + : Base() { + } + array(array const& _other) + : Base(_other) { + } + array(Base const& _other) + : Base(_other) { + } + array(std::vector const& _vec) { + operator=(_vec); + } + + array& operator=(std::vector const& _vec) { + SizeType n{static_cast(_vec.size())}; + Base::set_size(n); + Base::data_.copy(&_vec[0], n); + return *this; + } + + operator std::vector() const { + T const* p{&Base::data_[0]}; + return std::vector(p, p + Base::numel()); + } +}; +} // namespace coder + +#endif diff --git a/dereverbrate/dereveb_c/combineVectorElements.cpp b/dereverbrate/dereveb_c/combineVectorElements.cpp new file mode 100644 index 0000000..1b077a6 --- /dev/null +++ b/dereverbrate/dereveb_c/combineVectorElements.cpp @@ -0,0 +1,72 @@ +// +// File: combineVectorElements.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "combineVectorElements.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +// +// Arguments : const ::coder::array &x +// Return Type : double +// +namespace coder { +double combineVectorElements(const ::coder::array &x) +{ + double y; + if (x.size(0) == 0) { + y = 0.0; + } else { + int firstBlockLength; + int k; + int lastBlockLength; + int nblocks; + if (x.size(0) <= 1024) { + firstBlockLength = x.size(0); + lastBlockLength = 0; + nblocks = 1; + } else { + firstBlockLength = 1024; + nblocks = x.size(0) / 1024; + lastBlockLength = x.size(0) - (nblocks << 10); + if (lastBlockLength > 0) { + nblocks++; + } else { + lastBlockLength = 1024; + } + } + y = x[0]; + for (k = 2; k <= firstBlockLength; k++) { + y += x[k - 1]; + } + for (int ib{2}; ib <= nblocks; ib++) { + double bsum; + int hi; + firstBlockLength = (ib - 1) << 10; + bsum = x[firstBlockLength]; + if (ib == nblocks) { + hi = lastBlockLength; + } else { + hi = 1024; + } + for (k = 2; k <= hi; k++) { + bsum += x[(firstBlockLength + k) - 1]; + } + y += bsum; + } + } + return y; +} + +} // namespace coder + +// +// File trailer for combineVectorElements.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/combineVectorElements.h b/dereverbrate/dereveb_c/combineVectorElements.h new file mode 100644 index 0000000..23467e2 --- /dev/null +++ b/dereverbrate/dereveb_c/combineVectorElements.h @@ -0,0 +1,29 @@ +// +// File: combineVectorElements.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef COMBINEVECTORELEMENTS_H +#define COMBINEVECTORELEMENTS_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +double combineVectorElements(const ::coder::array &x); + +} + +#endif +// +// File trailer for combineVectorElements.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/computeDFT.cpp b/dereverbrate/dereveb_c/computeDFT.cpp new file mode 100644 index 0000000..0b17232 --- /dev/null +++ b/dereverbrate/dereveb_c/computeDFT.cpp @@ -0,0 +1,252 @@ +// +// File: computeDFT.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "computeDFT.h" +#include "FFTImplementationCallback.h" +#include "dereveb_c_rtwutil.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Declarations +static int div_s32(int numerator, int denominator); + +// Function Definitions +// +// Arguments : int numerator +// int denominator +// Return Type : int +// +static int div_s32(int numerator, int denominator) +{ + int quotient; + if (denominator == 0) { + if (numerator >= 0) { + quotient = MAX_int32_T; + } else { + quotient = MIN_int32_T; + } + } else { + unsigned int b_denominator; + unsigned int b_numerator; + if (numerator < 0) { + b_numerator = ~static_cast(numerator) + 1U; + } else { + b_numerator = static_cast(numerator); + } + if (denominator < 0) { + b_denominator = ~static_cast(denominator) + 1U; + } else { + b_denominator = static_cast(denominator); + } + b_numerator /= b_denominator; + if ((numerator < 0) != (denominator < 0)) { + quotient = -static_cast(b_numerator); + } else { + quotient = static_cast(b_numerator); + } + } + return quotient; +} + +// +// Arguments : const ::coder::array &xin +// double nfft +// ::coder::array &Xx +// ::coder::array &f +// Return Type : void +// +namespace coder { +void computeDFT(const ::coder::array &xin, double nfft, + ::coder::array &Xx, ::coder::array &f) +{ + array costab; + array costab1q; + array sintab; + array sintabinv; + array wrappedData; + array xw; + double freq_res; + double half_res; + int b_remainder; + int i; + int i1; + int k; + int loop_ub_tmp; + int nFullPasses; + int offset; + loop_ub_tmp = static_cast(nfft); + xw.set_size(loop_ub_tmp, xin.size(1)); + offset = static_cast(nfft) * xin.size(1); + for (i = 0; i < offset; i++) { + xw[i] = 0.0; + } + if (xin.size(0) > nfft) { + i = xin.size(1); + for (int j{0}; j < i; j++) { + if (xin.size(0) == 1) { + wrappedData.set_size(1, loop_ub_tmp); + for (i1 = 0; i1 < loop_ub_tmp; i1++) { + wrappedData[i1] = 0.0; + } + } else { + wrappedData.set_size(loop_ub_tmp, 1); + for (i1 = 0; i1 < loop_ub_tmp; i1++) { + wrappedData[i1] = 0.0; + } + } + nFullPasses = div_s32(xin.size(0), static_cast(nfft)); + offset = nFullPasses * static_cast(nfft); + b_remainder = (xin.size(0) - offset) - 1; + for (k = 0; k <= b_remainder; k++) { + wrappedData[k] = xin[(offset + k) + xin.size(0) * j]; + } + i1 = b_remainder + 2; + for (k = i1; k <= loop_ub_tmp; k++) { + wrappedData[k - 1] = 0.0; + } + for (b_remainder = 0; b_remainder < nFullPasses; b_remainder++) { + offset = b_remainder * static_cast(nfft); + for (k = 0; k < loop_ub_tmp; k++) { + wrappedData[k] = wrappedData[k] + xin[(offset + k) + xin.size(0) * j]; + } + } + offset = wrappedData.size(0) * wrappedData.size(1); + for (i1 = 0; i1 < offset; i1++) { + xw[i1 + xw.size(0) * j] = wrappedData[i1]; + } + } + } else { + xw.set_size(xin.size(0), xin.size(1)); + offset = xin.size(0) * xin.size(1); + for (i = 0; i < offset; i++) { + xw[i] = xin[i]; + } + } + if ((xw.size(0) == 0) || (xw.size(1) == 0)) { + Xx.set_size(loop_ub_tmp, xw.size(1)); + offset = static_cast(nfft) * xw.size(1); + for (i = 0; i < offset; i++) { + Xx[i].re = 0.0; + Xx[i].im = 0.0; + } + } else { + boolean_T useRadix2; + useRadix2 = + ((static_cast(nfft) > 0) && + ((static_cast(nfft) & (static_cast(nfft) - 1)) == 0)); + internal::FFTImplementationCallback::get_algo_sizes( + static_cast(nfft), useRadix2, &nFullPasses, &offset); + freq_res = 6.2831853071795862 / static_cast(offset); + b_remainder = offset / 2 / 2; + costab1q.set_size(1, b_remainder + 1); + costab1q[0] = 1.0; + offset = b_remainder / 2 - 1; + for (k = 0; k <= offset; k++) { + costab1q[k + 1] = std::cos(freq_res * (static_cast(k) + 1.0)); + } + i = offset + 2; + i1 = b_remainder - 1; + for (k = i; k <= i1; k++) { + costab1q[k] = std::sin(freq_res * static_cast(b_remainder - k)); + } + costab1q[b_remainder] = 0.0; + if (!useRadix2) { + b_remainder = costab1q.size(1) - 1; + offset = (costab1q.size(1) - 1) << 1; + costab.set_size(1, offset + 1); + sintab.set_size(1, offset + 1); + costab[0] = 1.0; + sintab[0] = 0.0; + sintabinv.set_size(1, offset + 1); + for (k = 0; k < b_remainder; k++) { + sintabinv[k + 1] = costab1q[(b_remainder - k) - 1]; + } + i = costab1q.size(1); + for (k = i; k <= offset; k++) { + sintabinv[k] = costab1q[k - b_remainder]; + } + for (k = 0; k < b_remainder; k++) { + costab[k + 1] = costab1q[k + 1]; + sintab[k + 1] = -costab1q[(b_remainder - k) - 1]; + } + i = costab1q.size(1); + for (k = i; k <= offset; k++) { + costab[k] = -costab1q[offset - k]; + sintab[k] = -costab1q[k - b_remainder]; + } + } else { + b_remainder = costab1q.size(1) - 1; + offset = (costab1q.size(1) - 1) << 1; + costab.set_size(1, offset + 1); + sintab.set_size(1, offset + 1); + costab[0] = 1.0; + sintab[0] = 0.0; + for (k = 0; k < b_remainder; k++) { + costab[k + 1] = costab1q[k + 1]; + sintab[k + 1] = -costab1q[(b_remainder - k) - 1]; + } + i = costab1q.size(1); + for (k = i; k <= offset; k++) { + costab[k] = -costab1q[offset - k]; + sintab[k] = -costab1q[k - b_remainder]; + } + sintabinv.set_size(1, 0); + } + if (useRadix2) { + internal::FFTImplementationCallback::r2br_r2dit_trig( + xw, static_cast(nfft), costab, sintab, Xx); + } else { + internal::FFTImplementationCallback::dobluesteinfft( + xw, nFullPasses, static_cast(nfft), costab, sintab, sintabinv, + Xx); + } + } + freq_res = 6.2831853071795862 / nfft; + if (nfft - 1.0 < 0.0) { + costab1q.set_size(costab1q.size(0), 0); + } else if (std::isinf(nfft - 1.0) && (0.0 == nfft - 1.0)) { + costab1q.set_size(1, 1); + costab1q[0] = rtNaN; + } else { + offset = static_cast(std::floor(nfft - 1.0)); + costab1q.set_size(1, offset + 1); + for (i = 0; i <= offset; i++) { + costab1q[i] = i; + } + } + costab1q.set_size(1, costab1q.size(1)); + offset = costab1q.size(1) - 1; + for (i = 0; i <= offset; i++) { + costab1q[i] = freq_res * costab1q[i]; + } + half_res = freq_res / 2.0; + if (rt_remd_snf(nfft, 2.0) != 0.0) { + double halfNPTS; + halfNPTS = (nfft + 1.0) / 2.0; + costab1q[static_cast(halfNPTS) - 1] = 3.1415926535897931 - half_res; + costab1q[static_cast(static_cast(halfNPTS))] = + half_res + 3.1415926535897931; + } else { + costab1q[static_cast(nfft / 2.0 + 1.0) - 1] = 3.1415926535897931; + } + costab1q[static_cast(nfft) - 1] = 6.2831853071795862 - freq_res; + f.set_size(costab1q.size(1)); + offset = costab1q.size(1); + for (i = 0; i < offset; i++) { + f[i] = costab1q[i]; + } +} + +} // namespace coder + +// +// File trailer for computeDFT.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/computeDFT.h b/dereverbrate/dereveb_c/computeDFT.h new file mode 100644 index 0000000..18b52b4 --- /dev/null +++ b/dereverbrate/dereveb_c/computeDFT.h @@ -0,0 +1,30 @@ +// +// File: computeDFT.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef COMPUTEDFT_H +#define COMPUTEDFT_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void computeDFT(const ::coder::array &xin, double nfft, + ::coder::array &Xx, ::coder::array &f); + +} + +#endif +// +// File trailer for computeDFT.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/defines.txt b/dereverbrate/dereveb_c/defines.txt new file mode 100644 index 0000000..79b9eed --- /dev/null +++ b/dereverbrate/dereveb_c/defines.txt @@ -0,0 +1 @@ +MODEL=dereveb_c diff --git a/dereverbrate/dereveb_c/dereveb_c.cpp b/dereverbrate/dereveb_c/dereveb_c.cpp new file mode 100644 index 0000000..6991522 --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c.cpp @@ -0,0 +1,1802 @@ +// +// File: dereveb_c.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "dereveb_c.h" +#include "cat.h" +#include "combineVectorElements.h" +#include "dereveb_c_data.h" +#include "dereveb_c_initialize.h" +#include "div.h" +#include "hann.h" +#include "ifft.h" +#include "ixfun.h" +#include "ref.h" +#include "rt_nonfinite.h" +#include "spectrogram.h" +#include "sum.h" +#include "coder_array.h" +#include +#include + +// Function Declarations +static void b_binary_expand_op(coder::array &unchanged, + const coder::array &newEstimates, + const coder::array &H_pow, + int blockIndex); + +static void binary_expand_op(coder::array &H_pow, int blockIndex, + const coder::array &M, + const coder::array &C); + +static void binary_expand_op(coder::array &G_R, + const coder::captured_var frequencyCount, + const coder::array &G_S); + +static void binary_expand_op(coder::array &allBlocks, + int inputFrameIndex, + const coder::array &G_S, + const coder::array &M); + +static void binary_expand_op(coder::array &vocal_effect, + const coder::array &G_R, + const coder::array &M, + int inputFrameIndex); + +static void binary_expand_op(coder::array &H_pow_sm, + const coder::array &H_pow); + +static void +binary_expand_op(coder::array &r, + const coder::array &previousSFramesPower_vc, + const coder::array &H_pow_sm); + +static void binary_expand_op(coder::array &G_R_vc, + const coder::array &M, + const coder::array &r1, + const coder::array &vocal_effect_sm, + const coder::array &vocal_effect, + const coder::array &inputFramePower); + +static void binary_expand_op(double output[220500], + const coder::array &r, + const coder::array &sampleRange, + const coder::array &window, + const coder::array &r1); + +static void c_binary_expand_op(coder::array &unchanged, + const coder::array &newEstimates, + const coder::array &inputFramePower); + +static void d_binary_expand_op(coder::array &G_S, + const coder::captured_var frequencyCount, + const coder::array &newEstimates); + +static void gt(coder::array &unchanged, + const coder::array &newEstimates, + const coder::array &inputFramePower); + +static void reconstruct(coder::captured_var *stftWindowSize, + coder::captured_var *frequencyCount, + coder::captured_var *frameCount, + const coder::array &spectrumx, + const coder::array &window, + double overlapSamples, double output[220500]); + +static double rt_hypotd_snf(double u0, double u1); + +// Function Definitions +// +// Arguments : coder::array &unchanged +// const coder::array &newEstimates +// const coder::array &H_pow +// int blockIndex +// Return Type : void +// +static void b_binary_expand_op(coder::array &unchanged, + const coder::array &newEstimates, + const coder::array &H_pow, + int blockIndex) +{ + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + i = H_pow.size(0); + if (i == 1) { + stride_0_0 = newEstimates.size(0); + } else { + stride_0_0 = i; + } + unchanged.set_size(stride_0_0); + stride_0_0 = (newEstimates.size(0) != 1); + stride_1_0 = (i != 1); + if (i == 1) { + loop_ub = newEstimates.size(0); + } else { + loop_ub = i; + } + for (i = 0; i < loop_ub; i++) { + unchanged[i] = (newEstimates[i * stride_0_0] >= + H_pow[i * stride_1_0 + H_pow.size(0) * blockIndex]); + } +} + +// +// Arguments : coder::array &H_pow +// int blockIndex +// const coder::array &M +// const coder::array &C +// Return Type : void +// +static void binary_expand_op(coder::array &H_pow, int blockIndex, + const coder::array &M, + const coder::array &C) +{ + coder::array r; + int b_H_pow; + int i; + int i1; + int i2; + int i3; + int stride_1_0; + int stride_3_0; + b_H_pow = H_pow.size(0) - 1; + i = M.size(0); + i1 = M.size(0); + i2 = C.size(0); + if (i2 == 1) { + i3 = i1; + } else { + i3 = i2; + } + if (i3 == 1) { + if (b_H_pow + 1 == 1) { + i3 = i; + } else { + i3 = b_H_pow + 1; + } + } else if (i2 == 1) { + i3 = i1; + } else { + i3 = i2; + } + r.set_size(i3); + stride_1_0 = (b_H_pow + 1 != 1); + stride_3_0 = (i2 != 1); + if (i2 == 1) { + i3 = i1; + } else { + i3 = i2; + } + if (i3 == 1) { + if (b_H_pow + 1 == 1) { + b_H_pow = i; + } else { + b_H_pow++; + } + } else if (i2 == 1) { + b_H_pow = i1; + } else { + b_H_pow = i2; + } + for (i = 0; i < b_H_pow; i++) { + r[i] = 0.2 * H_pow[i * stride_1_0 + H_pow.size(0) * blockIndex] + + 0.8 * C[i * stride_3_0 + C.size(0) * blockIndex]; + } + b_H_pow = r.size(0); + for (i = 0; i < b_H_pow; i++) { + H_pow[i + H_pow.size(0) * blockIndex] = r[i]; + } +} + +// +// Arguments : coder::array &G_R +// const coder::captured_var frequencyCount +// const coder::array &G_S +// Return Type : void +// +static void binary_expand_op(coder::array &G_R, + const coder::captured_var frequencyCount, + const coder::array &G_S) +{ + coder::array r; + int i; + int loop_ub; + int stride_1_0; + int stride_3_0; + if (G_S.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = G_S.size(0); + } + if (i == 1) { + if (G_R.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = G_R.size(0); + } + } else if (G_S.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = G_S.size(0); + } + r.set_size(i); + stride_1_0 = (G_R.size(0) != 1); + stride_3_0 = (G_S.size(0) != 1); + if (G_S.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = G_S.size(0); + } + if (i == 1) { + if (G_R.size(0) == 1) { + loop_ub = static_cast(frequencyCount.contents); + } else { + loop_ub = G_R.size(0); + } + } else if (G_S.size(0) == 1) { + loop_ub = static_cast(frequencyCount.contents); + } else { + loop_ub = G_S.size(0); + } + for (i = 0; i < loop_ub; i++) { + r[i] = 0.7 * G_R[i * stride_1_0] + 0.3 * (1.0 - G_S[i * stride_3_0]); + } + G_R.set_size(r.size(0)); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + G_R[i] = r[i]; + } +} + +// +// Arguments : coder::array &allBlocks +// int inputFrameIndex +// const coder::array &G_S +// const coder::array &M +// Return Type : void +// +static void binary_expand_op(coder::array &allBlocks, + int inputFrameIndex, + const coder::array &G_S, + const coder::array &M) +{ + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + i = M.size(0); + stride_0_0 = (G_S.size(0) != 1); + stride_1_0 = (i != 1); + if (i == 1) { + loop_ub = G_S.size(0); + } else { + loop_ub = i; + } + for (i = 0; i < loop_ub; i++) { + double d; + int i1; + i1 = i * stride_1_0; + d = G_S[i * stride_0_0]; + allBlocks[i + allBlocks.size(0) * inputFrameIndex].re = + d * M[i1 + M.size(0) * inputFrameIndex].re; + allBlocks[i + allBlocks.size(0) * inputFrameIndex].im = + d * M[i1 + M.size(0) * inputFrameIndex].im; + } +} + +// +// Arguments : coder::array &vocal_effect +// const coder::array &G_R +// const coder::array &M +// int inputFrameIndex +// Return Type : void +// +static void binary_expand_op(coder::array &vocal_effect, + const coder::array &G_R, + const coder::array &M, + int inputFrameIndex) +{ + int i; + int i1; + int loop_ub; + int stride_0_0; + int stride_1_0; + i = M.size(0); + if (i == 1) { + i1 = G_R.size(0); + } else { + i1 = i; + } + vocal_effect.set_size(i1); + stride_0_0 = (G_R.size(0) != 1); + stride_1_0 = (i != 1); + if (i == 1) { + loop_ub = G_R.size(0); + } else { + loop_ub = i; + } + for (i = 0; i < loop_ub; i++) { + double d; + i1 = i * stride_1_0; + d = G_R[i * stride_0_0]; + vocal_effect[i].re = d * M[i1 + M.size(0) * inputFrameIndex].re; + vocal_effect[i].im = d * M[i1 + M.size(0) * inputFrameIndex].im; + } +} + +// +// Arguments : coder::array &H_pow_sm +// const coder::array &H_pow +// Return Type : void +// +static void binary_expand_op(coder::array &H_pow_sm, + const coder::array &H_pow) +{ + coder::array r; + int i; + int i1; + int loop_ub; + int stride_0_0; + int stride_1_0; + if (H_pow.size(0) == 1) { + i = H_pow_sm.size(0); + } else { + i = H_pow.size(0); + } + r.set_size(i, 400); + stride_0_0 = (H_pow_sm.size(0) != 1); + stride_1_0 = (H_pow.size(0) != 1); + if (H_pow.size(0) == 1) { + loop_ub = H_pow_sm.size(0); + } else { + loop_ub = H_pow.size(0); + } + for (i = 0; i < 400; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + r[i1 + r.size(0) * i] = + 0.98 * H_pow_sm[i1 * stride_0_0 + H_pow_sm.size(0) * i] + + 0.02 * H_pow[i1 * stride_1_0 + H_pow.size(0) * i]; + } + } + H_pow_sm.set_size(r.size(0), 400); + loop_ub = r.size(0); + for (i = 0; i < 400; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + H_pow_sm[i1 + H_pow_sm.size(0) * i] = r[i1 + r.size(0) * i]; + } + } +} + +// +// Arguments : coder::array &r +// const coder::array &previousSFramesPower_vc +// const coder::array &H_pow_sm +// Return Type : void +// +static void +binary_expand_op(coder::array &r, + const coder::array &previousSFramesPower_vc, + const coder::array &H_pow_sm) +{ + coder::array b_previousSFramesPower_vc; + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + if (H_pow_sm.size(0) == 1) { + i = previousSFramesPower_vc.size(0); + } else { + i = H_pow_sm.size(0); + } + b_previousSFramesPower_vc.set_size(i, 400); + stride_0_0 = (previousSFramesPower_vc.size(0) != 1); + stride_1_0 = (H_pow_sm.size(0) != 1); + if (H_pow_sm.size(0) == 1) { + loop_ub = previousSFramesPower_vc.size(0); + } else { + loop_ub = H_pow_sm.size(0); + } + for (i = 0; i < 400; i++) { + for (int i1{0}; i1 < loop_ub; i1++) { + b_previousSFramesPower_vc[i1 + b_previousSFramesPower_vc.size(0) * i] = + previousSFramesPower_vc[i1 * stride_0_0 + + previousSFramesPower_vc.size(0) * i] * + H_pow_sm[i1 * stride_1_0 + H_pow_sm.size(0) * i]; + } + } + coder::sum(b_previousSFramesPower_vc, r); +} + +// +// Arguments : coder::array &G_R_vc +// const coder::array &M +// const coder::array &r1 +// const coder::array &vocal_effect_sm +// const coder::array &vocal_effect +// const coder::array &inputFramePower +// Return Type : void +// +static void binary_expand_op(coder::array &G_R_vc, + const coder::array &M, + const coder::array &r1, + const coder::array &vocal_effect_sm, + const coder::array &vocal_effect, + const coder::array &inputFramePower) +{ + coder::array r; + int M_idx_0; + int b_M_idx_0; + int i; + int stride_1_0; + int stride_3_0; + int stride_4_0; + int stride_5_0; + int stride_6_0; + M_idx_0 = M.size(0); + b_M_idx_0 = M.size(0); + if (inputFramePower.size(0) == 1) { + i = vocal_effect.size(0); + } else { + i = inputFramePower.size(0); + } + if (i == 1) { + i = vocal_effect_sm.size(0); + } else if (inputFramePower.size(0) == 1) { + i = vocal_effect.size(0); + } else { + i = inputFramePower.size(0); + } + if (r1.size(0) == 1) { + stride_1_0 = b_M_idx_0; + } else { + stride_1_0 = r1.size(0); + } + if (inputFramePower.size(0) == 1) { + stride_3_0 = vocal_effect.size(0); + } else { + stride_3_0 = inputFramePower.size(0); + } + if (i == 1) { + if (stride_1_0 == 1) { + if (G_R_vc.size(0) == 1) { + i = M_idx_0; + } else { + i = G_R_vc.size(0); + } + } else if (r1.size(0) == 1) { + i = b_M_idx_0; + } else { + i = r1.size(0); + } + } else if (stride_3_0 == 1) { + i = vocal_effect_sm.size(0); + } else if (inputFramePower.size(0) == 1) { + i = vocal_effect.size(0); + } else { + i = inputFramePower.size(0); + } + r.set_size(i); + stride_1_0 = (G_R_vc.size(0) != 1); + stride_3_0 = (r1.size(0) != 1); + stride_4_0 = (vocal_effect_sm.size(0) != 1); + stride_5_0 = (vocal_effect.size(0) != 1); + stride_6_0 = (inputFramePower.size(0) != 1); + if (inputFramePower.size(0) == 1) { + i = vocal_effect.size(0); + } else { + i = inputFramePower.size(0); + } + if (i == 1) { + i = vocal_effect_sm.size(0); + } else if (inputFramePower.size(0) == 1) { + i = vocal_effect.size(0); + } else { + i = inputFramePower.size(0); + } + if (i == 1) { + if (r1.size(0) == 1) { + i = b_M_idx_0; + } else { + i = r1.size(0); + } + if (i == 1) { + if (G_R_vc.size(0) == 1) { + b_M_idx_0 = M_idx_0; + } else { + b_M_idx_0 = G_R_vc.size(0); + } + } else if (r1.size(0) != 1) { + b_M_idx_0 = r1.size(0); + } + } else { + if (inputFramePower.size(0) == 1) { + i = vocal_effect.size(0); + } else { + i = inputFramePower.size(0); + } + if (i == 1) { + b_M_idx_0 = vocal_effect_sm.size(0); + } else if (inputFramePower.size(0) == 1) { + b_M_idx_0 = vocal_effect.size(0); + } else { + b_M_idx_0 = inputFramePower.size(0); + } + } + for (i = 0; i < b_M_idx_0; i++) { + double ai; + double br; + double vocal_effect_im; + double vocal_effect_re; + M_idx_0 = i * stride_5_0; + vocal_effect_im = vocal_effect[M_idx_0].re; + ai = vocal_effect[M_idx_0].im; + br = inputFramePower[i * stride_6_0] + 1.0E-5; + if (ai == 0.0) { + vocal_effect_re = vocal_effect_im / br; + vocal_effect_im = 0.0; + } else if (vocal_effect_im == 0.0) { + vocal_effect_re = 0.0; + vocal_effect_im = ai / br; + } else { + vocal_effect_re = vocal_effect_im / br; + vocal_effect_im = ai / br; + } + M_idx_0 = i * stride_1_0; + ai = vocal_effect_sm[i * stride_4_0]; + r[i].re = (0.7 * G_R_vc[M_idx_0].re + 0.3 * r1[i * stride_3_0]) + + ai * vocal_effect_re; + r[i].im = 0.7 * G_R_vc[M_idx_0].im + ai * vocal_effect_im; + } + G_R_vc.set_size(r.size(0)); + b_M_idx_0 = r.size(0); + for (i = 0; i < b_M_idx_0; i++) { + G_R_vc[i] = r[i]; + } +} + +// +// Arguments : double output[220500] +// const coder::array &r +// const coder::array &sampleRange +// const coder::array &window +// const coder::array &r1 +// Return Type : void +// +static void binary_expand_op(double output[220500], + const coder::array &r, + const coder::array &sampleRange, + const coder::array &window, + const coder::array &r1) +{ + coder::array b_output; + int i; + int loop_ub; + int stride_0_1; + int stride_1_1; + int stride_2_1; + b_output.set_size(1, r.size(1)); + stride_0_1 = (sampleRange.size(1) != 1); + stride_1_1 = (window.size(0) != 1); + stride_2_1 = (r1.size(0) != 1); + loop_ub = r.size(1); + for (i = 0; i < loop_ub; i++) { + b_output[i] = output[static_cast(sampleRange[i * stride_0_1]) - 1] + + window[i * stride_1_1] * r1[i * stride_2_1]; + } + loop_ub = b_output.size(1); + for (i = 0; i < loop_ub; i++) { + output[r[i] - 1] = b_output[i]; + } +} + +// +// Arguments : coder::array &unchanged +// const coder::array &newEstimates +// const coder::array &inputFramePower +// Return Type : void +// +static void c_binary_expand_op(coder::array &unchanged, + const coder::array &newEstimates, + const coder::array &inputFramePower) +{ + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + if (inputFramePower.size(0) == 1) { + i = newEstimates.size(0); + } else { + i = inputFramePower.size(0); + } + unchanged.set_size(i); + stride_0_0 = (newEstimates.size(0) != 1); + stride_1_0 = (inputFramePower.size(0) != 1); + if (inputFramePower.size(0) == 1) { + loop_ub = newEstimates.size(0); + } else { + loop_ub = inputFramePower.size(0); + } + for (i = 0; i < loop_ub; i++) { + unchanged[i] = + (newEstimates[i * stride_0_0] < 0.2 * inputFramePower[i * stride_1_0]); + } +} + +// +// Arguments : coder::array &G_S +// const coder::captured_var frequencyCount +// const coder::array &newEstimates +// Return Type : void +// +static void d_binary_expand_op(coder::array &G_S, + const coder::captured_var frequencyCount, + const coder::array &newEstimates) +{ + coder::array r; + int i; + int loop_ub; + int stride_1_0; + int stride_3_0; + if (newEstimates.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = newEstimates.size(0); + } + if (i == 1) { + if (G_S.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = G_S.size(0); + } + } else if (newEstimates.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = newEstimates.size(0); + } + r.set_size(i); + stride_1_0 = (G_S.size(0) != 1); + stride_3_0 = (newEstimates.size(0) != 1); + if (newEstimates.size(0) == 1) { + i = static_cast(frequencyCount.contents); + } else { + i = newEstimates.size(0); + } + if (i == 1) { + if (G_S.size(0) == 1) { + loop_ub = static_cast(frequencyCount.contents); + } else { + loop_ub = G_S.size(0); + } + } else if (newEstimates.size(0) == 1) { + loop_ub = static_cast(frequencyCount.contents); + } else { + loop_ub = newEstimates.size(0); + } + for (i = 0; i < loop_ub; i++) { + r[i] = 0.7 * G_S[i * stride_1_0] + 0.3 * newEstimates[i * stride_3_0]; + } + G_S.set_size(r.size(0)); + loop_ub = r.size(0); + for (i = 0; i < loop_ub; i++) { + G_S[i] = r[i]; + } +} + +// +// Arguments : coder::array &unchanged +// const coder::array &newEstimates +// const coder::array &inputFramePower +// Return Type : void +// +static void gt(coder::array &unchanged, + const coder::array &newEstimates, + const coder::array &inputFramePower) +{ + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + if (inputFramePower.size(0) == 1) { + i = newEstimates.size(0); + } else { + i = inputFramePower.size(0); + } + unchanged.set_size(i); + stride_0_0 = (newEstimates.size(0) != 1); + stride_1_0 = (inputFramePower.size(0) != 1); + if (inputFramePower.size(0) == 1) { + loop_ub = newEstimates.size(0); + } else { + loop_ub = inputFramePower.size(0); + } + for (i = 0; i < loop_ub; i++) { + unchanged[i] = + (newEstimates[i * stride_0_0] > inputFramePower[i * stride_1_0]); + } +} + +// +// Arguments : coder::captured_var *stftWindowSize +// coder::captured_var *frequencyCount +// coder::captured_var *frameCount +// const coder::array &spectrumx +// const coder::array &window +// double overlapSamples +// double output[220500] +// Return Type : void +// +static void reconstruct(coder::captured_var *stftWindowSize, + coder::captured_var *frequencyCount, + coder::captured_var *frameCount, + const coder::array &spectrumx, + const coder::array &window, + double overlapSamples, double output[220500]) +{ + coder::array r; + coder::array spectrum; + coder::array b_spectrum; + coder::array r1; + coder::array b_output; + coder::array sampleRange; + coder::array r2; + coder::array r3; + double xtmp_im; + double xtmp_re; + int b_i; + int i; + int i1; + int loop_ub; + int m; + int md2; + int n; + boolean_T exitg1; + // Helper functions + stftWindowSize->contents = window.size(0); + frameCount->contents = spectrumx.size(1); + frequencyCount->contents = spectrumx.size(0); + i = static_cast(stftWindowSize->contents); + loop_ub = static_cast(frameCount->contents); + spectrum.set_size(i, loop_ub); + md2 = i * loop_ub; + for (i = 0; i < md2; i++) { + spectrum[i].re = 0.0; + spectrum[i].im = 1.0E-5; + } + // spectrum(frequencyCount+1:stftWindowSize, :) = + // conj(flipud(spectrum(1:frequencyCount-2, :))); + xtmp_re = frequencyCount->contents; + if (2.0 > xtmp_re) { + i = 0; + i1 = -1; + } else { + i = 1; + i1 = static_cast(xtmp_re) - 1; + } + md2 = spectrumx.size(1); + for (n = 0; n < md2; n++) { + m = spectrumx.size(0); + for (b_i = 0; b_i < m; b_i++) { + spectrum[b_i + spectrum.size(0) * n] = + spectrumx[b_i + spectrumx.size(0) * n]; + } + } + sampleRange.set_size(1, loop_ub); + for (n = 0; n < loop_ub; n++) { + sampleRange[n] = 0.0; + } + loop_ub = sampleRange.size(1); + for (n = 0; n < loop_ub; n++) { + spectrum[spectrum.size(0) * n].re = 0.0; + spectrum[spectrum.size(0) * n].im = 0.0; + } + i1 -= i; + if (1 > i1) { + loop_ub = -1; + } else { + loop_ub = i1 - 1; + } + xtmp_re = frequencyCount->contents + 1.0; + if (xtmp_re > stftWindowSize->contents) { + i1 = 1; + } else { + i1 = static_cast(xtmp_re); + } + md2 = spectrumx.size(1) - 1; + r.set_size(loop_ub + 1, spectrumx.size(1)); + for (n = 0; n <= md2; n++) { + for (b_i = 0; b_i <= loop_ub; b_i++) { + m = i + b_i; + r[b_i + r.size(0) * n].re = spectrumx[m + spectrumx.size(0) * n].re; + r[b_i + r.size(0) * n].im = -spectrumx[m + spectrumx.size(0) * n].im; + } + } + m = r.size(0) - 1; + n = r.size(1); + md2 = r.size(0) >> 1; + for (loop_ub = 0; loop_ub < n; loop_ub++) { + for (b_i = 0; b_i < md2; b_i++) { + xtmp_re = r[b_i + r.size(0) * loop_ub].re; + xtmp_im = r[b_i + r.size(0) * loop_ub].im; + i = m - b_i; + r[b_i + r.size(0) * loop_ub] = r[i + r.size(0) * loop_ub]; + r[i + r.size(0) * loop_ub].re = xtmp_re; + r[i + r.size(0) * loop_ub].im = xtmp_im; + } + } + loop_ub = r.size(1); + for (i = 0; i < loop_ub; i++) { + md2 = r.size(0); + for (n = 0; n < md2; n++) { + spectrum[((i1 + n) + spectrum.size(0) * i) - 1] = r[n + r.size(0) * i]; + } + } + std::memset(&output[0], 0, 220500U * sizeof(double)); + xtmp_im = stftWindowSize->contents - overlapSamples; + xtmp_re = frameCount->contents; + md2 = 0; + exitg1 = false; + while ((!exitg1) && (md2 <= static_cast(xtmp_re) - 1)) { + double b; + double frameStart; + frameStart = ((static_cast(md2) + 1.0) - 1.0) * xtmp_im; + b = frameStart + stftWindowSize->contents; + if (b > 220500.0) { + exitg1 = true; + } else { + if (std::isnan(frameStart + 1.0) || std::isnan(b)) { + sampleRange.set_size(1, 1); + sampleRange[0] = rtNaN; + } else if (b < frameStart + 1.0) { + sampleRange.set_size(1, 0); + } else if ((std::isinf(frameStart + 1.0) || std::isinf(b)) && + (frameStart + 1.0 == b)) { + sampleRange.set_size(1, 1); + sampleRange[0] = rtNaN; + } else if (std::floor(frameStart + 1.0) == frameStart + 1.0) { + loop_ub = static_cast(std::floor(b - (frameStart + 1.0))); + sampleRange.set_size(1, loop_ub + 1); + for (i = 0; i <= loop_ub; i++) { + sampleRange[i] = (frameStart + 1.0) + static_cast(i); + } + } else { + double apnd; + double cdiff; + double ndbl; + ndbl = std::floor((b - (frameStart + 1.0)) + 0.5); + apnd = (frameStart + 1.0) + ndbl; + cdiff = apnd - b; + if (std::abs(cdiff) < + 4.4408920985006262E-16 * + std::fmax(std::abs(frameStart + 1.0), std::abs(b))) { + ndbl++; + apnd = b; + } else if (cdiff > 0.0) { + apnd = (frameStart + 1.0) + (ndbl - 1.0); + } else { + ndbl++; + } + if (ndbl >= 0.0) { + n = static_cast(ndbl); + } else { + n = 0; + } + sampleRange.set_size(1, n); + if (n > 0) { + sampleRange[0] = frameStart + 1.0; + if (n > 1) { + sampleRange[n - 1] = apnd; + m = (n - 1) / 2; + for (loop_ub = 0; loop_ub <= m - 2; loop_ub++) { + sampleRange[loop_ub + 1] = + (frameStart + 1.0) + (static_cast(loop_ub) + 1.0); + sampleRange[(n - loop_ub) - 2] = + apnd - (static_cast(loop_ub) + 1.0); + } + if (m << 1 == n - 1) { + sampleRange[m] = ((frameStart + 1.0) + apnd) / 2.0; + } else { + sampleRange[m] = (frameStart + 1.0) + static_cast(m); + sampleRange[m + 1] = apnd - static_cast(m); + } + } + } + } + // reconstructedFrame(:) = window .* ifft(spectrum(:, frameIndex), + // 'symmetric'); + // v = spectrum(:, frameIndex); + // v_conj= conj(v([1,end:-1:2])); + loop_ub = spectrum.size(0); + b_spectrum.set_size(spectrum.size(0)); + for (i = 0; i < loop_ub; i++) { + b_spectrum[i] = spectrum[i + spectrum.size(0) * md2]; + } + coder::ifft(b_spectrum, r1); + r2.set_size(r1.size(0)); + loop_ub = r1.size(0); + for (i = 0; i < loop_ub; i++) { + r2[i] = r1[i].re; + } + r3.set_size(1, sampleRange.size(1)); + loop_ub = sampleRange.size(1); + for (i = 0; i < loop_ub; i++) { + r3[i] = static_cast(sampleRange[i]); + } + if (window.size(0) == 1) { + i = r2.size(0); + } else { + i = window.size(0); + } + if ((window.size(0) == r2.size(0)) && (sampleRange.size(1) == i)) { + b_output.set_size(1, r3.size(1)); + loop_ub = r3.size(1); + for (i = 0; i < loop_ub; i++) { + b_output[i] = + output[static_cast(sampleRange[i]) - 1] + window[i] * r2[i]; + } + loop_ub = b_output.size(1); + for (i = 0; i < loop_ub; i++) { + output[r3[i] - 1] = b_output[i]; + } + } else { + binary_expand_op(output, r3, sampleRange, window, r2); + } + md2++; + } + } +} + +// +// Arguments : double u0 +// double u1 +// Return Type : double +// +static double rt_hypotd_snf(double u0, double u1) +{ + double a; + double y; + a = std::abs(u0); + y = std::abs(u1); + if (a < y) { + a /= y; + y *= std::sqrt(a * a + 1.0); + } else if (a > y) { + y /= a; + y = a * std::sqrt(y * y + 1.0); + } else if (!std::isnan(y)) { + y = a * 1.4142135623730951; + } + return y; +} + +// +// % inputFilename = 'audio/EchoSample.mp3'; +// inputFilename = +// '/Volumes/T7_2/starmaker_files/闊虫晥鎻愬彇绠楁硶/effect_files/2/vocal_left_16k.wav'; +// inputFilename = +// '/Volumes/T7_2/starmaker_files/闊虫晥鎻愬彇绠楁硶/effect_files/1/vocla_left.wav'; +// +// % inputFilename = 'audio/stalbans_omni_sing.mp3'; +// % inputFilename = 'audio/mozart_reverb_short.mp3'; +// [signal, fs] = audioread(inputFilename); +// signal= signal(1:fs*30); +// % Take only the left channel from the stereo recording +// signal = signal(:, 1); +// +// Arguments : const double b_signal[220500] +// const double signal_vc[220500] +// double fs +// const double impulseResponse[264600] +// double reverberated_vc[220500] +// Return Type : void +// +void dereveb_c(const double b_signal[220500], const double signal_vc[220500], + double fs, const double impulseResponse[264600], + double reverberated_vc[220500]) +{ + coder::captured_var frameCount; + coder::captured_var frequencyCount; + coder::captured_var stftWindowSize; + coder::array M; + coder::array M_vc; + coder::array R_vc; + coder::array S_vc; + coder::array allBlocks; + coder::array x; + coder::array G_R_vc; + coder::array vocal_effect; + coder::array C; + coder::array H_pow; + coder::array H_pow_sm; + coder::array b_previousSFramesPower; + coder::array b_x; + coder::array c_previousSFramesPower; + coder::array previousMFramesPower; + coder::array previousSFramesPower; + coder::array previousSFramesPower_vc; + coder::array y; + coder::array G_R; + coder::array G_S; + coder::array b_y; + coder::array inputFramePower; + coder::array newEstimates; + coder::array vocal_effect_sm; + coder::array window; + coder::array r; + coder::array r1; + coder::array r2; + coder::array unchanged; + double overlapSamples; + double scale_cl; + int en; + int i; + int i1; + int i2; + int loop_ub; + int nx; + if (!isInitialized_dereveb_c) { + dereveb_c_initialize(); + } + // Dereverberation + // inputFilename_vc = + // '/Volumes/T7_2/starmaker_files/闊虫晥鎻愬彇绠楁硶/effect_files/2/611752105030248995_8162774327817435_dv_44100_16k.wav'; + // inputFilename_vc = + // '/Volumes/T7_2/starmaker_files/闊虫晥鎻愬彇绠楁硶/effect_files/1/611752105030249000_8162774329368194_dv_44100.wav'; + // [signal_vc, fs] = audioread(inputFilename_vc); + // signal_vc= signal_vc(1:fs*30); + // % Take only the left channel from the stereo recording + // signal_vc = signal_vc(:, 1); + // Compute the signal's STFT + stftWindowSize.contents = 1024.0 * std::floor(fs / 16000.0); + // In the paper he used 0.5 (50% overlap). + overlapSamples = std::floor(0.75 * stftWindowSize.contents); + // TODO: zero padding? + coder::hann(stftWindowSize.contents, window); + // Specify empty Fs so that t is returned in samples and w in rad/sample. + // figure; + // [M,~,~] = spectrogram(signal, window, overlapSamples, [], []); + coder::spectrogram(b_signal, window, overlapSamples, M); + // M ('microphone') - input signal (reverberated) frequency-domain vectors. + // Rows - frequencies, Columns - time frames (middle time- + // point) + frequencyCount.contents = M.size(0); + // [M_vc,~,~] = spectrogram(signal_vc, window, overlapSamples, [], []); + coder::spectrogram(signal_vc, window, overlapSamples, M_vc); + // M ('microphone') - input signal (reverberated) frequency-domain vectors. + // Rows - frequencies, Columns - time frames (middle time-point) + frameCount.contents = std::fmin(static_cast(M.size(1)), + static_cast(M_vc.size(1))); + // Constants + // Impulse response block length - has to be 'sufficiently small' + // TODO: experiment with value. Is this really the same as the window size? + // Number of impulse response blocks. TODO: experiment. + // Minimum gain per frequency. TODO: Experiment. + // Maximum magnitude estimate per impulse response block and frequency. + // Should 'reflect real world systems'. (Page 11 - MaxValue.) + // maxHEstimate(:) = readImpulseResponse('audio/stalbans_a_mono.wav', B, + // window, overlapSamples); + // impulseResponse = audioread(irFilename); + // assert(irFs == fs); + // function image = spectrogramPlot(spectrum, t, w) + // figure; + // image = imagesc(t, w, 10*log10(abs(spectrum)+eps)); + // image.Parent.YDir = 'normal'; + // colorbar(); + // end + coder::b_spectrogram(impulseResponse, window, overlapSamples, allBlocks); + // pow = @(x) abs(x).^2; + loop_ub = allBlocks.size(0); + x.set_size(allBlocks.size(0), 400); + for (i = 0; i < 400; i++) { + for (i1 = 0; i1 < loop_ub; i1++) { + x[i1 + x.size(0) * i] = allBlocks[i1 + allBlocks.size(0) * i]; + } + } + nx = allBlocks.size(0) * 400; + y.set_size(allBlocks.size(0), 400); + for (en = 0; en < nx; en++) { + y[en] = rt_hypotd_snf(x[en].re, x[en].im); + } + loop_ub = y.size(0) * 400; + y.set_size(y.size(0), 400); + for (i = 0; i < loop_ub; i++) { + scale_cl = y[i]; + y[i] = scale_cl * scale_cl; + } + // maxHEstimate(:) = 0.9; + // Bias used to keep the magnitude estimate from getting stuck on a wrong + // minimum. + // TODO: Experiment + // From the paper - gamma (Page 10). Lower means more smoothing between + // gains vectors of consecutive frames. Value 0-1 (1 = no smoothing). + // From the paper - alpha (Page 11). Lower means less smoothing between + // magnitude response block estimates on consecutive frames. + // Value 0-1 (0 = no smoothing). + // Algorithm implementation: block-wise signal dereverberation. + allBlocks.set_size(M.size(0), M.size(1)); + loop_ub = M.size(0) * M.size(1); + for (i = 0; i < loop_ub; i++) { + allBlocks[i].re = 0.0; + allBlocks[i].im = 1.0E-5; + } + // Dry signal frequency-domain vectors. + // Reverberated components frequency-domain vectors. + S_vc.set_size(M.size(0), M.size(1)); + loop_ub = M.size(0) * M.size(1); + for (i = 0; i < loop_ub; i++) { + S_vc[i].re = 0.0; + S_vc[i].im = 1.0E-5; + } + R_vc.set_size(M.size(0), M.size(1)); + loop_ub = M.size(0) * M.size(1); + for (i = 0; i < loop_ub; i++) { + R_vc[i].re = 0.0; + R_vc[i].im = 1.0E-5; + } + // Reverberant system frequency response estimate blocks - power. + // H_pow = zeros(frequencyCount, B); + // Set initial estimates to half of the maximum. + H_pow.set_size(y.size(0), 400); + loop_ub = y.size(0) * 400; + for (i = 0; i < loop_ub; i++) { + H_pow[i] = y[i] / 2.0; + } + // pow = @(x) abs(x).^2; + previousSFramesPower.set_size(M.size(0), 400); + loop_ub = M.size(0) * 400; + for (i = 0; i < loop_ub; i++) { + previousSFramesPower[i] = 0.0; + } + // Most recent previous frame is first. + previousMFramesPower.set_size(M.size(0), 400); + loop_ub = M.size(0) * 400; + for (i = 0; i < loop_ub; i++) { + previousMFramesPower[i] = 1.0; + } + // Most recent previous frame is first. + // Reverberant system frequency response power estimate blocks - temporary. + C.set_size(H_pow.size(0), 400); + loop_ub = H_pow.size(0) * 400; + for (i = 0; i < loop_ub; i++) { + C[i] = 0.0; + } + // Matrix to keep all estimates over time (not needed by algorithm - just + // for visualization purposes). + // H_pow_all = zeros([HisCount size(H_pow)]); + // Initially, all components are estimated to belong to the dry signal. + G_S.set_size(M.size(0)); + loop_ub = M.size(0); + for (i = 0; i < loop_ub; i++) { + G_S[i] = 1.0; + } + G_R.set_size(M.size(0)); + loop_ub = M.size(0); + for (i = 0; i < loop_ub; i++) { + G_R[i] = 0.0; + } + previousSFramesPower_vc.set_size(M.size(0), 400); + loop_ub = M.size(0) * 400; + for (i = 0; i < loop_ub; i++) { + previousSFramesPower_vc[i] = 0.0; + } + // Most recent previous frame is first. + // Most recent previous frame is first. + G_R_vc.set_size(M.size(0)); + loop_ub = M.size(0); + for (i = 0; i < loop_ub; i++) { + G_R_vc[i].re = 0.0; + G_R_vc[i].im = 1.0E-5; + } + H_pow_sm.set_size(H_pow.size(0), 400); + loop_ub = H_pow.size(0) * 400; + for (i = 0; i < loop_ub; i++) { + H_pow_sm[i] = H_pow[i]; + } + i = static_cast(frameCount.contents); + if (0.0 <= i - 1) { + i2 = y.size(0); + } + for (int inputFrameIndex{0}; inputFrameIndex < i; inputFrameIndex++) { + double ai; + double varargin_2; + int b_i; + int blockIndex; + int i3; + // X = sprintf('frameidx: %d / %d \r',inputFrameIndex,frameCount); + // disp(X) + loop_ub = M.size(0); + vocal_effect_sm.set_size(M.size(0)); + for (en = 0; en < loop_ub; en++) { + vocal_effect_sm[en] = + rt_hypotd_snf(M[en + M.size(0) * inputFrameIndex].re, + M[en + M.size(0) * inputFrameIndex].im); + } + inputFramePower.set_size(vocal_effect_sm.size(0)); + loop_ub = vocal_effect_sm.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + scale_cl = vocal_effect_sm[i1]; + inputFramePower[i1] = scale_cl * scale_cl; + } + // Update system frequency response estimates. + loop_ub = inputFramePower.size(0); + for (blockIndex = 0; blockIndex < 400; blockIndex++) { + if (inputFramePower.size(0) == previousMFramesPower.size(0)) { + newEstimates.set_size(inputFramePower.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + newEstimates[i1] = + inputFramePower[i1] / + previousMFramesPower[i1 + + previousMFramesPower.size(0) * blockIndex]; + } + } else { + binary_expand_op(newEstimates, inputFramePower, previousMFramesPower, + blockIndex); + } + if (newEstimates.size(0) == H_pow.size(0)) { + unchanged.set_size(newEstimates.size(0)); + nx = newEstimates.size(0); + for (i1 = 0; i1 < nx; i1++) { + unchanged[i1] = + (newEstimates[i1] >= H_pow[i1 + H_pow.size(0) * blockIndex]); + } + } else { + b_binary_expand_op(unchanged, newEstimates, H_pow, blockIndex); + } + en = unchanged.size(0) - 1; + nx = 0; + for (b_i = 0; b_i <= en; b_i++) { + if (unchanged[b_i]) { + nx++; + } + } + r.set_size(nx); + nx = 0; + for (b_i = 0; b_i <= en; b_i++) { + if (unchanged[b_i]) { + r[nx] = b_i + 1; + nx++; + } + } + nx = r.size(0); + b_y.set_size(r.size(0)); + for (i1 = 0; i1 < nx; i1++) { + b_y[i1] = H_pow[(r[i1] + H_pow.size(0) * blockIndex) - 1] * 1.01; + } + en = unchanged.size(0); + nx = 0; + for (b_i = 0; b_i < en; b_i++) { + if (unchanged[b_i]) { + newEstimates[b_i] = b_y[nx] + 2.2204460492503131E-16; + nx++; + } + } + if (newEstimates.size(0) == i2) { + nx = newEstimates.size(0); + for (i1 = 0; i1 < nx; i1++) { + scale_cl = newEstimates[i1]; + varargin_2 = y[i1 + y.size(0) * blockIndex]; + C[i1 + C.size(0) * blockIndex] = std::fmin(scale_cl, varargin_2); + } + } else { + nx = y.size(0); + b_y.set_size(y.size(0)); + for (i1 = 0; i1 < nx; i1++) { + b_y[i1] = y[i1 + y.size(0) * blockIndex]; + } + coder::internal::expand_min(newEstimates, b_y, vocal_effect_sm); + nx = vocal_effect_sm.size(0); + for (i1 = 0; i1 < nx; i1++) { + C[i1 + C.size(0) * blockIndex] = vocal_effect_sm[i1]; + } + } + nx = M.size(0); + if (M.size(0) == 1) { + i1 = H_pow.size(0); + } else { + i1 = M.size(0); + } + if (M.size(0) == 1) { + i3 = C.size(0); + } else { + i3 = M.size(0); + } + if ((M.size(0) == H_pow.size(0)) && (M.size(0) == C.size(0)) && + (i1 == i3)) { + vocal_effect_sm.set_size(M.size(0)); + for (i1 = 0; i1 < nx; i1++) { + vocal_effect_sm[i1] = 0.2 * H_pow[i1 + H_pow.size(0) * blockIndex] + + 0.8 * C[i1 + C.size(0) * blockIndex]; + } + nx = vocal_effect_sm.size(0); + for (i1 = 0; i1 < nx; i1++) { + H_pow[i1 + H_pow.size(0) * blockIndex] = vocal_effect_sm[i1]; + } + } else { + binary_expand_op(H_pow, blockIndex, M, C); + } + } + // % H_pow_all(inputFrameIndex, :, :) = H_pow; + // H_pow_all(2:end,:,:) = H_pow_all( 1:end-1,:,:); + // H_pow_all(1,:, :) = H_pow; %%鏀惧湪鏈寮濮嬩綅缃 + // TODO: ?? G_S = sqrt(G_S); + // Enforce a minimum gain for each frequency. + if (previousSFramesPower.size(0) == H_pow.size(0)) { + b_previousSFramesPower.set_size(previousSFramesPower.size(0), 400); + loop_ub = previousSFramesPower.size(0) * 400; + for (i1 = 0; i1 < loop_ub; i1++) { + b_previousSFramesPower[i1] = previousSFramesPower[i1] * H_pow[i1]; + } + coder::sum(b_previousSFramesPower, b_y); + } else { + binary_expand_op(b_y, previousSFramesPower, H_pow); + } + if (b_y.size(0) == inputFramePower.size(0)) { + b_x.set_size(b_y.size(0), 2); + loop_ub = b_y.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_x[i1] = 1.0 - b_y[i1] / inputFramePower[i1]; + } + loop_ub = M.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_x[i1 + b_x.size(0)] = 0.0; + } + } else { + binary_expand_op(b_x, b_y, inputFramePower, M); + } + nx = b_x.size(0) - 1; + newEstimates.set_size(b_x.size(0)); + if (b_x.size(0) >= 1) { + for (b_i = 0; b_i <= nx; b_i++) { + newEstimates[b_i] = b_x[b_i]; + } + for (b_i = 0; b_i <= nx; b_i++) { + boolean_T p; + scale_cl = b_x[b_i + b_x.size(0)]; + if (std::isnan(scale_cl)) { + p = false; + } else if (std::isnan(newEstimates[b_i])) { + p = true; + } else { + p = (newEstimates[b_i] < scale_cl); + } + if (p) { + newEstimates[b_i] = scale_cl; + } + } + } + loop_ub = G_S.size(0); + i1 = static_cast(frequencyCount.contents); + if (frequencyCount.contents == 1.0) { + en = G_S.size(0); + } else { + en = static_cast(frequencyCount.contents); + } + if (frequencyCount.contents == 1.0) { + b_i = newEstimates.size(0); + } else { + b_i = static_cast(frequencyCount.contents); + } + if ((i1 == G_S.size(0)) && (i1 == newEstimates.size(0)) && (en == b_i)) { + for (blockIndex = 0; blockIndex < loop_ub; blockIndex++) { + G_S[blockIndex] = + 0.7 * G_S[blockIndex] + 0.3 * newEstimates[blockIndex]; + } + } else { + d_binary_expand_op(G_S, frequencyCount, newEstimates); + } + loop_ub = G_R.size(0); + if (frequencyCount.contents == 1.0) { + en = G_R.size(0); + } else { + en = static_cast(frequencyCount.contents); + } + if (frequencyCount.contents == 1.0) { + b_i = G_S.size(0); + } else { + b_i = static_cast(frequencyCount.contents); + } + if ((i1 == G_R.size(0)) && (i1 == G_S.size(0)) && (en == b_i)) { + for (i1 = 0; i1 < loop_ub; i1++) { + G_R[i1] = 0.7 * G_R[i1] + 0.3 * (1.0 - G_S[i1]); + } + } else { + binary_expand_op(G_R, frequencyCount, G_S); + } + loop_ub = G_S.size(0); + if (G_S.size(0) == M.size(0)) { + for (i1 = 0; i1 < loop_ub; i1++) { + allBlocks[i1 + allBlocks.size(0) * inputFrameIndex].re = + G_S[i1] * M[i1 + M.size(0) * inputFrameIndex].re; + allBlocks[i1 + allBlocks.size(0) * inputFrameIndex].im = + G_S[i1] * M[i1 + M.size(0) * inputFrameIndex].im; + } + } else { + binary_expand_op(allBlocks, inputFrameIndex, G_S, M); + } + // G_S .* real(inputFrame) + 1j*G_S .* imag(inputFrame); % %%骞插0 + loop_ub = G_R.size(0); + if (G_R.size(0) == M.size(0)) { + vocal_effect.set_size(G_R.size(0)); + for (i1 = 0; i1 < loop_ub; i1++) { + vocal_effect[i1].re = G_R[i1] * M[i1 + M.size(0) * inputFrameIndex].re; + vocal_effect[i1].im = G_R[i1] * M[i1 + M.size(0) * inputFrameIndex].im; + } + } else { + binary_expand_op(vocal_effect, G_R, M, inputFrameIndex); + } + // G_R .* real(inputFrame) + 1j*G_R .* imag(inputFrame); % %%娣峰搷 + // Shift all previous frames one column to the right, and insert the + // current frame at the beginning. + nx = previousSFramesPower.size(0) - 1; + c_previousSFramesPower.set_size(previousSFramesPower.size(0), 399); + for (i1 = 0; i1 < 399; i1++) { + for (blockIndex = 0; blockIndex <= nx; blockIndex++) { + c_previousSFramesPower[blockIndex + + c_previousSFramesPower.size(0) * i1] = + previousSFramesPower[blockIndex + + previousSFramesPower.size(0) * i1]; + } + } + loop_ub = c_previousSFramesPower.size(0); + for (i1 = 0; i1 < 399; i1++) { + for (blockIndex = 0; blockIndex < loop_ub; blockIndex++) { + previousSFramesPower[blockIndex + + previousSFramesPower.size(0) * (i1 + 1)] = + c_previousSFramesPower[blockIndex + + c_previousSFramesPower.size(0) * i1]; + } + } + loop_ub = allBlocks.size(0); + vocal_effect_sm.set_size(allBlocks.size(0)); + for (en = 0; en < loop_ub; en++) { + vocal_effect_sm[en] = + rt_hypotd_snf(allBlocks[en + allBlocks.size(0) * inputFrameIndex].re, + allBlocks[en + allBlocks.size(0) * inputFrameIndex].im); + } + loop_ub = vocal_effect_sm.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + scale_cl = vocal_effect_sm[i1]; + previousSFramesPower[i1] = scale_cl * scale_cl; + } + nx = previousMFramesPower.size(0) - 1; + c_previousSFramesPower.set_size(previousMFramesPower.size(0), 399); + for (i1 = 0; i1 < 399; i1++) { + for (blockIndex = 0; blockIndex <= nx; blockIndex++) { + c_previousSFramesPower[blockIndex + + c_previousSFramesPower.size(0) * i1] = + previousMFramesPower[blockIndex + + previousMFramesPower.size(0) * i1]; + } + } + loop_ub = c_previousSFramesPower.size(0); + for (i1 = 0; i1 < 399; i1++) { + for (blockIndex = 0; blockIndex < loop_ub; blockIndex++) { + previousMFramesPower[blockIndex + + previousMFramesPower.size(0) * (i1 + 1)] = + c_previousSFramesPower[blockIndex + + c_previousSFramesPower.size(0) * i1]; + } + } + loop_ub = inputFramePower.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + previousMFramesPower[i1] = inputFramePower[i1]; + } + // %%%%%%%%%%%娣诲姞鏂扮殑閮ㄥ垎%%%%%%%%%%%%%% + // %%%鏂规硶5: + // 鐩存帴浣跨敤vc鏂囦欢锛屼笉璁$畻澧炵泭,鐩存帴鐩稿姞,rir鍋氬钩婊,澧炲姞涓嬮檺(rir骞虫粦娌¢棶棰) + // CNT = 50;%10;% + // % st = max(1,inputFrameIndex-CNT); + // % en = inputFrameIndex; + // % H_pow = squeeze(mean(H_pow_all(st:en, :, :),1)); + // % newG_R_vc = (sum(previousSFramesPower_vc .* H_pow, 2)) ; + // H_pow_sm = (1- 1/CNT)*H_pow_sm + (1/CNT)*H_pow; + // newG_R_vc = (sum(previousSFramesPower_vc .* H_pow_sm, 2)) ; + // G_R_vc = (1-gainSmoothingFactor_vc).*G_R_vc + + // gainSmoothingFactor_vc.*newG_R_vc; + // + // % vocal_effect = G_R .* inputFrame; + // % % bk_revertant = min(G_R_vc,vocal_effect); + // % % bk_revertant = max(bk_revertant,0.2*vocal_effect); + // % G_R_vc_abs = abs(G_R_vc); + // % vocal_effect_abs = abs(vocal_effect); + // % idx_change = G_R_vc_abs > vocal_effect_abs; + // % G_R_vc(idx_change,:)= vocal_effect(idx_change,:); + // % idx_change = G_R_vc_abs < 0.2*vocal_effect_abs; + // % G_R_vc(idx_change,:)= vocal_effect(idx_change,:); + // bk_revertant = G_R_vc; + // + // + // % S_vc(:, inputFrameIndex) = inputFrame_vc; %%vc 骞插0 + // % R_vc(:, inputFrameIndex) = bk_revertant; %%娣峰搷 + // 鏂规硶6:rir鍋氬钩婊,鑳屾櫙娣峰搷(骞虫粦)鍜屽綋鍓嶆贩鍝嶇洿鎺ョ浉鍔 + // %%%%%褰撳墠娣峰搷 + // 10;% + // st = 1; + // en = CNT; + // H_pow_sm_tmp = mean(H_pow_all(st:en, :, :),1); + // H_pow_sm(:,:) = H_pow_sm_tmp(1,:,:); + if (H_pow_sm.size(0) == H_pow.size(0)) { + loop_ub = H_pow_sm.size(0) * 400; + H_pow_sm.set_size(H_pow_sm.size(0), 400); + for (i1 = 0; i1 < loop_ub; i1++) { + H_pow_sm[i1] = 0.98 * H_pow_sm[i1] + 0.02 * H_pow[i1]; + } + } else { + binary_expand_op(H_pow_sm, H_pow); + } + // %%%%%寰楀埌backgroud娣峰搷 + nx = vocal_effect.size(0); + inputFramePower.set_size(vocal_effect.size(0)); + for (en = 0; en < nx; en++) { + inputFramePower[en] = + rt_hypotd_snf(vocal_effect[en].re, vocal_effect[en].im); + } + vocal_effect_sm.set_size(inputFramePower.size(0)); + loop_ub = inputFramePower.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + vocal_effect_sm[i1] = inputFramePower[i1]; + } + i1 = inputFramePower.size(0); + for (b_i = 0; b_i < i1; b_i++) { + nx = static_cast( + std::fmax((static_cast(b_i) + 1.0) - 10.0, 1.0)); + en = static_cast( + std::fmin((static_cast(b_i) + 1.0) + 10.0, + static_cast(inputFramePower.size(0)))); + if (nx > en) { + blockIndex = -1; + nx = -1; + } else { + blockIndex = nx - 2; + nx = en - 1; + } + loop_ub = nx - blockIndex; + b_y.set_size(loop_ub); + for (nx = 0; nx < loop_ub; nx++) { + b_y[nx] = inputFramePower[(blockIndex + nx) + 1]; + } + vocal_effect_sm[b_i] = + coder::combineVectorElements(b_y) / static_cast(loop_ub); + } + // 娣峰搷鐩稿姞,骞跺仛闄愬埗 + // %%浣跨敤姣斿煎箙搴︾浉鍔狅紝鐩镐綅涓嶅彉 + // bli_h = bli_h*0.8 + 0.2*sum(vocal_effect_abs)/(sum(abs(G_R_vc)) + + // 1e-6); sum_spec = mixFactor .* vocal_effect_sm + (1 - mixFactor) .* + // abs(G_R_vc)*bli_h; G_R_vc = G_R_vc .* (sum_spec ./ + // (abs(G_R_vc)+1e-10)); + // + // %%澶嶆暟璋辩洿鎺ョ浉鍔狅紝鏁堟灉涓嶉敊 + if (previousSFramesPower_vc.size(0) == H_pow_sm.size(0)) { + b_previousSFramesPower.set_size(previousSFramesPower_vc.size(0), 400); + loop_ub = previousSFramesPower_vc.size(0) * 400; + for (i1 = 0; i1 < loop_ub; i1++) { + b_previousSFramesPower[i1] = previousSFramesPower_vc[i1] * H_pow_sm[i1]; + } + coder::sum(b_previousSFramesPower, b_y); + } else { + binary_expand_op(b_y, previousSFramesPower_vc, H_pow_sm); + } + loop_ub = G_R_vc.size(0); + if (M.size(0) == 1) { + i1 = G_R_vc.size(0); + } else { + i1 = M.size(0); + } + if (M.size(0) == 1) { + i3 = b_y.size(0); + } else { + i3 = M.size(0); + } + if (vocal_effect.size(0) == 1) { + en = inputFramePower.size(0); + } else { + en = vocal_effect.size(0); + } + if (M.size(0) == 1) { + b_i = G_R_vc.size(0); + } else { + b_i = M.size(0); + } + if (b_i == 1) { + if (M.size(0) == 1) { + b_i = b_y.size(0); + } else { + b_i = M.size(0); + } + } else if (M.size(0) == 1) { + b_i = G_R_vc.size(0); + } else { + b_i = M.size(0); + } + if (vocal_effect_sm.size(0) == 1) { + if (vocal_effect.size(0) == 1) { + nx = inputFramePower.size(0); + } else { + nx = vocal_effect.size(0); + } + } else { + nx = vocal_effect_sm.size(0); + } + if ((M.size(0) == G_R_vc.size(0)) && (M.size(0) == b_y.size(0)) && + (i1 == i3) && (vocal_effect.size(0) == inputFramePower.size(0)) && + (vocal_effect_sm.size(0) == en) && (b_i == nx)) { + for (i1 = 0; i1 < loop_ub; i1++) { + double br; + scale_cl = vocal_effect[i1].re; + ai = vocal_effect[i1].im; + br = inputFramePower[i1] + 1.0E-5; + if (ai == 0.0) { + varargin_2 = scale_cl / br; + scale_cl = 0.0; + } else if (scale_cl == 0.0) { + varargin_2 = 0.0; + scale_cl = ai / br; + } else { + varargin_2 = scale_cl / br; + scale_cl = ai / br; + } + G_R_vc[i1].re = (0.7 * G_R_vc[i1].re + 0.3 * b_y[i1]) + + vocal_effect_sm[i1] * varargin_2; + G_R_vc[i1].im = 0.7 * G_R_vc[i1].im + vocal_effect_sm[i1] * scale_cl; + } + } else { + binary_expand_op(G_R_vc, M, b_y, vocal_effect_sm, vocal_effect, + inputFramePower); + } + // bk_revertant = min(G_R_vc,vocal_effect); + // bk_revertant = max(bk_revertant,0.2*vocal_effect); + i1 = G_R_vc.size(0); + newEstimates.set_size(G_R_vc.size(0)); + for (en = 0; en < i1; en++) { + newEstimates[en] = rt_hypotd_snf(G_R_vc[en].re, G_R_vc[en].im); + } + if (newEstimates.size(0) == inputFramePower.size(0)) { + unchanged.set_size(newEstimates.size(0)); + loop_ub = newEstimates.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + unchanged[i1] = (newEstimates[i1] > inputFramePower[i1]); + } + } else { + gt(unchanged, newEstimates, inputFramePower); + } + en = unchanged.size(0) - 1; + nx = 0; + for (b_i = 0; b_i <= en; b_i++) { + if (unchanged[b_i]) { + nx++; + } + } + r1.set_size(nx); + nx = 0; + for (b_i = 0; b_i <= en; b_i++) { + if (unchanged[b_i]) { + r1[nx] = b_i + 1; + nx++; + } + } + loop_ub = r1.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + G_R_vc[r1[i1] - 1] = vocal_effect[r1[i1] - 1]; + } + if (newEstimates.size(0) == inputFramePower.size(0)) { + unchanged.set_size(newEstimates.size(0)); + loop_ub = newEstimates.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + unchanged[i1] = (newEstimates[i1] < 0.2 * inputFramePower[i1]); + } + } else { + c_binary_expand_op(unchanged, newEstimates, inputFramePower); + } + en = unchanged.size(0) - 1; + nx = 0; + for (b_i = 0; b_i <= en; b_i++) { + if (unchanged[b_i]) { + nx++; + } + } + r2.set_size(nx); + nx = 0; + for (b_i = 0; b_i <= en; b_i++) { + if (unchanged[b_i]) { + r2[nx] = b_i + 1; + nx++; + } + } + loop_ub = r2.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + G_R_vc[r2[i1] - 1] = vocal_effect[r2[i1] - 1]; + } + // % %%%% + // % scale_cl = sum(abs(inputFrame_vc)) / (sum(abs(inputFrame_vc)) + + // sum(abs(bk_revertant)) + 1e-10); % scale_cl = min(1,scale_cl); % + // S_vc(:, inputFrameIndex) = scale_cl * inputFrame_vc; %%vc 骞插0 % + // R_vc(:, inputFrameIndex) = (1-scale_cl) * bk_revertant; %%娣峰搷 + // %%% + i1 = G_R_vc.size(0); + vocal_effect_sm.set_size(G_R_vc.size(0)); + for (en = 0; en < i1; en++) { + vocal_effect_sm[en] = rt_hypotd_snf(G_R_vc[en].re, G_R_vc[en].im); + } + loop_ub = M_vc.size(0); + newEstimates.set_size(M_vc.size(0)); + for (en = 0; en < loop_ub; en++) { + newEstimates[en] = + rt_hypotd_snf(M_vc[en + M_vc.size(0) * inputFrameIndex].re, + M_vc[en + M_vc.size(0) * inputFrameIndex].im); + } + scale_cl = std::fmin( + 1.0, coder::combineVectorElements(vocal_effect_sm) / + (coder::combineVectorElements(newEstimates) + 1.0E-10)); + varargin_2 = (1.0 - scale_cl) * 0.0; + loop_ub = M_vc.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + ai = M_vc[i1 + M_vc.size(0) * inputFrameIndex].im; + S_vc[i1 + S_vc.size(0) * inputFrameIndex].re = + (1.0 - scale_cl) * M_vc[i1 + M_vc.size(0) * inputFrameIndex].re + + varargin_2 * ai; + S_vc[i1 + S_vc.size(0) * inputFrameIndex].im = (1.0 - scale_cl) * ai; + } + // vc 骞插0 + loop_ub = G_R_vc.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + R_vc[i1 + R_vc.size(0) * inputFrameIndex] = G_R_vc[i1]; + } + // 娣峰搷 + // Shift all previous frames one column to the right, and insert the + // current frame at the beginning. + nx = previousSFramesPower_vc.size(0) - 1; + c_previousSFramesPower.set_size(previousSFramesPower_vc.size(0), 399); + for (i1 = 0; i1 < 399; i1++) { + for (blockIndex = 0; blockIndex <= nx; blockIndex++) { + c_previousSFramesPower[blockIndex + + c_previousSFramesPower.size(0) * i1] = + previousSFramesPower_vc[blockIndex + + previousSFramesPower_vc.size(0) * i1]; + } + } + loop_ub = c_previousSFramesPower.size(0); + for (i1 = 0; i1 < 399; i1++) { + for (blockIndex = 0; blockIndex < loop_ub; blockIndex++) { + previousSFramesPower_vc[blockIndex + + previousSFramesPower_vc.size(0) * (i1 + 1)] = + c_previousSFramesPower[blockIndex + + c_previousSFramesPower.size(0) * i1]; + } + } + loop_ub = S_vc.size(0); + vocal_effect_sm.set_size(S_vc.size(0)); + for (en = 0; en < loop_ub; en++) { + vocal_effect_sm[en] = + rt_hypotd_snf(S_vc[en + S_vc.size(0) * inputFrameIndex].re, + S_vc[en + S_vc.size(0) * inputFrameIndex].im); + } + loop_ub = vocal_effect_sm.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + scale_cl = vocal_effect_sm[i1]; + previousSFramesPower_vc[i1] = scale_cl * scale_cl; + } + // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + } + // Reconstruct and play dry signal + // dry_vc = zeros(inputLength_vc,1); + // dry_vc(:) = reconstruct(S_vc, window, overlapSamples, inputLength_vc); + // Reconstruct and play reverberant components + reconstruct(&stftWindowSize, &frequencyCount, &frameCount, R_vc, window, + overlapSamples, reverberated_vc); + // Reconstruct and play original reverberant signal using both components + // reverbConstant = 5; + for (i = 0; i < 220500; i++) { + reverberated_vc[i] += signal_vc[i]; + } +} + +// +// File trailer for dereveb_c.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c.h b/dereverbrate/dereveb_c/dereveb_c.h new file mode 100644 index 0000000..e86e4e0 --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c.h @@ -0,0 +1,28 @@ +// +// File: dereveb_c.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DEREVEB_C_H +#define DEREVEB_C_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +extern void dereveb_c(const double b_signal[220500], + const double signal_vc[220500], double fs, + const double impulseResponse[264600], + double reverberated_vc[220500]); + +#endif +// +// File trailer for dereveb_c.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_data.cpp b/dereverbrate/dereveb_c/dereveb_c_data.cpp new file mode 100644 index 0000000..c705869 --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_data.cpp @@ -0,0 +1,21 @@ +// +// File: dereveb_c_data.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "dereveb_c_data.h" +#include "rt_nonfinite.h" + +// Variable Definitions +omp_nest_lock_t dereveb_c_nestLockGlobal; + +boolean_T isInitialized_dereveb_c{false}; + +// +// File trailer for dereveb_c_data.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_data.h b/dereverbrate/dereveb_c/dereveb_c_data.h new file mode 100644 index 0000000..20a41f0 --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_data.h @@ -0,0 +1,26 @@ +// +// File: dereveb_c_data.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DEREVEB_C_DATA_H +#define DEREVEB_C_DATA_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Variable Declarations +extern omp_nest_lock_t dereveb_c_nestLockGlobal; +extern boolean_T isInitialized_dereveb_c; + +#endif +// +// File trailer for dereveb_c_data.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_initialize.cpp b/dereverbrate/dereveb_c/dereveb_c_initialize.cpp new file mode 100644 index 0000000..f579cdc --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_initialize.cpp @@ -0,0 +1,28 @@ +// +// File: dereveb_c_initialize.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "dereveb_c_initialize.h" +#include "dereveb_c_data.h" +#include "rt_nonfinite.h" + +// Function Definitions +// +// Arguments : void +// Return Type : void +// +void dereveb_c_initialize() +{ + omp_init_nest_lock(&dereveb_c_nestLockGlobal); + isInitialized_dereveb_c = true; +} + +// +// File trailer for dereveb_c_initialize.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_initialize.h b/dereverbrate/dereveb_c/dereveb_c_initialize.h new file mode 100644 index 0000000..6311fe9 --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_initialize.h @@ -0,0 +1,25 @@ +// +// File: dereveb_c_initialize.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DEREVEB_C_INITIALIZE_H +#define DEREVEB_C_INITIALIZE_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +extern void dereveb_c_initialize(); + +#endif +// +// File trailer for dereveb_c_initialize.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_rtw.mk b/dereverbrate/dereveb_c/dereveb_c_rtw.mk new file mode 100644 index 0000000..0b4597b --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_rtw.mk @@ -0,0 +1,475 @@ +########################################################################### +## Makefile generated for component 'dereveb_c'. +## +## Makefile : dereveb_c_rtw.mk +## Generated on : Wed Mar 22 17:38:06 2023 +## Final product: ./dereveb_c.a +## Product type : static-library +## +########################################################################### + +########################################################################### +## MACROS +########################################################################### + +# Macro Descriptions: +# PRODUCT_NAME Name of the system to build +# MAKEFILE Name of this makefile +# MODELLIB Static library target + +PRODUCT_NAME = dereveb_c +MAKEFILE = dereveb_c_rtw.mk +MATLAB_ROOT = /Applications/MATLAB_R2021b.app +MATLAB_BIN = /Applications/MATLAB_R2021b.app/bin +MATLAB_ARCH_BIN = $(MATLAB_BIN)/maci64 +START_DIR = /Volumes/T7_2/starmaker_files/闊虫晥鎻愬彇绠楁硶/dereverberate +TGT_FCN_LIB = ISO_C++11 +SOLVER_OBJ = +CLASSIC_INTERFACE = 0 +MODEL_HAS_DYNAMICALLY_LOADED_SFCNS = +RELATIVE_PATH_TO_ANCHOR = ../../.. +C_STANDARD_OPTS = -fno-common -fexceptions +CPP_STANDARD_OPTS = -std=c++14 -fno-common -fexceptions +MODELLIB = dereveb_c.a + +########################################################################### +## TOOLCHAIN SPECIFICATIONS +########################################################################### + +# Toolchain Name: Clang v3.1 | gmake (64-bit Mac) +# Supported Version(s): 3.1 +# ToolchainInfo Version: 2021b +# Specification Revision: 1.0 +# +#------------------------------------------- +# Macros assumed to be defined elsewhere +#------------------------------------------- + +# C_STANDARD_OPTS +# CPP_STANDARD_OPTS + +#----------- +# MACROS +#----------- + +ARCHS = x86_64 +XCODE_SDK_VER = $(shell perl $(MATLAB_ROOT)/rtw/c/tools/macsdkver.pl) +XCODE_SDK = MacOSX$(XCODE_SDK_VER).sdk +XCODE_DEVEL_DIR = $(shell xcode-select -print-path) +XCODE_SDK_ROOT = $(XCODE_DEVEL_DIR)/Platforms/MacOSX.platform/Developer/SDKs/$(XCODE_SDK) + +TOOLCHAIN_SRCS = +TOOLCHAIN_INCS = +TOOLCHAIN_LIBS = + +#------------------------ +# BUILD TOOL COMMANDS +#------------------------ + +# C Compiler: Clang C Compiler +CC = xcrun clang + +# Linker: Clang Linker +LD = xcrun clang++ + +# C++ Compiler: Clang C++ Compiler +CPP = xcrun clang++ + +# C++ Linker: Clang C++ Linker +CPP_LD = xcrun clang++ + +# Archiver: Clang Archiver +AR = xcrun ar + +# MEX Tool: MEX Tool +MEX_PATH = $(MATLAB_ARCH_BIN) +MEX = "$(MEX_PATH)/mex" + +# Download: Download +DOWNLOAD = + +# Execute: Execute +EXECUTE = $(PRODUCT) + +# Builder: GMAKE Utility +MAKE_PATH = %MATLAB%/bin/maci64 +MAKE = "$(MAKE_PATH)/gmake" + + +#------------------------- +# Directives/Utilities +#------------------------- + +CDEBUG = -g +C_OUTPUT_FLAG = -o +LDDEBUG = -g +OUTPUT_FLAG = -o +CPPDEBUG = -g +CPP_OUTPUT_FLAG = -o +CPPLDDEBUG = -g +OUTPUT_FLAG = -o +ARDEBUG = +STATICLIB_OUTPUT_FLAG = +MEX_DEBUG = -g +RM = @rm -f +ECHO = @echo +MV = @mv +RUN = + +#-------------------------------------- +# "Faster Runs" Build Configuration +#-------------------------------------- + +ARFLAGS = ruvs +CFLAGS = -c -isysroot $(XCODE_SDK_ROOT) -arch $(ARCHS) $(C_STANDARD_OPTS) -mmacosx-version-min=10.15 \ + -O3 +CPPFLAGS = -c -isysroot $(XCODE_SDK_ROOT) -arch $(ARCHS) $(CPP_STANDARD_OPTS) -mmacosx-version-min=10.15 \ + -O3 +CPP_LDFLAGS = -arch $(ARCHS) -isysroot $(XCODE_SDK_ROOT) -Wl,-rpath,@executable_path -Wl,-rpath,@executable_path/$(RELATIVE_PATH_TO_ANCHOR) +CPP_SHAREDLIB_LDFLAGS = -dynamiclib -install_name @rpath/$(notdir $(PRODUCT)) -isysroot $(XCODE_SDK_ROOT) \ + -Wl,$(LD_NAMESPACE) $(LD_UNDEFS) +DOWNLOAD_FLAGS = +EXECUTE_FLAGS = +LDFLAGS = -arch $(ARCHS) -isysroot $(XCODE_SDK_ROOT) -Wl,-rpath,@executable_path -Wl,-rpath,@executable_path/$(RELATIVE_PATH_TO_ANCHOR) +MEX_CPPFLAGS = +MEX_CPPLDFLAGS = +MEX_CFLAGS = +MEX_LDFLAGS = +MAKE_FLAGS = -f $(MAKEFILE) +SHAREDLIB_LDFLAGS = -dynamiclib -install_name @rpath/$(notdir $(PRODUCT)) -isysroot $(XCODE_SDK_ROOT) \ + -Wl,$(LD_NAMESPACE) $(LD_UNDEFS) + + + +########################################################################### +## OUTPUT INFO +########################################################################### + +PRODUCT = ./dereveb_c.a +PRODUCT_TYPE = "static-library" +BUILD_TYPE = "Static Library" + +########################################################################### +## INCLUDE PATHS +########################################################################### + +INCLUDES_BUILDINFO = -I$(START_DIR)/codegen/lib/dereveb_c -I$(START_DIR) -I$(MATLAB_ROOT)/extern/include + +INCLUDES = $(INCLUDES_BUILDINFO) + +########################################################################### +## DEFINES +########################################################################### + +DEFINES_CUSTOM = +DEFINES_STANDARD = -DMODEL=dereveb_c + +DEFINES = $(DEFINES_CUSTOM) $(DEFINES_STANDARD) + +########################################################################### +## SOURCE FILES +########################################################################### + +SRCS = $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_data.cpp $(START_DIR)/codegen/lib/dereveb_c/rt_nonfinite.cpp $(START_DIR)/codegen/lib/dereveb_c/rtGetNaN.cpp $(START_DIR)/codegen/lib/dereveb_c/rtGetInf.cpp $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_initialize.cpp $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_terminate.cpp $(START_DIR)/codegen/lib/dereveb_c/dereveb_c.cpp $(START_DIR)/codegen/lib/dereveb_c/hann.cpp $(START_DIR)/codegen/lib/dereveb_c/iseven.cpp $(START_DIR)/codegen/lib/dereveb_c/gencoswin.cpp $(START_DIR)/codegen/lib/dereveb_c/spectrogram.cpp $(START_DIR)/codegen/lib/dereveb_c/hamming.cpp $(START_DIR)/codegen/lib/dereveb_c/ixfun.cpp $(START_DIR)/codegen/lib/dereveb_c/sum.cpp $(START_DIR)/codegen/lib/dereveb_c/combineVectorElements.cpp $(START_DIR)/codegen/lib/dereveb_c/ifft.cpp $(START_DIR)/codegen/lib/dereveb_c/computeDFT.cpp $(START_DIR)/codegen/lib/dereveb_c/welchparse.cpp $(START_DIR)/codegen/lib/dereveb_c/pspectrogram.cpp $(START_DIR)/codegen/lib/dereveb_c/div.cpp $(START_DIR)/codegen/lib/dereveb_c/cat.cpp $(START_DIR)/codegen/lib/dereveb_c/FFTImplementationCallback.cpp $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_rtwutil.cpp + +ALL_SRCS = $(SRCS) + +########################################################################### +## OBJECTS +########################################################################### + +OBJS = dereveb_c_data.o rt_nonfinite.o rtGetNaN.o rtGetInf.o dereveb_c_initialize.o dereveb_c_terminate.o dereveb_c.o hann.o iseven.o gencoswin.o spectrogram.o hamming.o ixfun.o sum.o combineVectorElements.o ifft.o computeDFT.o welchparse.o pspectrogram.o div.o cat.o FFTImplementationCallback.o dereveb_c_rtwutil.o + +ALL_OBJS = $(OBJS) + +########################################################################### +## PREBUILT OBJECT FILES +########################################################################### + +PREBUILT_OBJS = + +########################################################################### +## LIBRARIES +########################################################################### + +LIBS = + +########################################################################### +## SYSTEM LIBRARIES +########################################################################### + +SYSTEM_LIBS = -L"$(MATLAB_ROOT)/sys/os/maci64" -lm -lstdc++ -liomp5 + +########################################################################### +## ADDITIONAL TOOLCHAIN FLAGS +########################################################################### + +#--------------- +# C Compiler +#--------------- + +CFLAGS_OPTS = -Xpreprocessor -fopenmp -I/Applications/MATLAB_R2021b.app/toolbox/eml/externalDependency/omp/maci64/include -DOpenMP_omp_LIBRARY=/Applications/MATLAB_R2021b.app/sys/os/maci64/libiomp5.dylib +CFLAGS_BASIC = $(DEFINES) $(INCLUDES) + +CFLAGS += $(CFLAGS_OPTS) $(CFLAGS_BASIC) + +#----------------- +# C++ Compiler +#----------------- + +CPPFLAGS_OPTS = -Xpreprocessor -fopenmp -I/Applications/MATLAB_R2021b.app/toolbox/eml/externalDependency/omp/maci64/include -DOpenMP_omp_LIBRARY=/Applications/MATLAB_R2021b.app/sys/os/maci64/libiomp5.dylib +CPPFLAGS_BASIC = $(DEFINES) $(INCLUDES) + +CPPFLAGS += $(CPPFLAGS_OPTS) $(CPPFLAGS_BASIC) + +#--------------- +# C++ Linker +#--------------- + +CPP_LDFLAGS_ = -Wl,-rpath,$(MATLAB_ROOT)/sys/os/$(ARCH)/ + +CPP_LDFLAGS += $(CPP_LDFLAGS_) + +#------------------------------ +# C++ Shared Library Linker +#------------------------------ + +CPP_SHAREDLIB_LDFLAGS_ = -Wl,-rpath,$(MATLAB_ROOT)/sys/os/$(ARCH)/ + +CPP_SHAREDLIB_LDFLAGS += $(CPP_SHAREDLIB_LDFLAGS_) + +#----------- +# Linker +#----------- + +LDFLAGS_ = -Wl,-rpath,$(MATLAB_ROOT)/sys/os/$(ARCH)/ + +LDFLAGS += $(LDFLAGS_) + +#-------------------------- +# Shared Library Linker +#-------------------------- + +SHAREDLIB_LDFLAGS_ = -Wl,-rpath,$(MATLAB_ROOT)/sys/os/$(ARCH)/ + +SHAREDLIB_LDFLAGS += $(SHAREDLIB_LDFLAGS_) + +########################################################################### +## INLINED COMMANDS +########################################################################### + +########################################################################### +## PHONY TARGETS +########################################################################### + +.PHONY : all build clean info prebuild download execute + + +all : build + @echo "### Successfully generated all binary outputs." + + +build : prebuild $(PRODUCT) + + +prebuild : + + +download : $(PRODUCT) + + +execute : download + + +########################################################################### +## FINAL TARGET +########################################################################### + +#--------------------------------- +# Create a static library +#--------------------------------- + +$(PRODUCT) : $(OBJS) $(PREBUILT_OBJS) + @echo "### Creating static library "$(PRODUCT)" ..." + $(AR) $(ARFLAGS) $(PRODUCT) $(OBJS) + @echo "### Created: $(PRODUCT)" + + +########################################################################### +## INTERMEDIATE TARGETS +########################################################################### + +#--------------------- +# SOURCE-TO-OBJECT +#--------------------- + +%.o : %.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : %.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +%.o : $(RELATIVE_PATH_TO_ANCHOR)/%.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : $(RELATIVE_PATH_TO_ANCHOR)/%.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/codegen/lib/dereveb_c/%.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/codegen/lib/dereveb_c/%.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/%.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/%.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +dereveb_c_data.o : $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_data.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +rt_nonfinite.o : $(START_DIR)/codegen/lib/dereveb_c/rt_nonfinite.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +rtGetNaN.o : $(START_DIR)/codegen/lib/dereveb_c/rtGetNaN.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +rtGetInf.o : $(START_DIR)/codegen/lib/dereveb_c/rtGetInf.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +dereveb_c_initialize.o : $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_initialize.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +dereveb_c_terminate.o : $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_terminate.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +dereveb_c.o : $(START_DIR)/codegen/lib/dereveb_c/dereveb_c.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +hann.o : $(START_DIR)/codegen/lib/dereveb_c/hann.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +iseven.o : $(START_DIR)/codegen/lib/dereveb_c/iseven.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +gencoswin.o : $(START_DIR)/codegen/lib/dereveb_c/gencoswin.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +spectrogram.o : $(START_DIR)/codegen/lib/dereveb_c/spectrogram.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +hamming.o : $(START_DIR)/codegen/lib/dereveb_c/hamming.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +ixfun.o : $(START_DIR)/codegen/lib/dereveb_c/ixfun.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +sum.o : $(START_DIR)/codegen/lib/dereveb_c/sum.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +combineVectorElements.o : $(START_DIR)/codegen/lib/dereveb_c/combineVectorElements.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +ifft.o : $(START_DIR)/codegen/lib/dereveb_c/ifft.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +computeDFT.o : $(START_DIR)/codegen/lib/dereveb_c/computeDFT.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +welchparse.o : $(START_DIR)/codegen/lib/dereveb_c/welchparse.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +pspectrogram.o : $(START_DIR)/codegen/lib/dereveb_c/pspectrogram.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +div.o : $(START_DIR)/codegen/lib/dereveb_c/div.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +cat.o : $(START_DIR)/codegen/lib/dereveb_c/cat.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +FFTImplementationCallback.o : $(START_DIR)/codegen/lib/dereveb_c/FFTImplementationCallback.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +dereveb_c_rtwutil.o : $(START_DIR)/codegen/lib/dereveb_c/dereveb_c_rtwutil.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +########################################################################### +## DEPENDENCIES +########################################################################### + +$(ALL_OBJS) : rtw_proj.tmw $(MAKEFILE) + + +########################################################################### +## MISCELLANEOUS TARGETS +########################################################################### + +info : + @echo "### PRODUCT = $(PRODUCT)" + @echo "### PRODUCT_TYPE = $(PRODUCT_TYPE)" + @echo "### BUILD_TYPE = $(BUILD_TYPE)" + @echo "### INCLUDES = $(INCLUDES)" + @echo "### DEFINES = $(DEFINES)" + @echo "### ALL_SRCS = $(ALL_SRCS)" + @echo "### ALL_OBJS = $(ALL_OBJS)" + @echo "### LIBS = $(LIBS)" + @echo "### MODELREF_LIBS = $(MODELREF_LIBS)" + @echo "### SYSTEM_LIBS = $(SYSTEM_LIBS)" + @echo "### TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS)" + @echo "### CFLAGS = $(CFLAGS)" + @echo "### LDFLAGS = $(LDFLAGS)" + @echo "### SHAREDLIB_LDFLAGS = $(SHAREDLIB_LDFLAGS)" + @echo "### CPPFLAGS = $(CPPFLAGS)" + @echo "### CPP_LDFLAGS = $(CPP_LDFLAGS)" + @echo "### CPP_SHAREDLIB_LDFLAGS = $(CPP_SHAREDLIB_LDFLAGS)" + @echo "### ARFLAGS = $(ARFLAGS)" + @echo "### MEX_CFLAGS = $(MEX_CFLAGS)" + @echo "### MEX_CPPFLAGS = $(MEX_CPPFLAGS)" + @echo "### MEX_LDFLAGS = $(MEX_LDFLAGS)" + @echo "### MEX_CPPLDFLAGS = $(MEX_CPPLDFLAGS)" + @echo "### DOWNLOAD_FLAGS = $(DOWNLOAD_FLAGS)" + @echo "### EXECUTE_FLAGS = $(EXECUTE_FLAGS)" + @echo "### MAKE_FLAGS = $(MAKE_FLAGS)" + + +clean : + $(ECHO) "### Deleting all derived files..." + $(RM) $(PRODUCT) + $(RM) $(ALL_OBJS) + $(ECHO) "### Deleted all derived files." + + diff --git a/dereverbrate/dereveb_c/dereveb_c_rtwutil.cpp b/dereverbrate/dereveb_c/dereveb_c_rtwutil.cpp new file mode 100644 index 0000000..90d095b --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_rtwutil.cpp @@ -0,0 +1,89 @@ +// +// File: dereveb_c_rtwutil.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "dereveb_c_rtwutil.h" +#include "rt_nonfinite.h" +#include +#include + +// Function Definitions +// +// Arguments : int numerator +// int denominator +// Return Type : int +// +int div_s32_floor(int numerator, int denominator) +{ + int quotient; + if (denominator == 0) { + if (numerator >= 0) { + quotient = MAX_int32_T; + } else { + quotient = MIN_int32_T; + } + } else { + unsigned int absDenominator; + unsigned int absNumerator; + unsigned int tempAbsQuotient; + boolean_T quotientNeedsNegation; + if (numerator < 0) { + absNumerator = ~static_cast(numerator) + 1U; + } else { + absNumerator = static_cast(numerator); + } + if (denominator < 0) { + absDenominator = ~static_cast(denominator) + 1U; + } else { + absDenominator = static_cast(denominator); + } + quotientNeedsNegation = ((numerator < 0) != (denominator < 0)); + tempAbsQuotient = absNumerator / absDenominator; + if (quotientNeedsNegation) { + absNumerator %= absDenominator; + if (absNumerator > 0U) { + tempAbsQuotient++; + } + quotient = -static_cast(tempAbsQuotient); + } else { + quotient = static_cast(tempAbsQuotient); + } + } + return quotient; +} + +// +// Arguments : double u0 +// double u1 +// Return Type : double +// +double rt_remd_snf(double u0, double u1) +{ + double y; + if (std::isnan(u0) || std::isnan(u1) || std::isinf(u0)) { + y = rtNaN; + } else if (std::isinf(u1)) { + y = u0; + } else if ((u1 != 0.0) && (u1 != std::trunc(u1))) { + double q; + q = std::abs(u0 / u1); + if (!(std::abs(q - std::floor(q + 0.5)) > DBL_EPSILON * q)) { + y = 0.0 * u0; + } else { + y = std::fmod(u0, u1); + } + } else { + y = std::fmod(u0, u1); + } + return y; +} + +// +// File trailer for dereveb_c_rtwutil.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_rtwutil.h b/dereverbrate/dereveb_c/dereveb_c_rtwutil.h new file mode 100644 index 0000000..73cfa2b --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_rtwutil.h @@ -0,0 +1,27 @@ +// +// File: dereveb_c_rtwutil.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DEREVEB_C_RTWUTIL_H +#define DEREVEB_C_RTWUTIL_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +extern int div_s32_floor(int numerator, int denominator); + +extern double rt_remd_snf(double u0, double u1); + +#endif +// +// File trailer for dereveb_c_rtwutil.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_terminate.cpp b/dereverbrate/dereveb_c/dereveb_c_terminate.cpp new file mode 100644 index 0000000..103d774 --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_terminate.cpp @@ -0,0 +1,28 @@ +// +// File: dereveb_c_terminate.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "dereveb_c_terminate.h" +#include "dereveb_c_data.h" +#include "rt_nonfinite.h" + +// Function Definitions +// +// Arguments : void +// Return Type : void +// +void dereveb_c_terminate() +{ + omp_destroy_nest_lock(&dereveb_c_nestLockGlobal); + isInitialized_dereveb_c = false; +} + +// +// File trailer for dereveb_c_terminate.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_terminate.h b/dereverbrate/dereveb_c/dereveb_c_terminate.h new file mode 100644 index 0000000..c5d610b --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_terminate.h @@ -0,0 +1,25 @@ +// +// File: dereveb_c_terminate.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DEREVEB_C_TERMINATE_H +#define DEREVEB_C_TERMINATE_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +extern void dereveb_c_terminate(); + +#endif +// +// File trailer for dereveb_c_terminate.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/dereveb_c_types.h b/dereverbrate/dereveb_c/dereveb_c_types.h new file mode 100644 index 0000000..a6b3b1b --- /dev/null +++ b/dereverbrate/dereveb_c/dereveb_c_types.h @@ -0,0 +1,20 @@ +// +// File: dereveb_c_types.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DEREVEB_C_TYPES_H +#define DEREVEB_C_TYPES_H + +// Include Files +#include "rtwtypes.h" +#define MAX_THREADS omp_get_max_threads() + +#endif +// +// File trailer for dereveb_c_types.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/div.cpp b/dereverbrate/dereveb_c/div.cpp new file mode 100644 index 0000000..e51a8d6 --- /dev/null +++ b/dereverbrate/dereveb_c/div.cpp @@ -0,0 +1,56 @@ +// +// File: div.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "div.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +// +// Arguments : coder::array &newEstimates +// const coder::array &inputFramePower +// const coder::array &previousMFramesPower +// int blockIndex +// Return Type : void +// +void binary_expand_op(coder::array &newEstimates, + const coder::array &inputFramePower, + const coder::array &previousMFramesPower, + int blockIndex) +{ + int i; + int loop_ub; + int stride_0_0; + int stride_1_0; + i = previousMFramesPower.size(0); + if (i == 1) { + stride_0_0 = inputFramePower.size(0); + } else { + stride_0_0 = i; + } + newEstimates.set_size(stride_0_0); + stride_0_0 = (inputFramePower.size(0) != 1); + stride_1_0 = (i != 1); + if (i == 1) { + loop_ub = inputFramePower.size(0); + } else { + loop_ub = i; + } + for (i = 0; i < loop_ub; i++) { + newEstimates[i] = + inputFramePower[i * stride_0_0] / + previousMFramesPower[i * stride_1_0 + + previousMFramesPower.size(0) * blockIndex]; + } +} + +// +// File trailer for div.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/div.h b/dereverbrate/dereveb_c/div.h new file mode 100644 index 0000000..cf91ae0 --- /dev/null +++ b/dereverbrate/dereveb_c/div.h @@ -0,0 +1,29 @@ +// +// File: div.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef DIV_H +#define DIV_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +void binary_expand_op(coder::array &newEstimates, + const coder::array &inputFramePower, + const coder::array &previousMFramesPower, + int blockIndex); + +#endif +// +// File trailer for div.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/examples/main.cpp b/dereverbrate/dereveb_c/examples/main.cpp new file mode 100644 index 0000000..e687210 --- /dev/null +++ b/dereverbrate/dereveb_c/examples/main.cpp @@ -0,0 +1,127 @@ +// +// File: main.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +/*************************************************************************/ +/* This automatically generated example C++ main file shows how to call */ +/* entry-point functions that MATLAB Coder generated. You must customize */ +/* this file for your application. Do not modify this file directly. */ +/* Instead, make a copy of this file, modify it, and integrate it into */ +/* your development environment. */ +/* */ +/* This file initializes entry-point function arguments to a default */ +/* size and value before calling the entry-point functions. It does */ +/* not store or use any values returned from the entry-point functions. */ +/* If necessary, it does pre-allocate memory for returned values. */ +/* You can use this file as a starting point for a main function that */ +/* you can deploy in your application. */ +/* */ +/* After you copy the file, and before you deploy it, you must make the */ +/* following changes: */ +/* * For variable-size function arguments, change the example sizes to */ +/* the sizes that your application requires. */ +/* * Change the example values of function arguments to the values that */ +/* your application requires. */ +/* * If the entry-point functions return values, store these values or */ +/* otherwise use them as required by your application. */ +/* */ +/*************************************************************************/ + +// Include Files +#include "main.h" +#include "dereveb_c.h" +#include "dereveb_c_terminate.h" +#include "rt_nonfinite.h" + +// Function Declarations +static void argInit_220500x1_real_T(double result[220500]); + +static void argInit_264600x1_real_T(double result[264600]); + +static double argInit_real_T(); + +static void main_dereveb_c(); + +// Function Definitions +// +// Arguments : double result[220500] +// Return Type : void +// +static void argInit_220500x1_real_T(double result[220500]) +{ + // Loop over the array to initialize each element. + for (int idx0{0}; idx0 < 220500; idx0++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx0] = argInit_real_T(); + } +} + +// +// Arguments : double result[264600] +// Return Type : void +// +static void argInit_264600x1_real_T(double result[264600]) +{ + // Loop over the array to initialize each element. + for (int idx0{0}; idx0 < 264600; idx0++) { + // Set the value of the array element. + // Change this value to the value that the application requires. + result[idx0] = argInit_real_T(); + } +} + +// +// Arguments : void +// Return Type : double +// +static double argInit_real_T() +{ + return 0.0; +} + +// +// Arguments : void +// Return Type : void +// +static void main_dereveb_c() +{ + static double dv[264600]; + static double reverberated_vc[220500]; + static double signal_tmp[220500]; + // Initialize function 'dereveb_c' input arguments. + // Initialize function input argument 'signal'. + argInit_220500x1_real_T(signal_tmp); + // Initialize function input argument 'signal_vc'. + // Initialize function input argument 'impulseResponse'. + // Call the entry-point 'dereveb_c'. + argInit_264600x1_real_T(dv); + dereveb_c(signal_tmp, signal_tmp, argInit_real_T(), dv, reverberated_vc); +} + +// +// Arguments : int argc +// char **argv +// Return Type : int +// +int main(int, char **) +{ + // The initialize function is being called automatically from your entry-point + // function. So, a call to initialize is not included here. Invoke the + // entry-point functions. + // You can call entry-point functions multiple times. + main_dereveb_c(); + // Terminate the application. + // You do not need to do this more than one time. + dereveb_c_terminate(); + return 0; +} + +// +// File trailer for main.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/examples/main.h b/dereverbrate/dereveb_c/examples/main.h new file mode 100644 index 0000000..e9e0ce1 --- /dev/null +++ b/dereverbrate/dereveb_c/examples/main.h @@ -0,0 +1,50 @@ +// +// File: main.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +/*************************************************************************/ +/* This automatically generated example C++ main file shows how to call */ +/* entry-point functions that MATLAB Coder generated. You must customize */ +/* this file for your application. Do not modify this file directly. */ +/* Instead, make a copy of this file, modify it, and integrate it into */ +/* your development environment. */ +/* */ +/* This file initializes entry-point function arguments to a default */ +/* size and value before calling the entry-point functions. It does */ +/* not store or use any values returned from the entry-point functions. */ +/* If necessary, it does pre-allocate memory for returned values. */ +/* You can use this file as a starting point for a main function that */ +/* you can deploy in your application. */ +/* */ +/* After you copy the file, and before you deploy it, you must make the */ +/* following changes: */ +/* * For variable-size function arguments, change the example sizes to */ +/* the sizes that your application requires. */ +/* * Change the example values of function arguments to the values that */ +/* your application requires. */ +/* * If the entry-point functions return values, store these values or */ +/* otherwise use them as required by your application. */ +/* */ +/*************************************************************************/ + +#ifndef MAIN_H +#define MAIN_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +extern int main(int argc, char **argv); + +#endif +// +// File trailer for main.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/gencoswin.cpp b/dereverbrate/dereveb_c/gencoswin.cpp new file mode 100644 index 0000000..2f28e01 --- /dev/null +++ b/dereverbrate/dereveb_c/gencoswin.cpp @@ -0,0 +1,104 @@ +// +// File: gencoswin.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "gencoswin.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : double m +// double n +// ::coder::array &w +// Return Type : void +// +namespace coder { +void b_calc_window(double m, double n, ::coder::array &w) +{ + array y; + int k; + int nx; + if (std::isnan(m - 1.0)) { + y.set_size(1, 1); + y[0] = rtNaN; + } else if (m - 1.0 < 0.0) { + y.set_size(1, 0); + } else if (std::isinf(m - 1.0) && (0.0 == m - 1.0)) { + y.set_size(1, 1); + y[0] = rtNaN; + } else { + nx = static_cast(std::floor(m - 1.0)); + y.set_size(1, nx + 1); + for (k = 0; k <= nx; k++) { + y[k] = k; + } + } + w.set_size(y.size(1)); + nx = y.size(1); + for (k = 0; k < nx; k++) { + w[k] = 6.2831853071795862 * (y[k] / (n - 1.0)); + } + nx = w.size(0); + for (k = 0; k < nx; k++) { + w[k] = std::cos(w[k]); + } + nx = w.size(0); + for (k = 0; k < nx; k++) { + w[k] = 0.54 - 0.46 * w[k]; + } +} + +// +// Arguments : double m +// double n +// ::coder::array &w +// Return Type : void +// +void calc_window(double m, double n, ::coder::array &w) +{ + array y; + int k; + int nx; + if (std::isnan(m - 1.0)) { + y.set_size(1, 1); + y[0] = rtNaN; + } else if (m - 1.0 < 0.0) { + y.set_size(1, 0); + } else if (std::isinf(m - 1.0) && (0.0 == m - 1.0)) { + y.set_size(1, 1); + y[0] = rtNaN; + } else { + nx = static_cast(std::floor(m - 1.0)); + y.set_size(1, nx + 1); + for (k = 0; k <= nx; k++) { + y[k] = k; + } + } + w.set_size(y.size(1)); + nx = y.size(1); + for (k = 0; k < nx; k++) { + w[k] = 6.2831853071795862 * (y[k] / (n - 1.0)); + } + nx = w.size(0); + for (k = 0; k < nx; k++) { + w[k] = std::cos(w[k]); + } + nx = w.size(0); + for (k = 0; k < nx; k++) { + w[k] = 0.5 - 0.5 * w[k]; + } +} + +} // namespace coder + +// +// File trailer for gencoswin.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/gencoswin.h b/dereverbrate/dereveb_c/gencoswin.h new file mode 100644 index 0000000..596f7e8 --- /dev/null +++ b/dereverbrate/dereveb_c/gencoswin.h @@ -0,0 +1,31 @@ +// +// File: gencoswin.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef GENCOSWIN_H +#define GENCOSWIN_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void b_calc_window(double m, double n, ::coder::array &w); + +void calc_window(double m, double n, ::coder::array &w); + +} // namespace coder + +#endif +// +// File trailer for gencoswin.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/hamming.cpp b/dereverbrate/dereveb_c/hamming.cpp new file mode 100644 index 0000000..3cf7c8a --- /dev/null +++ b/dereverbrate/dereveb_c/hamming.cpp @@ -0,0 +1,116 @@ +// +// File: hamming.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "hamming.h" +#include "dereveb_c_rtwutil.h" +#include "gencoswin.h" +#include "iseven.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : double varargin_1 +// ::coder::array &w +// Return Type : void +// +namespace coder { +void hamming(double varargin_1, ::coder::array &w) +{ + array b_w; + double L; + int i; + int trivialwin; + int w_size; + signed char w_data; + w_size = 1; + w_data = 0; + trivialwin = 0; + if (varargin_1 == std::floor(varargin_1)) { + L = varargin_1; + } else { + L = std::round(varargin_1); + } + if (L == 0.0) { + w_size = 0; + trivialwin = 1; + } else if (L == 1.0) { + w_data = 1; + trivialwin = 1; + } + w.set_size(w_size); + for (i = 0; i < w_size; i++) { + w[0] = w_data; + } + if (trivialwin == 0) { + if (iseven(L)) { + int i1; + int loop_ub; + b_calc_window(L / 2.0, L, w); + if (1 > w.size(0)) { + i = 0; + w_size = 1; + i1 = -1; + } else { + i = w.size(0) - 1; + w_size = -1; + i1 = 0; + } + trivialwin = div_s32_floor(i1 - i, w_size); + b_w.set_size((w.size(0) + trivialwin) + 1); + loop_ub = w.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_w[i1] = w[i1]; + } + for (i1 = 0; i1 <= trivialwin; i1++) { + b_w[i1 + w.size(0)] = w[i + w_size * i1]; + } + w.set_size(b_w.size(0)); + trivialwin = b_w.size(0); + for (i = 0; i < trivialwin; i++) { + w[i] = b_w[i]; + } + } else { + int i1; + int loop_ub; + b_calc_window((L + 1.0) / 2.0, L, w); + if (1 > w.size(0) - 1) { + i = 0; + w_size = 1; + i1 = -1; + } else { + i = w.size(0) - 2; + w_size = -1; + i1 = 0; + } + trivialwin = div_s32_floor(i1 - i, w_size); + b_w.set_size((w.size(0) + trivialwin) + 1); + loop_ub = w.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_w[i1] = w[i1]; + } + for (i1 = 0; i1 <= trivialwin; i1++) { + b_w[i1 + w.size(0)] = w[i + w_size * i1]; + } + w.set_size(b_w.size(0)); + trivialwin = b_w.size(0); + for (i = 0; i < trivialwin; i++) { + w[i] = b_w[i]; + } + } + } +} + +} // namespace coder + +// +// File trailer for hamming.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/hamming.h b/dereverbrate/dereveb_c/hamming.h new file mode 100644 index 0000000..4ebd72d --- /dev/null +++ b/dereverbrate/dereveb_c/hamming.h @@ -0,0 +1,29 @@ +// +// File: hamming.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef HAMMING_H +#define HAMMING_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void hamming(double varargin_1, ::coder::array &w); + +} + +#endif +// +// File trailer for hamming.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/hann.cpp b/dereverbrate/dereveb_c/hann.cpp new file mode 100644 index 0000000..5dfe724 --- /dev/null +++ b/dereverbrate/dereveb_c/hann.cpp @@ -0,0 +1,116 @@ +// +// File: hann.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "hann.h" +#include "dereveb_c_rtwutil.h" +#include "gencoswin.h" +#include "iseven.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : double varargin_1 +// ::coder::array &w +// Return Type : void +// +namespace coder { +void hann(double varargin_1, ::coder::array &w) +{ + array b_w; + double L; + int i; + int trivialwin; + int w_size; + signed char w_data; + w_size = 1; + w_data = 0; + trivialwin = 0; + if (varargin_1 == std::floor(varargin_1)) { + L = varargin_1; + } else { + L = std::round(varargin_1); + } + if (L == 0.0) { + w_size = 0; + trivialwin = 1; + } else if (L == 1.0) { + w_data = 1; + trivialwin = 1; + } + w.set_size(w_size); + for (i = 0; i < w_size; i++) { + w[0] = w_data; + } + if (trivialwin == 0) { + if (iseven(L + 1.0)) { + int i1; + int loop_ub; + calc_window((L + 1.0) / 2.0, L + 1.0, w); + if (2 > w.size(0)) { + i = 0; + w_size = 1; + i1 = -1; + } else { + i = w.size(0) - 1; + w_size = -1; + i1 = 1; + } + trivialwin = div_s32_floor(i1 - i, w_size); + b_w.set_size((w.size(0) + trivialwin) + 1); + loop_ub = w.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_w[i1] = w[i1]; + } + for (i1 = 0; i1 <= trivialwin; i1++) { + b_w[i1 + w.size(0)] = w[i + w_size * i1]; + } + w.set_size(b_w.size(0)); + trivialwin = b_w.size(0); + for (i = 0; i < trivialwin; i++) { + w[i] = b_w[i]; + } + } else { + int i1; + int loop_ub; + calc_window(((L + 1.0) + 1.0) / 2.0, L + 1.0, w); + if (2 > w.size(0) - 1) { + i = 0; + w_size = 1; + i1 = -1; + } else { + i = w.size(0) - 2; + w_size = -1; + i1 = 1; + } + trivialwin = div_s32_floor(i1 - i, w_size); + b_w.set_size((w.size(0) + trivialwin) + 1); + loop_ub = w.size(0); + for (i1 = 0; i1 < loop_ub; i1++) { + b_w[i1] = w[i1]; + } + for (i1 = 0; i1 <= trivialwin; i1++) { + b_w[i1 + w.size(0)] = w[i + w_size * i1]; + } + w.set_size(b_w.size(0)); + trivialwin = b_w.size(0); + for (i = 0; i < trivialwin; i++) { + w[i] = b_w[i]; + } + } + } +} + +} // namespace coder + +// +// File trailer for hann.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/hann.h b/dereverbrate/dereveb_c/hann.h new file mode 100644 index 0000000..ca7fd9d --- /dev/null +++ b/dereverbrate/dereveb_c/hann.h @@ -0,0 +1,29 @@ +// +// File: hann.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef HANN_H +#define HANN_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void hann(double varargin_1, ::coder::array &w); + +} + +#endif +// +// File trailer for hann.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/html/report.mldatx b/dereverbrate/dereveb_c/html/report.mldatx new file mode 100644 index 0000000..9f5c0e3 Binary files /dev/null and b/dereverbrate/dereveb_c/html/report.mldatx differ diff --git a/dereverbrate/dereveb_c/ifft.cpp b/dereverbrate/dereveb_c/ifft.cpp new file mode 100644 index 0000000..872b9c5 --- /dev/null +++ b/dereverbrate/dereveb_c/ifft.cpp @@ -0,0 +1,225 @@ +// +// File: ifft.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "ifft.h" +#include "FFTImplementationCallback.h" +#include "dereveb_c_data.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : const ::coder::array &x +// ::coder::array &y +// Return Type : void +// +namespace coder { +void ifft(const ::coder::array &x, ::coder::array &y) +{ + array b_fv; + array fv; + array wwc; + array costab; + array costab1q; + array sintab; + array sintabinv; + int N2blue; + int nd2; + int nfft; + nfft = x.size(0); + if (x.size(0) == 0) { + y.set_size(0); + } else { + double nt_im; + int i; + int k; + int nInt2; + int rt; + boolean_T useRadix2; + useRadix2 = ((x.size(0) & (x.size(0) - 1)) == 0); + internal::FFTImplementationCallback::get_algo_sizes(x.size(0), useRadix2, + &N2blue, &nd2); + nt_im = 6.2831853071795862 / static_cast(nd2); + nInt2 = nd2 / 2 / 2; + costab1q.set_size(1, nInt2 + 1); + costab1q[0] = 1.0; + nd2 = nInt2 / 2 - 1; + for (k = 0; k <= nd2; k++) { + costab1q[k + 1] = std::cos(nt_im * (static_cast(k) + 1.0)); + } + i = nd2 + 2; + rt = nInt2 - 1; + for (k = i; k <= rt; k++) { + costab1q[k] = std::sin(nt_im * static_cast(nInt2 - k)); + } + costab1q[nInt2] = 0.0; + if (!useRadix2) { + nInt2 = costab1q.size(1) - 1; + nd2 = (costab1q.size(1) - 1) << 1; + costab.set_size(1, nd2 + 1); + sintab.set_size(1, nd2 + 1); + costab[0] = 1.0; + sintab[0] = 0.0; + sintabinv.set_size(1, nd2 + 1); + for (k = 0; k < nInt2; k++) { + sintabinv[k + 1] = costab1q[(nInt2 - k) - 1]; + } + i = costab1q.size(1); + for (k = i; k <= nd2; k++) { + sintabinv[k] = costab1q[k - nInt2]; + } + for (k = 0; k < nInt2; k++) { + costab[k + 1] = costab1q[k + 1]; + sintab[k + 1] = -costab1q[(nInt2 - k) - 1]; + } + i = costab1q.size(1); + for (k = i; k <= nd2; k++) { + costab[k] = -costab1q[nd2 - k]; + sintab[k] = -costab1q[k - nInt2]; + } + } else { + nInt2 = costab1q.size(1) - 1; + nd2 = (costab1q.size(1) - 1) << 1; + costab.set_size(1, nd2 + 1); + sintab.set_size(1, nd2 + 1); + costab[0] = 1.0; + sintab[0] = 0.0; + for (k = 0; k < nInt2; k++) { + costab[k + 1] = costab1q[k + 1]; + sintab[k + 1] = costab1q[(nInt2 - k) - 1]; + } + i = costab1q.size(1); + for (k = i; k <= nd2; k++) { + costab[k] = -costab1q[nd2 - k]; + sintab[k] = costab1q[k - nInt2]; + } + sintabinv.set_size(1, 0); + } + if (useRadix2) { + internal::FFTImplementationCallback::r2br_r2dit_trig_impl( + x, x.size(0), costab, sintab, y); + if (y.size(0) > 1) { + nt_im = 1.0 / static_cast(y.size(0)); + nd2 = y.size(0); + for (i = 0; i < nd2; i++) { + y[i].re = nt_im * y[i].re; + y[i].im = nt_im * y[i].im; + } + } + } else { + double b_re_tmp; + double c_re_tmp; + double nt_re; + double re_tmp; + nd2 = (x.size(0) + x.size(0)) - 1; + wwc.set_size(nd2); + rt = 0; + wwc[x.size(0) - 1].re = 1.0; + wwc[x.size(0) - 1].im = 0.0; + nInt2 = x.size(0) << 1; + i = x.size(0); + for (k = 0; k <= i - 2; k++) { + int b_y; + b_y = ((k + 1) << 1) - 1; + if (nInt2 - rt <= b_y) { + rt += b_y - nInt2; + } else { + rt += b_y; + } + nt_im = 3.1415926535897931 * static_cast(rt) / + static_cast(nfft); + if (nt_im == 0.0) { + nt_re = 1.0; + nt_im = 0.0; + } else { + nt_re = std::cos(nt_im); + nt_im = std::sin(nt_im); + } + wwc[(x.size(0) - k) - 2].re = nt_re; + wwc[(x.size(0) - k) - 2].im = -nt_im; + } + i = nd2 - 1; + for (k = i; k >= nfft; k--) { + wwc[k] = wwc[(nd2 - k) - 1]; + } + y.set_size(x.size(0)); + nd2 = x.size(0); + for (k = 0; k < nd2; k++) { + nt_re = wwc[(nfft + k) - 1].re; + nt_im = wwc[(nfft + k) - 1].im; + re_tmp = x[k].im; + b_re_tmp = x[k].re; + y[k].re = nt_re * b_re_tmp + nt_im * re_tmp; + y[k].im = nt_re * re_tmp - nt_im * b_re_tmp; + } + i = x.size(0) + 1; + for (k = i; k <= nfft; k++) { + y[k - 1].re = 0.0; + y[k - 1].im = 0.0; + } + internal::FFTImplementationCallback::r2br_r2dit_trig_impl( + y, N2blue, costab, sintab, fv); + internal::FFTImplementationCallback::r2br_r2dit_trig_impl( + wwc, N2blue, costab, sintab, b_fv); + b_fv.set_size(fv.size(0)); + nd2 = fv.size(0); + for (i = 0; i < nd2; i++) { + nt_im = fv[i].re; + re_tmp = b_fv[i].im; + b_re_tmp = fv[i].im; + c_re_tmp = b_fv[i].re; + b_fv[i].re = nt_im * c_re_tmp - b_re_tmp * re_tmp; + b_fv[i].im = nt_im * re_tmp + b_re_tmp * c_re_tmp; + } + internal::FFTImplementationCallback::r2br_r2dit_trig_impl( + b_fv, N2blue, costab, sintabinv, fv); + if (fv.size(0) > 1) { + nt_im = 1.0 / static_cast(fv.size(0)); + nd2 = fv.size(0); + for (i = 0; i < nd2; i++) { + fv[i].re = nt_im * fv[i].re; + fv[i].im = nt_im * fv[i].im; + } + } + nt_re = x.size(0); + i = x.size(0); + rt = wwc.size(0); + for (k = i; k <= rt; k++) { + double ar; + nt_im = wwc[k - 1].re; + re_tmp = fv[k - 1].im; + b_re_tmp = wwc[k - 1].im; + c_re_tmp = fv[k - 1].re; + ar = nt_im * c_re_tmp + b_re_tmp * re_tmp; + nt_im = nt_im * re_tmp - b_re_tmp * c_re_tmp; + if (nt_im == 0.0) { + nd2 = k - i; + y[nd2].re = ar / nt_re; + y[nd2].im = 0.0; + } else if (ar == 0.0) { + nd2 = k - i; + y[nd2].re = 0.0; + y[nd2].im = nt_im / nt_re; + } else { + nd2 = k - i; + y[nd2].re = ar / nt_re; + y[nd2].im = nt_im / nt_re; + } + } + } + } +} + +} // namespace coder + +// +// File trailer for ifft.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/ifft.h b/dereverbrate/dereveb_c/ifft.h new file mode 100644 index 0000000..b7a7d2c --- /dev/null +++ b/dereverbrate/dereveb_c/ifft.h @@ -0,0 +1,29 @@ +// +// File: ifft.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef IFFT_H +#define IFFT_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void ifft(const ::coder::array &x, ::coder::array &y); + +} + +#endif +// +// File trailer for ifft.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/interface/_coder_dereveb_c_api.cpp b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_api.cpp new file mode 100644 index 0000000..90f9123 --- /dev/null +++ b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_api.cpp @@ -0,0 +1,324 @@ +// +// File: _coder_dereveb_c_api.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "_coder_dereveb_c_api.h" +#include "_coder_dereveb_c_mex.h" + +// Variable Definitions +emlrtCTX emlrtRootTLSGlobal{nullptr}; + +emlrtContext emlrtContextGlobal{ + true, // bFirstTime + false, // bInitialized + 131611U, // fVersionInfo + nullptr, // fErrorFunction + "dereveb_c", // fFunctionName + nullptr, // fRTCallStack + false, // bDebugMode + {2045744189U, 2170104910U, 2743257031U, 4284093946U}, // fSigWrd + nullptr // fSigMem +}; + +// Function Declarations +static real_T b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *fs, + const char_T *identifier); + +static real_T b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, + const emlrtMsgIdentifier *parentId); + +static real_T (*c_emlrt_marshallIn(const emlrtStack *sp, + const mxArray *impulseResponse, + const char_T *identifier))[264600]; + +static real_T (*c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, + const emlrtMsgIdentifier *parentId))[264600]; + +static real_T (*d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, + const emlrtMsgIdentifier *msgId))[220500]; + +static real_T e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, + const emlrtMsgIdentifier *msgId); + +static real_T (*emlrt_marshallIn(const emlrtStack *sp, const mxArray *b_signal, + const char_T *identifier))[220500]; + +static real_T (*emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, + const emlrtMsgIdentifier *parentId))[220500]; + +static const mxArray *emlrt_marshallOut(const real_T u[220500]); + +static real_T (*f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, + const emlrtMsgIdentifier *msgId))[264600]; + +// Function Definitions +// +// Arguments : const emlrtStack *sp +// const mxArray *fs +// const char_T *identifier +// Return Type : real_T +// +static real_T b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *fs, + const char_T *identifier) +{ + emlrtMsgIdentifier thisId; + real_T y; + thisId.fIdentifier = const_cast(identifier); + thisId.fParent = nullptr; + thisId.bParentIsCell = false; + y = b_emlrt_marshallIn(sp, emlrtAlias(fs), &thisId); + emlrtDestroyArray(&fs); + return y; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *u +// const emlrtMsgIdentifier *parentId +// Return Type : real_T +// +static real_T b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, + const emlrtMsgIdentifier *parentId) +{ + real_T y; + y = e_emlrt_marshallIn(sp, emlrtAlias(u), parentId); + emlrtDestroyArray(&u); + return y; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *impulseResponse +// const char_T *identifier +// Return Type : real_T (*)[264600] +// +static real_T (*c_emlrt_marshallIn(const emlrtStack *sp, + const mxArray *impulseResponse, + const char_T *identifier))[264600] +{ + emlrtMsgIdentifier thisId; + real_T(*y)[264600]; + thisId.fIdentifier = const_cast(identifier); + thisId.fParent = nullptr; + thisId.bParentIsCell = false; + y = c_emlrt_marshallIn(sp, emlrtAlias(impulseResponse), &thisId); + emlrtDestroyArray(&impulseResponse); + return y; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *u +// const emlrtMsgIdentifier *parentId +// Return Type : real_T (*)[264600] +// +static real_T (*c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, + const emlrtMsgIdentifier *parentId))[264600] +{ + real_T(*y)[264600]; + y = f_emlrt_marshallIn(sp, emlrtAlias(u), parentId); + emlrtDestroyArray(&u); + return y; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *src +// const emlrtMsgIdentifier *msgId +// Return Type : real_T (*)[220500] +// +static real_T (*d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, + const emlrtMsgIdentifier *msgId))[220500] +{ + static const int32_T dims{220500}; + real_T(*ret)[220500]; + emlrtCheckBuiltInR2012b((emlrtCTX)sp, msgId, src, (const char_T *)"double", + false, 1U, (void *)&dims); + ret = (real_T(*)[220500])emlrtMxGetData(src); + emlrtDestroyArray(&src); + return ret; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *src +// const emlrtMsgIdentifier *msgId +// Return Type : real_T +// +static real_T e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, + const emlrtMsgIdentifier *msgId) +{ + static const int32_T dims{0}; + real_T ret; + emlrtCheckBuiltInR2012b((emlrtCTX)sp, msgId, src, (const char_T *)"double", + false, 0U, (void *)&dims); + ret = *(real_T *)emlrtMxGetData(src); + emlrtDestroyArray(&src); + return ret; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *b_signal +// const char_T *identifier +// Return Type : real_T (*)[220500] +// +static real_T (*emlrt_marshallIn(const emlrtStack *sp, const mxArray *b_signal, + const char_T *identifier))[220500] +{ + emlrtMsgIdentifier thisId; + real_T(*y)[220500]; + thisId.fIdentifier = const_cast(identifier); + thisId.fParent = nullptr; + thisId.bParentIsCell = false; + y = emlrt_marshallIn(sp, emlrtAlias(b_signal), &thisId); + emlrtDestroyArray(&b_signal); + return y; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *u +// const emlrtMsgIdentifier *parentId +// Return Type : real_T (*)[220500] +// +static real_T (*emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, + const emlrtMsgIdentifier *parentId))[220500] +{ + real_T(*y)[220500]; + y = d_emlrt_marshallIn(sp, emlrtAlias(u), parentId); + emlrtDestroyArray(&u); + return y; +} + +// +// Arguments : const real_T u[220500] +// Return Type : const mxArray * +// +static const mxArray *emlrt_marshallOut(const real_T u[220500]) +{ + static const int32_T i{0}; + static const int32_T i1{220500}; + const mxArray *m; + const mxArray *y; + y = nullptr; + m = emlrtCreateNumericArray(1, (const void *)&i, mxDOUBLE_CLASS, mxREAL); + emlrtMxSetData((mxArray *)m, (void *)&u[0]); + emlrtSetDimensions((mxArray *)m, &i1, 1); + emlrtAssign(&y, m); + return y; +} + +// +// Arguments : const emlrtStack *sp +// const mxArray *src +// const emlrtMsgIdentifier *msgId +// Return Type : real_T (*)[264600] +// +static real_T (*f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, + const emlrtMsgIdentifier *msgId))[264600] +{ + static const int32_T dims{264600}; + real_T(*ret)[264600]; + emlrtCheckBuiltInR2012b((emlrtCTX)sp, msgId, src, (const char_T *)"double", + false, 1U, (void *)&dims); + ret = (real_T(*)[264600])emlrtMxGetData(src); + emlrtDestroyArray(&src); + return ret; +} + +// +// Arguments : const mxArray * const prhs[4] +// const mxArray **plhs +// Return Type : void +// +void dereveb_c_api(const mxArray *const prhs[4], const mxArray **plhs) +{ + emlrtStack st{ + nullptr, // site + nullptr, // tls + nullptr // prev + }; + real_T(*impulseResponse)[264600]; + real_T(*b_signal)[220500]; + real_T(*reverberated_vc)[220500]; + real_T(*signal_vc)[220500]; + real_T fs; + st.tls = emlrtRootTLSGlobal; + reverberated_vc = (real_T(*)[220500])mxMalloc(sizeof(real_T[220500])); + // Marshall function inputs + b_signal = emlrt_marshallIn(&st, emlrtAlias(prhs[0]), "signal"); + signal_vc = emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "signal_vc"); + fs = b_emlrt_marshallIn(&st, emlrtAliasP(prhs[2]), "fs"); + impulseResponse = + c_emlrt_marshallIn(&st, emlrtAlias(prhs[3]), "impulseResponse"); + // Invoke the target function + dereveb_c(*b_signal, *signal_vc, fs, *impulseResponse, *reverberated_vc); + // Marshall function outputs + *plhs = emlrt_marshallOut(*reverberated_vc); +} + +// +// Arguments : void +// Return Type : void +// +void dereveb_c_atexit() +{ + emlrtStack st{ + nullptr, // site + nullptr, // tls + nullptr // prev + }; + mexFunctionCreateRootTLS(); + st.tls = emlrtRootTLSGlobal; + emlrtEnterRtStackR2012b(&st); + emlrtLeaveRtStackR2012b(&st); + emlrtDestroyRootTLS(&emlrtRootTLSGlobal); + dereveb_c_xil_terminate(); + dereveb_c_xil_shutdown(); + emlrtExitTimeCleanup(&emlrtContextGlobal); +} + +// +// Arguments : void +// Return Type : void +// +void dereveb_c_initialize() +{ + emlrtStack st{ + nullptr, // site + nullptr, // tls + nullptr // prev + }; + mexFunctionCreateRootTLS(); + st.tls = emlrtRootTLSGlobal; + emlrtClearAllocCountR2012b(&st, false, 0U, nullptr); + emlrtEnterRtStackR2012b(&st); + emlrtFirstTimeR2012b(emlrtRootTLSGlobal); +} + +// +// Arguments : void +// Return Type : void +// +void dereveb_c_terminate() +{ + emlrtStack st{ + nullptr, // site + nullptr, // tls + nullptr // prev + }; + st.tls = emlrtRootTLSGlobal; + emlrtLeaveRtStackR2012b(&st); + emlrtDestroyRootTLS(&emlrtRootTLSGlobal); +} + +// +// File trailer for _coder_dereveb_c_api.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/interface/_coder_dereveb_c_api.h b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_api.h new file mode 100644 index 0000000..8ae1d6e --- /dev/null +++ b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_api.h @@ -0,0 +1,42 @@ +// +// File: _coder_dereveb_c_api.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef _CODER_DEREVEB_C_API_H +#define _CODER_DEREVEB_C_API_H + +// Include Files +#include "emlrt.h" +#include "tmwtypes.h" +#include +#include + +// Variable Declarations +extern emlrtCTX emlrtRootTLSGlobal; +extern emlrtContext emlrtContextGlobal; + +// Function Declarations +void dereveb_c(real_T b_signal[220500], real_T signal_vc[220500], real_T fs, + real_T impulseResponse[264600], real_T reverberated_vc[220500]); + +void dereveb_c_api(const mxArray *const prhs[4], const mxArray **plhs); + +void dereveb_c_atexit(); + +void dereveb_c_initialize(); + +void dereveb_c_terminate(); + +void dereveb_c_xil_shutdown(); + +void dereveb_c_xil_terminate(); + +#endif +// +// File trailer for _coder_dereveb_c_api.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/interface/_coder_dereveb_c_mex.cpp b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_mex.cpp new file mode 100644 index 0000000..987cf0c --- /dev/null +++ b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_mex.cpp @@ -0,0 +1,85 @@ +// +// File: _coder_dereveb_c_mex.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "_coder_dereveb_c_mex.h" +#include "_coder_dereveb_c_api.h" + +// Function Definitions +// +// Arguments : int32_T nlhs +// mxArray *plhs[] +// int32_T nrhs +// const mxArray *prhs[] +// Return Type : void +// +void mexFunction(int32_T nlhs, mxArray *plhs[], int32_T nrhs, + const mxArray *prhs[]) +{ + mexAtExit(&dereveb_c_atexit); + // Module initialization. + dereveb_c_initialize(); + try { + emlrtShouldCleanupOnError((emlrtCTX *)emlrtRootTLSGlobal, false); + // Dispatch the entry-point. + unsafe_dereveb_c_mexFunction(nlhs, plhs, nrhs, prhs); + // Module termination. + dereveb_c_terminate(); + } catch (...) { + emlrtCleanupOnException((emlrtCTX *)emlrtRootTLSGlobal); + throw; + } +} + +// +// Arguments : void +// Return Type : emlrtCTX +// +emlrtCTX mexFunctionCreateRootTLS() +{ + emlrtCreateRootTLSR2021a(&emlrtRootTLSGlobal, &emlrtContextGlobal, nullptr, 1, + nullptr); + return emlrtRootTLSGlobal; +} + +// +// Arguments : int32_T nlhs +// mxArray *plhs[1] +// int32_T nrhs +// const mxArray *prhs[4] +// Return Type : void +// +void unsafe_dereveb_c_mexFunction(int32_T nlhs, mxArray *plhs[1], int32_T nrhs, + const mxArray *prhs[4]) +{ + emlrtStack st{ + nullptr, // site + nullptr, // tls + nullptr // prev + }; + const mxArray *outputs; + st.tls = emlrtRootTLSGlobal; + // Check for proper number of arguments. + if (nrhs != 4) { + emlrtErrMsgIdAndTxt(&st, "EMLRT:runTime:WrongNumberOfInputs", 5, 12, 4, 4, + 9, "dereveb_c"); + } + if (nlhs > 1) { + emlrtErrMsgIdAndTxt(&st, "EMLRT:runTime:TooManyOutputArguments", 3, 4, 9, + "dereveb_c"); + } + // Call the function. + dereveb_c_api(prhs, &outputs); + // Copy over outputs to the caller. + emlrtReturnArrays(1, &plhs[0], &outputs); +} + +// +// File trailer for _coder_dereveb_c_mex.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/interface/_coder_dereveb_c_mex.h b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_mex.h new file mode 100644 index 0000000..86aa734 --- /dev/null +++ b/dereverbrate/dereveb_c/interface/_coder_dereveb_c_mex.h @@ -0,0 +1,30 @@ +// +// File: _coder_dereveb_c_mex.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef _CODER_DEREVEB_C_MEX_H +#define _CODER_DEREVEB_C_MEX_H + +// Include Files +#include "emlrt.h" +#include "mex.h" +#include "tmwtypes.h" + +// Function Declarations +MEXFUNCTION_LINKAGE void mexFunction(int32_T nlhs, mxArray *plhs[], + int32_T nrhs, const mxArray *prhs[]); + +emlrtCTX mexFunctionCreateRootTLS(); + +void unsafe_dereveb_c_mexFunction(int32_T nlhs, mxArray *plhs[1], int32_T nrhs, + const mxArray *prhs[4]); + +#endif +// +// File trailer for _coder_dereveb_c_mex.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/interface/coder_array_mex.h b/dereverbrate/dereveb_c/interface/coder_array_mex.h new file mode 100644 index 0000000..3667cf9 --- /dev/null +++ b/dereverbrate/dereveb_c/interface/coder_array_mex.h @@ -0,0 +1,1359 @@ +/* Copyright 2019-2020 The MathWorks, Inc. */ +/* Copied from fullfile(matlabroot,'extern','include','coder','coder_array','coder_array_mex.h') */ +#pragma once + +#ifndef _mw_coder_array_mex_h +#define _mw_coder_array_mex_h + +// ------------------------------------------------------------------------------------------------------------------------------------------- +// Usage: +// +// coder::array: T base type of data, N number of dimensions +// +// coder::array() +// : default constructor +// coder::array(const coder::array &) +// : copy constructor (always make a deep copy of other array) +// coder::array(const T *data, const SizeType *sz) +// : Set data with sizes of this array. +// : (Data is not copied, data is not deleted) +// coder::array::operator = (coder coder::array &) +// : Assign into this array; +// : delete its previous contents (if owning the data.) +// set(const T *data, SizeType sz1, SizeType sz2, ...) +// : Set data with dimensions. +// : (Data is not copied, data is not deleted) +// set_size(SizeType sz1, SizeType sz2, ...) +// : Set sizes of array. Reallocate memory of data if needed. +// bool is_owner() : Return true if the data is owned by the class. +// void no_free() +// : Mark that the class does no longer owns its data; +// : data is no longer deleted. +// SizeType capacity() : How many entries are reserved by memory allocation. +// reshape( SizeType sz1, SizeType sz2, ...) +// : Reshape array to a different ND shape. Do not copy the data. +// : The number of elements must not be changed (numel()==sz1*sz2*...) +// : Return the array with possibly new number of dimensions. +// clear() : Reset array to be empty. +// SizeType numel() : Return the number of elements. +// operator [] (SizeType index) : Extract element at linear index (0 based.) +// size(SizeType dimension) : Size of array of the provided dimension. +// SizeType * size() : Return the pointer to all the sizes of this array. +// SizeType index(SizeType i1, SizeType i2, ...) +// : Compute the linear index from ND index (i1,i2,...) +// at(SizeType i1, SizeType i2, ...) : The element at index (i1,i2,...) + +#include +#include +#include +#include +#include +#include +#include "mex.h" +#include "emlrt.h" +#include "tmwtypes.h" + +namespace coder { + +#ifndef CODER_ARRAY_SIZE_TYPE_DEFINED +typedef int32_T SizeType; +#endif + +namespace detail { + +#ifndef CODER_ARRAY_DATA_PTR_DEFINED +template +class data_ptr { + public: + typedef T value_type; + typedef SZ size_type; + + data_ptr() + : mem_(NULL) + , data_(NULL) + , size_(0) + , capacity_(0) + , owner_(false) { + } + data_ptr(const T* _data, SZ _sz) + : mem_(NULL) + , data_(const_cast(_data)) + , size_(_sz) + , capacity_(_sz) + , owner_(false) { + } + + data_ptr(const data_ptr& _other) + : mem_(_other.owner_ ? NULL : _other.mem_) + , data_(_other.owner_ ? NULL : _other.data_) + , size_(_other.owner_ ? 0 : _other.size_) + , capacity_(_other.owner_ ? 0 : _other.capacity_) + , owner_(_other.owner_) { + if (owner_) { + resize(_other.size_); + std::copy(_other.data_, _other.data_ + size_, data_); + } + } + ~data_ptr() { + deallocate(mem_, data_); + } + + std::pair allocate_primitive(SZ _n) { + char* m = reinterpret_cast(emlrtMallocMex(_n * sizeof(T))); + T* d = new (m) T[_n]; + return std::make_pair(m, d); + } + + void deallocate_primitive(char* _m, T* _d) { + if (_m == NULL || !owner_) { + return; + } + emlrtFreeMex(_m); + mem_ = NULL; + } + + std::pair allocate_with_destructor(SZ _n) { + char* m = reinterpret_cast(emlrtMallocMex(sizeof(SZ) * 2 + _n * sizeof(T))); + *reinterpret_cast(m) = _n; + T* d = new (m + sizeof(SZ)) T[_n]; + return std::make_pair(m, d); + } + + void deallocate_with_destructor(char* _m, T* _d) { + if (_m == NULL || !owner_) { + return; + } + SZ n = *reinterpret_cast(_m); + for (SZ i = 0; i < n; i++) { + _d[i].~T(); + } + emlrtFreeMex(_m); + mem_ = NULL; + } + + std::pair allocate(SZ _n) { + if (std::is_pod::value) { + return allocate_primitive(_n); + } else { + return allocate_with_destructor(_n); + } + } + + void deallocate(char* _m, T* _d) { + if (std::is_pod::value) { + deallocate_primitive(_m, _d); + } else { + deallocate_with_destructor(_m, _d); + } + } + + void prealloc(SZ _numel) { + size_ = _numel; + capacity_ = _numel; + } + + SZ capacity() const { + return capacity_; + } + void reserve(SZ _n, emlrtRTEInfo* _rteInfo = NULL, emlrtConstCTX _ctx = NULL) { + if (_n > capacity_) { + char* new_mem = NULL; + T* new_data = NULL; + std::tie(new_mem, new_data) = allocate(_n); + if (new_data == NULL) { + emlrtHeapAllocationErrorR2012b(_rteInfo, _ctx); + } + if (size_ != 0) { + std::copy(data_, data_ + size_, new_data); + } + deallocate(mem_, data_); + mem_ = new_mem; + data_ = new_data; + capacity_ = _n; + owner_ = true; + } + } + void resize(SZ _n, emlrtRTEInfo* _rteInfo = NULL, emlrtConstCTX _ctx = NULL) { + reserve(_n, _rteInfo, _ctx); + size_ = _n; + } + + private: + // Prohibit use of assignment operator to prevent subtle bugs + void operator=(const data_ptr& _other); + + public: + void set(T* _data, const SZ _sz) { + deallocate(mem_, data_); + mem_ = NULL; + data_ = _data; + size_ = _sz; + owner_ = false; + capacity_ = size_; + } + + void copy(const T* _data, SZ _size) { + if (data_ == _data) { + size_ = _size; + return; + } + deallocate(mem_, data_); + std::tie(mem_, data_) = allocate(_size); + owner_ = true; + size_ = _size; + capacity_ = size_; + std::copy(_data, _data + _size, data_); + } + + void copy(const data_ptr& _other) { + copy(_other.data_, _other.size_); + } + + operator T*() { + return &data_[0]; + } + + operator const T*() const { + return &data_[0]; + } + + T& operator[](SZ _index) { + return data_[_index]; + } + const T& operator[](SZ _index) const { + return data_[_index]; + } + + T* operator->() { + return data_; + } + + const T* operator->() const { + return data_; + } + + bool is_null() const { + return data_ == NULL; + } + + void clear() { + deallocate(mem_, data_); + mem_ = NULL; + data_ = NULL; + size_ = 0; + capacity_ = 0; + owner_ = false; + } + + bool is_owner() const { + return owner_; + } + + void set_owner(bool _b) { + owner_ = _b; + } + + private: + char* mem_; + T* data_; + SZ size_; + SZ capacity_; + bool owner_; +}; +#endif + +} // namespace detail + +// Implementing the random access iterator class so coder::array can be +// used in STL iterators. +template +class array_iterator : public std::iterator { + public: + array_iterator() + : arr_(NULL) + , i_(0) { + } + array_iterator(const array_iterator& other) + : arr_(other.arr_) + , i_(other.i_) { + } + ~array_iterator() { + } + typename T::value_type& operator*() const { + return (*arr_)[i_]; + } + typename T::value_type* operator->() const { + return &(*arr_)[i_]; + } + typename T::value_type& operator[](typename T::size_type _di) const { + return (*arr_)[i_ + _di]; + } + array_iterator& operator++() { + ++i_; + return *this; + } + array_iterator& operator--() { + --i_; + return *this; + } + array_iterator operator++(int) { + array_iterator cp(*this); + ++i_; + return cp; + } + array_iterator operator--(int) { + array_iterator cp(*this); + --i_; + return cp; + } + array_iterator& operator=(const array_iterator& _other) { + this->i_ = _other.i_; + return *this; + } + bool operator==(const array_iterator& _other) const { + return i_ == _other.i_; + } + bool operator!=(const array_iterator& _other) const { + return i_ != _other.i_; + } + bool operator<(const array_iterator& _other) const { + return i_ < _other.i_; + } + bool operator>(const array_iterator& _other) const { + return i_ > _other.i_; + } + bool operator<=(const array_iterator& _other) const { + return i_ <= _other.i_; + } + bool operator>=(const array_iterator& _other) const { + return i_ >= _other.i_; + } + array_iterator operator+(typename T::size_type _add) const { + array_iterator cp(*this); + cp.i_ += _add; + return cp; + } + array_iterator& operator+=(typename T::size_type _add) { + this->i_ += _add; + return *this; + } + array_iterator operator-(typename T::size_type _subtract) const { + array_iterator cp(*this); + cp.i_ -= _subtract; + return cp; + } + array_iterator& operator-=(typename T::size_type _subtract) { + this->i_ -= _subtract; + return *this; + } + typename T::size_type operator-(const array_iterator& _other) const { + return static_cast(this->i_ - _other.i_); + } + + array_iterator(T* _arr, typename T::size_type _i) + : arr_(_arr) + , i_(_i) { + } + + private: + T* arr_; + typename T::size_type i_; +}; + +// Const version of the array iterator. +template +class const_array_iterator : public std::iterator { + public: + const_array_iterator() + : arr_(NULL) + , i_(0) { + } + const_array_iterator(const const_array_iterator& other) + : arr_(other.arr_) + , i_(other.i_) { + } + ~const_array_iterator() { + } + const typename T::value_type& operator*() const { + return (*arr_)[i_]; + } + const typename T::value_type* operator->() const { + return &(*arr_)[i_]; + } + const typename T::value_type& operator[](typename T::size_type _di) const { + return (*arr_)[i_ + _di]; + } + const_array_iterator& operator++() { + ++i_; + return *this; + } + const_array_iterator& operator--() { + --i_; + return *this; + } + const_array_iterator operator++(int) { + const_array_iterator copy(*this); + ++i_; + return copy; + } + const_array_iterator operator--(int) { + const_array_iterator copy(*this); + --i_; + return copy; + } + const_array_iterator& operator=(const const_array_iterator& _other) { + this->i_ = _other.i_; + return *this; + } + bool operator==(const const_array_iterator& _other) const { + return i_ == _other.i_; + } + bool operator!=(const const_array_iterator& _other) const { + return i_ != _other.i_; + } + bool operator<(const const_array_iterator& _other) const { + return i_ < _other.i_; + } + bool operator>(const const_array_iterator& _other) const { + return i_ > _other.i_; + } + bool operator<=(const const_array_iterator& _other) const { + return i_ <= _other.i_; + } + bool operator>=(const const_array_iterator& _other) const { + return i_ >= _other.i_; + } + const_array_iterator operator+(typename T::size_type _add) const { + const_array_iterator cp(*this); + cp.i_ += _add; + return cp; + } + const_array_iterator& operator+=(typename T::size_type _add) { + this->i_ += _add; + return *this; + } + const_array_iterator operator-(typename T::size_type _subtract) const { + const_array_iterator cp(*this); + cp.i_ -= _subtract; + return cp; + } + + const_array_iterator& operator-=(typename T::size_type _subtract) { + this->i_ -= _subtract; + return *this; + } + + typename T::size_type operator-(const const_array_iterator& _other) const { + return static_cast(this->i_ - _other.i_); + } + + const_array_iterator(const T* _arr, typename T::size_type _i) + : arr_(_arr) + , i_(_i) { + } + + private: + const T* arr_; + typename T::size_type i_, n_; +}; + +namespace detail { + +// detail::numel: Compile-time product of the given size vector of length N. +template +class numel { + public: + template + static SZ compute(SZ _size[]) { + return _size[N - 1] * numel::compute(_size); + } +}; +template <> +class numel<0> { + public: + template + static SZ compute(SZ[]) { + return 1; + } +}; + +// detail::numel_check +// : Compile-time product of the given size vector of length N with runtime check. +template +class numel_check { + public: + template + static SZ compute(emlrtRTEInfo* _rteInfo, emlrtConstCTX _ctx, SZ _size[]) { + return static_cast(emlrtSizeMulR2012b( + static_cast(_size[N - 1]), + static_cast(numel_check::compute(_rteInfo, _ctx, _size)), _rteInfo, + _ctx)); + } +}; +template <> +class numel_check<0> { + public: + template + static SZ compute(emlrtRTEInfo*, emlrtConstCTX, SZ[]) { + return 1; + } +}; + +// Compute flat index from (column-major) ND size vector and a list of indices. +template +class index_nd { + public: + template + static SZ compute(const SZ _size[], const SZ _indices[]) { + const SZ weight = numel::compute(_size); + return weight * _indices[I - 1] + index_nd::compute(_size, _indices); + } +}; + +template <> +class index_nd<0> { + public: + template + static SZ compute(SZ[], SZ[]) { + return 0; + } +}; + +template +struct match_dimensions {}; + +template <> +struct match_dimensions { + static void check() { + } +}; + +template <> +struct match_dimensions { + static void check() { + assert(false && "Method with wrong number of dimensions used."); + } +}; + +} // namespace detail + +// Base class for code::array. SZ is the type used for sizes (currently int32_t.) +// Overloading up to 10 dimensions (not using variadic templates to +// stay compatible with C++98.) +template +class array_base { + public: + typedef T value_type; + typedef SZ size_type; + + // This is for MEX only. To prevent memory allocation when set_size is called later. + void prealloc(SZ _numel) { + data_.prealloc(_numel); + } + + array_base() { + std::memset(size_, 0, sizeof(SZ) * N); + } + + array_base(T* _data, const SZ* _sz) + : data_(_data, ::coder::detail::numel::compute(_sz)) { + std::copy(_sz, _sz + N, size_); + } + + array_base& operator=(const array_base& _other) { + data_.copy(_other.data_); + std::copy(_other.size_, _other.size_ + N, size_); + return *this; + } + + void set(T* _data, SZ _n1) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1); + size_[0] = _n1; + } + + void set(T* _data, SZ _n1, SZ _n2) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2); + size_[0] = _n1; + size_[1] = _n2; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4 * _n5); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4 * _n5 * _n6); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4 * _n5 * _n6 * _n7); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4 * _n5 * _n6 * _n7 * _n8); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + } + + void set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4 * _n5 * _n6 * _n7 * _n8 * _n9); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + size_[8] = _n9; + } + + void + set(T* _data, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9, SZ _n10) { + ::coder::detail::match_dimensions::check(); + data_.set(_data, _n1 * _n2 * _n3 * _n4 * _n5 * _n6 * _n7 * _n8 * _n9 * _n10); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + size_[8] = _n9; + size_[9] = _n10; + } + + bool is_owner() const { + return data_.is_owner(); + } + + void no_free() { + data_.set_owner(false); + } + + SZ capacity() const { + return data_.capacity(); + } + + void set_size(emlrtRTEInfo* _rteInfo, emlrtConstCTX _ctx, SZ _n1) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, emlrtConstCTX _ctx, SZ _n1, SZ _n2) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, emlrtConstCTX _ctx, SZ _n1, SZ _n2, SZ _n3) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, emlrtConstCTX _ctx, SZ _n1, SZ _n2, SZ _n3, SZ _n4) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void + set_size(emlrtRTEInfo* _rteInfo, emlrtConstCTX _ctx, SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, + emlrtConstCTX _ctx, + SZ _n1, + SZ _n2, + SZ _n3, + SZ _n4, + SZ _n5, + SZ _n6) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, + emlrtConstCTX _ctx, + SZ _n1, + SZ _n2, + SZ _n3, + SZ _n4, + SZ _n5, + SZ _n6, + SZ _n7) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, + emlrtConstCTX _ctx, + SZ _n1, + SZ _n2, + SZ _n3, + SZ _n4, + SZ _n5, + SZ _n6, + SZ _n7, + SZ _n8) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, + emlrtConstCTX _ctx, + SZ _n1, + SZ _n2, + SZ _n3, + SZ _n4, + SZ _n5, + SZ _n6, + SZ _n7, + SZ _n8, + SZ _n9) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + size_[8] = _n9; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(emlrtRTEInfo* _rteInfo, + emlrtConstCTX _ctx, + SZ _n1, + SZ _n2, + SZ _n3, + SZ _n4, + SZ _n5, + SZ _n6, + SZ _n7, + SZ _n8, + SZ _n9, + SZ _n10) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + size_[8] = _n9; + size_[9] = _n10; + ensureCapacity(numel_check(_rteInfo, _ctx), _rteInfo, _ctx); + } + + void set_size(SZ _n1) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + size_[8] = _n9; + ensureCapacity(numel()); + } + + void set_size(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9, SZ _n10) { + ::coder::detail::match_dimensions::check(); + size_[0] = _n1; + size_[1] = _n2; + size_[2] = _n3; + size_[3] = _n4; + size_[4] = _n5; + size_[5] = _n6; + size_[6] = _n7; + size_[7] = _n8; + size_[8] = _n9; + size_[9] = _n10; + ensureCapacity(numel()); + } + + template + array_base reshape_n(const SZ (&_ns)[N1]) const { + array_base reshaped(const_cast(&data_[0]), _ns); + return reshaped; + } + + array_base reshape(SZ _n1) const { + const SZ ns[] = {_n1}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2) const { + const SZ ns[] = {_n1, _n2}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2, SZ _n3) const { + const SZ ns[] = {_n1, _n2, _n3}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4) const { + const SZ ns[] = {_n1, _n2, _n3, _n4}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5) const { + const SZ ns[] = {_n1, _n2, _n3, _n4, _n5}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6) const { + const SZ ns[] = {_n1, _n2, _n3, _n4, _n5, _n6}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7) const { + const SZ ns[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7}; + return reshape_n(ns); + } + + array_base reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8) + const { + const SZ ns[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7, _n8}; + return reshape_n(ns); + } + + array_base + reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9) const { + const SZ ns[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7, _n8, _n9}; + return reshape_n(ns); + } + + array_base + reshape(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9, SZ _n10) const { + const SZ ns[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7, _n8, _n9, _n10}; + return reshape_n(ns); + } + + T& operator[](SZ _index) { + return data_[_index]; + } + + const T& operator[](SZ _index) const { + return data_[_index]; + } + + void clear() { + data_.clear(); + } + + T* data() { + return data_; + } + + const T* data() const { + return data_; + } + + SZ* size() { + return &size_[0]; + } + + const SZ* size() const { + return &size_[0]; + } + + SZ size(SZ _index) const { + return size_[_index]; + } + + SZ numel() const { + return ::coder::detail::numel::compute(size_); + } + + SZ numel_check(emlrtRTEInfo* _rteInfo, const void* _ctx) const { + return ::coder::detail::numel_check::compute(_rteInfo, _ctx, size_); + } + + SZ index(SZ _n1) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1}; + return ::coder::detail::index_nd<1>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2}; + return ::coder::detail::index_nd<2>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3}; + return ::coder::detail::index_nd<3>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4}; + return ::coder::detail::index_nd<4>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4, _n5}; + return ::coder::detail::index_nd<5>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4, _n5, _n6}; + return ::coder::detail::index_nd<6>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7}; + return ::coder::detail::index_nd<7>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7, _n8}; + return ::coder::detail::index_nd<8>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9) const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7, _n8, _n9}; + return ::coder::detail::index_nd<9>::compute(size_, indices); + } + SZ index(SZ _n1, SZ _n2, SZ _n3, SZ _n4, SZ _n5, SZ _n6, SZ _n7, SZ _n8, SZ _n9, SZ _n10) + const { + ::coder::detail::match_dimensions::check(); + const SZ indices[] = {_n1, _n2, _n3, _n4, _n5, _n6, _n7, _n8, _n9, _n10}; + return ::coder::detail::index_nd<10>::compute(size_, indices); + } + + T& at(SZ _i1) { + ::coder::detail::match_dimensions::check(); + return data_[_i1]; + } + T& at(SZ _i1, SZ _i2) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7, SZ _i8) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7, SZ _i8, SZ _i9) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9)]; + } + T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7, SZ _i8, SZ _i9, SZ _i10) { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9, _i10)]; + } + + const T& at(SZ _i1) const { + ::coder::detail::match_dimensions::check(); + return data_[_i1]; + } + const T& at(SZ _i1, SZ _i2) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7, SZ _i8) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7, SZ _i8, SZ _i9) const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9)]; + } + const T& at(SZ _i1, SZ _i2, SZ _i3, SZ _i4, SZ _i5, SZ _i6, SZ _i7, SZ _i8, SZ _i9, SZ _i10) + const { + ::coder::detail::match_dimensions::check(); + return data_[index(_i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9, _i10)]; + } + + array_iterator > begin() { + return array_iterator >(this, 0); + } + array_iterator > end() { + return array_iterator >(this, this->numel()); + } + const_array_iterator > begin() const { + return const_array_iterator >(this, 0); + } + const_array_iterator > end() const { + return const_array_iterator >(this, this->numel()); + } + + protected: + ::coder::detail::data_ptr data_; + SZ size_[N]; + + private: + void ensureCapacity(SZ _newNumel, emlrtRTEInfo* _rteInfo = NULL, emlrtConstCTX _ctx = NULL) { + if (_newNumel > data_.capacity()) { + SZ i = data_.capacity(); + if (i < 16) { + i = 16; + } + + while (i < _newNumel) { + if (i > 1073741823) { + i = MAX_int32_T; + } else { + i <<= 1; + } + } + data_.reserve(i, _rteInfo, _ctx); + } + data_.resize(_newNumel, _rteInfo, _ctx); + } +}; + +// The standard coder::array class with base type and number of dimensions. +template +class array : public array_base { + private: + typedef array_base Base; + + public: + array() + : Base() { + } + array(const array& _other) + : Base(_other) { + } + array(const Base& _other) + : Base(_other) { + } + array(T* _data, const SizeType* _sz) + : Base(_data, _sz) { + } +}; + +// Specialize on char_T (row vector) for better support on strings. +template <> +class array : public array_base { + private: + typedef array_base Base; + + public: + array() + : array_base() { + } + array(const array& _other) + : Base(_other) { + } + array(const Base& _other) + : Base(_other) { + } + + array(const std::string& _str) { + operator=(_str); + } + + array(const char_T* _str) { + operator=(_str); + } + + array(const std::vector& _vec) { + SizeType n = static_cast(_vec.size()); + set_size(1, n); + data_.copy(&_vec[0], n); + } + + array& operator=(const std::string& _str) { + SizeType n = static_cast(_str.size()); + set_size(1, n); + data_.copy(_str.c_str(), n); + return *this; + } + + array& operator=(const char_T* _str) { + SizeType n = static_cast(strlen(_str)); + set_size(1, n); + data_.copy(_str, n); + return *this; + } + + operator std::string() const { + return std::string(static_cast(&(*this)[0]), static_cast(size(1))); + } +}; + +// Specialize on 2 dimensions for better support interactions with +// std::vector and row vectors. +template +class array : public array_base { + private: + typedef array_base Base; + + public: + array() + : Base() { + } + array(const array& _other) + : Base(_other) { + } + array(const Base& _other) + : Base(_other) { + } + array(const std::vector& _vec) { + operator=(_vec); + } + + array& operator=(const std::vector& _vec) { + SizeType n = static_cast(_vec.size()); + Base::set_size(1, n); + Base::data_.copy(&_vec[0], n); + return *this; + } + + operator std::vector() const { + const T* p = &Base::data_[0]; + return std::vector(p, p + Base::numel()); + } +}; + +// Specialize on 1 dimension for better support with std::vector and +// column vectors. +template +class array : public array_base { + private: + typedef array_base Base; + + public: + array() + : Base() { + } + array(const array& _other) + : Base(_other) { + } + array(const Base& _other) + : Base(_other) { + } + array(const std::vector& _vec) { + operator=(_vec); + } + + array& operator=(const std::vector& _vec) { + SizeType n = static_cast(_vec.size()); + Base::set_size(n); + Base::data_.copy(&_vec[0], n); + return *this; + } + + operator std::vector() const { + const T* p = &Base::data_[0]; + return std::vector(p, p + Base::numel()); + } +}; +} // namespace coder + +#endif diff --git a/dereverbrate/dereveb_c/iseven.cpp b/dereverbrate/dereveb_c/iseven.cpp new file mode 100644 index 0000000..1d3193d --- /dev/null +++ b/dereverbrate/dereveb_c/iseven.cpp @@ -0,0 +1,43 @@ +// +// File: iseven.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "iseven.h" +#include "rt_nonfinite.h" +#include + +// Function Definitions +// +// Arguments : double x +// Return Type : boolean_T +// +namespace coder { +boolean_T iseven(double x) +{ + double r; + if (std::isnan(x) || std::isinf(x)) { + r = rtNaN; + } else if (x == 0.0) { + r = 0.0; + } else { + r = std::fmod(x, 2.0); + if (r == 0.0) { + r = 0.0; + } else if (x < 0.0) { + r += 2.0; + } + } + return r == 0.0; +} + +} // namespace coder + +// +// File trailer for iseven.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/iseven.h b/dereverbrate/dereveb_c/iseven.h new file mode 100644 index 0000000..b8c5c0c --- /dev/null +++ b/dereverbrate/dereveb_c/iseven.h @@ -0,0 +1,28 @@ +// +// File: iseven.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef ISEVEN_H +#define ISEVEN_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +boolean_T iseven(double x); + +} + +#endif +// +// File trailer for iseven.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/ixfun.cpp b/dereverbrate/dereveb_c/ixfun.cpp new file mode 100644 index 0000000..a1b025c --- /dev/null +++ b/dereverbrate/dereveb_c/ixfun.cpp @@ -0,0 +1,65 @@ +// +// File: ixfun.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "ixfun.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : const ::coder::array &a +// const ::coder::array &b +// ::coder::array &c +// Return Type : void +// +namespace coder { +namespace internal { +void expand_min(const ::coder::array &a, + const ::coder::array &b, + ::coder::array &c) +{ + int acoef; + int csz_idx_0; + int u0; + u0 = a.size(0); + acoef = b.size(0); + if (u0 <= acoef) { + acoef = u0; + } + if (a.size(0) == 1) { + csz_idx_0 = b.size(0); + } else { + csz_idx_0 = acoef; + } + u0 = a.size(0); + acoef = b.size(0); + if (u0 <= acoef) { + acoef = u0; + } + if (a.size(0) == 1) { + acoef = b.size(0); + } + c.set_size(acoef); + if (csz_idx_0 != 0) { + acoef = (a.size(0) != 1); + u0 = csz_idx_0 - 1; + for (csz_idx_0 = 0; csz_idx_0 <= u0; csz_idx_0++) { + c[csz_idx_0] = std::fmin(a[acoef * csz_idx_0], b[csz_idx_0]); + } + } +} + +} // namespace internal +} // namespace coder + +// +// File trailer for ixfun.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/ixfun.h b/dereverbrate/dereveb_c/ixfun.h new file mode 100644 index 0000000..805c525 --- /dev/null +++ b/dereverbrate/dereveb_c/ixfun.h @@ -0,0 +1,33 @@ +// +// File: ixfun.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef IXFUN_H +#define IXFUN_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +namespace internal { +void expand_min(const ::coder::array &a, + const ::coder::array &b, + ::coder::array &c); + +} +} // namespace coder + +#endif +// +// File trailer for ixfun.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/pspectrogram.cpp b/dereverbrate/dereveb_c/pspectrogram.cpp new file mode 100644 index 0000000..68b511a --- /dev/null +++ b/dereverbrate/dereveb_c/pspectrogram.cpp @@ -0,0 +1,124 @@ +// +// File: pspectrogram.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "pspectrogram.h" +#include "dereveb_c_rtwutil.h" +#include "rt_nonfinite.h" +#include "coder_array.h" +#include + +// Function Definitions +// +// Arguments : ::coder::array &y +// ::coder::array &f +// double nfft +// const char options_range[8] +// Return Type : void +// +namespace coder { +void formatSpectrogram(::coder::array &y, + ::coder::array &f, double nfft, + const char options_range[8]) +{ + static const char cv[128]{ + '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', + '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', '\x10', '\x11', + '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', + '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', ' ', '!', '\"', '#', + '$', '%', '&', '\'', '(', ')', '*', '+', ',', + '-', '.', '/', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', ':', ';', '<', '=', '>', + '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', + 'z', '[', '\\', ']', '^', '_', '`', 'a', 'b', + 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', + 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', + '~', '\x7f'}; + static const char cv1[8]{'o', 'n', 'e', 's', 'i', 'd', 'e', 'd'}; + array w1; + int kstr; + boolean_T b_bool; + b_bool = false; + kstr = 0; + int exitg1; + do { + exitg1 = 0; + if (kstr < 8) { + if (cv[static_cast(options_range[kstr])] != + cv[static_cast(cv1[kstr])]) { + exitg1 = 1; + } else { + kstr++; + } + } else { + b_bool = true; + exitg1 = 1; + } + } while (exitg1 == 0); + if (b_bool) { + double freq_res; + double halfNPTS; + double half_res; + int b_y; + int i; + freq_res = 6.2831853071795862 / nfft; + if (std::isnan(nfft - 1.0)) { + w1.set_size(1, 1); + w1[0] = rtNaN; + } else if (nfft - 1.0 < 0.0) { + w1.set_size(w1.size(0), 0); + } else if (std::isinf(nfft - 1.0) && (0.0 == nfft - 1.0)) { + w1.set_size(1, 1); + w1[0] = rtNaN; + } else { + kstr = static_cast(std::floor(nfft - 1.0)); + w1.set_size(1, kstr + 1); + for (i = 0; i <= kstr; i++) { + w1[i] = i; + } + } + w1.set_size(1, w1.size(1)); + kstr = w1.size(1) - 1; + for (i = 0; i <= kstr; i++) { + w1[i] = freq_res * w1[i]; + } + half_res = freq_res / 2.0; + if (rt_remd_snf(nfft, 2.0) != 0.0) { + halfNPTS = (nfft + 1.0) / 2.0; + w1[static_cast(halfNPTS) - 1] = 3.1415926535897931 - half_res; + w1[static_cast(static_cast(halfNPTS))] = + half_res + 3.1415926535897931; + } else { + halfNPTS = nfft / 2.0 + 1.0; + w1[static_cast(halfNPTS) - 1] = 3.1415926535897931; + } + w1[static_cast(nfft) - 1] = 6.2831853071795862 - freq_res; + kstr = static_cast(halfNPTS); + f.set_size(kstr); + for (i = 0; i < kstr; i++) { + f[i] = w1[i]; + } + b_y = y.size(1) - 1; + for (i = 0; i <= b_y; i++) { + for (int i1{0}; i1 < kstr; i1++) { + y[i1 + static_cast(halfNPTS) * i] = y[i1 + y.size(0) * i]; + } + } + y.set_size(kstr, b_y + 1); + } +} + +} // namespace coder + +// +// File trailer for pspectrogram.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/pspectrogram.h b/dereverbrate/dereveb_c/pspectrogram.h new file mode 100644 index 0000000..b2a1657 --- /dev/null +++ b/dereverbrate/dereveb_c/pspectrogram.h @@ -0,0 +1,31 @@ +// +// File: pspectrogram.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef PSPECTROGRAM_H +#define PSPECTROGRAM_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void formatSpectrogram(::coder::array &y, + ::coder::array &f, double nfft, + const char options_range[8]); + +} + +#endif +// +// File trailer for pspectrogram.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/ref.h b/dereverbrate/dereveb_c/ref.h new file mode 100644 index 0000000..24b4170 --- /dev/null +++ b/dereverbrate/dereveb_c/ref.h @@ -0,0 +1,31 @@ +// +// File: ref.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef REF_H +#define REF_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Type Definitions +namespace coder { +class captured_var { +public: + double contents; +}; + +} // namespace coder + +#endif +// +// File trailer for ref.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rtGetInf.cpp b/dereverbrate/dereveb_c/rtGetInf.cpp new file mode 100644 index 0000000..53a5de9 --- /dev/null +++ b/dereverbrate/dereveb_c/rtGetInf.cpp @@ -0,0 +1,55 @@ +// +// File: rtGetInf.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Abstract: +// MATLAB for code generation function to initialize non-finite, Inf and +// MinusInf +// Include Files +#include "rtGetInf.h" +#include "rt_nonfinite.h" + +// Function: rtGetInf +// ================================================================== +// Abstract: +// Initialize rtInf needed by the generated code. +real_T rtGetInf(void) +{ + return rtInf; +} + +// Function: rtGetInfF +// ================================================================= +// Abstract: +// Initialize rtInfF needed by the generated code. +real32_T rtGetInfF(void) +{ + return rtInfF; +} + +// Function: rtGetMinusInf +// ============================================================= +// Abstract: +// Initialize rtMinusInf needed by the generated code. +real_T rtGetMinusInf(void) +{ + return rtMinusInf; +} + +// Function: rtGetMinusInfF +// ============================================================ +// Abstract: +// Initialize rtMinusInfF needed by the generated code. +real32_T rtGetMinusInfF(void) +{ + return rtMinusInfF; +} + +// +// File trailer for rtGetInf.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rtGetInf.h b/dereverbrate/dereveb_c/rtGetInf.h new file mode 100644 index 0000000..fac518d --- /dev/null +++ b/dereverbrate/dereveb_c/rtGetInf.h @@ -0,0 +1,31 @@ +// +// File: rtGetInf.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef RTGETINF_H +#define RTGETINF_H + +// Include Files +#include "rtwtypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern real_T rtGetInf(void); +extern real32_T rtGetInfF(void); +extern real_T rtGetMinusInf(void); +extern real32_T rtGetMinusInfF(void); + +#ifdef __cplusplus +} +#endif +#endif +// +// File trailer for rtGetInf.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rtGetNaN.cpp b/dereverbrate/dereveb_c/rtGetNaN.cpp new file mode 100644 index 0000000..b88f72f --- /dev/null +++ b/dereverbrate/dereveb_c/rtGetNaN.cpp @@ -0,0 +1,38 @@ +// +// File: rtGetNaN.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Abstract: +// MATLAB for code generation function to initialize non-finite, NaN +// Include Files +#include "rtGetNaN.h" +#include "rt_nonfinite.h" + +// Function: rtGetNaN +// ====================================================================== +// Abstract: +// Initialize rtNaN needed by the generated code. +// NaN is initialized as non-signaling. Assumes IEEE. +real_T rtGetNaN(void) +{ + return rtNaN; +} + +// Function: rtGetNaNF +// ===================================================================== +// Abstract: +// Initialize rtNaNF needed by the generated code. +// NaN is initialized as non-signaling. Assumes IEEE +real32_T rtGetNaNF(void) +{ + return rtNaNF; +} + +// +// File trailer for rtGetNaN.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rtGetNaN.h b/dereverbrate/dereveb_c/rtGetNaN.h new file mode 100644 index 0000000..32af9ff --- /dev/null +++ b/dereverbrate/dereveb_c/rtGetNaN.h @@ -0,0 +1,29 @@ +// +// File: rtGetNaN.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef RTGETNAN_H +#define RTGETNAN_H + +// Include Files +#include "rtwtypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern real_T rtGetNaN(void); +extern real32_T rtGetNaNF(void); + +#ifdef __cplusplus +} +#endif +#endif +// +// File trailer for rtGetNaN.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rt_nonfinite.cpp b/dereverbrate/dereveb_c/rt_nonfinite.cpp new file mode 100644 index 0000000..4dc1a6f --- /dev/null +++ b/dereverbrate/dereveb_c/rt_nonfinite.cpp @@ -0,0 +1,27 @@ +// +// File: rt_nonfinite.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Abstract: +// MATLAB for code generation function to initialize non-finites, +// (Inf, NaN and -Inf). +// Include Files +#include "rt_nonfinite.h" +#include +#include + +real_T rtNaN{std::numeric_limits::quiet_NaN()}; +real_T rtInf{std::numeric_limits::infinity()}; +real_T rtMinusInf{-std::numeric_limits::infinity()}; +real32_T rtNaNF{std::numeric_limits::quiet_NaN()}; +real32_T rtInfF{std::numeric_limits::infinity()}; +real32_T rtMinusInfF{-std::numeric_limits::infinity()}; + +// +// File trailer for rt_nonfinite.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rt_nonfinite.h b/dereverbrate/dereveb_c/rt_nonfinite.h new file mode 100644 index 0000000..2549c97 --- /dev/null +++ b/dereverbrate/dereveb_c/rt_nonfinite.h @@ -0,0 +1,33 @@ +// +// File: rt_nonfinite.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef RT_NONFINITE_H +#define RT_NONFINITE_H + +// Include Files +#include "rtwtypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern real_T rtInf; +extern real_T rtMinusInf; +extern real_T rtNaN; +extern real32_T rtInfF; +extern real32_T rtMinusInfF; +extern real32_T rtNaNF; + +#ifdef __cplusplus +} +#endif +#endif +// +// File trailer for rt_nonfinite.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/rtwtypes.h b/dereverbrate/dereveb_c/rtwtypes.h new file mode 100644 index 0000000..c42628e --- /dev/null +++ b/dereverbrate/dereveb_c/rtwtypes.h @@ -0,0 +1,45 @@ +// +// File: rtwtypes.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef RTWTYPES_H +#define RTWTYPES_H + +/*=======================================================================* + * Fixed width word size data types: * + * int64_T - signed 64 bit integers * + * uint64_T - unsigned 64 bit integers * + *=======================================================================*/ + +#if defined(__APPLE__) +#ifndef INT64_T +#define INT64_T long +#define FMT64 "l" +#if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +#define INT_TYPE_64_IS_LONG +#endif +#endif +#endif + +#if defined(__APPLE__) +#ifndef UINT64_T +#define UINT64_T unsigned long +#define FMT64 "l" +#if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +#define INT_TYPE_64_IS_LONG +#endif +#endif +#endif + +// Include Files +#include "tmwtypes.h" + +#endif +// +// File trailer for rtwtypes.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/spectrogram.cpp b/dereverbrate/dereveb_c/spectrogram.cpp new file mode 100644 index 0000000..388e90b --- /dev/null +++ b/dereverbrate/dereveb_c/spectrogram.cpp @@ -0,0 +1,270 @@ +// +// File: spectrogram.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "spectrogram.h" +#include "computeDFT.h" +#include "hamming.h" +#include "pspectrogram.h" +#include "rt_nonfinite.h" +#include "welchparse.h" +#include "coder_array.h" +#include +#include + +// Type Definitions +struct cell_wrap_6 { + double f1[220500]; +}; + +struct cell_wrap_22 { + double f1[264600]; +}; + +// Function Definitions +// +// Arguments : const double x[264600] +// const ::coder::array &varargin_1 +// double varargin_2 +// ::coder::array &varargout_1 +// Return Type : void +// +namespace coder { +void b_spectrogram(const double x[264600], + const ::coder::array &varargin_1, + double varargin_2, ::coder::array &varargout_1) +{ + static cell_wrap_22 r; + array r1; + array xin; + array win; + double b_expl_temp; + double expl_temp; + double hopSize; + double options_nfft; + int acoef; + int bcoef; + int i; + int i1; + int iCol; + char options_range[8]; + boolean_T c_expl_temp; + boolean_T d_expl_temp; + boolean_T e_expl_temp; + boolean_T f_expl_temp; + boolean_T g_expl_temp; + boolean_T h_expl_temp; + std::copy(&x[0], &x[264600], &r.f1[0]); + if (varargin_1.size(0) == 0) { + hopSize = std::trunc((7.0 * varargin_2 + 264600.0) / 8.0); + hamming(hopSize, win); + } else if (varargin_1.size(0) > 1) { + hopSize = varargin_1.size(0); + win.set_size(varargin_1.size(0)); + bcoef = varargin_1.size(0); + for (i = 0; i < bcoef; i++) { + win[i] = varargin_1[i]; + } + } else { + hamming(varargin_1[0], win); + hopSize = win.size(0); + } + signal::internal::spectral::welch_options( + hopSize, &options_nfft, &expl_temp, &b_expl_temp, &c_expl_temp, + &d_expl_temp, &e_expl_temp, &f_expl_temp, &g_expl_temp, &h_expl_temp, + options_range); + hopSize = static_cast(win.size(0)) - varargin_2; + i = static_cast(std::trunc((264600.0 - varargin_2) / hopSize)); + xin.set_size(win.size(0), i); + bcoef = win.size(0) * + static_cast(std::trunc((264600.0 - varargin_2) / hopSize)); + for (i1 = 0; i1 < bcoef; i1++) { + xin[i1] = 0.0; + } + for (iCol = 0; iCol < i; iCol++) { + expl_temp = hopSize * ((static_cast(iCol) + 1.0) - 1.0); + b_expl_temp = static_cast(win.size(0)) + expl_temp; + if (expl_temp + 1.0 > b_expl_temp) { + i1 = 0; + acoef = 0; + } else { + i1 = static_cast(expl_temp + 1.0) - 1; + acoef = static_cast(b_expl_temp); + } + bcoef = acoef - i1; + for (acoef = 0; acoef < bcoef; acoef++) { + xin[acoef + xin.size(0) * iCol] = r.f1[i1 + acoef]; + } + } + bcoef = xin.size(0); + iCol = win.size(0); + if (bcoef <= iCol) { + iCol = bcoef; + } + if (xin.size(0) == 1) { + iCol = win.size(0); + } else if (win.size(0) == 1) { + iCol = xin.size(0); + } else if (win.size(0) == xin.size(0)) { + iCol = win.size(0); + } + r1.set_size(iCol, xin.size(1)); + bcoef = xin.size(0); + iCol = win.size(0); + if (bcoef <= iCol) { + iCol = bcoef; + } + if (xin.size(0) == 1) { + iCol = win.size(0); + } else if (win.size(0) == 1) { + iCol = xin.size(0); + } else if (win.size(0) == xin.size(0)) { + iCol = win.size(0); + } + if ((iCol != 0) && (xin.size(1) != 0)) { + bcoef = (xin.size(1) != 1); + i = xin.size(1) - 1; + for (int k{0}; k <= i; k++) { + int b_bcoef; + iCol = bcoef * k; + acoef = (win.size(0) != 1); + b_bcoef = (xin.size(0) != 1); + i1 = r1.size(0) - 1; + for (int b_k{0}; b_k <= i1; b_k++) { + r1[b_k + r1.size(0) * k] = + win[acoef * b_k] * xin[b_bcoef * b_k + xin.size(0) * iCol]; + } + } + } + computeDFT(r1, options_nfft, varargout_1, win); + formatSpectrogram(varargout_1, win, options_nfft, options_range); +} + +// +// Arguments : const double x[220500] +// const ::coder::array &varargin_1 +// double varargin_2 +// ::coder::array &varargout_1 +// Return Type : void +// +void spectrogram(const double x[220500], + const ::coder::array &varargin_1, + double varargin_2, ::coder::array &varargout_1) +{ + static cell_wrap_6 r; + array r1; + array xin; + array win; + double b_expl_temp; + double expl_temp; + double hopSize; + double options_nfft; + int acoef; + int bcoef; + int i; + int i1; + int iCol; + char options_range[8]; + boolean_T c_expl_temp; + boolean_T d_expl_temp; + boolean_T e_expl_temp; + boolean_T f_expl_temp; + boolean_T g_expl_temp; + boolean_T h_expl_temp; + std::copy(&x[0], &x[220500], &r.f1[0]); + if (varargin_1.size(0) == 0) { + hopSize = std::trunc((7.0 * varargin_2 + 220500.0) / 8.0); + hamming(hopSize, win); + } else if (varargin_1.size(0) > 1) { + hopSize = varargin_1.size(0); + win.set_size(varargin_1.size(0)); + bcoef = varargin_1.size(0); + for (i = 0; i < bcoef; i++) { + win[i] = varargin_1[i]; + } + } else { + hamming(varargin_1[0], win); + hopSize = win.size(0); + } + signal::internal::spectral::welch_options( + hopSize, &options_nfft, &expl_temp, &b_expl_temp, &c_expl_temp, + &d_expl_temp, &e_expl_temp, &f_expl_temp, &g_expl_temp, &h_expl_temp, + options_range); + hopSize = static_cast(win.size(0)) - varargin_2; + i = static_cast(std::trunc((220500.0 - varargin_2) / hopSize)); + xin.set_size(win.size(0), i); + bcoef = win.size(0) * + static_cast(std::trunc((220500.0 - varargin_2) / hopSize)); + for (i1 = 0; i1 < bcoef; i1++) { + xin[i1] = 0.0; + } + for (iCol = 0; iCol < i; iCol++) { + expl_temp = hopSize * ((static_cast(iCol) + 1.0) - 1.0); + b_expl_temp = static_cast(win.size(0)) + expl_temp; + if (expl_temp + 1.0 > b_expl_temp) { + i1 = 0; + acoef = 0; + } else { + i1 = static_cast(expl_temp + 1.0) - 1; + acoef = static_cast(b_expl_temp); + } + bcoef = acoef - i1; + for (acoef = 0; acoef < bcoef; acoef++) { + xin[acoef + xin.size(0) * iCol] = r.f1[i1 + acoef]; + } + } + bcoef = xin.size(0); + iCol = win.size(0); + if (bcoef <= iCol) { + iCol = bcoef; + } + if (xin.size(0) == 1) { + iCol = win.size(0); + } else if (win.size(0) == 1) { + iCol = xin.size(0); + } else if (win.size(0) == xin.size(0)) { + iCol = win.size(0); + } + r1.set_size(iCol, xin.size(1)); + bcoef = xin.size(0); + iCol = win.size(0); + if (bcoef <= iCol) { + iCol = bcoef; + } + if (xin.size(0) == 1) { + iCol = win.size(0); + } else if (win.size(0) == 1) { + iCol = xin.size(0); + } else if (win.size(0) == xin.size(0)) { + iCol = win.size(0); + } + if ((iCol != 0) && (xin.size(1) != 0)) { + bcoef = (xin.size(1) != 1); + i = xin.size(1) - 1; + for (int k{0}; k <= i; k++) { + int b_bcoef; + iCol = bcoef * k; + acoef = (win.size(0) != 1); + b_bcoef = (xin.size(0) != 1); + i1 = r1.size(0) - 1; + for (int b_k{0}; b_k <= i1; b_k++) { + r1[b_k + r1.size(0) * k] = + win[acoef * b_k] * xin[b_bcoef * b_k + xin.size(0) * iCol]; + } + } + } + computeDFT(r1, options_nfft, varargout_1, win); + formatSpectrogram(varargout_1, win, options_nfft, options_range); +} + +} // namespace coder + +// +// File trailer for spectrogram.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/spectrogram.h b/dereverbrate/dereveb_c/spectrogram.h new file mode 100644 index 0000000..83404a5 --- /dev/null +++ b/dereverbrate/dereveb_c/spectrogram.h @@ -0,0 +1,35 @@ +// +// File: spectrogram.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef SPECTROGRAM_H +#define SPECTROGRAM_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void b_spectrogram(const double x[264600], + const ::coder::array &varargin_1, + double varargin_2, ::coder::array &varargout_1); + +void spectrogram(const double x[220500], + const ::coder::array &varargin_1, + double varargin_2, ::coder::array &varargout_1); + +} // namespace coder + +#endif +// +// File trailer for spectrogram.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/sum.cpp b/dereverbrate/dereveb_c/sum.cpp new file mode 100644 index 0000000..bf07a8d --- /dev/null +++ b/dereverbrate/dereveb_c/sum.cpp @@ -0,0 +1,48 @@ +// +// File: sum.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "sum.h" +#include "rt_nonfinite.h" +#include "coder_array.h" + +// Function Definitions +// +// Arguments : const ::coder::array &x +// ::coder::array &y +// Return Type : void +// +namespace coder { +void sum(const ::coder::array &x, ::coder::array &y) +{ + if (x.size(0) == 0) { + y.set_size(0); + } else { + int vstride; + int xj; + vstride = x.size(0); + y.set_size(x.size(0)); + for (xj = 0; xj < vstride; xj++) { + y[xj] = x[xj]; + } + for (int k{0}; k < 399; k++) { + int xoffset; + xoffset = (k + 1) * vstride; + for (xj = 0; xj < vstride; xj++) { + y[xj] = y[xj] + x[xoffset + xj]; + } + } + } +} + +} // namespace coder + +// +// File trailer for sum.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/sum.h b/dereverbrate/dereveb_c/sum.h new file mode 100644 index 0000000..c54aad0 --- /dev/null +++ b/dereverbrate/dereveb_c/sum.h @@ -0,0 +1,29 @@ +// +// File: sum.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef SUM_H +#define SUM_H + +// Include Files +#include "rtwtypes.h" +#include "coder_array.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +void sum(const ::coder::array &x, ::coder::array &y); + +} + +#endif +// +// File trailer for sum.h +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/welchparse.cpp b/dereverbrate/dereveb_c/welchparse.cpp new file mode 100644 index 0000000..4b93fd7 --- /dev/null +++ b/dereverbrate/dereveb_c/welchparse.cpp @@ -0,0 +1,127 @@ +// +// File: welchparse.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +// Include Files +#include "welchparse.h" +#include "rt_nonfinite.h" +#include +#include + +// Function Declarations +static double rt_powd_snf(double u0, double u1); + +// Function Definitions +// +// Arguments : double u0 +// double u1 +// Return Type : double +// +static double rt_powd_snf(double u0, double u1) +{ + double y; + if (std::isnan(u0) || std::isnan(u1)) { + y = rtNaN; + } else { + double d; + double d1; + d = std::abs(u0); + d1 = std::abs(u1); + if (std::isinf(u1)) { + if (d == 1.0) { + y = 1.0; + } else if (d > 1.0) { + if (u1 > 0.0) { + y = rtInf; + } else { + y = 0.0; + } + } else if (u1 > 0.0) { + y = 0.0; + } else { + y = rtInf; + } + } else if (d1 == 0.0) { + y = 1.0; + } else if (d1 == 1.0) { + if (u1 > 0.0) { + y = u0; + } else { + y = 1.0 / u0; + } + } else if (u1 == 2.0) { + y = u0 * u0; + } else if ((u1 == 0.5) && (u0 >= 0.0)) { + y = std::sqrt(u0); + } else if ((u0 < 0.0) && (u1 > std::floor(u1))) { + y = rtNaN; + } else { + y = std::pow(u0, u1); + } + } + return y; +} + +// +// Arguments : double N +// double *options1_nfft +// double *options1_Fs +// double *options1_conflevel +// boolean_T *options1_average +// boolean_T *options1_maxhold +// boolean_T *options1_minhold +// boolean_T *options1_MIMO +// boolean_T *options1_isNFFTSingle +// boolean_T *options1_centerdc +// char options1_range[8] +// Return Type : void +// +namespace coder { +namespace signal { +namespace internal { +namespace spectral { +void welch_options(double N, double *options1_nfft, double *options1_Fs, + double *options1_conflevel, boolean_T *options1_average, + boolean_T *options1_maxhold, boolean_T *options1_minhold, + boolean_T *options1_MIMO, boolean_T *options1_isNFFTSingle, + boolean_T *options1_centerdc, char options1_range[8]) +{ + static const char cv[8]{'o', 'n', 'e', 's', 'i', 'd', 'e', 'd'}; + double absn; + int eint; + for (int i{0}; i < 8; i++) { + options1_range[i] = cv[i]; + } + absn = std::abs(N); + if ((!std::isinf(absn)) && (!std::isnan(absn))) { + double f; + f = frexp(absn, &eint); + absn = eint; + if (f == 0.5) { + absn = static_cast(eint) - 1.0; + } + } + *options1_nfft = std::fmax(256.0, rt_powd_snf(2.0, absn)); + *options1_Fs = rtNaN; + *options1_average = true; + *options1_maxhold = false; + *options1_minhold = false; + *options1_MIMO = false; + *options1_conflevel = rtNaN; + *options1_isNFFTSingle = false; + *options1_centerdc = false; +} + +} // namespace spectral +} // namespace internal +} // namespace signal +} // namespace coder + +// +// File trailer for welchparse.cpp +// +// [EOF] +// diff --git a/dereverbrate/dereveb_c/welchparse.h b/dereverbrate/dereveb_c/welchparse.h new file mode 100644 index 0000000..97d4421 --- /dev/null +++ b/dereverbrate/dereveb_c/welchparse.h @@ -0,0 +1,38 @@ +// +// File: welchparse.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 22-Mar-2023 20:50:16 +// + +#ifndef WELCHPARSE_H +#define WELCHPARSE_H + +// Include Files +#include "rtwtypes.h" +#include "omp.h" +#include +#include + +// Function Declarations +namespace coder { +namespace signal { +namespace internal { +namespace spectral { +void welch_options(double N, double *options1_nfft, double *options1_Fs, + double *options1_conflevel, boolean_T *options1_average, + boolean_T *options1_maxhold, boolean_T *options1_minhold, + boolean_T *options1_MIMO, boolean_T *options1_isNFFTSingle, + boolean_T *options1_centerdc, char options1_range[8]); + +} +} // namespace internal +} // namespace signal +} // namespace coder + +#endif +// +// File trailer for welchparse.h +// +// [EOF] +// diff --git a/dereverbrate/inverse/.gitignore b/dereverbrate/inverse/.gitignore new file mode 100644 index 0000000..9c66351 --- /dev/null +++ b/dereverbrate/inverse/.gitignore @@ -0,0 +1,22 @@ +*.asv +*.m~ +*.mex* +*.o +*.obj +*.dll +*.so +*.dylib +*.a +*.lib +*.exe +*.map +*.rsp +*.tmw +*.mat +sil/ +interface/_coder_*_info.* +coderassumptions/ +target/ +build/ +debug/ +*.slxc diff --git a/dereverbrate/inverse/CMakeLists.txt b/dereverbrate/inverse/CMakeLists.txt new file mode 100644 index 0000000..f491d5a --- /dev/null +++ b/dereverbrate/inverse/CMakeLists.txt @@ -0,0 +1,10 @@ +# 全局配置 +#add_definitions(-DWEBRTC_POSIX) + +# 头文件 +include_directories(./) + +# 源文件 +file(GLOB INVERSE_SRC ./*.cpp) + +add_library(inverse STATIC ${INVERSE_SRC} ) \ No newline at end of file diff --git a/dereverbrate/inverse/_clang-format b/dereverbrate/inverse/_clang-format new file mode 100644 index 0000000..55a16f7 --- /dev/null +++ b/dereverbrate/inverse/_clang-format @@ -0,0 +1,27 @@ +BasedOnStyle: LLVM +Language: Cpp +IndentWidth: 2 +ColumnLimit: 80 +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +CommentPragmas: '^(Return Type|Arguments)\s*' +DeriveLineEnding : true +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + SplitEmptyFunction: true + SplitEmptyRecord: true diff --git a/dereverbrate/inverse/codedescriptor.dmr b/dereverbrate/inverse/codedescriptor.dmr new file mode 100644 index 0000000..6188e98 Binary files /dev/null and b/dereverbrate/inverse/codedescriptor.dmr differ diff --git a/dereverbrate/inverse/defines.txt b/dereverbrate/inverse/defines.txt new file mode 100644 index 0000000..14e5c3c --- /dev/null +++ b/dereverbrate/inverse/defines.txt @@ -0,0 +1 @@ +MODEL=inverse diff --git a/dereverbrate/inverse/html/report.mldatx b/dereverbrate/inverse/html/report.mldatx new file mode 100644 index 0000000..a653c40 Binary files /dev/null and b/dereverbrate/inverse/html/report.mldatx differ diff --git a/dereverbrate/inverse/inverse.cpp b/dereverbrate/inverse/inverse.cpp new file mode 100644 index 0000000..774b993 --- /dev/null +++ b/dereverbrate/inverse/inverse.cpp @@ -0,0 +1,38 @@ +// +// File: inverse.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +// Include Files +#include "inverse.h" + +// Function Definitions +// +// 鐭╅樀姹傞 +// +// Arguments : const double src[6] +// double n +// double en[6] +// Return Type : void +// +void inverse(const double src[6], double n, double en[6]) +{ + int i; + for (i = 0; i < 6; i++) { + en[i] = src[i]; + } + i = static_cast(n); + for (int b_i{0}; b_i < i; b_i++) { + double d; + d = src[b_i]; + en[b_i] = d * d; + } +} + +// +// File trailer for inverse.cpp +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse.h b/dereverbrate/inverse/inverse.h new file mode 100644 index 0000000..8ddc144 --- /dev/null +++ b/dereverbrate/inverse/inverse.h @@ -0,0 +1,24 @@ +// +// File: inverse.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +#ifndef INVERSE_H +#define INVERSE_H + +// Include Files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +void inverse(const double src[6], double n, double en[6]); + +#endif +// +// File trailer for inverse.h +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_data.cpp b/dereverbrate/inverse/inverse_data.cpp new file mode 100644 index 0000000..7009ef6 --- /dev/null +++ b/dereverbrate/inverse/inverse_data.cpp @@ -0,0 +1,15 @@ +// +// File: inverse_data.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +// Include Files +#include "inverse_data.h" + +// +// File trailer for inverse_data.cpp +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_data.h b/dereverbrate/inverse/inverse_data.h new file mode 100644 index 0000000..3a5a325 --- /dev/null +++ b/dereverbrate/inverse/inverse_data.h @@ -0,0 +1,21 @@ +// +// File: inverse_data.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +#ifndef INVERSE_DATA_H +#define INVERSE_DATA_H + +// Include Files +#include "rtwtypes.h" +#include +#include + +#endif +// +// File trailer for inverse_data.h +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_initialize.cpp b/dereverbrate/inverse/inverse_initialize.cpp new file mode 100644 index 0000000..634fcc6 --- /dev/null +++ b/dereverbrate/inverse/inverse_initialize.cpp @@ -0,0 +1,24 @@ +// +// File: inverse_initialize.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +// Include Files +#include "inverse_initialize.h" + +// Function Definitions +// +// Arguments : void +// Return Type : void +// +void inverse_initialize() +{ +} + +// +// File trailer for inverse_initialize.cpp +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_initialize.h b/dereverbrate/inverse/inverse_initialize.h new file mode 100644 index 0000000..6d5ccde --- /dev/null +++ b/dereverbrate/inverse/inverse_initialize.h @@ -0,0 +1,24 @@ +// +// File: inverse_initialize.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +#ifndef INVERSE_INITIALIZE_H +#define INVERSE_INITIALIZE_H + +// Include Files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +extern void inverse_initialize(); + +#endif +// +// File trailer for inverse_initialize.h +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_rtw.mk b/dereverbrate/inverse/inverse_rtw.mk new file mode 100644 index 0000000..5b25999 --- /dev/null +++ b/dereverbrate/inverse/inverse_rtw.mk @@ -0,0 +1,365 @@ +########################################################################### +## Makefile generated for component 'inverse'. +## +## Makefile : inverse_rtw.mk +## Generated on : Tue Mar 21 14:41:06 2023 +## Final product: ./inverse.a +## Product type : static-library +## +########################################################################### + +########################################################################### +## MACROS +########################################################################### + +# Macro Descriptions: +# PRODUCT_NAME Name of the system to build +# MAKEFILE Name of this makefile +# MODELLIB Static library target + +PRODUCT_NAME = inverse +MAKEFILE = inverse_rtw.mk +MATLAB_ROOT = /Applications/MATLAB_R2021b.app +MATLAB_BIN = /Applications/MATLAB_R2021b.app/bin +MATLAB_ARCH_BIN = $(MATLAB_BIN)/maci64 +START_DIR = /Volumes/T7_2/starmaker_files/闊虫晥鎻愬彇绠楁硶/dereverberate +TGT_FCN_LIB = ISO_C++11 +SOLVER_OBJ = +CLASSIC_INTERFACE = 0 +MODEL_HAS_DYNAMICALLY_LOADED_SFCNS = +RELATIVE_PATH_TO_ANCHOR = ../../.. +C_STANDARD_OPTS = -fno-common -fexceptions +CPP_STANDARD_OPTS = -std=c++14 -fno-common -fexceptions +MODELLIB = inverse.a + +########################################################################### +## TOOLCHAIN SPECIFICATIONS +########################################################################### + +# Toolchain Name: Clang v3.1 | gmake (64-bit Mac) +# Supported Version(s): 3.1 +# ToolchainInfo Version: 2021b +# Specification Revision: 1.0 +# +#------------------------------------------- +# Macros assumed to be defined elsewhere +#------------------------------------------- + +# C_STANDARD_OPTS +# CPP_STANDARD_OPTS + +#----------- +# MACROS +#----------- + +ARCHS = x86_64 +XCODE_SDK_VER = $(shell perl $(MATLAB_ROOT)/rtw/c/tools/macsdkver.pl) +XCODE_SDK = MacOSX$(XCODE_SDK_VER).sdk +XCODE_DEVEL_DIR = $(shell xcode-select -print-path) +XCODE_SDK_ROOT = $(XCODE_DEVEL_DIR)/Platforms/MacOSX.platform/Developer/SDKs/$(XCODE_SDK) + +TOOLCHAIN_SRCS = +TOOLCHAIN_INCS = +TOOLCHAIN_LIBS = + +#------------------------ +# BUILD TOOL COMMANDS +#------------------------ + +# C Compiler: Clang C Compiler +CC = xcrun clang + +# Linker: Clang Linker +LD = xcrun clang++ + +# C++ Compiler: Clang C++ Compiler +CPP = xcrun clang++ + +# C++ Linker: Clang C++ Linker +CPP_LD = xcrun clang++ + +# Archiver: Clang Archiver +AR = xcrun ar + +# MEX Tool: MEX Tool +MEX_PATH = $(MATLAB_ARCH_BIN) +MEX = "$(MEX_PATH)/mex" + +# Download: Download +DOWNLOAD = + +# Execute: Execute +EXECUTE = $(PRODUCT) + +# Builder: GMAKE Utility +MAKE_PATH = %MATLAB%/bin/maci64 +MAKE = "$(MAKE_PATH)/gmake" + + +#------------------------- +# Directives/Utilities +#------------------------- + +CDEBUG = -g +C_OUTPUT_FLAG = -o +LDDEBUG = -g +OUTPUT_FLAG = -o +CPPDEBUG = -g +CPP_OUTPUT_FLAG = -o +CPPLDDEBUG = -g +OUTPUT_FLAG = -o +ARDEBUG = +STATICLIB_OUTPUT_FLAG = +MEX_DEBUG = -g +RM = @rm -f +ECHO = @echo +MV = @mv +RUN = + +#-------------------------------------- +# "Faster Runs" Build Configuration +#-------------------------------------- + +ARFLAGS = ruvs +CFLAGS = -c -isysroot $(XCODE_SDK_ROOT) -arch $(ARCHS) $(C_STANDARD_OPTS) -mmacosx-version-min=10.15 \ + -O3 +CPPFLAGS = -c -isysroot $(XCODE_SDK_ROOT) -arch $(ARCHS) $(CPP_STANDARD_OPTS) -mmacosx-version-min=10.15 \ + -O3 +CPP_LDFLAGS = -arch $(ARCHS) -isysroot $(XCODE_SDK_ROOT) -Wl,-rpath,@executable_path -Wl,-rpath,@executable_path/$(RELATIVE_PATH_TO_ANCHOR) +CPP_SHAREDLIB_LDFLAGS = -dynamiclib -install_name @rpath/$(notdir $(PRODUCT)) -isysroot $(XCODE_SDK_ROOT) \ + -Wl,$(LD_NAMESPACE) $(LD_UNDEFS) +DOWNLOAD_FLAGS = +EXECUTE_FLAGS = +LDFLAGS = -arch $(ARCHS) -isysroot $(XCODE_SDK_ROOT) -Wl,-rpath,@executable_path -Wl,-rpath,@executable_path/$(RELATIVE_PATH_TO_ANCHOR) +MEX_CPPFLAGS = +MEX_CPPLDFLAGS = +MEX_CFLAGS = +MEX_LDFLAGS = +MAKE_FLAGS = -f $(MAKEFILE) +SHAREDLIB_LDFLAGS = -dynamiclib -install_name @rpath/$(notdir $(PRODUCT)) -isysroot $(XCODE_SDK_ROOT) \ + -Wl,$(LD_NAMESPACE) $(LD_UNDEFS) + + + +########################################################################### +## OUTPUT INFO +########################################################################### + +PRODUCT = ./inverse.a +PRODUCT_TYPE = "static-library" +BUILD_TYPE = "Static Library" + +########################################################################### +## INCLUDE PATHS +########################################################################### + +INCLUDES_BUILDINFO = -I$(START_DIR)/codegen/lib/inverse -I$(START_DIR) -I$(MATLAB_ROOT)/extern/include + +INCLUDES = $(INCLUDES_BUILDINFO) + +########################################################################### +## DEFINES +########################################################################### + +DEFINES_CUSTOM = +DEFINES_STANDARD = -DMODEL=inverse + +DEFINES = $(DEFINES_CUSTOM) $(DEFINES_STANDARD) + +########################################################################### +## SOURCE FILES +########################################################################### + +SRCS = $(START_DIR)/codegen/lib/inverse/inverse_data.cpp $(START_DIR)/codegen/lib/inverse/inverse_initialize.cpp $(START_DIR)/codegen/lib/inverse/inverse_terminate.cpp $(START_DIR)/codegen/lib/inverse/inverse.cpp + +ALL_SRCS = $(SRCS) + +########################################################################### +## OBJECTS +########################################################################### + +OBJS = inverse_data.o inverse_initialize.o inverse_terminate.o inverse.o + +ALL_OBJS = $(OBJS) + +########################################################################### +## PREBUILT OBJECT FILES +########################################################################### + +PREBUILT_OBJS = + +########################################################################### +## LIBRARIES +########################################################################### + +LIBS = + +########################################################################### +## SYSTEM LIBRARIES +########################################################################### + +SYSTEM_LIBS = -lm -lstdc++ + +########################################################################### +## ADDITIONAL TOOLCHAIN FLAGS +########################################################################### + +#--------------- +# C Compiler +#--------------- + +CFLAGS_BASIC = $(DEFINES) $(INCLUDES) + +CFLAGS += $(CFLAGS_BASIC) + +#----------------- +# C++ Compiler +#----------------- + +CPPFLAGS_BASIC = $(DEFINES) $(INCLUDES) + +CPPFLAGS += $(CPPFLAGS_BASIC) + +########################################################################### +## INLINED COMMANDS +########################################################################### + +########################################################################### +## PHONY TARGETS +########################################################################### + +.PHONY : all build clean info prebuild download execute + + +all : build + @echo "### Successfully generated all binary outputs." + + +build : prebuild $(PRODUCT) + + +prebuild : + + +download : $(PRODUCT) + + +execute : download + + +########################################################################### +## FINAL TARGET +########################################################################### + +#--------------------------------- +# Create a static library +#--------------------------------- + +$(PRODUCT) : $(OBJS) $(PREBUILT_OBJS) + @echo "### Creating static library "$(PRODUCT)" ..." + $(AR) $(ARFLAGS) $(PRODUCT) $(OBJS) + @echo "### Created: $(PRODUCT)" + + +########################################################################### +## INTERMEDIATE TARGETS +########################################################################### + +#--------------------- +# SOURCE-TO-OBJECT +#--------------------- + +%.o : %.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : %.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +%.o : $(RELATIVE_PATH_TO_ANCHOR)/%.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : $(RELATIVE_PATH_TO_ANCHOR)/%.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/codegen/lib/inverse/%.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/codegen/lib/inverse/%.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/%.c + $(CC) $(CFLAGS) -o "$@" "$<" + + +%.o : $(START_DIR)/%.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +inverse_data.o : $(START_DIR)/codegen/lib/inverse/inverse_data.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +inverse_initialize.o : $(START_DIR)/codegen/lib/inverse/inverse_initialize.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +inverse_terminate.o : $(START_DIR)/codegen/lib/inverse/inverse_terminate.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +inverse.o : $(START_DIR)/codegen/lib/inverse/inverse.cpp + $(CPP) $(CPPFLAGS) -o "$@" "$<" + + +########################################################################### +## DEPENDENCIES +########################################################################### + +$(ALL_OBJS) : rtw_proj.tmw $(MAKEFILE) + + +########################################################################### +## MISCELLANEOUS TARGETS +########################################################################### + +info : + @echo "### PRODUCT = $(PRODUCT)" + @echo "### PRODUCT_TYPE = $(PRODUCT_TYPE)" + @echo "### BUILD_TYPE = $(BUILD_TYPE)" + @echo "### INCLUDES = $(INCLUDES)" + @echo "### DEFINES = $(DEFINES)" + @echo "### ALL_SRCS = $(ALL_SRCS)" + @echo "### ALL_OBJS = $(ALL_OBJS)" + @echo "### LIBS = $(LIBS)" + @echo "### MODELREF_LIBS = $(MODELREF_LIBS)" + @echo "### SYSTEM_LIBS = $(SYSTEM_LIBS)" + @echo "### TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS)" + @echo "### CFLAGS = $(CFLAGS)" + @echo "### LDFLAGS = $(LDFLAGS)" + @echo "### SHAREDLIB_LDFLAGS = $(SHAREDLIB_LDFLAGS)" + @echo "### CPPFLAGS = $(CPPFLAGS)" + @echo "### CPP_LDFLAGS = $(CPP_LDFLAGS)" + @echo "### CPP_SHAREDLIB_LDFLAGS = $(CPP_SHAREDLIB_LDFLAGS)" + @echo "### ARFLAGS = $(ARFLAGS)" + @echo "### MEX_CFLAGS = $(MEX_CFLAGS)" + @echo "### MEX_CPPFLAGS = $(MEX_CPPFLAGS)" + @echo "### MEX_LDFLAGS = $(MEX_LDFLAGS)" + @echo "### MEX_CPPLDFLAGS = $(MEX_CPPLDFLAGS)" + @echo "### DOWNLOAD_FLAGS = $(DOWNLOAD_FLAGS)" + @echo "### EXECUTE_FLAGS = $(EXECUTE_FLAGS)" + @echo "### MAKE_FLAGS = $(MAKE_FLAGS)" + + +clean : + $(ECHO) "### Deleting all derived files..." + $(RM) $(PRODUCT) + $(RM) $(ALL_OBJS) + $(ECHO) "### Deleted all derived files." + + diff --git a/dereverbrate/inverse/inverse_terminate.cpp b/dereverbrate/inverse/inverse_terminate.cpp new file mode 100644 index 0000000..7299cd9 --- /dev/null +++ b/dereverbrate/inverse/inverse_terminate.cpp @@ -0,0 +1,25 @@ +// +// File: inverse_terminate.cpp +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +// Include Files +#include "inverse_terminate.h" + +// Function Definitions +// +// Arguments : void +// Return Type : void +// +void inverse_terminate() +{ + // (no terminate code required) +} + +// +// File trailer for inverse_terminate.cpp +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_terminate.h b/dereverbrate/inverse/inverse_terminate.h new file mode 100644 index 0000000..8dba6a4 --- /dev/null +++ b/dereverbrate/inverse/inverse_terminate.h @@ -0,0 +1,24 @@ +// +// File: inverse_terminate.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +#ifndef INVERSE_TERMINATE_H +#define INVERSE_TERMINATE_H + +// Include Files +#include "rtwtypes.h" +#include +#include + +// Function Declarations +extern void inverse_terminate(); + +#endif +// +// File trailer for inverse_terminate.h +// +// [EOF] +// diff --git a/dereverbrate/inverse/inverse_types.h b/dereverbrate/inverse/inverse_types.h new file mode 100644 index 0000000..8886889 --- /dev/null +++ b/dereverbrate/inverse/inverse_types.h @@ -0,0 +1,19 @@ +// +// File: inverse_types.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +#ifndef INVERSE_TYPES_H +#define INVERSE_TYPES_H + +// Include Files +#include "rtwtypes.h" + +#endif +// +// File trailer for inverse_types.h +// +// [EOF] +// diff --git a/dereverbrate/inverse/rtwtypes.h b/dereverbrate/inverse/rtwtypes.h new file mode 100644 index 0000000..e26fbfb --- /dev/null +++ b/dereverbrate/inverse/rtwtypes.h @@ -0,0 +1,45 @@ +// +// File: rtwtypes.h +// +// MATLAB Coder version : 5.3 +// C/C++ source code generated on : 21-Mar-2023 14:41:00 +// + +#ifndef RTWTYPES_H +#define RTWTYPES_H + +/*=======================================================================* + * Fixed width word size data types: * + * int64_T - signed 64 bit integers * + * uint64_T - unsigned 64 bit integers * + *=======================================================================*/ + +#if defined(__APPLE__) +#ifndef INT64_T +#define INT64_T long +#define FMT64 "l" +#if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +#define INT_TYPE_64_IS_LONG +#endif +#endif +#endif + +#if defined(__APPLE__) +#ifndef UINT64_T +#define UINT64_T unsigned long +#define FMT64 "l" +#if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +#define INT_TYPE_64_IS_LONG +#endif +#endif +#endif + +// Include Files +#include "tmwtypes.h" + +#endif +// +// File trailer for rtwtypes.h +// +// [EOF] +// diff --git a/dereverbrate/main.cpp b/dereverbrate/main.cpp new file mode 100644 index 0000000..3c39327 --- /dev/null +++ b/dereverbrate/main.cpp @@ -0,0 +1,160 @@ + +#include +#include +//#include +#include +#include +#include + +#include "inverse/inverse.h" //无用文件 +#include "STWaveFile.h" //wav文件 + +#include "./dereveb_c/dereveb_c.h" + +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define min(a,b) (((a) < (b)) ? (a) : (b)) + +int process(short* vocal_buf, short* vc_buf, short* out_buf, int frame_len, int fs){ + + std::string impulseResponse_name = "../audio/stalbans_a_mono_16bit.wav"; // 输出的结果 + + STCWaveFile impulseResponse = STCWaveFile(impulseResponse_name.c_str(), false); + if (!impulseResponse.GetStatus() ) + { + printf("impulseResponse wav read =%s err !!!\n", impulseResponse_name.c_str()); + return -1; + } + int rir_len = impulseResponse.GetTotalFrames() * impulseResponse.GetChannels(); + short *rir_buf = new short[rir_len]; + impulseResponse.ReadFrameAsS16(rir_buf, impulseResponse.GetTotalFrames()); + + /// input double type + double* vocal_buf_double = new double[frame_len]; + double* vc_buf_double = new double[frame_len]; + double* out_buf_double = new double[frame_len]; + double* rir_buf_double = new double[rir_len]; + for(int i=0; i 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)) +# pragma once +#endif + +#ifndef tmwtypes_h +#define tmwtypes_h + +#ifndef __TMWTYPES__ +#define __TMWTYPES__ +/* + * File : tmwtypes.h + * Abstract: + * Data types for use with MATLAB/SIMULINK and the Real-Time Workshop. + * + * When compiling stand-alone model code, data types can be overridden + * via compiler switches. + * + * Define NO_FLOATS to eliminate reference to real_T, etc. + */ + +#ifdef MW_LIBTOOLING +#include "mwstdint.h" +#endif + +#include + +/* __STDC_VERSION__ version check below means "check for a C99 compiler". + + Visual Studio (checked on versions 2015 and 2017) does + not define __STDC_VERSION__, however it has stdbool.h available, + thus a separate check for _MSC_VER below. + */ +#if defined(__APPLE_CC__) \ + || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) \ + || (defined(_MSC_VER) && (_MSC_VER >= 1900)) +#ifndef tmwtypes_do_not_include_stdbool +#include +#endif +#endif + +#define LOGICAL_IS_A_TYPE +#define SPARSE_GENERALIZATION + +#ifdef NO_FLOATS +# define double double_not_allowed +# define float float_not_allowed +#endif /*NO_FLOATS*/ + +#ifndef NO_FLOATS + +#ifndef __MWERKS__ +# ifdef __STDC__ +# include +# else +# ifndef FLT_MANT_DIG +# define FLT_MANT_DIG 24 +# endif +# ifndef DBL_MANT_DIG +# define DBL_MANT_DIG 53 +# endif +# endif +#endif + +#endif /*NO_FLOATS*/ + +/* + * The following data types cannot be overridden when building MEX files. + */ +#ifdef MATLAB_MEX_FILE +# undef CHARACTER_T +# undef INTEGER_T +# undef BOOLEAN_T +# undef REAL_T +# undef TIME_T +#endif + +/* + * The uchar_T, ushort_T and ulong_T types are needed for compilers which do + * not allow defines to be specified, at the command line, with spaces in them. + */ + +typedef unsigned char uchar_T; +typedef unsigned short ushort_T; +typedef unsigned long ulong_T; + +#if (defined(_MSC_VER) && _MSC_VER >= 1500) \ + || defined(__x86_64__) || defined(__LP64__) \ + || defined(__LCC64__) + +typedef unsigned long long ulonglong_T; +#endif + + + +/*=======================================================================* + * Fixed width word size data types: * + * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * + * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * + * real32_T, real64_T - 32 and 64 bit floating point numbers * + *=======================================================================*/ + +/* When used with Real Time Workshop generated code, this + * header file can be used with a variety of compilers. + * + * The compiler could be for an 8 bit embedded processor that + * only had 8 bits per integer and 16 bits per long. + * In that example, a 32 bit integer size is not even available. + * This header file should be robust to that. + * + * For the case of an 8 bit processor, the preprocessor + * may be limited to 16 bit math like its target. That limitation + * would mean that 32 bit comparisons can't be done accurately. + * To increase robustness to this, comparisons are done against + * smaller values first. An inaccurate 32 bit comparison isn't + * attempted if the 16 bit comparison has already succeeded. + * + * Limitations on preprocessor math can also be stricter than + * for the target. There are known cases where a compiler + * targeting processors with 64 bit longs can't do accurate + * preprocessor comparisons on more than 32 bits. + */ + +/* Determine the number of bits for int, long, short, and char. + * If one fails to be determined, set the number of bits to -1 + */ + +#ifndef TMW_BITS_PER_INT +# if INT_MAX == 0x7FL +# define TMW_BITS_PER_INT 8 +# elif INT_MAX == 0x7FFFL +# define TMW_BITS_PER_INT 16 +# elif INT_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_INT 32 +# else +# define TMW_BITS_PER_INT -1 +# endif +#endif + +#ifndef TMW_BITS_PER_LONG +# if LONG_MAX == 0x7FL +# define TMW_BITS_PER_LONG 8 +# elif LONG_MAX == 0x7FFFL +# define TMW_BITS_PER_LONG 16 +# elif LONG_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_LONG 32 +# else +# define TMW_BITS_PER_LONG -1 +# endif +#endif + +#ifndef TMW_BITS_PER_SHRT +# if SHRT_MAX == 0x7FL +# define TMW_BITS_PER_SHRT 8 +# elif SHRT_MAX == 0x7FFFL +# define TMW_BITS_PER_SHRT 16 +# elif SHRT_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_SHRT 32 +# else +# define TMW_BITS_PER_SHRT -1 +# endif +#endif + +#ifndef TMW_BITS_PER_SCHAR +# if SCHAR_MAX == 0x7FL +# define TMW_BITS_PER_SCHAR 8 +# elif SCHAR_MAX == 0x7FFFL +# define TMW_BITS_PER_SCHAR 16 +# elif SCHAR_MAX == 0x7FFFFFFFL +# define TMW_BITS_PER_SCHAR 32 +# else +# define TMW_BITS_PER_SCHAR -1 +# endif +#endif + +#ifndef TMW_CHAR_SIGNED +# if SCHAR_MAX == CHAR_MAX +# define TMW_CHAR_SIGNED 1 +# else +# define TMW_CHAR_SIGNED 0 +# endif +#endif + +/* It is common for one or more of the integer types + * to be the same size. For example, on many embedded + * processors, both shorts and ints are 16 bits. On + * processors used for workstations, it is quite common + * for both int and long to be 32 bits. + * When there is more than one choice for typdef'ing + * a portable type like int16_T or uint32_T, in + * concept, it should not matter which choice is made. + * However, some style guides and some code checking + * tools do identify and complain about seemingly + * irrelevant differences. For example, a code + * checking tool may complain about an implicit + * conversion from int to short even though both + * are 16 bits. To reduce these types of + * complaints, it is best to make int the + * preferred choice when more than one is available. + */ + +#ifndef INT8_T +# if defined(MW_LIBTOOLING) +# define INT8_T int8_t +# elif TMW_BITS_PER_INT == 8 +# define INT8_T int +# elif TMW_BITS_PER_LONG == 8 +# define INT8_T long +# elif TMW_BITS_PER_SCHAR == 8 +# define INT8_T signed char +# elif TMW_BITS_PER_SHRT == 8 +# define INT8_T short +# endif +#endif +#ifdef INT8_T + typedef INT8_T int8_T; +#endif + +#ifndef UINT8_T +# if defined(MW_LIBTOOLING) +# define UINT8_T uint8_t +# elif TMW_BITS_PER_INT == 8 +# define UINT8_T unsigned int +# elif TMW_BITS_PER_LONG == 8 +# define UINT8_T unsigned long +# elif TMW_BITS_PER_SCHAR == 8 +# define UINT8_T unsigned char +# elif TMW_BITS_PER_SHRT == 8 +# define UINT8_T unsigned short +# endif +#endif +#ifdef UINT8_T + typedef UINT8_T uint8_T; +#endif + + +#ifndef INT16_T +# if defined(MW_LIBTOOLING) +# define INT16_T int16_t +# elif TMW_BITS_PER_INT == 16 +# define INT16_T int +# elif TMW_BITS_PER_LONG == 16 +# define INT16_T long +# elif TMW_BITS_PER_SCHAR == 16 +# define INT16_T signed char +# elif TMW_BITS_PER_SHRT == 16 +# define INT16_T short +# endif +#endif +#ifdef INT16_T + typedef INT16_T int16_T; +#endif + + +#ifndef UINT16_T +# if defined(MW_LIBTOOLING) +# define UINT16_T uint16_t +# elif TMW_BITS_PER_INT == 16 +# define UINT16_T unsigned int +# elif TMW_BITS_PER_LONG == 16 +# define UINT16_T unsigned long +# elif TMW_BITS_PER_SCHAR == 16 +# define UINT16_T unsigned char +# elif TMW_BITS_PER_SHRT == 16 +# define UINT16_T unsigned short +# endif +#endif +#ifdef UINT16_T + typedef UINT16_T uint16_T; +#endif + + +#ifndef INT32_T +# if defined(MW_LIBTOOLING) +# define INT32_T int32_t +# elif TMW_BITS_PER_INT == 32 +# define INT32_T int +# elif TMW_BITS_PER_LONG == 32 +# define INT32_T long +# elif TMW_BITS_PER_SCHAR == 32 +# define INT32_T signed char +# elif TMW_BITS_PER_SHRT == 32 +# define INT32_T short +# endif +#endif +#ifdef INT32_T + typedef INT32_T int32_T; +#endif + + +#ifndef UINT32_T +# if defined(MW_LIBTOOLING) +# define UINT32_T uint32_t +# elif TMW_BITS_PER_INT == 32 +# define UINT32_T unsigned int +# elif TMW_BITS_PER_LONG == 32 +# define UINT32_T unsigned long +# elif TMW_BITS_PER_SCHAR == 32 +# define UINT32_T unsigned char +# elif TMW_BITS_PER_SHRT == 32 +# define UINT32_T unsigned short +# endif +#endif +#ifdef UINT32_T + typedef UINT32_T uint32_T; +#endif + +/* The following is used to emulate smaller integer types when only + * larger types are available. For example, compilers for TI C3x/C4x DSPs + * define char and short to be 32 bits, so 8 and 16 bits are not directly + * available. This target is commonly used with RTW rapid prototyping. + * Other DSPs define char to be 16 bits, so 8 bits is not directly + * available. + */ +#ifndef INT8_T +# ifdef INT16_T +# define INT8_T INT16_T + typedef INT8_T int8_T; +# else +# ifdef INT32_T +# define INT8_T INT32_T + typedef INT8_T int8_T; +# endif +# endif +#endif + +#ifndef UINT8_T +# ifdef UINT16_T +# define UINT8_T UINT16_T + typedef UINT8_T uint8_T; +# else +# ifdef UINT32_T +# define UINT8_T UINT32_T + typedef UINT8_T uint8_T; +# endif +# endif +#endif + +#ifndef INT16_T +# ifdef INT32_T +# define INT16_T INT32_T + typedef INT16_T int16_T; +# endif +#endif + +#ifndef UINT16_T +# ifdef UINT32_T +# define UINT16_T UINT32_T + typedef UINT16_T uint16_T; +# endif +#endif + + +#ifndef NO_FLOATS + +#ifndef REAL32_T +# ifndef __MWERKS__ +# if FLT_MANT_DIG >= 23 +# define REAL32_T float +# endif +# else +# define REAL32_T float +# endif +#endif +#ifdef REAL32_T + typedef REAL32_T real32_T; +#endif + + +#ifndef REAL64_T +# ifndef __MWERKS__ +# if DBL_MANT_DIG >= 52 +# define REAL64_T double +# endif +# else +# define REAL64_T double +# endif +#endif +#ifdef REAL64_T + typedef REAL64_T real64_T; +#endif + +#endif /* NO_FLOATS*/ + +/*=======================================================================* + * Fixed width word size data types: * + * int64_T - signed 64 bit integers * + * uint64_T - unsigned 64 bit integers * + *=======================================================================*/ + +# if defined(MW_LIBTOOLING) +# ifdef INT64_T +# undef INT64_T +# endif +# define INT64_T int64_t +# ifdef UINT64_T +# undef UINT64_T +# endif +# define UINT64_T uint64_t +# endif +#if !defined(INT64_T) || !defined(UINT64_T) || !defined(FMT64) +# if defined(__APPLE__) || defined(__clang__) +# ifndef INT64_T +# define INT64_T long long +# endif +# ifndef UINT64_T +# define UINT64_T unsigned long long +# endif +# ifndef FMT64 +# define FMT64 "ll" +# endif +# if defined(__LP64__) && !defined(INT_TYPE_64_IS_LONG) +# define INT_TYPE_64_IS_LONG +# endif +# elif (defined(__x86_64__) || defined(__LP64__))&& !defined(__MINGW64__) +# ifndef INT64_T +# define INT64_T long +# endif +# ifndef UINT64_T +# define UINT64_T unsigned long +# endif +# ifndef FMT64 +# define FMT64 "l" +# endif +# if !defined(INT_TYPE_64_IS_LONG) +# define INT_TYPE_64_IS_LONG +# endif +# elif defined(_MSC_VER) || (defined(__BORLANDC__) && __BORLANDC__ >= 0x530) \ + || (defined(__WATCOMC__) && __WATCOMC__ >= 1100) +# ifndef INT64_T +# define INT64_T __int64 +# endif +# ifndef UINT64_T +# define UINT64_T unsigned __int64 +# endif +# ifndef FMT64 +# define FMT64 "I64" +# endif +# elif defined(__GNUC__) || defined(TMW_ENABLE_INT64) \ + || defined(__LCC64__) +# ifndef INT64_T +# define INT64_T long long +# endif +# ifndef UINT64_T +# define UINT64_T unsigned long long +# endif +# ifndef FMT64 +# define FMT64 "ll" +# endif +# endif + +#endif + +#if defined(INT64_T) +# if defined(__GNUC__) && \ + ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >=9))) + __extension__ +# endif + typedef INT64_T int64_T; +#endif + +#if defined(_WIN64) || (defined(__APPLE__) && defined(__LP64__)) \ + || defined(__x86_64__) \ + || defined(__LP64__) +# define INT_TYPE_64_IS_SUPPORTED +#endif + +#if defined(UINT64_T) +# if defined(__GNUC__) && \ + ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >=9))) + __extension__ +# endif + typedef UINT64_T uint64_T; +#endif + +/*===========================================================================* + * Format string modifiers for using size_t variables in printf statements. * + *===========================================================================*/ + +#ifndef FMT_SIZE_T +# if (defined( __GNUC__ ) || defined(_STDC_C99))&& !defined(__MINGW64__) +# define FMT_SIZE_T "z" +# elif defined (__WATCOMC__) +# define FMT_SIZE_T "l" +# elif defined (_WIN32 ) +# define FMT_SIZE_T "I" +# else +# define FMT_SIZE_T "l" +# endif +#endif + +#ifndef FMT_PTRDIFF_T +# if defined(__APPLE__) +# define FMT_PTRDIFF_T "l" +# elif defined( __GNUC__ ) || defined(_STDC_C99) +# define FMT_PTRDIFF_T "t" +# elif defined (__WATCOMC__) +# define FMT_PTRDIFF_T "l" +# elif defined (_WIN32 ) +# define FMT_PTRDIFF_T "I" +# else +# define FMT_PTRDIFF_T "l" +# endif +#endif + +/*===========================================================================* + * General or logical data types where the word size is not guaranteed. * + * real_T - possible settings include real32_T or real64_T * + * time_T - possible settings include real32_T or real64_T * + * boolean_T * + * char_T * + * int_T * + * uint_T * + * byte_T * + *===========================================================================*/ + +#ifndef NO_FLOATS + +#ifndef REAL_T +# ifdef REAL64_T +# define REAL_T real64_T +# else +# ifdef REAL32_T +# define REAL_T real32_T +# endif +# endif +#endif +#ifdef REAL_T + typedef REAL_T real_T; +#endif + +#ifndef TIME_T +# ifdef REAL_T +# define TIME_T real_T +# endif +#endif +#ifdef TIME_T + typedef TIME_T time_T; +#endif + +#endif /* NO_FLOATS */ + +#ifndef BOOLEAN_T +# if defined(UINT8_T) +# define BOOLEAN_T UINT8_T +# else +# define BOOLEAN_T unsigned int +# endif +#endif +typedef BOOLEAN_T boolean_T; + + +#ifndef CHARACTER_T +# define CHARACTER_T char +#endif +typedef CHARACTER_T char_T; + + +#ifndef INTEGER_T +# define INTEGER_T int +#endif +typedef INTEGER_T int_T; + + +#ifndef UINTEGER_T +# define UINTEGER_T unsigned +#endif +typedef UINTEGER_T uint_T; + + +#ifndef BYTE_T +# define BYTE_T unsigned char +#endif +typedef BYTE_T byte_T; + + +/*===========================================================================* + * Define Complex Structures * + *===========================================================================*/ +#ifndef NO_FLOATS + +#ifndef CREAL32_T +# ifdef REAL32_T + typedef struct { + real32_T re, im; + } creal32_T; +# define CREAL32_T creal32_T +# endif +#endif + +#ifndef CREAL64_T +# ifdef REAL64_T + typedef struct { + real64_T re, im; + } creal64_T; +# define CREAL64_T creal64_T +# endif +#endif + +#ifndef CREAL_T +# ifdef REAL_T + typedef struct { + real_T re, im; + } creal_T; +# define CREAL_T creal_T +# endif +#endif + +#endif /* NO_FLOATS */ + +#ifndef CINT8_T +# ifdef INT8_T + typedef struct { + int8_T re, im; + } cint8_T; +# define CINT8_T cint8_T +# endif +#endif + +#ifndef CUINT8_T +# ifdef UINT8_T + typedef struct { + uint8_T re, im; + } cuint8_T; +# define CUINT8_T cuint8_T +# endif +#endif + +#ifndef CINT16_T +# ifdef INT16_T + typedef struct { + int16_T re, im; + } cint16_T; +# define CINT16_T cint16_T +# endif +#endif + +#ifndef CUINT16_T +# ifdef UINT16_T + typedef struct { + uint16_T re, im; + } cuint16_T; +# define CUINT16_T cuint16_T +# endif +#endif + +#ifndef CINT32_T +# ifdef INT32_T + typedef struct { + int32_T re, im; + } cint32_T; +# define CINT32_T cint32_T +# endif +#endif + +#ifndef CUINT32_T +# ifdef UINT32_T + typedef struct { + uint32_T re, im; + } cuint32_T; +# define CUINT32_T cuint32_T +# endif +#endif + +#ifndef CINT64_T +# ifdef INT64_T + typedef struct { + int64_T re, im; + } cint64_T; +# define CINT64_T cint64_T +# endif +#endif + +#ifndef CUINT64_T +# ifdef UINT64_T + typedef struct { + uint64_T re, im; + } cuint64_T; +# define CUINT64_T cuint64_T +# endif +#endif + +/*=======================================================================* + * Min and Max: * + * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * + * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * + *=======================================================================*/ + +#define MAX_int8_T ((int8_T)(127)) /* 127 */ +#define MIN_int8_T ((int8_T)(-128)) /* -128 */ +#define MAX_uint8_T ((uint8_T)(255)) /* 255 */ +#define MIN_uint8_T ((uint8_T)(0)) + +#define MAX_int16_T ((int16_T)(32767)) /* 32767 */ +#define MIN_int16_T ((int16_T)(-32768)) /* -32768 */ +#define MAX_uint16_T ((uint16_T)(65535)) /* 65535 */ +#define MIN_uint16_T ((uint16_T)(0)) + +#define MAX_int32_T ((int32_T)(2147483647)) /* 2147483647 */ +#define MIN_int32_T ((int32_T)(-2147483647-1)) /* -2147483648 */ +#define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU)) /* 4294967295 */ +#define MIN_uint32_T ((uint32_T)(0)) + +#if defined(_MSC_VER) || (defined(__BORLANDC__) && __BORLANDC__ >= 0x530) \ + || (defined(__WATCOMC__) && __WATCOMC__ >= 1100) \ + || defined(__LCC64__) +# ifdef INT64_T +# define MAX_int64_T ((int64_T)(9223372036854775807LL)) +# define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL)) +# endif +# ifdef UINT64_T +# define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL)) +# define MIN_uint64_T ((uint64_T)(0)) +# endif +#else +# ifdef INT64_T +# ifdef INT_TYPE_64_IS_LONG +# define MAX_int64_T ((int64_T)(9223372036854775807L)) +# define MIN_int64_T ((int64_T)(-9223372036854775807L-1L)) +# else +# define MAX_int64_T ((int64_T)(9223372036854775807LL)) +# define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL)) +# endif +# endif +# ifdef UINT64_T +# ifdef INT_TYPE_64_IS_LONG +# define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFUL)) +# define MIN_uint64_T ((uint64_T)(0)) +# else +# define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL)) +# define MIN_uint64_T ((uint64_T)(0)) +# endif +# endif +#endif + +#if (defined(_MSC_VER) && !defined(__clang__)) + +/* Conversion from unsigned __int64 to double is not implemented in Visual Studio + * and results in a compile error, thus the value must first be cast to + * signed __int64, and then to double. + * + * If the 64 bit int value is greater than 2^63-1, which is the signed int64 max, + * the macro below provides a workaround for casting a uint64 value to a double + * in windows. + */ +# define uint64_to_double(u) ( ((u) > _I64_MAX) ? \ + (double)(__int64)((u) - _I64_MAX - 1) + (double)_I64_MAX + 1: \ + (double)(__int64)(u) ) + +/* The following inline function should only be used in the macro double_to_uint64, + * as it only handles the specfic range of double between 2^63 and 2^64-1 */ +__forceinline +uint64_T double_to_uint64_helper(double d) { + union double_to_uint64_union_type { + double dd; + uint64_T i64; + } di; + di.dd = d; + return (((di.i64 & 0x000fffffffffffff) | 0x0010000000000000) << 11); +} + +/* The largest double value that can be cast to uint64 in windows is the + * signed int64 max, which is 2^63-1. The macro below provides + * a workaround for casting large double values to uint64 in windows. + */ +/* The magic number 18446744073709551616.0 is 2^64 */ +/* The magic number 9223372036854775808.0 is 2^63 */ +# define double_to_uint64(d) ( ((d) >= 18446744073709551616.0) ? \ + 0xffffffffffffffffULL : \ + ((d) >= 0.0) ? \ + ((d) >= 9223372036854775808.0) ? \ + double_to_uint64_helper(d) : \ + (unsigned __int64)(d) : \ + 0ULL ) +#else +# define uint64_to_double(u) ((double)(u)) +# if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__TICCSC__) +/* double_to_uint64 defined only for MSVC and UNIX */ +# else +# define double_to_uint64(d) ( ((d) >= 18446744073709551616.0) ? \ + (unsigned long long) 0xffffffffffffffffULL : \ + ((d) >= 0) ? (unsigned long long)(d) : (unsigned long long) 0 ) +# endif +#endif + +#if !defined(__cplusplus) && !defined(__bool_true_false_are_defined) + +#ifndef _bool_T +#define _bool_T + +typedef boolean_T bool; + +#ifndef false +#define false (0) +#endif +#ifndef true +#define true (1) +#endif + +#endif /* _bool_T */ + +#endif /* !__cplusplus */ + +/* + * This software assumes that the code is being compiled on a target using a + * 2's complement representation for signed integer values. + */ +#if ((SCHAR_MIN + 1) != -SCHAR_MAX) +#error "This code must be compiled using a 2's complement representation for signed integer values" +#endif + +/* + * Maximum length of a MATLAB identifier (function/variable/model) + * including the null-termination character. + */ +#define TMW_NAME_LENGTH_MAX 64 + +/* + * Maximum values for indices and dimensions + */ +#include + +#ifdef MX_COMPAT_32 +typedef int mwSize; +typedef int mwIndex; +typedef int mwSignedIndex; +#else +typedef size_t mwSize; /* unsigned pointer-width integer */ +typedef size_t mwIndex; /* unsigned pointer-width integer */ +typedef ptrdiff_t mwSignedIndex; /* a signed pointer-width integer */ +#endif + + /* for the individual dim */ +#ifndef SLSIZE_SLINDEX + #define SLSIZE_SLINDEX + #ifdef INT_TYPE_64_IS_SUPPORTED + typedef int64_T SLIndex; + typedef int64_T SLSize; + #else + typedef int SLIndex; + typedef int SLSize; + #endif +#endif + +/* for the total size */ +#define SLIndexType size_t +#define INVALID_SIZET_VALUE (std::numeric_limits::max()) +#define MAX_VALID_SIZET_VALUE (std::numeric_limits::max() -1) + + +#if (defined(_LP64) || defined(_WIN64)) && !defined(MX_COMPAT_32) +/* Currently 2^48 based on hardware limitations */ +# define MWSIZE_MAX 281474976710655UL +# define MWINDEX_MAX 281474976710655UL +# define MWSINDEX_MAX 281474976710655L +# define MWSINDEX_MIN -281474976710655L +#else +# define MWSIZE_MAX 2147483647UL +# define MWINDEX_MAX 2147483647UL +# define MWSINDEX_MAX 2147483647L +# define MWSINDEX_MIN -2147483647L +#endif +#define MWSIZE_MIN 0UL +#define MWINDEX_MIN 0UL + +/** UTF-16 character type */ + +#if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT) +typedef char16_t CHAR16_T; +#define U16_STRING_LITERAL_PREFIX u +#elif defined(_MSC_VER) +typedef wchar_t CHAR16_T; +#define U16_STRING_LITERAL_PREFIX L +#else +typedef UINT16_T CHAR16_T; +#endif + +#endif /* __TMWTYPES__ */ + +#endif /* tmwtypes_h */ diff --git a/dereverbrate/waves/CMakeLists.txt b/dereverbrate/waves/CMakeLists.txt new file mode 100644 index 0000000..fc1cfe0 --- /dev/null +++ b/dereverbrate/waves/CMakeLists.txt @@ -0,0 +1,4 @@ +include_directories(inc) +AUX_SOURCE_DIRECTORY(src DIR_WAVES_SRCS) +add_library(waves ${DIR_WAVES_SRCS}) +#set_target_properties(waves PROPERTIES CXX_VISIBILITY_PRESET hidden) \ No newline at end of file diff --git a/dereverbrate/waves/inc/ExtraMono.h b/dereverbrate/waves/inc/ExtraMono.h new file mode 100644 index 0000000..280fab0 --- /dev/null +++ b/dereverbrate/waves/inc/ExtraMono.h @@ -0,0 +1,230 @@ + +#include +#include + +#define SIZE_LONG 4 +#define SIZE_SHORT 2 + +#define SIZE_FLAG 4 +#define FMT_TAG 0x0001 + +#define BITS_PER_BYTE 8 + +#ifndef AFS_CMPL_MAX_WAV +#define AFS_CMPL_MAX_WAV 15360000 // 鏃堕暱16鍒嗭紙960*16000锛 +#endif + +//+---------------------------------------------------------------------------+ +//+ 浠庢枃浠朵腑璇诲彇涓涓32浣嶆暟鎹 +//+---------------------------------------------------------------------------+ +unsigned long fa_read_u32(FILE* fp) +{ + unsigned long cx; + unsigned char temp[SIZE_LONG]; + + fread(temp, sizeof(unsigned char), SIZE_LONG, fp); + cx = (unsigned long)temp[0]; + cx |= (unsigned long)temp[1] << 8; + cx |= (unsigned long)temp[2] << 16; + cx |= (unsigned long)temp[3] << 24; + return cx; +} + +//+---------------------------------------------------------------------------+ +//+ 浠庢枃浠朵腑璇诲彇涓涓16浣嶆暟鎹 +//+---------------------------------------------------------------------------+ +unsigned short fa_read_u16(FILE *fp) +{ + unsigned short cx; + unsigned char temp[SIZE_SHORT]; + + fread(temp, sizeof(unsigned char), SIZE_SHORT, fp); + cx = temp[0] | (temp[1] * 256); + return cx; +} + +int GetWaveHeadLen(const char* pszFile,unsigned short &channels, int &nPos, int& nLength) +{ + //+---------------------------------------------------------------------------+ + //+ 璇诲彇WAVE鐨勫ご淇℃伅 + //+---------------------------------------------------------------------------+ + unsigned char temp[SIZE_FLAG]; + unsigned short bits_per_sample; + unsigned long x_size; + unsigned long n_skip; + + unsigned short format; + //unsigned short channels; + unsigned long sample_rate; + unsigned short block_align; + unsigned long data_size; + int nCnt = 0; + + /* 璇诲彇閫氱敤淇℃伅 */ + FILE* pWavFile = fopen(pszFile, "rb"); + if ( pWavFile == NULL ) + { + printf("Input file can not be opened!\n"); + return -1; + } + + fseek(pWavFile, 0, SEEK_END ); + nLength = ftell(pWavFile); + fseek(pWavFile, 0, SEEK_SET ); + + // 鍒ゆ柇璧勬簮鏍囪瘑涓"RIFF" + fread(temp, sizeof(unsigned char), SIZE_FLAG, pWavFile); + if ( memcmp(temp, "RIFF", (size_t)SIZE_FLAG) != 0 ) + { + fprintf(stderr, "Resource flag is not RIFF!\n"); + fclose(pWavFile); + + return -1; + } + nCnt += SIZE_FLAG; + + fseek(pWavFile, SIZE_LONG, SEEK_CUR); + nCnt += SIZE_LONG; + + // 鍒ゆ柇鏂囦欢鏍囪瘑涓"WAVE" + fread(temp, sizeof(unsigned char), SIZE_FLAG, pWavFile); + if ( memcmp(temp, "WAVE", (size_t)SIZE_FLAG) != 0 ) + { + fprintf(stderr, "File flag is not WAVE\n"); + fclose(pWavFile); + + return -1; + } + nCnt += SIZE_FLAG; + + // 鍒ゆ柇鏍煎紡鏍囪瘑涓"fmt " + fread(temp, sizeof(unsigned char), SIZE_FLAG, pWavFile); + if ( memcmp(temp, "fmt ", (size_t)SIZE_FLAG) != 0 ) + { + fprintf(stderr, "Format flag is not FMT!\n"); + fclose(pWavFile); + + return -1; + } + nCnt += SIZE_FLAG; + + x_size = fa_read_u32(pWavFile); + nCnt += SIZE_LONG; + + // 鍒ゆ柇缂栫爜鏍煎紡涓0x0001 + format = fa_read_u16(pWavFile); + nCnt += SIZE_SHORT; + if ( format != FMT_TAG ) + { + fprintf(stderr, "Encoding format is not 0x0001!\n"); + fclose(pWavFile); + + return -1; + } + + // 璇诲彇澹伴亾鏁扮洰鍜岄噰鏍烽鐜 + channels = fa_read_u16(pWavFile); + sample_rate = fa_read_u32(pWavFile); + + fseek(pWavFile, SIZE_LONG, SEEK_CUR); + + // 璇诲彇瀵归綈鍗曚綅鍜屾牱鏈綅鏁 + block_align = fa_read_u16(pWavFile); + bits_per_sample = fa_read_u16(pWavFile); + + /* 璇诲彇鐗规畩淇℃伅 */ + x_size -= (4*SIZE_SHORT + 2*SIZE_LONG); + if ( x_size != 0 ) + { + fseek(pWavFile, x_size, SEEK_CUR); + } + + // 璇诲彇鏁版嵁澶у皬 + fread(temp, sizeof(unsigned char), SIZE_FLAG, pWavFile); + while ( memcmp(temp, "data", SIZE_FLAG) != 0 ) + { + n_skip = fa_read_u32(pWavFile); + fseek(pWavFile, n_skip, SEEK_CUR); + + fread(temp, sizeof(unsigned char), SIZE_FLAG, pWavFile); + } + + data_size = fa_read_u32(pWavFile); + fclose(pWavFile); + + //+---------------------------------------------------------------------------+ + //+ 杩斿洖WAVE鐨勫ご闀垮害 + //+---------------------------------------------------------------------------+ + nPos = nCnt; + int nHeadLength = nLength - data_size; + return nHeadLength; +} + +bool ExtraMono(const std::string &sInput, const std::string &sOutput) +{ + FILE *pFile = fopen(sInput.c_str(), "rb"); + if ( NULL == pFile ) + { + printf("Fopen Error %s", sInput.c_str()); + return false; + } + + FILE *pFile2 = fopen(sOutput.c_str(), "wb"); + if ( NULL == pFile2 ) + { + printf("Fopen2 Error %s", sOutput.c_str()); + return false; + } + + short *pBuf = new short[AFS_CMPL_MAX_WAV]; + int nLen = 0; + + nLen = fread(pBuf, sizeof(short), AFS_CMPL_MAX_WAV, pFile); + if ( nLen <= 0 ) + { + perror("Fread Error!"); + return false; + } + + unsigned short channels=0; + int nPos; + int nLength; + int nHeadByte = GetWaveHeadLen(sInput.c_str(),channels, nPos, nLength); + int nHeadShort = nHeadByte/2; + + if (channels==1) + { + fwrite(pBuf + nHeadShort, sizeof(short), nLen - nHeadShort, pFile2); + } + else + { + short *pBuf2 = new short[AFS_CMPL_MAX_WAV]; + memcpy( pBuf2, pBuf, nHeadShort*sizeof(short)); + pBuf2[nPos] = 1; + + unsigned char tmp[2]; + memcpy(tmp, &pBuf2[nPos], 2); + + pBuf2[nPos] = static_cast(tmp[0] | tmp[1]*256); + + short *pWav = pBuf + nHeadShort; + nLen -= nHeadShort; + + int halfnlen=nLen/2; + for (int i=0;i<=halfnlen;i++ ) + { + pBuf2[nHeadShort+i] = *(pWav+i*2); + } + fwrite(pBuf2, sizeof(short), nLen+nHeadShort, pFile2); + + delete []pBuf; + delete []pBuf2; + pBuf = NULL; + pBuf2 = NULL; + } + + + fclose(pFile); + fclose(pFile2); + return true; +} diff --git a/dereverbrate/waves/inc/STWaveFile.h b/dereverbrate/waves/inc/STWaveFile.h new file mode 100644 index 0000000..0593058 --- /dev/null +++ b/dereverbrate/waves/inc/STWaveFile.h @@ -0,0 +1,74 @@ +#ifndef WAVE_FILE_H +#define WAVE_FILE_H + +#include +#include + + +typedef enum SAMPLE_FORMAT +{ + SF_U8 = 8, + SF_S16 = 16, + SF_S24 = 24, + SF_S32 = 32, + SF_IEEE_FLOAT = 0x100 + 32, + SF_IEEE_DOUBLE = 0x100 + 64, + SF_MAX, +} SAMPLE_FORMAT; + +/* 涓诲鐞嗗璞 **/ +class STCWaveFile +{ +public: + /* 鏋勯犱紶鍏ユ枃浠跺強 鏄杩樻槸鍐 **/ + STCWaveFile(const char* Filename, bool Write); + virtual ~STCWaveFile(); + +public: + int GetChannels(); + int GetSampleRate(); + double GetDuration(); // in second + uint32_t GetChannelMask(); + void SetChannels(int Channels); + void SetSampleRate(int SampleRate); + void SetSampleFormat(SAMPLE_FORMAT Format); + void SetChannelMask(uint32_t Mask); + void Stat(); + void SetupDone(); + bool ReadFrameAsS16(short* FrameSamples, int Frames = 1); + bool ReadFrameAsDouble(double* FrameSamples, int Frames = 1); + bool ReadFrameAsfloat(float* FrameSamples, int Frames = 1); + void WriteRaw(void* Raw, int Size); + void WriteFrame(uint8_t* FrameSamples, int Frames = 1); + void WriteFrame(short* FrameSamples, int Frames = 1); + void WriteFrame(int32_t* FrameSamples, int Frames = 1); + void WriteFrameS24(int32_t* FrameSamples, int Frames = 1); + void WriteFrame(double* FrameSamples, int Frames = 1); + void WriteFrame(float* FrameSamples, int Frames=1); + void Seek(int FramePos, int Where = SEEK_SET); + bool GetStatus(); + SAMPLE_FORMAT GetFormat(); + int GetTotalFrames(); + int GetFramesRead(); + + +protected: + FILE* File; + int Channels; /* 閫氶亾鏁 **/ + int SampleRate; /* 閲囨牱鐜 **/ + SAMPLE_FORMAT Format; /* 閲囨牱绮惧害 **/ + int SampleSize; // Measured in Bits + unsigned int FrameStartPos; /* 闊抽鏁版嵁鐨勮捣濮嬩綅缃 **/ + unsigned long TotalFrames; /* 鎬诲抚鏁帮紝濡傛灉16bit锛屽垯涓涓猻hort涓轰竴甯 **/ + unsigned long FramesRead; + double Duration; /* 鏃堕暱 **/ + + bool ReadOnly; /* 鏄害杩樻槸鍐 **/ + + uint32_t ChannelMask; + + bool m_bOK; /* 鏂囦欢鏄惁宸茬粡琚墦寮 **/ +}; + + +#endif \ No newline at end of file diff --git a/dereverbrate/waves/src/STWaveFile.cpp b/dereverbrate/waves/src/STWaveFile.cpp new file mode 100644 index 0000000..29d5b32 --- /dev/null +++ b/dereverbrate/waves/src/STWaveFile.cpp @@ -0,0 +1,822 @@ + +#include +#include +#include +#include + +#if WIN32 +#else +#include +#endif + +#include "STWaveFile.h" +#define SPEAKER_FRONT_LEFT 0x1 +#define SPEAKER_FRONT_RIGHT 0x2 +#define SPEAKER_FRONT_CENTER 0x4 +#define SPEAKER_LOW_FREQUENCY 0x8 +#define SPEAKER_BACK_LEFT 0x10 +#define SPEAKER_BACK_RIGHT 0x20 +#define SPEAKER_FRONT_LEFT_OF_CENTER 0x40 +#define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80 +#define SPEAKER_BACK_CENTER 0x100 +#define SPEAKER_SIDE_LEFT 0x200 +#define SPEAKER_SIDE_RIGHT 0x400 +#define SPEAKER_TOP_CENTER 0x800 +#define SPEAKER_TOP_FRONT_LEFT 0x1000 +#define SPEAKER_TOP_FRONT_CENTER 0x2000 +#define SPEAKER_TOP_FRONT_RIGHT 0x4000 +#define SPEAKER_TOP_BACK_LEFT 0x8000 +#define SPEAKER_TOP_BACK_CENTER 0x10000 +#define SPEAKER_TOP_BACK_RIGHT 0x20000 +#define SPEAKER_RESERVED 0x80000000 + + +#define SPEAKER_REAR_CENTER_SURROUND SPEAKER_BACK_CENTER + +#define DCA_MONO 0 +#define DCA_CHANNEL 1 +#define DCA_STEREO 2 +#define DCA_STEREO_SUMDIFF 3 +#define DCA_STEREO_TOTAL 4 +#define DCA_3F 5 +#define DCA_2F1R 6 +#define DCA_3F1R 7 +#define DCA_2F2R 8 +#define DCA_3F2R 9 +#define DCA_4F2R 10 + +#define DCA_DOLBY 101 /* FIXME */ + +#define DCA_CHANNEL_MAX DCA_3F2R /* We don't handle anything above that */ +#define DCA_CHANNEL_BITS 6 +#define DCA_CHANNEL_MASK 0x3F + +#define DCA_LFE 0x80 +#define DCA_ADJUST_LEVEL 0x100 + +#define WAVE_FORMAT_PCM 0x0001 +#define WAVE_FORMAT_IEEE_FLOAT 0x0003 +#define WAVE_FORMAT_EXTENSIBLE 0xFFFE + +static uint8_t wav_header[] = { + 'R', 'I', 'F', 'F', 0xfc, 0xff, 0xff, 0xff, 'W', 'A', 'V', 'E', + 'f', 'm', 't', ' ', 16, 0, 0, 0, + WAVE_FORMAT_PCM, WAVE_FORMAT_PCM >> 8, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, + 'd', 'a', 't', 'a', 0xd8, 0xff, 0xff, 0xff +}; + +static uint8_t wavmulti_header[] = { + 'R', 'I', 'F', 'F', 0xf0, 0xff, 0xff, 0xff, 'W', 'A', 'V', 'E', + 'f', 'm', 't', ' ', 40, 0, 0, 0, + (uint8_t)(WAVE_FORMAT_EXTENSIBLE & 0xFF), WAVE_FORMAT_EXTENSIBLE >> 8, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 22, 0, + 0, 0, 0, 0, 0, 0, + WAVE_FORMAT_IEEE_FLOAT, WAVE_FORMAT_IEEE_FLOAT >> 8, + 0, 0, 0, 0, 0x10, 0x00, 0x80, 0, 0, 0xaa, 0, 0x38, 0x9b, 0x71, + 'd', 'a', 't', 'a', 0xb4, 0xff, 0xff, 0xff +}; + +static void store4 (uint8_t * buf, int value) +{ + buf[0] = value; + buf[1] = value >> 8; + buf[2] = value >> 16; + buf[3] = value >> 24; +} + +static void store2 (uint8_t * buf, int value) +{ + buf[0] = value; + buf[1] = value >> 8; +} + + +static uint32_t find_chunk(FILE * file, const uint8_t chunk_id[4]) +{ + uint8_t buffer[8]; + while (1) { + size_t chunksize; + size_t s = fread(buffer, 1, 8, file); + if (s < 8) + return 0; + chunksize = (uint32_t)buffer[4] | ((uint32_t)buffer[5] << 8) | + ((uint32_t)buffer[6] << 16) | ((uint32_t)buffer[7] << 24); + if (!memcmp(buffer, chunk_id, 4)) + return chunksize; + fseek(file, chunksize, SEEK_CUR); + } +} + + +STCWaveFile::STCWaveFile(const char* Filename, bool Write) + : Duration(0), ReadOnly(false), m_bOK(false) +{ + Channels = 0; + + /* 鎵撳紑鏂囦欢 **/ + File = fopen(Filename, Write ? "wb":"rb"); + if ( !File ) + return; + + /* 璁剧疆鍐欐枃浠跺垵濮嬪弬鏁 **/ + if ( Write ) + { + SampleRate = 44100; + Channels = 2; + Format = SF_S16; + SampleSize = 16; + ChannelMask = 0; + m_bOK = true; + return; + } + + ReadOnly = true; + + size_t s; + uint8_t buffer[8]; + uint8_t *fmt = NULL; + uint32_t v; + uint32_t avg_bps; + uint32_t block_align; + unsigned short FormatType; + unsigned short SampleType; + + static const uint8_t riff[4] = { 'R', 'I', 'F', 'F' }; + static const uint8_t wave[4] = { 'W', 'A', 'V', 'E' }; + static const uint8_t fmt_[4] = { 'f', 'm', 't', ' ' }; + static const uint8_t data[4] = { 'd', 'a', 't', 'a' }; + + /* 鍓嶅洓涓瓧鑺備负 riff **/ + s = fread(buffer, 1, 8, File); + if (s < 8) + goto err2; + + if (memcmp(buffer, riff, 4)) + goto err2; + + /* 8~12涓簑ave **/ + /* TODO: check size (in buffer[4..8]) */ + s = fread(buffer, 1, 4, File); + if (s < 4) + goto err2; + + if (memcmp(buffer, wave, 4)) + goto err2; + + s = find_chunk(File, fmt_); + if ( s != 16 && s != 18 && s != 40 ) + goto err2; + + fmt = (uint8_t*)malloc(s); + if (!fmt) + goto err2; + + if (fread(fmt, 1, s, File) != s) + goto err3; + + /* wFormatTag */ + v = (uint32_t)fmt[0] | ((uint32_t)fmt[1] << 8); + if (v != WAVE_FORMAT_PCM && v != WAVE_FORMAT_IEEE_FLOAT && v != WAVE_FORMAT_EXTENSIBLE) + goto err3; + + FormatType = v; + + if (s == 40 && 0xfffe == v) + { + // fmt begins at 0x14 of the wave file + v = *(unsigned short*)&fmt[0x2C - 0x14]; + } + + SampleType = v; + + /* wChannels */ + v = (uint32_t)fmt[2] | ((uint32_t)fmt[3] << 8); + + Channels = v; + + if (v < 1 || v > 32) + goto err3; + + /* dwSamplesPerSec */ + SampleRate = (uint32_t)fmt[4] | ((uint32_t)fmt[5] << 8) | + ((uint32_t)fmt[6] << 16) | ((uint32_t)fmt[7] << 24); + + /* dwAvgBytesPerSec */ + avg_bps = (uint32_t)fmt[8] | ((uint32_t)fmt[9] << 8) | + ((uint32_t)fmt[10] << 16) | ((uint32_t)fmt[11] << 24); + + /* wBlockAlign */ + block_align = (uint32_t)fmt[12] | ((uint32_t)fmt[13] << 8); + + /* wBitsPerSample */ + SampleSize = (uint32_t)fmt[14] | ((uint32_t)fmt[15] << 8); + if (SampleSize != 8 && SampleSize != 16 && SampleSize != 32 && SampleSize != 24 && SampleSize != 64) + goto err3; + + switch (SampleSize) + { + case 8: + Format = SF_U8; + break; + case 16: + Format = SF_S16; + break; + case 24: + Format = SF_S24; + break; + case 32: + { + if (SampleType == WAVE_FORMAT_IEEE_FLOAT) + Format = SF_IEEE_FLOAT; + else + Format = SF_S32; + + } + break; + case 64: + if (SampleType != WAVE_FORMAT_IEEE_FLOAT) + goto err3; + Format = SF_IEEE_DOUBLE; + break; + } + + + // Handle 24-bit samples individually +#if 0 + if (SampleSize == 24 && Channels <= 2) + { + int ba24 = Channels * (SampleSize / 8); // Align to 4x + + ba24 = (ba24 + 3) / 4 * 4; + + if (block_align != ba24) + goto err3; + } + else +#endif + { + if (block_align != Channels * (SampleSize / 8)) + goto err3; + } + + if (avg_bps != block_align * SampleRate) + goto err3; + + v = find_chunk(File, data); + + if (v == 0 || v % block_align != 0) + goto err3; + + TotalFrames = v / block_align; + + FramesRead = 0; + + if (FormatType == WAVE_FORMAT_EXTENSIBLE) + { + ChannelMask = *(unsigned int*)(&fmt[0x14]); + } + else + { + ChannelMask = 0; + } + + FrameStartPos = ftell(File); + + free(fmt); + m_bOK = true; + return; + +err3: + free(fmt); +err2: + fclose(File); + + File = NULL; +} + +bool STCWaveFile::GetStatus() +{ + return m_bOK; +} + +SAMPLE_FORMAT STCWaveFile::GetFormat() +{ + return Format; +} + +int STCWaveFile::GetTotalFrames() +{ + return TotalFrames; +} + +int STCWaveFile::GetFramesRead() +{ + return FramesRead; +} + +STCWaveFile::~STCWaveFile() +{ + if (File != NULL) + { + if (!ReadOnly) + { + unsigned int Size = ftell(File) - FrameStartPos;// 44; + + fseek(File, FrameStartPos - 4, SEEK_SET); + fwrite(&Size, 4, 1, File); + + Size += FrameStartPos - 8; + + fseek(File, 4, SEEK_SET); + fwrite(&Size, 4, 1, File); + } + + fclose(File); + } +} + +int STCWaveFile::GetSampleRate() +{ + return SampleRate; +} + +void STCWaveFile::SetSampleRate(int SampleRate) +{ + this->SampleRate = SampleRate; +} + +void STCWaveFile::SetupDone() +{ + unsigned char Header[68]; + + fseek(File, 0, SEEK_SET); + + SampleSize = Format & 0xFF; + + if (ChannelMask) + { + memcpy(Header, wavmulti_header, sizeof(wavmulti_header)); + + if (Format < SF_IEEE_FLOAT) + { + // store2(Header + 20, WAVE_FORMAT_PCM); + store2(Header + 44, WAVE_FORMAT_PCM); + } + + store2(Header + 22, Channels); + store4(Header + 24, SampleRate); + store4(Header + 28, SampleSize / 8 * SampleRate * Channels); + store2(Header + 32, SampleSize / 8 * Channels); + store2(Header + 34, SampleSize / 8 * 8); + + store2(Header + 38, SampleSize / 8 * 8); + store4(Header + 40, ChannelMask); + + fwrite(Header, sizeof(wavmulti_header), 1, File); + } + else + { + memcpy(Header, wav_header, sizeof(wav_header)); + + if (Format >= SF_IEEE_FLOAT) + { + store2(Header + 20, WAVE_FORMAT_IEEE_FLOAT); + } + + store2(Header + 22, Channels); + store4(Header + 24, SampleRate); + store4(Header + 28, SampleSize / 8 * SampleRate * Channels); + store2(Header + 32, SampleSize / 8 * Channels); + store2(Header + 34, SampleSize / 8 * 8); + + fwrite(Header, sizeof(wav_header), 1, File); + } + + + FrameStartPos = ftell(File); +} + + +void STCWaveFile::Seek(int FramePos, int Where) +{ + // Ignoring Where + + fseek(File, FrameStartPos + FramePos * Channels* (SampleSize / 8), Where); + + FramesRead = FramePos; + +} + +int STCWaveFile::GetChannels() +{ + return Channels; +} + +void STCWaveFile::SetChannels(int Channels) +{ + this->Channels = Channels; +} + +void STCWaveFile::SetSampleFormat(SAMPLE_FORMAT Format) +{ + this->Format = Format; +} + +uint32_t STCWaveFile::GetChannelMask() +{ + return ChannelMask; +} + +void STCWaveFile::SetChannelMask(uint32_t Mask) +{ + ChannelMask = Mask; +} + +bool STCWaveFile::ReadFrameAsS16(short* FrameSamples, int Frames) +{ + if (FramesRead >= TotalFrames) + return false; + + FramesRead += Frames; + + switch (Format) + { + case SF_U8: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + short DirectSample = 0; + if (1 == fread(&DirectSample, 1, 1, File)) + { + FrameSamples[ch + frame*Channels] = (DirectSample - 128) << 8; + } + else + { + return false; + } + } + } + return true; + } + case SF_S16: + return Frames == fread(FrameSamples, sizeof(FrameSamples[0])*Channels, Frames, File); + case SF_S24: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + unsigned int DirectSample = 0; + if (1 == fread(&DirectSample, 3, 1, File)) + { + FrameSamples[ch + frame*Channels] = (short)(unsigned short)(DirectSample >> 8); // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S32: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + unsigned int DirectSample = 0; + if (1 == fread(&DirectSample, 4, 1, File)) + { + FrameSamples[ch + frame*Channels] = (short)(unsigned short)(DirectSample >> 16); // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_IEEE_FLOAT: + { + float DirectSamples[Frames * Channels]; + + if (Frames == fread(DirectSamples, sizeof(DirectSamples[0]) * Channels, Frames, File)) + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + FrameSamples[ch + frame*Channels] = (short)(DirectSamples[ch + frame*Channels] * 32768); + } + } + return true; + } + return false; + } + case SF_IEEE_DOUBLE: + { + double DirectSamples[32]; + + if (Frames == fread(DirectSamples, sizeof(DirectSamples[0]) * Channels, Frames, File)) + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + FrameSamples[ch + frame*Channels] = (short)(DirectSamples[ch + frame*Channels] * 32768); + } + } + return true; + } + return false; + } + } + return false; +} + +bool STCWaveFile::ReadFrameAsfloat(float* FrameSamples, int Frames) +{ + if (FramesRead >= TotalFrames) + return false; + + FramesRead += Frames; + + switch (Format) + { + case SF_U8: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + short DirectSample = 0; + if (1 == fread(&DirectSample, 1, 1, File)) + { + FrameSamples[ch + frame*Channels] = (DirectSample - 128) / 128.0; // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S16: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + short DirectSample = 0; + if (1 == fread(&DirectSample, 2, 1, File)) + { + FrameSamples[ch + frame*Channels] = DirectSample / 32768.0; // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S24: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + uint32_t DirectSample = 0; + if (1 == fread(&DirectSample, 3, 1, File)) + { + FrameSamples[ch + frame*Channels] = ((int32_t)((uint32_t)(DirectSample << 8))) / + (double)(((uint32_t)(1 << 31))); // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S32: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + uint32_t DirectSample = 0; + if (1 == fread(&DirectSample, 4, 1, File)) + { + FrameSamples[ch + frame*Channels] = ((int32_t)((uint32_t)(DirectSample))) / + (double)(((uint32_t)(1 << 31))); // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_IEEE_FLOAT: + { + if(fread(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File)) + { + return true; + } + return false; +// float DirectSamples[32]; +// +// if (Frames == fread(DirectSamples, sizeof(DirectSamples[0]) * Channels, Frames, File)) +// { +// for (int frame = 0; frame < Frames; frame++) +// { +// for (int ch = 0; ch < Channels; ch++) +// { +// FrameSamples[ch + frame*Channels] = (double)(DirectSamples[ch + frame*Channels]); +// } +// } +// return true; +// } +// return false; + } + case SF_IEEE_DOUBLE: + { + if (Frames == fread(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File)) + { + return true; + } + return false; + } + } + return false; +} + +bool STCWaveFile::ReadFrameAsDouble(double* FrameSamples, int Frames) +{ + if (FramesRead >= TotalFrames) + return false; + + FramesRead += Frames; + + switch (Format) + { + case SF_U8: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + short DirectSample = 0; + if (1 == fread(&DirectSample, 1, 1, File)) + { + FrameSamples[ch + frame*Channels] = (DirectSample - 128) / 128.0; // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S16: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + short DirectSample = 0; + if (1 == fread(&DirectSample, 2, 1, File)) + { + FrameSamples[ch + frame*Channels] = DirectSample / 32768.0; // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S24: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + uint32_t DirectSample = 0; + if (1 == fread(&DirectSample, 3, 1, File)) + { + FrameSamples[ch + frame*Channels] = ((int32_t)((uint32_t)(DirectSample << 8))) / + (double)(((uint32_t)(1 << 31))); // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_S32: + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + uint32_t DirectSample = 0; + if (1 == fread(&DirectSample, 4, 1, File)) + { + FrameSamples[ch + frame*Channels] = ((int32_t)((uint32_t)(DirectSample ))) / + (double)(((uint32_t)(1 << 31))); // (short)(DirectSample * 32767.0 / ((1 << 24) - 1)); + } + else + { + return false; + } + } + } + return true; + } + case SF_IEEE_FLOAT: + { + float DirectSamples[32]; + + if (Frames == fread(DirectSamples, sizeof(DirectSamples[0]) * Channels, Frames, File)) + { + for (int frame = 0; frame < Frames; frame++) + { + for (int ch = 0; ch < Channels; ch++) + { + FrameSamples[ch + frame*Channels] = (double)(DirectSamples[ch + frame*Channels]); + } + } + return true; + } + return false; + } + case SF_IEEE_DOUBLE: + { + if (Frames == fread(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File)) + { + return true; + } + return false; + } + } + return false; +} + +void STCWaveFile::WriteRaw(void* Raw, int Size) +{ + fwrite(Raw, Size, 1, File); +} + + +void STCWaveFile::WriteFrame(uint8_t* FrameSamples, int Frames) +{ + fwrite(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File); +} + +void STCWaveFile::WriteFrame(short* FrameSamples, int Frames) +{ + fwrite(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File); +} + +void STCWaveFile::WriteFrame(int32_t* FrameSamples, int Frames) +{ + fwrite(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File); +} + +void STCWaveFile::WriteFrameS24(int32_t* FrameSamples, int Frames) +{ + for (int c = 0; c < Channels; c++) + { + fwrite(&FrameSamples[c], 3, 1, File); + } +} + +void STCWaveFile::WriteFrame(double* FrameSamples, int Frames) +{ + fwrite(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File); +} + +void STCWaveFile::WriteFrame(float* FrameSamples, int Frames) +{ + fwrite(FrameSamples, sizeof(FrameSamples[0]) * Channels, Frames, File); +} + + +double STCWaveFile::GetDuration() +{ + return Duration; +}