Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 1a919b68 authored by hhakim's avatar hhakim
Browse files

Add an help function to access mxArray data in FaustMat2mxArray when...

Add an help function to access mxArray data in FaustMat2mxArray when interleaved complex API (R2018a) is enabled (#3).

It fixes issue #238.
parent 1d5cc280
Branches
Tags
No related merge requests found
...@@ -139,6 +139,15 @@ void mxArray2Scalar(const mxArray* scalar, typename std::enable_if<std::is_float ...@@ -139,6 +139,15 @@ void mxArray2Scalar(const mxArray* scalar, typename std::enable_if<std::is_float
template<typename FPP> template<typename FPP>
void mxArray2Scalar(const mxArray* scalar, complex<FPP>* out); void mxArray2Scalar(const mxArray* scalar, complex<FPP>* out);
#ifdef MX_HAS_INTERLEAVED_COMPLEX
/**
* Allow to access to mxMat data as double, float, complex<double>, complex<float> ptr.
* There is no copy (direct access) but the mxArray must match the type asked (otherwise a runtime error is raised).
*/
template<typename FPP>
void newMxGetData(FPP* ptr_out, const mxArray* mxMat);
#endif
#include "faust2Mx.hpp" #include "faust2Mx.hpp"
#endif #endif
...@@ -87,7 +87,7 @@ mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,DEV>& M) ...@@ -87,7 +87,7 @@ mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,DEV>& M)
FPP* ptr_out; FPP* ptr_out;
#ifdef MX_HAS_INTERLEAVED_COMPLEX #ifdef MX_HAS_INTERLEAVED_COMPLEX
ptr_out = static_cast<FPP*> (mxGetDoubles(mxMat)); newMxGetData(ptr_out, mxMat);
#else #else
ptr_out = static_cast<FPP*> (mxGetData(mxMat)); ptr_out = static_cast<FPP*> (mxGetData(mxMat));
#endif #endif
...@@ -99,7 +99,39 @@ mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,DEV>& M) ...@@ -99,7 +99,39 @@ mxArray* FaustMat2mxArray(const Faust::MatDense<FPP,DEV>& M)
} }
#ifdef MX_HAS_INTERLEAVED_COMPLEX
template<>
void newMxGetData<float>(float* ptr_out, const mxArray* mxMat)
{
if(mxGetClassID(mxMat) != mxSINGLE_CLASS || mxIsComplex(mxMat))
mexErrMsgTxt("newMxGetData: the mex matrix must be double as the ptr is.");
ptr_out = static_cast<float*> (mxGetSingles(mxMat));
}
template<>
void newMxGetData<double>(double* ptr_out, const mxArray* mxMat)
{
if(mxGetClassID(mxMat) != mxDOUBLE_CLASS && mxIsComplex(mxMat))
mexErrMsgTxt("newMxGetData: the mex matrix must be double as the ptr.");
ptr_out = static_cast<double*> (mxGetDoubles(mxMat));
}
template<>
void newMxGetData<std::complex<double>>(complex<double>* ptr_out, const mxArray* mxMat)
{
if(mxGetClassID(mxMat) != mxDOUBLE_CLASS || ! mxIsComplex(mxMat))
mexErrMsgTxt("newMxGetData: the mex matrix must be complex double as the ptr.");
ptr_out = reinterpret_cast<std::complex<double>*> (mxGetComplexDoubles(mxMat));
}
template<>
void newMxGetData<std::complex<float>>(complex<float>* ptr_out, const mxArray* mxMat)
{
if(mxGetClassID(mxMat) != mxSINGLE_CLASS || ! mxIsComplex(mxMat))
mexErrMsgTxt("newMxGetData: the mex matrix must be complex float as the ptr.");
ptr_out = reinterpret_cast<std::complex<float>*> (mxGetComplexDoubles(mxMat));
}
#endif
template<typename FPP> template<typename FPP>
mxArray* FaustMat2mxArray(const Faust::MatDense<std::complex<FPP>,Cpu>& M) mxArray* FaustMat2mxArray(const Faust::MatDense<std::complex<FPP>,Cpu>& M)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment