C-Code Error: Pitch Method Conversion to C Won't Work
1 view (last 30 days)
Show older comments
David Besonen
on 9 Mar 2020
Commented: David Besonen
on 12 Mar 2020
I am trying to convert MatLab's pitch method to C using the MatLab Coder app, but I am running into an error I do not understand. I am trying to convert this method to C for use in a real-time pitch shifter program that will work much better in C than it does in MatLab. I'm using the pitch method in the main script for the pitch-shifter. Here is how I am trying to convert the pitch method to C so far:
I open the Coder app and input the following script to auto-define the variable types of the pitch method. In this example, mySignal is a 1024x1 double.
pitch(mySignal, 1852.2, 'NumChannels', size(1024, 2), 'SamplesPerChannel', size(1024, 1), 'Range', [50,400], 'WindowLength', round(1852.2 * 0.052), 'OverlapLength', round(1852.2 * 0.042), 'Method', 'NCF', 'MedianFilterLength', 1);
I then get the following auto-defined variable definitions:

From here, I attempt to run the MEX test generator to detect errors. The following image details the error I receive:

There is some issue with my auto-defined variables and the MatLab setProperties() method:



Any help you can give on this, I greatly appreciate. I need this for a school project in less than a month and I am just at a loss for what the problem is. The method should be able to be converted, as it contains the C Generation tag on its MatLab documentation page. Thank you for your help, please let me know if you need any clarification.
0 Comments
Accepted Answer
Brian Hemmat
on 10 Mar 2020
Hi David,
You're specifying a couple name-value pairs that aren't actually parameters of the pitch function (NumChannels, SamplesPerChannel). The parameters of the function are documented here.
Also, it looks like you're specifying a number of parameters that you don't have to (since you are just specifying their defaults). The following generates code for me, and I believe is what you're after:
mySignal = pinknoise(1024);
fs = 1.8522e+03;
codegen pitch -args {mySignal,fs}
If your project does not require you to actually implement the pitch shifting, you might also look at the shiftPitch function (which you can generate code from) or the audiopluginexample.PitchShifter (in the Audio Plugin Gallery). You can generate a VST plugin from the audiopluginexample.PitchShifter.
5 Comments
More Answers (0)
See Also
Categories
Find more on Audio Plugin Creation and Hosting in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!