view java/src/com/aurellem/send/AudioSend.java @ 13:92b416b4e027

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