1import("stdfaust.lib"); 2 3/*DISCLAMER: 4 This is a creative "non physical" finite difference scheme physical model 5 of a string, intended to show how changing the different physical 6 parameters has an impact on the sounding characteristics of the string. 7 8 I have to say that to make things physically correct, the number of 9 string points should change according to the variations of each 10 parameter. However, this cannot be done at run time, so physically 11 correct models can become a bit boring. You can use this model to 12 get an idea on how the parameters work, and then try with values even 13 outside these sliders range, to explore new sounds. 14 15 Beware that, being non physical, some parameters configurations could 16 blow up the model. In case that happens, simply re-run the program 17 to reset the dsp. 18 Have fun! 19*/ 20 21declare name "ControllableNonPhysicalString"; 22declare description "Linear string model with controllable (non physical) parameters."; 23declare author "Riccardo Russo"; 24 25//----------------------------------String Settings---------------------------// 26//nPoints=int(Length/h); 27nPoints = 100; 28 29k = 1/ma.SR; 30//Stability condition 31coeff = c^2*k^2 + 4*sigma1*k; 32h = sqrt((coeff + sqrt((coeff)^2 + 16*k^2*K^2))/2); 33 34T = hslider("[4]String Tension (N)", 150,20,1000,0.1); // Tension [N] 35radius = hslider("[5]String Radius (m)", 3.6e-04,2e-5,1e-3,0.00001); // Radius (0.016 gauge) [m] 36rho = hslider("[6]String Material Density (kg/m^3)", 8.05*10^3,1e1,1e6,1); // Density [kg/m^3]; 37Emod = hslider("[7]String Young Modulus (Pa)",174e4,1e-3,1e8,1); // Young modulus [Pa] 38Area = ma.PI*radius^2; // Area of string section 39I = (ma.PI*radius^4)/ 4; // Moment of Inertia 40K = sqrt(Emod*I/rho/Area); // Stiffness parameter 41c = sqrt(T/rho/Area); // Wave speed 42sigma1 = hslider("[9]Frequency Dependent Damping", 0.01,1e-5,1,0.0001); // Frequency dependent damping 43sigma0 = hslider("[8]Damping", 0.0005,1e-6,100,0.0001); // Frequency independent damping 44 45//----------------------------------Equations--------------------------------// 46den = 1+sigma0*k; 47A = (2*h^4-2*c^2*k^2*h^2-4*sigma1*k*h^2-6*K^2*k^2)/den/h^4; 48B = (sigma0*k*h^2-h^2+4*sigma1*k)/den/h^2; 49C = (c^2*k^2*h^2+2*sigma1*k*h^2+4*K^2*k^2)/den/h^4; 50D = -2*sigma1*k/den/h^2; 51E = -K^2*k^2/den/h^4; 52 53midCoeff = E,C,A,C,E; 54midCoeffDel = 0,D,B,D,0; 55 56r = 2; 57t = 1; 58 59scheme(points) = par(i,points,midCoeff,midCoeffDel); 60 61//----------------------------------Controls---------------------------------// 62play = button("[3]Play"); 63inPoint = hslider("[1]Input Point",floor(nPoints/2),0,nPoints-1,0.01); 64outPoint = hslider("[2]Output Point",floor(nPoints/2),0,nPoints-1,0.01):si.smoo; 65 66//----------------------------------Force---------------------------------// 67forceModel = play:ba.impulsify; 68 69//----------------------------------Process---------------------------------// 70process = forceModel<:fd.linInterp1D(nPoints,inPoint): 71 fd.model1D(nPoints,r,t,scheme(nPoints)): 72 fd.linInterp1DOut(nPoints,outPoint)<:_,_;