Turn off rt_roundd inserted function

8 ビュー (過去 30 日間)
Matthew
Matthew 2013 年 7 月 22 日
編集済み: Stephen23 2017 年 4 月 25 日
Hi,
During generating my C code I constantly get preparing to casting function. It's definition is:
static real_T rt_roundd(real_T u)
{
real_T y;
if (fabs(u) < 4.503599627370496E+15) {
if (u >= 0.5) {
y = floor(u + 0.5);
} else if (u > -0.5) {
y = 0.0;
} else {
y = ceil(u - 0.5);
}
} else {
y = u;
}
return y;
}
No matter what it does, it works horribly for my audio processing algorithm so I don't want it. How can I achieve it?
Removing it's calls works fine for my algorithm but I don't want to do it manually every time I get that code.
  2 件のコメント
Ryan Livingston
Ryan Livingston 2013 年 7 月 23 日
編集済み: Stephen23 2017 年 4 月 25 日
When you say it works horribly, do you mean it gives unexpected answers, it seems inefficient or something else?
Matthew
Matthew 2013 年 7 月 23 日
I don't care. Audio samples become distorted after calculations in floating point and casting to C code and I'm not sure what causes that. Maybe it's Keil's compiler issue, maybe some optimalization I don't know.
What really works is removing all rt_roundd calls or putting "return y;" as first instruction in this function.

サインインしてコメントする。

回答 (1 件)

Ryan Livingston
Ryan Livingston 2013 年 7 月 23 日
編集済み: Ryan Livingston 2017 年 4 月 25 日
You can use a Code Replacement library and define a function replacement for the round function. The library says map function foo to function bar in the generated code and math functions like ROUND are generally replaceable.
Here's a demo for using these libraries:
and general doc for creating them:

カテゴリ

Help Center および File ExchangeCode Generation and Deployment についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by