Morph2Applet

Author: Kees van den Doel


This demo hits a vibrating object represented by a modal reson bank. Two models are loaded, of a church bell and of a metal desklamp. The "morph" slider allows you to morph the soundmodels into each other.

Source code:

import jass.render.*;
import jass.engine.*;
import jass.generators.*;
import java.util.*;
import java.net.*;
import java.io.*;

public class Morph2Applet extends AppletController {

    SourcePlayer player;
    ModalModel mm,mm1,mm2; // morph between the two
    ModalObjectWithOneContact mob;
    OneShotBuffer force;
    double hitFreq = 1.;
    Hitter hitter;
    String syfile1;
    String syfile2;
    float morphPar = 0; // 0 is nodel 1, 1 is model 2
    int maxModes;
    
    public void setNSliders() {
        nsliders = 5;
    }

    public void setNButtons() {
        nbuttons = 1;
    }

    //for x = 0 is syfile1, for x = 1 is syfile2
    public void morph(double x) {
        for(int i=0;i< maxModes;i++) {
            mm.f[i] = (float)((1-x)*mm1.f[i] + x*mm2.f[i]);
            mm.d[i] = (float)((1-x)*mm1.d[i] + x*mm2.d[i]);
            mm.a[0][i] = (float)((1-x)*mm1.a[0][i] + x*mm2.a[0][i]);
        }
    }

    public void init() {
        super.init();
        syfile1 = getParameter("syfile1");
        syfile2 = getParameter("syfile2");
    }
    
    public void start() {
        float srate = 44100.f;
        int bufferSize = 128;
        int bufferSizeJavaSound = 8*1024;

        player = new SourcePlayer(bufferSize,bufferSizeJavaSound,srate);
        URL codebase = getCodeBase();
        URL syurl1 = null;
        URL syurl2 = null;
        try {
            syurl1 = new URL(codebase,syfile1);
            syurl2 = new URL(codebase,syfile2);
        } catch(MalformedURLException e) {
            System.out.println(e+" Malformed URL");
        }
        try {
            mm = new ModalModel(syurl1); // warp this one
            mm1 = new ModalModel(syurl1); // don't change this one
            mm2 = new ModalModel(syurl2); // don't change this one
        } catch(IOException e) {
            System.out.println(e);
        }
        maxModes = mm1.nfUsed;
        if(mm2.nfUsed < maxModes) {
            maxModes = mm2.nfUsed;
        }
        mob = new ModalObjectWithOneContact(mm,srate,bufferSize);
        float dur = .002f; // 2 ms
        int nsamples = (int)(srate * dur);
        float[] cosForce = new float[nsamples];
        for(int i=0;i