Mercurial > hg > human-echolocation-java-webapp
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:dd2c566cdaf9 | 11:2129d2bac6cb |
---|---|
2 import javax.servlet.http.HttpServletRequest; | 2 import javax.servlet.http.HttpServletRequest; |
3 import javax.servlet.http.HttpServletResponse; | 3 import javax.servlet.http.HttpServletResponse; |
4 import javax.servlet.ServletException; | 4 import javax.servlet.ServletException; |
5 import javax.servlet.ServletConfig; | 5 import javax.servlet.ServletConfig; |
6 import java.io.IOException; | 6 import java.io.IOException; |
7 | |
7 import uk.ac.soton.isvr.*; | 8 import uk.ac.soton.isvr.*; |
8 | 9 |
9 import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; | 10 import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; |
10 import com.mathworks.toolbox.javabuilder.MWNumericArray; | 11 import com.mathworks.toolbox.javabuilder.MWNumericArray; |
12 import com.mathworks.toolbox.javabuilder.MWStructArray; | |
11 import com.mathworks.toolbox.javabuilder.MWException; | 13 import com.mathworks.toolbox.javabuilder.MWException; |
12 | 14 |
13 public class HumanEchoServlet extends HttpServlet { | 15 public class HumanEchoServlet extends HttpServlet { |
14 private HumanEcho echo; | 16 private HumanEcho echo; |
15 | 17 |
30 if(echo!=null) { | 32 if(echo!=null) { |
31 echo.dispose(); | 33 echo.dispose(); |
32 } | 34 } |
33 } | 35 } |
34 | 36 |
37 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
35 | 38 |
36 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | 39 // todo: validate/normalise distance |
37 // Test parameter | 40 int dist = Integer.parseInt(request.getParameter("dist")); |
38 MWNumericArray test = new MWNumericArray(Integer.parseInt(request.getParameter("test"))); | 41 MWStructArray Input = null; |
42 HumanEcho echo; | |
39 | 43 |
40 double[][] square = new double[0][]; | 44 try { |
45 echo = new HumanEcho(); | |
41 | 46 |
42 // double[][] square = new double[0][]; | 47 // Matlab structure: |
43 // WebFigure figure = null; | 48 // Input = struct('dist', 0.9, 'azim', 0, 'orient', 'horz', 'dirweight', 0.2, 'outputfname', 'foo.wav') |
44 /* | |
45 try { | |
46 // refers to the mcode function gen_echo.m | |
47 Object[] result = echo.gen_echo(1, test); | |
48 | 49 |
49 MWNumericArray array = (MWNumericArray)result[0]; | 50 String[] InputStructFields = {"dist", "azim", "orient", "dirweight", "outputfname"}; |
50 square = (double[][])array.toArray(); | 51 Input = new MWStructArray(1, 1, InputStructFields); |
52 Input.set("dist", 1, Double.valueOf(dist)); | |
53 Input.set("azim", 1, Double.valueOf(0)); | |
54 Input.set("orient", 1, "horz"); | |
55 Input.set("dirweight", 1, Double.valueOf(0.2)); | |
51 | 56 |
57 // the ofname should depend on the parameters | |
58 StringBuilder sb = new StringBuilder(); | |
59 sb.append("e_d"); | |
60 sb.append(dist); | |
61 sb.append(".wav"); | |
62 String outputfname = sb.toString(); | |
63 | |
64 Input.set("outputfname", 1, outputfname); | |
65 | |
66 // todo: before calling should test if wav already exists.. | |
67 Object[] result = echo.simulateBinauralSignals(Input); | |
52 } | 68 } |
53 catch(MWException e) { | 69 catch(MWException e) { |
54 e.printStackTrace(); | 70 e.printStackTrace(); |
55 } | 71 } |
56 | 72 |
73 /* | |
57 StringBuffer buffer = new StringBuffer(); | 74 StringBuffer buffer = new StringBuffer(); |
58 | 75 |
59 buffer.append("<BR>"); | 76 buffer.append("<BR>"); |
60 buffer.append("<BR>"); | 77 buffer.append("<BR>"); |
61 | 78 |