First steps on Vectorizing Audio Plugins: which Instruction Set do you use in 2018?

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Nowhk wrote: Fri Jan 25, 2019 2:29 pm ...
2DaT wrote: Fri Jan 25, 2019 1:35 pm Also, your relative error calculation is wrong. :roll:
Where am I wrong?

Code: Select all

float relativeError = fabs(ref - approx);
if (relativeError > absoluteError) absoluteError = relativeError;


Hmm... maybe https://en.wikipedia.org/wiki/Approximation_error

i.e.
abserr = fabs(libexp-Remez);
relerr = fabs((libexp-Remez)/libexp);

Code: Select all

  x          exp(x)              Remez(x)     abserr       relerr
-2.782  0.0619397802  approx: 0.0619397802 0.000000e+00 0.000000e+00
-2.762  0.0631910467  approx: 0.0631910467 1.387779e-17 2.196164e-16
-2.742  0.0644675905  approx: 0.0644675905 0.000000e+00 0.000000e+00
-2.722  0.0657699223  approx: 0.0657699223 0.000000e+00 0.000000e+00
-2.702  0.0670985628  approx: 0.0670985628 0.000000e+00 0.000000e+00
-2.682  0.0684540437  approx: 0.0684540437 0.000000e+00 0.000000e+00
-2.662  0.0698369071  approx: 0.0698369071 0.000000e+00 0.000000e+00
-2.642  0.0712477062  approx: 0.0712477062 0.000000e+00 0.000000e+00
-2.622  0.0726870054  approx: 0.0726870054 0.000000e+00 0.000000e+00
-2.602  0.0741553803  approx: 0.0741553803 0.000000e+00 0.000000e+00
-2.582  0.0756534183  approx: 0.0756534183 0.000000e+00 0.000000e+00
-2.562  0.0771817188  approx: 0.0771817188 0.000000e+00 0.000000e+00
-2.542  0.0787408929  approx: 0.0787408929 0.000000e+00 0.000000e+00
-2.522  0.0803315645  approx: 0.0803315645 0.000000e+00 0.000000e+00
-2.502  0.0819543697  approx: 0.0819543697 0.000000e+00 0.000000e+00
-2.482  0.0836099578  approx: 0.0836099578 0.000000e+00 0.000000e+00
-2.462  0.0852989910  approx: 0.0852989910 0.000000e+00 0.000000e+00
-2.442  0.0870221449  approx: 0.0870221449 0.000000e+00 0.000000e+00
-2.422  0.0887801088  approx: 0.0887801088 0.000000e+00 0.000000e+00
-2.402  0.0905735860  approx: 0.0905735860 1.387779e-17 1.532211e-16
-2.382  0.0924032938  approx: 0.0924032938 0.000000e+00 0.000000e+00
-2.362  0.0942699642  approx: 0.0942699642 0.000000e+00 0.000000e+00
-2.342  0.0961743438  approx: 0.0961743438 0.000000e+00 0.000000e+00
-2.322  0.0981171944  approx: 0.0981171944 1.387779e-17 1.414409e-16
-2.302  0.1000992932  approx: 0.1000992932 0.000000e+00 0.000000e+00
-2.282  0.1021214331  approx: 0.1021214331 0.000000e+00 0.000000e+00
-2.262  0.1041844229  approx: 0.1041844229 0.000000e+00 0.000000e+00
-2.242  0.1062890878  approx: 0.1062890878 0.000000e+00 0.000000e+00
-2.222  0.1084362698  approx: 0.1084362698 1.387779e-17 1.279811e-16
-2.202  0.1106268278  approx: 0.1106268278 0.000000e+00 0.000000e+00
-2.182  0.1128616379  approx: 0.1128616379 0.000000e+00 0.000000e+00
-2.162  0.1151415943  approx: 0.1151415943 0.000000e+00 0.000000e+00
-2.142  0.1174676088  approx: 0.1174676088 0.000000e+00 0.000000e+00
-2.122  0.1198406119  approx: 0.1198406119 1.387779e-17 1.158020e-16
-2.102  0.1222615528  approx: 0.1222615528 0.000000e+00 0.000000e+00
-2.082  0.1247314000  approx: 0.1247314000 0.000000e+00 0.000000e+00
-2.062  0.1272511414  approx: 0.1272511414 0.000000e+00 0.000000e+00
-2.042  0.1298217850  approx: 0.1298217850 0.000000e+00 0.000000e+00
-2.022  0.1324443590  approx: 0.1324443590 0.000000e+00 0.000000e+00
-2.002  0.1351199126  approx: 0.1351199126 0.000000e+00 0.000000e+00
-1.982  0.1378495159  approx: 0.1378495159 0.000000e+00 0.000000e+00
-1.962  0.1406342608  approx: 0.1406342608 2.775558e-17 1.973600e-16
-1.942  0.1434752613  approx: 0.1434752613 0.000000e+00 0.000000e+00
-1.922  0.1463736539  approx: 0.1463736539 0.000000e+00 0.000000e+00
-1.902  0.1493305978  approx: 0.1493305978 2.775558e-17 1.858666e-16
-1.882  0.1523472760  approx: 0.1523472760 0.000000e+00 0.000000e+00
-1.862  0.1554248951  approx: 0.1554248951 0.000000e+00 0.000000e+00
-1.842  0.1585646863  approx: 0.1585646863 0.000000e+00 0.000000e+00
-1.822  0.1617679054  approx: 0.1617679054 0.000000e+00 0.000000e+00
-1.802  0.1650358339  approx: 0.1650358339 0.000000e+00 0.000000e+00
-1.782  0.1683697789  approx: 0.1683697789 0.000000e+00 0.000000e+00
-1.762  0.1717710740  approx: 0.1717710740 0.000000e+00 0.000000e+00
-1.742  0.1752410799  approx: 0.1752410799 0.000000e+00 0.000000e+00
-1.722  0.1787811846  approx: 0.1787811846 0.000000e+00 0.000000e+00
-1.702  0.1823928041  approx: 0.1823928041 0.000000e+00 0.000000e+00
-1.682  0.1860773831  approx: 0.1860773831 0.000000e+00 0.000000e+00
-1.662  0.1898363956  approx: 0.1898363956 0.000000e+00 0.000000e+00
-1.642  0.1936713452  approx: 0.1936713452 0.000000e+00 0.000000e+00
-1.622  0.1975837659  approx: 0.1975837659 2.775558e-17 1.404750e-16
-1.602  0.2015752227  approx: 0.2015752227 0.000000e+00 0.000000e+00
-1.582  0.2056473123  approx: 0.2056473123 0.000000e+00 0.000000e+00
-1.562  0.2098016636  approx: 0.2098016636 0.000000e+00 0.000000e+00
-1.542  0.2140399383  approx: 0.2140399383 0.000000e+00 0.000000e+00
-1.522  0.2183638319  approx: 0.2183638319 2.775558e-17 1.271070e-16
-1.502  0.2227750739  approx: 0.2227750739 0.000000e+00 0.000000e+00
-1.482  0.2272754290  approx: 0.2272754290 0.000000e+00 0.000000e+00
-1.462  0.2318666972  approx: 0.2318666972 0.000000e+00 0.000000e+00
-1.442  0.2365507152  approx: 0.2365507152 0.000000e+00 0.000000e+00
-1.422  0.2413293566  approx: 0.2413293566 0.000000e+00 0.000000e+00
-1.402  0.2462045330  approx: 0.2462045330 0.000000e+00 0.000000e+00
-1.382  0.2511781945  approx: 0.2511781945 0.000000e+00 0.000000e+00
-1.362  0.2562523306  approx: 0.2562523306 0.000000e+00 0.000000e+00
-1.342  0.2614289711  approx: 0.2614289711 0.000000e+00 0.000000e+00
-1.322  0.2667101866  approx: 0.2667101866 0.000000e+00 0.000000e+00
-1.302  0.2720980898  approx: 0.2720980898 0.000000e+00 0.000000e+00
-1.282  0.2775948358  approx: 0.2775948358 0.000000e+00 0.000000e+00
-1.262  0.2832026235  approx: 0.2832026235 0.000000e+00 0.000000e+00
-1.242  0.2889236959  approx: 0.2889236959 0.000000e+00 0.000000e+00
-1.222  0.2947603418  approx: 0.2947603418 0.000000e+00 0.000000e+00
-1.202  0.3007148957  approx: 0.3007148957 0.000000e+00 0.000000e+00
-1.182  0.3067897395  approx: 0.3067897395 0.000000e+00 0.000000e+00
-1.162  0.3129873034  approx: 0.3129873034 0.000000e+00 0.000000e+00
-1.142  0.3193100663  approx: 0.3193100663 5.551115e-17 1.738472e-16
-1.122  0.3257605575  approx: 0.3257605575 5.551115e-17 1.704048e-16
-1.102  0.3323413573  approx: 0.3323413573 0.000000e+00 0.000000e+00
-1.082  0.3390550981  approx: 0.3390550981 0.000000e+00 0.000000e+00
-1.062  0.3459044654  approx: 0.3459044654 0.000000e+00 0.000000e+00
-1.042  0.3528921991  approx: 0.3528921991 0.000000e+00 0.000000e+00
-1.022  0.3600210944  approx: 0.3600210944 0.000000e+00 0.000000e+00
-1.002  0.3672940030  approx: 0.3672940030 0.000000e+00 0.000000e+00
-0.982  0.3747138340  approx: 0.3747138340 0.000000e+00 0.000000e+00
-0.962  0.3822835556  approx: 0.3822835556 5.551115e-17 1.452094e-16
-0.942  0.3900061957  approx: 0.3900061957 0.000000e+00 0.000000e+00
-0.922  0.3978848435  approx: 0.3978848435 0.000000e+00 0.000000e+00
-0.902  0.4059226505  approx: 0.4059226505 0.000000e+00 0.000000e+00
-0.882  0.4141228320  approx: 0.4141228320 0.000000e+00 0.000000e+00
-0.862  0.4224886681  approx: 0.4224886681 0.000000e+00 0.000000e+00
-0.842  0.4310235054  approx: 0.4310235054 0.000000e+00 0.000000e+00
-0.822  0.4397307577  approx: 0.4397307577 0.000000e+00 0.000000e+00
-0.802  0.4486139083  approx: 0.4486139083 0.000000e+00 0.000000e+00
-0.782  0.4576765104  approx: 0.4576765104 0.000000e+00 0.000000e+00
-0.762  0.4669221892  approx: 0.4669221892 5.551115e-17 1.188874e-16
-0.742  0.4763546431  approx: 0.4763546431 0.000000e+00 0.000000e+00
-0.722  0.4859776452  approx: 0.4859776452 0.000000e+00 0.000000e+00
-0.702  0.4957950449  approx: 0.4957950449 0.000000e+00 0.000000e+00
-0.682  0.5058107692  approx: 0.5058107692 0.000000e+00 0.000000e+00
-0.662  0.5160288245  approx: 0.5160288245 0.000000e+00 0.000000e+00
-0.642  0.5264532983  approx: 0.5264532983 1.110223e-16 2.108873e-16
-0.622  0.5370883604  approx: 0.5370883604 0.000000e+00 0.000000e+00
-0.602  0.5479382649  approx: 0.5479382649 0.000000e+00 0.000000e+00
-0.582  0.5590073521  approx: 0.5590073521 0.000000e+00 0.000000e+00
-0.562  0.5703000497  approx: 0.5703000497 0.000000e+00 0.000000e+00
-0.542  0.5818208750  approx: 0.5818208750 0.000000e+00 0.000000e+00
-0.522  0.5935744363  approx: 0.5935744363 0.000000e+00 0.000000e+00
-0.502  0.6055654353  approx: 0.6055654353 0.000000e+00 0.000000e+00
-0.482  0.6177986686  approx: 0.6177986686 0.000000e+00 0.000000e+00
-0.462  0.6302790296  approx: 0.6302790296 0.000000e+00 0.000000e+00
-0.442  0.6430115105  approx: 0.6430115105 0.000000e+00 0.000000e+00
-0.422  0.6560012047  approx: 0.6560012047 0.000000e+00 0.000000e+00
-0.402  0.6692533081  approx: 0.6692533081 0.000000e+00 0.000000e+00
-0.382  0.6827731217  approx: 0.6827731217 0.000000e+00 0.000000e+00
-0.362  0.6965660537  approx: 0.6965660537 0.000000e+00 0.000000e+00
-0.342  0.7106376214  approx: 0.7106376214 1.110223e-16 1.562291e-16
-0.322  0.7249934537  approx: 0.7249934537 0.000000e+00 0.000000e+00
-0.302  0.7396392929  approx: 0.7396392929 1.110223e-16 1.501033e-16
-0.282  0.7545809978  approx: 0.7545809978 0.000000e+00 0.000000e+00
-0.262  0.7698245451  approx: 0.7698245451 0.000000e+00 0.000000e+00
-0.242  0.7853760325  approx: 0.7853760325 0.000000e+00 0.000000e+00
-0.222  0.8012416808  approx: 0.8012416808 0.000000e+00 0.000000e+00
-0.202  0.8174278364  approx: 0.8174278364 0.000000e+00 0.000000e+00
-0.182  0.8339409741  approx: 0.8339409741 0.000000e+00 0.000000e+00
-0.162  0.8507876993  approx: 0.8507876993 0.000000e+00 0.000000e+00
-0.142  0.8679747509  approx: 0.8679747509 0.000000e+00 0.000000e+00
-0.122  0.8855090040  approx: 0.8855090040 1.110223e-16 1.253768e-16
-0.102  0.9033974724  approx: 0.9033974724 0.000000e+00 0.000000e+00
-0.082  0.9216473120  approx: 0.9216473120 1.110223e-16 1.204607e-16
-0.062  0.9402658227  approx: 0.9402658227 0.000000e+00 0.000000e+00
-0.042  0.9592604523  approx: 0.9592604523 0.000000e+00 0.000000e+00
-0.022  0.9786387989  approx: 0.9786387989 0.000000e+00 0.000000e+00
-0.002  0.9984086140  approx: 0.9984086140 0.000000e+00 0.000000e+00
0.018  1.0185778059  approx: 1.0185778059 0.000000e+00 0.000000e+00
0.038  1.0391544425  approx: 1.0391544425 0.000000e+00 0.000000e+00
0.058  1.0601467547  approx: 1.0601467547 0.000000e+00 0.000000e+00
0.078  1.0815631398  approx: 1.0815631398 0.000000e+00 0.000000e+00
0.098  1.1034121646  approx: 1.1034121646 0.000000e+00 0.000000e+00
0.118  1.1257025689  approx: 1.1257025689 0.000000e+00 0.000000e+00
0.138  1.1484432692  approx: 1.1484432692 0.000000e+00 0.000000e+00
0.158  1.1716433622  approx: 1.1716433622 0.000000e+00 0.000000e+00
0.178  1.1953121282  approx: 1.1953121282 2.220446e-16 1.857629e-16
0.198  1.2194590349  approx: 1.2194590349 0.000000e+00 0.000000e+00
0.218  1.2440937415  approx: 1.2440937415 0.000000e+00 0.000000e+00
0.238  1.2692261022  approx: 1.2692261022 2.220446e-16 1.749449e-16
0.258  1.2948661703  approx: 1.2948661703 0.000000e+00 0.000000e+00
0.278  1.3210242021  approx: 1.3210242021 0.000000e+00 0.000000e+00
0.298  1.3477106612  approx: 1.3477106612 2.220446e-16 1.647569e-16
0.318  1.3749362225  approx: 1.3749362225 2.220446e-16 1.614945e-16
0.338  1.4027117767  approx: 1.4027117767 0.000000e+00 0.000000e+00
0.358  1.4310484342  approx: 1.4310484342 0.000000e+00 0.000000e+00
0.378  1.4599575302  approx: 1.4599575302 0.000000e+00 0.000000e+00
0.398  1.4894506287  approx: 1.4894506287 2.220446e-16 1.490782e-16
0.418  1.5195395273  approx: 1.5195395273 0.000000e+00 0.000000e+00
0.438  1.5502362620  approx: 1.5502362620 0.000000e+00 0.000000e+00
0.458  1.5815531118  approx: 1.5815531118 0.000000e+00 0.000000e+00
0.478  1.6135026040  approx: 1.6135026040 0.000000e+00 0.000000e+00
0.498  1.6460975188  approx: 1.6460975188 2.220446e-16 1.348915e-16
0.518  1.6793508945  approx: 1.6793508945 0.000000e+00 0.000000e+00
0.538  1.7132760329  approx: 1.7132760329 2.220446e-16 1.296024e-16
0.558  1.7478865046  approx: 1.7478865046 2.220446e-16 1.270361e-16
0.578  1.7831961542  approx: 1.7831961542 0.000000e+00 0.000000e+00
0.598  1.8192191061  approx: 1.8192191061 0.000000e+00 0.000000e+00
0.618  1.8559697698  approx: 1.8559697698 0.000000e+00 0.000000e+00
0.638  1.8934628462  approx: 1.8934628462 0.000000e+00 0.000000e+00
0.658  1.9317133330  approx: 1.9317133330 0.000000e+00 0.000000e+00
0.678  1.9707365309  approx: 1.9707365309 0.000000e+00 0.000000e+00
0.698  2.0105480496  approx: 2.0105480496 0.000000e+00 0.000000e+00
0.718  2.0511638144  approx: 2.0511638144 0.000000e+00 0.000000e+00
0.738  2.0926000721  approx: 2.0926000721 0.000000e+00 0.000000e+00
0.758  2.1348733977  approx: 2.1348733977 0.000000e+00 0.000000e+00
0.778  2.1780007011  approx: 2.1780007011 0.000000e+00 0.000000e+00
0.798  2.2219992338  approx: 2.2219992338 0.000000e+00 0.000000e+00
0.818  2.2668865959  approx: 2.2668865959 0.000000e+00 0.000000e+00
0.838  2.3126807428  approx: 2.3126807428 0.000000e+00 0.000000e+00
0.858  2.3593999929  approx: 2.3593999929 0.000000e+00 0.000000e+00
0.878  2.4070630344  approx: 2.4070630344 4.440892e-16 1.844942e-16
0.898  2.4556889332  approx: 2.4556889332 4.440892e-16 1.808410e-16
0.918  2.5052971404  approx: 2.5052971404 0.000000e+00 0.000000e+00
0.938  2.5559074998  approx: 2.5559074998 4.440892e-16 1.737501e-16
0.958  2.6075402562  approx: 2.6075402562 0.000000e+00 0.000000e+00
0.978  2.6602160636  approx: 2.6602160636 0.000000e+00 0.000000e+00
0.998  2.7139559928  approx: 2.7139559928 0.000000e+00 0.000000e+00
1.018  2.7687815407  approx: 2.7687815407 0.000000e+00 0.000000e+00
1.038  2.8247146380  approx: 2.8247146380 0.000000e+00 0.000000e+00
1.058  2.8817776589  approx: 2.8817776589 0.000000e+00 0.000000e+00
1.078  2.9399934293  approx: 2.9399934293 4.440892e-16 1.510511e-16
1.098  2.9993852362  approx: 2.9993852362 0.000000e+00 0.000000e+00
1.118  3.0599768373  approx: 3.0599768373 0.000000e+00 0.000000e+00
1.138  3.1217924698  approx: 3.1217924698 0.000000e+00 0.000000e+00
1.158  3.1848568610  approx: 3.1848568610 4.440892e-16 1.394377e-16
1.178  3.2491952374  approx: 3.2491952374 0.000000e+00 0.000000e+00
1.198  3.3148333352  approx: 3.3148333352 0.000000e+00 0.000000e+00
1.218  3.3817974105  approx: 3.3817974105 0.000000e+00 0.000000e+00
1.238  3.4501142499  approx: 3.4501142499 4.440892e-16 1.287172e-16
1.258  3.5198111810  approx: 3.5198111810 0.000000e+00 0.000000e+00
1.278  3.5909160835  approx: 3.5909160835 4.440892e-16 1.236702e-16
1.298  3.6634574003  approx: 3.6634574003 0.000000e+00 0.000000e+00
1.318  3.7374641489  approx: 3.7374641489 0.000000e+00 0.000000e+00
1.338  3.8129659330  approx: 3.8129659330 0.000000e+00 0.000000e+00
1.358  3.8899929544  approx: 3.8899929544 0.000000e+00 0.000000e+00
1.378  3.9685760247  approx: 3.9685760247 0.000000e+00 0.000000e+00
1.398  4.0487465784  approx: 4.0487465784 0.000000e+00 0.000000e+00
1.418  4.1305366847  approx: 4.1305366847 0.000000e+00 0.000000e+00
1.438  4.2139790608  approx: 4.2139790608 0.000000e+00 0.000000e+00
1.458  4.2991070847  approx: 4.2991070847 0.000000e+00 0.000000e+00
1.478  4.3859548087  approx: 4.3859548087 0.000000e+00 0.000000e+00
1.498  4.4745569731  approx: 4.4745569731 0.000000e+00 0.000000e+00
1.518  4.5649490200  approx: 4.5649490200 0.000000e+00 0.000000e+00
1.538  4.6571671074  approx: 4.6571671074 0.000000e+00 0.000000e+00
1.558  4.7512481237  approx: 4.7512481237 0.000000e+00 0.000000e+00
1.578  4.8472297026  approx: 4.8472297026 0.000000e+00 0.000000e+00
1.598  4.9451502380  approx: 4.9451502380 0.000000e+00 0.000000e+00
1.618  5.0450488994  approx: 5.0450488994 8.881784e-16 1.760495e-16
1.638  5.1469656477  approx: 5.1469656477 0.000000e+00 0.000000e+00
1.658  5.2509412509  approx: 5.2509412509 0.000000e+00 0.000000e+00
1.678  5.3570173005  approx: 5.3570173005 8.881784e-16 1.657972e-16
1.698  5.4652362285  approx: 5.4652362285 0.000000e+00 0.000000e+00
1.718  5.5756413239  approx: 5.5756413239 0.000000e+00 0.000000e+00
1.738  5.6882767502  approx: 5.6882767502 0.000000e+00 0.000000e+00
1.758  5.8031875630  approx: 5.8031875630 0.000000e+00 0.000000e+00
1.778  5.9204197282  approx: 5.9204197282 0.000000e+00 0.000000e+00
1.798  6.0400201402  approx: 6.0400201402 8.881784e-16 1.470489e-16
1.818  6.1620366408  approx: 6.1620366408 8.881784e-16 1.441372e-16
1.838  6.2865180383  approx: 6.2865180383 8.881784e-16 1.412830e-16
1.858  6.4135141267  approx: 6.4135141267 0.000000e+00 0.000000e+00
1.878  6.5430757064  approx: 6.5430757064 0.000000e+00 0.000000e+00
1.898  6.6752546035  approx: 6.6752546035 0.000000e+00 0.000000e+00
1.918  6.8101036915  approx: 6.8101036915 0.000000e+00 0.000000e+00
1.938  6.9476769118  approx: 6.9476769118 0.000000e+00 0.000000e+00
1.958  7.0880292955  approx: 7.0880292955 0.000000e+00 0.000000e+00
1.978  7.2312169854  approx: 7.2312169854 0.000000e+00 0.000000e+00
1.998  7.3772972586  approx: 7.3772972586 0.000000e+00 0.000000e+00
2.018  7.5263285490  approx: 7.5263285490 0.000000e+00 0.000000e+00
2.038  7.6783704711  approx: 7.6783704711 0.000000e+00 0.000000e+00
2.058  7.8334838439  approx: 7.8334838439 0.000000e+00 0.000000e+00
2.078  7.9917307146  approx: 7.9917307146 0.000000e+00 0.000000e+00
2.098  8.1531743842  approx: 8.1531743842 0.000000e+00 0.000000e+00
2.118  8.3178794322  approx: 8.3178794322 0.000000e+00 0.000000e+00
2.138  8.4859117429  approx: 8.4859117429 0.000000e+00 0.000000e+00
2.158  8.6573385315  approx: 8.6573385315 0.000000e+00 0.000000e+00
2.178  8.8322283709  approx: 8.8322283709 0.000000e+00 0.000000e+00
2.198  9.0106512194  approx: 9.0106512194 0.000000e+00 0.000000e+00
2.218  9.1926784485  approx: 9.1926784485 0.000000e+00 0.000000e+00
2.238  9.3783828716  approx: 9.3783828716 0.000000e+00 0.000000e+00
2.258  9.5678387729  approx: 9.5678387729 0.000000e+00 0.000000e+00
2.278  9.7611219373  approx: 9.7611219373 0.000000e+00 0.000000e+00
2.298  9.9583096806  approx: 9.9583096806 0.000000e+00 0.000000e+00
2.318  10.1594808805  approx: 10.1594808805 0.000000e+00 0.000000e+00
2.338  10.3647160083  approx: 10.3647160083 1.776357e-15 1.713850e-16
2.358  10.5740971607  approx: 10.5740971607 0.000000e+00 0.000000e+00
2.378  10.7877080929  approx: 10.7877080929 0.000000e+00 0.000000e+00
2.398  11.0056342522  approx: 11.0056342522 0.000000e+00 0.000000e+00
2.418  11.2279628119  approx: 11.2279628119 0.000000e+00 0.000000e+00
2.438  11.4547827065  approx: 11.4547827065 0.000000e+00 0.000000e+00
2.458  11.6861846669  approx: 11.6861846669 0.000000e+00 0.000000e+00
2.478  11.9222612570  approx: 11.9222612570 0.000000e+00 0.000000e+00
2.498  12.1631069105  approx: 12.1631069105 0.000000e+00 0.000000e+00
2.518  12.4088179690  approx: 12.4088179690 0.000000e+00 0.000000e+00
2.538  12.6594927201  approx: 12.6594927201 0.000000e+00 0.000000e+00
2.558  12.9152314371  approx: 12.9152314371 0.000000e+00 0.000000e+00
2.578  13.1761364189  approx: 13.1761364189 0.000000e+00 0.000000e+00
2.598  13.4423120309  approx: 13.4423120309 0.000000e+00 0.000000e+00
2.618  13.7138647470  approx: 13.7138647470 0.000000e+00 0.000000e+00
2.638  13.9909031918  approx: 13.9909031918 0.000000e+00 0.000000e+00
2.658  14.2735381845  approx: 14.2735381845 1.776357e-15 1.244511e-16
2.678  14.5618827827  approx: 14.5618827827 0.000000e+00 0.000000e+00
2.698  14.8560523283  approx: 14.8560523283 0.000000e+00 0.000000e+00
2.718  15.1561644928  approx: 15.1561644928 0.000000e+00 0.000000e+00
2.738  15.4623393252  approx: 15.4623393252 1.776357e-15 1.148828e-16
2.758  15.7746992995  approx: 15.7746992995 0.000000e+00 0.000000e+00
2.778  16.0933693639  approx: 16.0933693639 0.000000e+00 0.000000e+00
2.798  16.4184769906  approx: 16.4184769906 0.000000e+00 0.000000e+00

