1 /*
2  * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * - Redistribution of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistribution in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in the
13  *   documentation and/or other materials provided with the distribution.
14  *
15  * Neither the name of Sun Microsystems, Inc. or the names of
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * This software is provided "AS IS," without a warranty of any kind. ALL
20  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23  * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26  * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27  * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28  * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29  * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30  * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  */
32 
33 package com.jogamp.audio.windows.waveout;
34 
35 import java.io.*;
36 import com.jogamp.nativewindow.NativeSurface;
37 import com.jogamp.opengl.GLDrawableFactory;
38 
39 public class TestSpatialization {
main(String[] args)40     public static void main(String[] args) {
41         if (args.length != 1) {
42             System.out.println("Usage: TestSpatialization [file name]");
43             System.exit(1);
44         }
45 
46         try {
47             // FIXME: this is a hack to get the native library loaded
48             try {
49                 GLDrawableFactory.getFactory(NativeSurface.class);
50             } catch (Exception e) {}
51             // Initialize the audio subsystem
52             Audio audio = Audio.getInstance();
53             // Create a track
54             Track track = audio.newTrack(new File(args[0]));
55             track.setPosition(1, 0, 0);
56             // Run for ten seconds
57             long startTime = System.currentTimeMillis();
58             long duration = 10000;
59             long curTime = 0;
60             try {
61                 Thread.sleep(500);
62             } catch (InterruptedException e) {
63             }
64             System.out.println("Playing...");
65             track.setLooping(true);
66             track.play();
67             while ((curTime = System.currentTimeMillis()) < startTime + duration) {
68                 // Make one revolution every two seconds
69                 float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2);
70                 track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads));
71                 // Would like to make it go in a circle, but since
72                 // stereo doesn't work now, make it move along a line
73                 // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads));
74                 // Sleep a little between updates
75                 try {
76                     Thread.sleep(10);
77                 } catch (InterruptedException e) {
78                 }
79             }
80             System.out.println("Shutting down audio subsystem");
81             audio.shutdown();
82             System.out.println("Exiting.");
83             System.exit(0);
84         } catch (Exception e) {
85             e.printStackTrace();
86             System.exit(1);
87         }
88     }
89 }
90