<div dir="ltr"><div><div>I'm trying to translate CSound code from the FLOSS manuals for a van der Pol oscillator to make a Pd external. The CSound code is here <a href="http://en.flossmanuals.net/csound/g-physical-modelling/">http://en.flossmanuals.net/csound/g-physical-modelling/</a> (you have to scroll down till you reach the van der Pol section). I think I get what's going on there, but the results I get when writing the output to an array, are not the same as the ones provided in th FLOSS manuals.<br>
<br></div>Here's my perform routine:<br>t_int *vanDerPol_perform(t_int *w)<br>{<br>    // Copy the object pointer<br>    t_vanDerPol *x = (t_vanDerPol *) (w[1]);<br><br>    // Copy signal vector pointers<br>    t_float *frequency = (t_float *) (w[2]);<br>
    t_float *factor = (t_float*) (w[3]);<br>    t_float *excitor_freq = (t_float*) (w[4]);<br>    t_float *excitor_amp = (t_float*) (w[5]);<br>    t_float *output = (t_float *) (w[6]);<br><br>    // Copy the signal vector size<br>
    t_int n = w[7];<br><br>    // Dereference components from the object structure<br>    float twopi = x->x_twopi;<br>    float sr = x->x_sr;<br>    float si = x->x_si;<br>    float si_factor = x->x_sifactor;<br>
    float phase = x->x_phase;<br>    float step = (float) EXCITOR_STEPSIZE;<br><br>    // Local variables<br>    float phase_local;<br>    float drive_sine; // sinewave to excite the oscillator<br>    // van der Pol samples<br>
    float aa;<br>    float av = 0;<br>    float ax = 0;<br>    // damping factor<br>    float c;<br><br>    // Perform the DSP loop<br>    while(n--){<br>        // excitor code<br>        si = *excitor_freq++ * si_factor;<br>
        phase_local = phase / step;<br>        drive_sine = cos(phase_local * twopi) * *excitor_amp++;<br><br>        // van der Pol code<br>        c = 2 - 2 * cos(*frequency++ * twopi / sr);<br>        aa = (-c) * ax + *factor++ * (1 - ax * ax) * av;<br>
        av += aa;<br>        ax = ax + av + drive_sine;<br>        *output++ = av;<br><br>        // update phase<br>        phase += si;<br>        while(phase > step) phase -= step;<br>        while(phase < 0) phase += step;<br>
        }<br><br>    // Update object's variables<br>    x->x_phase = phase;<br>    x->x_si = si;<br><br>    // Return the next address in the DSP chain<br>    return w + 8;<br>}<br><br></div>In the FLOSS manuals it says that it is excited by a sine wave oscillator, so this is what I do in the code above, but I don't know what I'm doing wrong. Are there specific values I should set for frequency, excitation frequency, excitation amplitude and damping? The math is over my head to be honest, so I'm trying to copy an applied example and this code looks much like the CSound's code...Can someone give some insight?<br>
</div>