MIN relative error = 0.00000000000000000000e+00 
MAX relative error = 2.19616362234809118805e-16

Post

juha_p wrote: Fri Jan 25, 2019 3:27 pm Hmm... maybe https://en.wikipedia.org/wiki/Approximation_error
Ok, terminology typo I think! Sorry!
I meant "relative" what's absolute for you, and than made a Max Absolute (and not max relative).

I do this because I feel I'd like to measure the MAX drift/error I can have once I set a random frequency and pitch, rather than have a sort of error average - i.e. it makes more sense to me to evalutate the worst case instead of "general" error case. Once I got the worst case, I would confirm that the error introduced by the system can't go higher that value. Does it makes sense? :hihi:

In any case, if I Play C11 (16744.03515625 hz) with +47.7 pitch, it drifts of 0.03125!!
But I'm realizing right now that I won't never play a 263302.125 hz signal :dog: :lol:

I should limit cases where the freq*pitch is <= samplerate/2 (and see which "max absolute" error I got).

juha_p wrote: Fri Jan 25, 2019 3:27 pm -2.762 0.0631910467 approx: 0.0631910467 1.387779e-17 2.196164e-16
[/code]
Not sure how you got this results. exp(-2.762f) gives to me 0.06316530704498291015625 (not 0.0631910467).

