I'm writing a c++ mex file that uses the open-source portaudio library to access my soundcard. When the read buffer is full, it calls a callback function, which is where I want to use mexCallMATLAB to export the data so I can process it using m-files. For the moment, I set up a simple test where the callback function calls an m-file that does nothing more than increment a global counter:
----------------------------------------------------------------
mexaudio.cpp
----------------------------------------------------------------
static char errmsg[30];
static int audiocallback( const float *inputbuffer, float *outputbuffer){
mxArray *err=mexCallMATLABWithTrap(0,NULL,0,NULL,"mycounter");
if (err != NULL) {
mxArray *msg = mxGetProperty(err,0,"message");
mxGetString(msg,errmsg,30);
}
}
----------------------------------------------------------------
mycounter.m
----------------------------------------------------------------
function mycounter()
global mycount;
mycount=mycount+1;
end
If I run the program through the Matlab Desktop, I sometimes (1 in 3 chance) get the "JVM not running" error the first few times audiocallback is executed. After the first few errors, the program runs as expected. If I don't use WithTrap, then Matlab just crashes and closes without complaining. If I run the program through a console with the -nojvm option, I never get the error.
Is there a reason I'm not thinking of for why I'm getting the JVM error? Is there a work-around so I can continue to work with the matlab GUI?
In case it helps, I'm using MATLAB 7.10.0.499 (R2010a), 32-bit (glnx86) on a 32-bit linux operating system.
Cheers,
Antonio
Have you found what was going on? I am experiencing the same problem. I am using Matlab 2010b x64 in Windows XP Professional x64.
Regards,
Walfredo Fagundes
"Antonio" wrote in message <i5p76p$4bj$1...@fred.mathworks.com>...