| Motorola DSP Developer's Kit | ![]() |
Instantiating Input and Output Objects
To instantiate input and output objects you should use the macros defined as CREATE_INPUT_ARG and CREATE_OUTPUT_ARG in the <matlab>/toolbox/motdsp/motdspmex/include/headers/56k/motdsp_api.h file. Also, CREATE_NORM_INPUT_ARG is available if you are sure that the input will always be normalized. See Chapter 3, Motorola DSP MEX-File Programming Reference.
CREATE_INPUT_ARG(a, 0);
CREATE_INPUT_ARG(b, 1);
num_data_inputs = config.GetFixedInputs();
if (num_data_inputs == 2) // i.e., two Matlab inputs
{
/ REAL conditions...
if ((a->GetType() == REAL_DOUBLE) &&
(b->GetType() == REAL_DOUBLE))
{
CREATE_OUTPUT_ARG(y, 0, REAL_DOUBLE);
}
}
Once the mapping of arguments to objects is complete, all access to the MEX-file arguments is through these newly created objects (i.e., the input objects a and b, and output object y in this example).
For advanced MEX-files, use the CREATE_OPT_INPUT_ARG macro to create input objects from optional string input variables. For example, a filter function may require string inputs as optional arguments to indicate a high-pass or low-pass filter type. Implement this functionality by using code similar to
MOTDSP_Input* c = PTR_NIL;
...
try {
// Validation Code goes here - see template
...
char *opts[] = {'high', 'low'};
int num_opts = sizeof(opts)/sizeof(opts[0]);
// Instantiate the optional string arguments
CREATE_OPT_INPUT_ARG(c,2,opts,num_opts);
// The 2 indicates that the optional string input
// is mapped from position 2 -- i.e. it is the third argument
// expected on the command line.
...
// To use the optional string inputs.
// They are treated as fixed inputs...
if (config.GetFixedInputs()==3) {
// This suggest there are three input arguments -- NOT
// including the possible OPTIONAL arguments; DSP type
// or command file
// strings that may be included on the command line.
if (*(c->GetData()) == 0) {
// This suggests an input of 'high'
// Some useful code goes here ...
}
if (*(c->GetData()) == 1) {
// This suggests an input of 'low'
// Some more useful code goes here ...
}
else {
// Error in string input arg
// Throw an exception here ...
sprintf(err_msg, "Invalid string input argument\n");
THROW_MEX_ERROR(err_msg);
}
}
}
| Declaring Input and Output Objects | Instantiating the Motorola DSP Simulator | ![]() |