Post

Nowhk wrote: Fri Jan 25, 2019 4:23 pm ...

juha_p wrote: Fri Jan 25, 2019 3:27 pm -2.762 0.0631910467 approx: 0.0631910467 1.387779e-17 2.196164e-16
[/code]
Not sure how you got this results. exp(-2.762f) gives to me 0.06316530704498291015625 (not 0.0631910467).
%.3f (my range there was ±M_PI and increment 0.02 in loop).

Post

Nowhk wrote: Wed Jan 16, 2019 11:16 am
juha_p wrote: Wed Jan 16, 2019 8:09 am (Pade) - https://root.cern.ch/doc/v606/exp_8h_source.html
Awesome...
I've tried this, and in that range the max error is 1.7763568394002504646778106689453125e-15 :love:

It seems perfect to calculate a pitch multiplier!!! Thanks!!!
Do you already have the SSE2 version?

Note: how much a sin(freq * pitchMultiplier) will (in this worst case, since is the max error) drift?
Keep in mind that the source above is licensed under the LGPL. If you build the source into your project you'll also have to release your code under the LGPL or the GPL and that's not compatible with the IPP license you were using earlier in this thread.

You can build the Pade exp function above into a library then link your program with that and not be required to license your code under the LGPL, but then I think you'll have some extra function call overhead.

