view webapp/WEB-INF/src/HumanEchoServlet.java @ 11:2129d2bac6cb

working on the servlet: calling the simulateBinauralSignals function on the doGet method.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 29 Nov 2013 15:48:07 +0000
parents 76f809129f98
children 08262829d456
line wrap: on
line source
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import java.io.IOException;

import uk.ac.soton.isvr.*;

import com.mathworks.toolbox.javabuilder.MWJavaObjectRef;
import com.mathworks.toolbox.javabuilder.MWNumericArray;
import com.mathworks.toolbox.javabuilder.MWStructArray;
import com.mathworks.toolbox.javabuilder.MWException;

public class HumanEchoServlet extends HttpServlet {
    private HumanEcho echo;

    public void init(ServletConfig config) throws ServletException {
        super.init(config);

        try {
            echo = new HumanEcho();
        }
        catch(MWException e) {
            e.printStackTrace();
        }
    }

    public void destroy() {
        super.destroy();

        if(echo!=null) {
            echo.dispose();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // todo: validate/normalise distance
        int dist = Integer.parseInt(request.getParameter("dist"));
        MWStructArray Input = null;
        HumanEcho echo;

        try {
            echo = new HumanEcho();

            // Matlab structure:
            // Input = struct('dist', 0.9, 'azim', 0, 'orient', 'horz', 'dirweight', 0.2, 'outputfname', 'foo.wav')

            String[] InputStructFields = {"dist", "azim", "orient", "dirweight", "outputfname"};
            Input = new MWStructArray(1, 1, InputStructFields);
            Input.set("dist", 1, Double.valueOf(dist));
            Input.set("azim", 1, Double.valueOf(0));
            Input.set("orient", 1, "horz");
            Input.set("dirweight", 1, Double.valueOf(0.2));

            // the ofname should depend on the parameters
            StringBuilder sb = new StringBuilder();
            sb.append("e_d");
            sb.append(dist);
            sb.append(".wav");
            String outputfname = sb.toString();

            Input.set("outputfname", 1, outputfname);

            // todo: before calling should test if wav already exists..
            Object[] result = echo.simulateBinauralSignals(Input);
        }
        catch(MWException e) {
            e.printStackTrace();
        }

 /*
        StringBuffer buffer = new StringBuffer();

        buffer.append("<BR>");
        buffer.append("<BR>");

        buffer.append("<TABLE >");
        for (double[] row : square)
        {
            buffer.append("<TR>");
            for (double value : row)
            {
                buffer.append("<TH>");
                buffer.append(new Double(value).intValue());
            }
        }
        buffer.append("</TABLE>");
        buffer.append("<BR>");
        response.getOutputStream().print(buffer.toString());
*/
    }
}