rlm@7
|
1 package com.aurellem.send;
|
rlm@7
|
2
|
rlm@7
|
3 import java.nio.ByteBuffer;
|
rlm@7
|
4
|
rlm@13
|
5 import javax.sound.sampled.AudioFormat;
|
rlm@13
|
6
|
rlm@7
|
7 public class AudioSend {
|
rlm@7
|
8
|
rlm@19
|
9 private final long deviceID;
|
rlm@7
|
10
|
rlm@19
|
11 public AudioSend(long deviceID){
|
rlm@19
|
12 this.deviceID = deviceID;
|
rlm@19
|
13 }
|
rlm@7
|
14
|
rlm@19
|
15 /** This establishes the LWJGL context as the context which
|
rlm@19
|
16 * will be copies to all other contexts. It must be called
|
rlm@19
|
17 * before any calls to <code>addListener();</code>
|
rlm@19
|
18 */
|
rlm@19
|
19 public void initDevice(){
|
rlm@19
|
20 ninitDevice(this.deviceID);}
|
rlm@19
|
21 public static native void ninitDevice(long device);
|
rlm@7
|
22
|
rlm@19
|
23 /**
|
rlm@19
|
24 * The send device does not automatically process sound. This
|
rlm@19
|
25 * step function will cause the desired number of samples to
|
rlm@19
|
26 * be processed for each listener. The results will then be
|
rlm@19
|
27 * available via calls to <code>getSamples()</code> for each
|
rlm@19
|
28 * listener.
|
rlm@19
|
29 * @param samples
|
rlm@19
|
30 */
|
rlm@19
|
31 public void step(int samples){
|
rlm@19
|
32 nstep(this.deviceID, samples);}
|
rlm@19
|
33 public static native void nstep(long device, int samples);
|
rlm@7
|
34
|
rlm@19
|
35 /**
|
rlm@19
|
36 * Retrieve the final rendered sound for a particular
|
rlm@19
|
37 * listener. <code>contextNum == 0</code> is the main LWJGL
|
rlm@19
|
38 * context.
|
rlm@19
|
39 * @param buffer
|
rlm@19
|
40 * @param samples
|
rlm@19
|
41 * @param contextNum
|
rlm@19
|
42 */
|
rlm@19
|
43 public void getSamples(ByteBuffer buffer,
|
rlm@19
|
44 int samples, int contextNum){
|
rlm@19
|
45 ngetSamples(this.deviceID, buffer,
|
rlm@19
|
46 buffer.position(), samples, contextNum);}
|
rlm@19
|
47 public static native void
|
rlm@19
|
48 ngetSamples(long device, ByteBuffer buffer,
|
rlm@19
|
49 int position, int samples, int contextNum);
|
rlm@7
|
50
|
rlm@19
|
51 /**
|
rlm@19
|
52 * Create an additional listener on the recorder device. The
|
rlm@19
|
53 * device itself will manage this listener and synchronize it
|
rlm@19
|
54 * with the main LWJGL context. Processed sound samples for
|
rlm@19
|
55 * this listener will be available via a call to
|
rlm@19
|
56 * <code>getSamples()</code> with <code>contextNum</code>
|
rlm@19
|
57 * equal to the number of times this method has been called.
|
rlm@19
|
58 */
|
rlm@19
|
59 public void addListener(){naddListener(this.deviceID);}
|
rlm@19
|
60 public static native void naddListener(long device);
|
rlm@7
|
61
|
rlm@19
|
62 /**
|
rlm@19
|
63 * This will internally call <code>alListener3f<code> in the
|
rlm@19
|
64 * appropriate slave context and update that context's
|
rlm@19
|
65 * listener's parameters. Calling this for a number greater
|
rlm@19
|
66 * than the current number of slave contexts will have no
|
rlm@19
|
67 * effect.
|
rlm@19
|
68 * @param pname
|
rlm@19
|
69 * @param v1
|
rlm@19
|
70 * @param v2
|
rlm@19
|
71 * @param v3
|
rlm@19
|
72 * @param contextNum
|
rlm@19
|
73 */
|
rlm@19
|
74 public void
|
rlm@19
|
75 setNthListener3f(int pname, float v1,
|
rlm@19
|
76 float v2, float v3, int contextNum){
|
rlm@19
|
77 nsetNthListener3f(pname, v1, v2, v3,
|
rlm@19
|
78 this.deviceID, contextNum);}
|
rlm@19
|
79 public static native void
|
rlm@19
|
80 nsetNthListener3f(int pname, float v1, float v2,
|
rlm@19
|
81 float v3, long device, int contextNum);
|
rlm@19
|
82
|
rlm@19
|
83 /**
|
rlm@19
|
84 * This will internally call <code>alListenerf<code> in the
|
rlm@19
|
85 * appropriate slave context and update that context's
|
rlm@19
|
86 * listener's parameters. Calling this for a number greater
|
rlm@19
|
87 * than the current number of slave contexts will have no
|
rlm@19
|
88 * effect.
|
rlm@19
|
89 * @param pname
|
rlm@19
|
90 * @param v1
|
rlm@19
|
91 * @param contextNum
|
rlm@19
|
92 */
|
rlm@19
|
93 public void setNthListenerf(int pname, float v1, int contextNum){
|
rlm@19
|
94 nsetNthListenerf(pname, v1, this.deviceID, contextNum);}
|
rlm@19
|
95 public static native void
|
rlm@19
|
96 nsetNthListenerf(int pname, float v1,
|
rlm@19
|
97 long device, int contextNum);
|
rlm@19
|
98
|
rlm@19
|
99 /**
|
rlm@19
|
100 * Retrieve the AudioFormat which the device is using. This
|
rlm@19
|
101 * format is itself derived from the OpenAL config file under
|
rlm@19
|
102 * the "format" variable.
|
rlm@19
|
103 */
|
rlm@19
|
104 public AudioFormat getAudioFormat(){
|
rlm@19
|
105 return ngetAudioFormat(this.deviceID);}
|
rlm@19
|
106 public static native AudioFormat ngetAudioFormat(long device);
|
rlm@7
|
107 }
|