Post

Nowhk wrote: Fri Jan 25, 2019 4:23 pmI do this because I feel I'd like to measure the MAX drift/error I can have once I set a random frequency and pitch, rather than have a sort of error average - i.e. it makes more sense to me to evalutate the worst case instead of "general" error case. Once I got the worst case, I would confirm that the error introduced by the system can't go higher that value. Does it makes sense?
Hmm... I still suspect you've got it wrong.

Let's try to start from yet more basic example: So what's wrong with 'absolute error'?
Suppose you need to count a million (1000000) people. The absolute error of 1 man will basically be pretty much insignificant in this case - okay. Then you need to count a few folks in a small room - let's say 4 or 5. Now the same 1 man drift is obviously a huge error.

And this is basically what the initial version of your utility does.
(Roughly speaking: C0 multiplier = 5 men, C10 multiplier = 1000000 and you compare the same 1 man errors for all note values in between w/o counting that the actual impact of these absolute error values changes drastically).

And this is how a relative error comes handy.
Dividing the absolute error by the reference value itself (this is how we acquire the word "relative" there) we get values that can be used to estimate "the impact" amount of the errors, the values that can be compared to each other (incl. finding the worst case and other comparison related analysis). E.g.:
1man / 1000000men = 0.000001 (= 0.001%)
1man / 5men = 0.2 (= 20%)
Now we can actually compare them and see the first error is insignificant and the second one is huge.
(Now 0.2 > 0.000001 -> worstCase = 0.2 makes perfect sense; Contrary to 1 == 1 comparison of the absolute errors showing nothing valuable).

