📄 note2pvmex.cpp
字号:
// How to compile:
// MATLAB 7.1: mex note2pvMex.cpp d:/users/jang/c/lib/audio.cpp d:/users/jang/c/lib/utility.cpp -output note2pvMex.dll
// Others: mex note2pvMex.cpp d:/users/jang/c/lib/audio.cpp d:/users/jang/c/lib/utility.cpp
#include <string.h>
#include <math.h>
#include "mex.h"
#include "d:\users\jang\c\lib\audio.h""
#define NOTE prhs[0] /* Pairs of pitch/duration */
#define TIMESTEP prhs[1] /* Time step for pv vector */
#define DURATION prhs[2] /* Duration of pv vector, in terms of second */
#define PV plhs[0] /* Output pv vector */
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *note, *pv, timeStep, duration;
int i, noteLen, pvLen, pvLenMax;
double totalDuration;
/* Check for proper number of arguments */
if ((nrhs!=2) && (nrhs!=3)){
char message[200];
strcpy(message, mexFunctionName());
strcat(message, " requires 2 or 3 input arguments.\n");
strcat(message, "Usage: pv = ");
strcat(message, mexFunctionName());
strcat(message, "(note, timeStep, overallDuration)");
mexErrMsgTxt(message);
}
/* Check data types */
if (!mxIsDouble(NOTE))
mexErrMsgTxt("NOTE should be double array!");
/* Assign pointers to the input arguments */
note = mxGetPr(NOTE);
noteLen = mxGetM(NOTE)*mxGetN(NOTE);
timeStep = mxGetScalar(TIMESTEP);
duration = mxGetScalar(DURATION);
totalDuration = 0.0;
for (i=0; i<noteLen/2; i++)
totalDuration += note[i*2+1];
pvLenMax = ceil(totalDuration/timeStep);
if (nrhs==3)
pvLen=MIN(ceil(duration/timeStep), pvLenMax);
else
pvLen=pvLenMax;
/* Create matrix for the return argument */
PV = mxCreateDoubleMatrix(1, pvLen, mxREAL);
pv = mxGetPr(PV);
// Call the major function
note2pv(note, noteLen, timeStep, pv, pvLen);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -