Coming up again with the 'smoother' topic: Is [phasor~]-[cos~ ] precision-wise and interpolation-wise the same as an [osc~]? If not, which has less error and why?
I think each one is 512-point linear interpolated.
m_pd.h: #define LOGCOSTABSIZE 9 #define COSTABSIZE (1<<LOGCOSTABSIZE)
This would give you 512 points.
The code for both osc~ and cos~ have:
*out++ = f1 + frac * (f2 - f1);
Which, if the mnemonically named "frac" variable is just the fractional part of the index between f1 and f2, is a simple linear interpolation between the two points.
For this reason I almost always use an 8192-point [table] and [tabread4~] if I need more accurate sinusoids; I've gotten pretty severe errors especially in cases where I need to divide a signal by the output of a cosine oscillator near 90-degrees phase (near the zero-crossing), and even more especially where the numerator is also near zero, just using [cos~], presumably both because the values from the oscillator output are near zero and because the function is changing at the greatest rate there.
IIRC SuperCollider's SinOsc uses an 8192-point table with linear interpolation, and Phasor+BufRd you specify the table size and the type of interpolation (the cubic is the same as the Hermite one in [tabread4c~]).
In csound's oscil* or phasor+table* opcodes you specify the table size (power of 2) and the type of interpolation (the cubic is identical to the Lagrange one in Pd).
Someone please correct me if I'm mistaken.
MB
Thanks a lot for your explanations!
On Sun, 2010-04-18 at 22:14 -0400, Matt Barber wrote:
For this reason I almost always use an 8192-point [table] and [tabread4~] if I need more accurate sinusoids;
By using 'sinesum' messages to [table]s? I can't think of another way to have access to more precise sinusoids in Pd, or is there any?
Roman
Thanks a lot for your explanations!
On Sun, 2010-04-18 at 22:14 -0400, Matt Barber wrote:
For this reason I almost always use an 8192-point [table] and [tabread4~] if I need more accurate sinusoids;
By using 'sinesum' messages to [table]s? I can't think of another way to have access to more precise sinusoids in Pd, or is there any?
Yes, either that (which seems to use the <math.h> sin or cos functions), or an [until] + [sin] + [tabwrite] routine. The former is easier, obviously, and also adds the three guard points automatically (it also seems to use the same precision of PI=3.14159 that you can get with floats in Pd patches).
If you want the code, look for the function garray_dofo in g_array.c
Matt