---
Do you mean to convert it back to semitones after
Yes, personally I would do this. Simply because a error value of (let's say) "0.00012345 semitones" is more easy to understand (in terms of seeing how significant the error actually is) than an unitless "0.00012345" (<- obviously assuming it's a proper relative error) for the frequency multiplier.

What error should we use if we want to compare the pitch errors instead of frequency multiplier errors?
For a pitch we'll need to use the absolute error instead of the relative one simply because the pitch scale itself is a relative (and logarithmic) scale. I.e. ±1 man (e.g. octave, semitone or cent) there means the same change (same impact) regardless of how low or high the reference note is.

Post

mtytel wrote: Fri Jan 25, 2019 10:01 pm Keep in mind that the source above is licensed under the LGPL. If you build the source into your project you'll also have to release your code under the LGPL or the GPL and that's not compatible with the IPP license you were using earlier in this thread.

You can build the Pade exp function above into a library then link your program with that and not be required to license your code under the LGPL, but then I think you'll have some extra function call overhead.
:wink: Never considered license/release right now: only homemade learning and build on my pc for test. Of course I'll get into this topic asap, thanks!

Max M. wrote: Sat Jan 26, 2019 12:15 am And this is how a relative error comes handy.
Dividing the absolute error by the reference value itself (this is how we acquire the word "relative" there) we get values that can be used to estimate "the impact" amount of the errors, the values that can be compared to each other (incl. finding the worst case and other comparison related analysis). E.g.:
1man / 1000000men = 0.000001 (= 0.001%)
1man / 5men = 0.2 (= 20%)
Now we can actually compare them and see the first error is insignificant and the second one is huge.
(Now 0.2 > 0.000001 -> worstCase = 0.2 makes perfect sense; Contrary to 1 == 1 comparison of the absolute errors showing nothing valuable).
Thanks dude for this analysis.
Let me see if I got it...

Code: Select all

// errors
const int numOctaves = 11;
float octaves[numOctaves] = { 16.352f, 32.703f, 65.406f, 130.813f, 261.626f, 523.251f, 1046.502f, 2093.005f, 4186.009f , 8372.018f, 16744.036f }; // C0-C10

std::cout << "oct" << std::setw(14) << "absolute" << std::setw(34) << "relative" << std::setw(50) << "error" << std::setw(34) << "freq" << std::setw(34) << "semitone" << std::endl;
for (int octaveIndex = 0; octaveIndex < numOctaves; octaveIndex++) {
	float freq = octaves[octaveIndex];

	Errors errors;
	for (int i = 0; i < numSteps; i++) {
		float ref = refValues[i] * freq;
		float approx = approxValues[i] * freq;

		float error = fabs(ref - approx);
		float relativeError = fabs((ref - approx) / ref);

		if (error > errors.maxAbsoluteError) {
			errors.maxAbsoluteError = error;
		}
		if (relativeError > errors.maxRelativeError) {
			errors.maxRelativeError = relativeError;
			errors.error = error;
			errors.freq = freq;
			errors.semitones = log(refValues[i]) / ln2per12f;
		}
	}

	std::cout << "C" << octaveIndex << std::setw(24) << errors.maxAbsoluteError << std::setw(62) << errors.maxRelativeError << std::setw(28) << errors.error << std::setw(37) << errors.freq << std::setw(32) << errors.semitones << std::endl;
}
which output this:

Code: Select all

oct      absolute                          relative                                             error                              freq                          semitone
C0       1.52587890625e-05                 1.819785353518454940058290958404541015625e-07         1.9073486328125e-06               16.3519992828369140625        -7.700000286102294921875
C1         6.103515625e-05                     1.71770125234615989029407501220703125e-07        4.76837158203125e-07                32.702999114990234375          -42.700000762939453125
C2         0.0001220703125                     1.71770125234615989029407501220703125e-07         9.5367431640625e-07                 65.40599822998046875          -42.700000762939453125
C3          0.000244140625                 1.566054805834937724284827709197998046875e-07          3.814697265625e-06                 130.8130035400390625         -29.1000003814697265625
C4           0.00048828125                 1.566054805834937724284827709197998046875e-07           7.62939453125e-06                  261.626007080078125         -29.1000003814697265625
C5            0.0009765625                 1.186849800660638720728456974029541015625e-07               0.00048828125                       523.2509765625           35.700000762939453125
C6             0.001953125                 1.186849800660638720728456974029541015625e-07                0.0009765625                       1046.501953125           35.700000762939453125
C7              0.00390625                 1.830371587629997520707547664642333984375e-07                 0.001953125                      2093.0048828125           28.200000762939453125
C8               0.0078125                  2.26650655577032011933624744415283203125e-07               0.00048828125                      4186.0087890625                           -11.5
C9                0.015625                  2.26650655577032011933624744415283203125e-07                0.0009765625                       8372.017578125                           -11.5
C10                 0.03125                  2.26650655577032011933624744415283203125e-07                 0.001953125                       16744.03515625                           -11.5
Now, let me consider the first octave (C0): the absolute error is 1.52587890625e-05, which happens (for example) on C0 * 36.5 semitones, or also in C0 * 39.2 semitones.

But the relative error is 1.819785353518454940058290958404541015625e-07, which happens at C0 * -7.7 semitones, introducing a "local" error lower than the absolute one (1.9073486328125e-06 < 1.52587890625e-05).

Are you saying that this "local" error has more impact than the others freq*semitones with higher local error? i.e. C0 * -7.7 (which drift by 1.9073486328125e-06) has more "negative" effect than C0 * 36.5 (which drift more, 1.52587890625e-05)?

Post

Nowhk wrote: Sat Jan 26, 2019 3:10 pm ... i.e. C0 * -7.7 (which drift by 1.9073486328125e-06) has more "negative" effect than C0 * 36.5 (which drift more, 1.52587890625e-05)?
Yes.
Let's see:
Absolute error of 1.9073486328125e-06 at C0-7.7 corresponds to 0.000315 cents pitch drift.
And 1.52587890625e-05 at C0+36.5 results in 0.000196 cents drift.
So yes, it's correct: the C0-7.7 error is greater.

---

Btw., for such error analysis always use doubles for anything but the approximated function I/O. Otherwise instead of analyzing the function itself you measure `function + analysis code` errors (well, let's assume double-precision errors are low enough to be ignored).
E.g. for the code above everything except `approxValues` should be in doubles.

Post

Max M. wrote: Sun Jan 27, 2019 12:36 pm Yes.
Let's see:
Absolute error of 1.9073486328125e-06 at C0-7.7 corresponds to 0.000315 cents pitch drift.
And 1.52587890625e-05 at C0+36.5 results in 0.000196 cents drift.
So yes, it's correct: the C0-7.7 error is greater.
Uhm, I miss that :)

Isn't 1.9073486328125e-06 (or 1.52587890625e-05) the actual frequency drift?
Where does 0.000315 (or 0.000196) come from?

Sorry for being so idiot :dog:

Max M. wrote: Sun Jan 27, 2019 12:36 pm Btw., for such error analysis always use doubles for anything but the approximated function I/O. Otherwise instead of analyzing the function itself you measure `function + analysis code` errors (well, let's assume double-precision errors are low enough to be ignored).
E.g. for the code above everything except `approxValues` should be in doubles.
Right! Thanks... I'll do it in the next tests (once I got it haha).

Post

Nowhk wrote: Mon Jan 28, 2019 10:42 am Isn't 1.9073486328125e-06 (or 1.52587890625e-05) the actual frequency drift?
It is, but we have no interest in that (linear) frequency drift (in Hz) at all.
Pitch drift is the thing we really care (simply because this is how we'll hear it - remember? It's not like "Oh, what a nice quint - it's so shiny 12.345Hz interval between these two notes!" :)).
Where does 0.000315 (or 0.000196) come from?
pseudocode:

Code: Select all

refPitchShift    = -7.7; // semitones
approxFreqMul    = yourApproxFunToConvertOneToAnother(refShift); // frequency multiplier
approxPitchShift = 12 * log2(approxFreqMul); // (or any equivalent equation to) convert freq multiplier value back to pitch shift

pitchError = abs(refPitchShift - approxPitchShift); // -> 0.00000315 semitones
In reality, since I did not have your approx function (nor I would want to bother with it anyway), I had to use more complex calculation to reuse your absolute error Hz values directly:

Code: Select all

refFreq = 16.352 * 2^(-7.7/12) = 10.4811748137839; // C0-7.7 frequency, Hz
approxFreq = 10.4811748137839 - 1.9073486328125e-06 = 10.4811729064353; // Hz
approxFreqMul = approxFreq / 16.352 = 0.640971924317227;
approxPitchShift = 12 * log2(approxFreqMul) = -7.70000315047423; // semitones

pitchError = abs(refPitchShift - approxPitchShift) = 0.00000315; // semitones, aka 0.000315 cents
Notice how no actual frequency values and no "base note" values are involved in the first snippet at all. The whole thing is really just about pitchShift <-> frequencyMultiplier conversion and their inaccuracy when approximated.
(Linear frequency will be somewhat involved in (for example) recursive phase accumulation code - if you'll go with that - but that's another story and another (unrelated) errors).

Post

Max M. wrote: Mon Jan 28, 2019 2:06 pm pseudocode:

Code: Select all

refPitchShift    = -7.7; // semitones
approxFreqMul    = yourApproxFunToConvertOneToAnother(refShift); // frequency multiplier
approxPitchShift = 12 * log2(approxFreqMul); // (or any equivalent equation to) convert freq multiplier value back to pitch shift

pitchError = abs(refPitchShift - approxPitchShift); // -> 0.00000315 semitones
Can't got the same results, unfortunately :ud:
Not sure where I'm wrong right now:

Code: Select all

float freq = 16.352f; // C0

Errors errors;
int inc = min; // -480
for (int i = 0; i < numSteps; i++) {
	float note = (inc / (float)step);

	float refFreqMul = refValues[i] * freq;
	float approxFreqMul = approxValues[i] * freq;

	float refPitch = log(refValues[i]) / ln2per12f;
	float approxPitch = log(approxValues[i]) / ln2per12f;

	float absoluteError = fabs(refFreqMul - approxFreqMul);
	if (absoluteError > errors.maxAbsoluteError) {
		errors.maxAbsoluteError = absoluteError;
	}

	float relativeError = fabs((refFreqMul - approxFreqMul) / refFreqMul);
	if (relativeError > errors.maxRelativeError) {
		errors.maxRelativeError = relativeError;
	}

	float pitchShiftError = fabs(refPitch - approxPitch);
	if (pitchShiftError > errors.maxPitchShiftError) {
		errors.maxPitchShiftError = pitchShiftError;
	}

	if (i == 403 || i == 621 || i == 845) { // check for example -7.7, 14.1, 36.5
		std::cout << i << " -               oct " << note << std::endl;
		std::cout << i << " -          ref freq " << refFreqMul << std::endl;
		std::cout << i << " -       approx freq " << approxFreqMul << std::endl;
		std::cout << i << " -          absolute " << absoluteError << std::endl;
		std::cout << i << " -          relative " << relativeError << std::endl;
		std::cout << i << " - pitch shift error " << pitchShiftError << std::endl;
		std::cout << std::endl;
	}

	inc++;
}

std::cout << "max absolute error: " << errors.maxAbsoluteError << std::endl;
std::cout << "max relative error: " << errors.maxRelativeError << std::endl;
std::cout << "max pitch shift error: " << errors.maxPitchShiftError << std::endl;
Which output:

Code: Select all

403 -               oct -7.69999980926513671875
403 -          ref freq 10.48117351531982421875
403 -       approx freq 10.48117542266845703125
403 -          absolute 1.9073486328125e-06
403 -          relative 1.819785353518454940058290958404541015625e-07
403 -              freq 16.3519992828369140625
403 - pitch shift error 1.430511474609375e-06

621 -               oct 14.1000003814697265625
621 -          ref freq 36.921649932861328125
621 -       approx freq 36.9216461181640625
621 -          absolute 3.814697265625e-06
621 -          relative 1.033187118082423694431781768798828125e-07
621 -              freq 16.3519992828369140625
621 - pitch shift error 2.86102294921875e-06

845 -               oct 36.5
845 -          ref freq 134.649200439453125
845 -       approx freq 134.6491851806640625
845 -          absolute 1.52587890625e-05
845 -          relative 1.1332253535556446877308189868927001953125e-07
845 -              freq 16.3519992828369140625
845 - pitch shift error 0

max absolute error: 1.52587890625e-05
max relative error: 1.819785353518454940058290958404541015625e-07
max pitch shift error: 2.86102294921875e-06
For what I see, the max pitch shift (i.e. the worst error, 2.86102294921875e-06) happens at 14.1, which doesn't hold the max relative error (it happens at -7.7, as said previously).

The pitch shift error at -7.7 is lower, 1.430511474609375e-06 < 2.86102294921875e-06.
So the "relative indicator" seems wrong? Uhm...

Post

This has been said several times already, but I'll say it again: you want to do your error computation using the highest available machine precision, because you do not want to contaminate your actual approximation error with the additional errors that occur when you are computing the error.

In other words: do your error computation in (at least) double precision!

edit: Also in all honesty, unless you are interested in this for academic reasons, you are really just wasting your time and should really just use 2DaT's approximation and be done with it. Anything else you're going to find is almost guaranteed to be either less accurate, slower or (as is the case for most exp() approximations you'll find on the internet) both.

Post

mystran wrote: Wed Jan 30, 2019 11:59 am edit: Also in all honesty, unless you are interested in this for academic reasons, you are really just wasting your time and should really just use 2DaT's approximation and be done with it. Anything else you're going to find is almost guaranteed to be either less accurate, slower or (as is the case for most exp() approximations you'll find on the internet) both.
I would says "learning" stuff; approaching to simd, performance, precision/errors/accuracy, analysis, programming, dsp, math, and so on. I'm not here to hurt you guys (or at least, that's not my intention): I just ask for getting support and learn from pro.
Probably 2DaT approx is "the better" and you got the truth, but I want to see how and why, myself.

mystran wrote: Wed Jan 30, 2019 11:59 am This has been said several times already, but I'll say it again: you want to do your error computation using the highest available machine precision, because you do not want to contaminate your actual approximation error with the additional errors that occur when you are computing the error.

In other words: do your error computation in (at least) double precision!
I think it has been said one time, by Max M.
And I've also tried it (note: only approxValues is in float here, which are the values from vdt::fast_expf):

Code: Select all

double freq = 16.352;

Errors errors;
inc = min;
for (int i = 0; i < numSteps; i++) {
	double note = (inc / (double)step);

	double refFreqMul = refValues[i] * freq;
	double approxFreqMul = approxValues[i] * freq;

	double refPitch = log(refValues[i]) / ln2per12;
	double approxPitch = log(approxValues[i]) / ln2per12;

	double absoluteError = abs(refFreqMul - approxFreqMul);
	if (absoluteError > errors.maxAbsoluteError) {
		errors.maxAbsoluteError = absoluteError;
		errors.indexMaxAbsoluteError = i;
	}

	double relativeError = abs((refFreqMul - approxFreqMul) / refFreqMul);
	if (relativeError > errors.maxRelativeError) {
		errors.maxRelativeError = relativeError;
		errors.indexMaxRelativeError = i;
	}

	double pitchShiftError = abs(refPitch - approxPitch);
	if (pitchShiftError > errors.maxPitchShiftError) {
		errors.maxPitchShiftError = pitchShiftError;
		errors.indexMaxPitchShiftError = i;
	}

	if (i == 46 || i == 623 || i == 954) {
		std::cout << i << " -               oct " << note << std::endl;
		std::cout << i << " -          ref freq " << refFreqMul << std::endl;
		std::cout << i << " -       approx freq " << approxFreqMul << std::endl;
		std::cout << i << " -          absolute " << absoluteError << std::endl;
		std::cout << i << " -          relative " << relativeError << std::endl;
		std::cout << i << " -              freq " << freq << std::endl;
		std::cout << i << " - pitch shift error " << pitchShiftError << std::endl;
		std::cout << std::endl;
	}

	inc++;
}

std::cout << "   max absolute error: " << errors.maxAbsoluteError << " (" << errors.indexMaxAbsoluteError << ")" << std::endl;
std::cout << "   max relative error: " << errors.maxRelativeError << " (" << errors.indexMaxRelativeError << ")" << std::endl;
std::cout << "max pitch shift error: " << errors.maxPitchShiftError << " (" << errors.indexMaxPitchShiftError << ")" << std::endl;
Thus, the relationship between relative and pitch shift errors seems unlinked:

Code: Select all

46 -               oct -43.39999999999999857891452847979962825775146484375
46 -          ref freq 1.3330477568358347628674209772725589573383331298828125
46 -       approx freq 1.33304797524971263555926270782947540283203125
46 -          absolute 2.184138778726918417305569164454936981201171875e-07
46 -          relative 1.638455012227964657309654643302376797464603441767394542694091796875e-07
46 -              freq 16.3519992828369140625
46 - pitch shift error 1.9445357537506424705497920513153076171875e-06

623 -               oct 14.300000000000000710542735760100185871124267578125
623 -          ref freq 37.350659186700880809439695440232753753662109375
623 -       approx freq 37.3506628974037084844894707202911376953125
623 -          absolute 3.710702827675049775280058383941650390625e-06
623 -          relative 9.9347719919124937555137051271858528167513213702477514743804931640625e-08
623 -              freq 16.3519992828369140625
623 - pitch shift error 2.10308585479879184276796877384185791015625e-06

954 -               oct 47.39999999999999857891452847979962825775146484375
954 -          ref freq 252.71984252552312000261736102402210235595703125
954 -       approx freq 252.719804590087733231484889984130859375
954 -          absolute 3.793543538677113247103989124298095703125e-05
954 -          relative 1.50108653945286833111596720528868598165672665345482528209686279296875e-07
954 -              freq 16.3519992828369140625
954 - pitch shift error 1.93354441080373362638056278228759765625e-06

   max absolute error: 3.793543538677113247103989124298095703125e-05 (954)
   max relative error: 1.638455012227964657309654643302376797464603441767394542694091796875e-07 (46)
max pitch shift error: 2.10308585479879184276796877384185791015625e-06 (623)
My analysis error should be elsewhere...

Post

Code: Select all

double approxFreqMul = approxValues[i] * freq;
This is not frequency multiplier. The approxValues[.i] is.
Same for refFreqMul.
At this point I think I'd suggest to reread last two or three pages of the thread and take your time for digging into physical meaning of each variable of your own code (by now the recent versions look like a random editing in panic).

Post

Nowhk wrote: Wed Jan 30, 2019 1:29 pm
mystran wrote: Wed Jan 30, 2019 11:59 am edit: Also in all honesty, unless you are interested in this for academic reasons, you are really just wasting your time and should really just use 2DaT's approximation and be done with it. Anything else you're going to find is almost guaranteed to be either less accurate, slower or (as is the case for most exp() approximations you'll find on the internet) both.
I would says "learning" stuff; approaching to simd, performance, precision/errors/accuracy, analysis, programming, dsp, math, and so on. I'm not here to hurt you guys (or at least, that's not my intention): I just ask for getting support and learn from pro.
Sure, that qualifies as "academic reasons" which is entirely reasonable, I just wanted to make sure. :)

Post

mystran wrote: Wed Jan 30, 2019 4:06 pmSure, that qualifies as "academic reasons" which is entirely reasonable, I just wanted to make sure. :)
:tu:

Max M. wrote: Wed Jan 30, 2019 2:44 pm

Code: Select all

double approxFreqMul = approxValues[i] * freq;
This is not frequency multiplier. The approxValues[.i] is.
Same for refFreqMul.
Typo :) "random editing in panic" sounds a bit exagerate, isn't? The code its pretty short and easy to understand I believe. Anyway, that's the same with a better "terminology":

Code: Select all

double freq = 16.352;

Errors errors;
inc = min;
for (int i = 0; i < numSteps; i++) {
	double note = (inc / (double)step);

	double refFreq = refFreqMul[i] * freq;
	double approxFreq = approxFreqMul[i] * freq;

	double refPitchShift = log(refFreqMul[i]) / ln2per12;
	double approxPitchShift = log(approxFreqMul[i]) / ln2per12;

	double absoluteError = abs(refFreq - approxFreq);
	if (absoluteError > errors.maxAbsoluteError) {
		errors.maxAbsoluteError = absoluteError;
		errors.indexMaxAbsoluteError = i;
	}

	double relativeError = abs((refFreq - approxFreq) / refFreq);
	if (relativeError > errors.maxRelativeError) {
		errors.maxRelativeError = relativeError;
		errors.indexMaxRelativeError = i;
	}

	double pitchShiftError = abs(refPitchShift - approxPitchShift);
	if (pitchShiftError > errors.maxPitchShiftError) {
		errors.maxPitchShiftError = pitchShiftError;
		errors.indexMaxPitchShiftError = i;
	}

	std::cout << i << " -               oct " << note << std::endl;
	std::cout << i << " -          ref freq " << refFreq << std::endl;
	std::cout << i << " -       approx freq " << approxFreq << std::endl;
	std::cout << i << " -          absolute " << absoluteError << std::endl;
	std::cout << i << " -          relative " << relativeError << std::endl;
	std::cout << i << " - pitch shift error " << pitchShiftError << std::endl;
	std::cout << std::endl;

	inc++;
}

std::cout << "   max absolute error: " << errors.maxAbsoluteError << " (" << errors.indexMaxAbsoluteError << ")" << std::endl;
std::cout << "   max relative error: " << errors.maxRelativeError << " (" << errors.indexMaxRelativeError << ")" << std::endl;
std::cout << "max pitch shift error: " << errors.maxPitchShiftError << " (" << errors.indexMaxPitchShiftError << ")" << std::endl;
Here the output with only some results:

Code: Select all

46 -               oct -43.39999999999999857891452847979962825775146484375
46 -          ref freq 1.3330477568358347628674209772725589573383331298828125
46 -       approx freq 1.33304797524971263555926270782947540283203125
46 -          absolute 2.184138778726918417305569164454936981201171875e-07
46 -          relative 1.638455012227964657309654643302376797464603441767394542694091796875e-07
46 - pitch shift error 1.9445357537506424705497920513153076171875e-06

623 -               oct 14.300000000000000710542735760100185871124267578125
623 -          ref freq 37.350659186700880809439695440232753753662109375
623 -       approx freq 37.3506628974037084844894707202911376953125
623 -          absolute 3.710702827675049775280058383941650390625e-06
623 -          relative 9.9347719919124937555137051271858528167513213702477514743804931640625e-08
623 - pitch shift error 2.10308585479879184276796877384185791015625e-06

954 -               oct 47.39999999999999857891452847979962825775146484375
954 -          ref freq 252.71984252552312000261736102402210235595703125
954 -       approx freq 252.719804590087733231484889984130859375
954 -          absolute 3.793543538677113247103989124298095703125e-05
954 -          relative 1.50108653945286833111596720528868598165672665345482528209686279296875e-07
954 - pitch shift error 1.93354441080373362638056278228759765625e-06

   max absolute error: 3.793543538677113247103989124298095703125e-05 (954)
   max relative error: 1.638455012227964657309654643302376797464603441767394542694091796875e-07 (46)
max pitch shift error: 2.10308585479879184276796877384185791015625e-06 (623)
Same problem: max pitch shift error doesn't occurs at the same semitone having the max relative error.

Note: I've used exp(value * ln2per12) and log(value) / ln2per12 to convert from/to pitch/frequency (not pow/log2, as in your example).

Post Reply

Return to “DSP and Plugin Development”