rlm@7: package com.aurellem.send; rlm@7: rlm@7: import java.nio.ByteBuffer; rlm@7: rlm@13: import javax.sound.sampled.AudioFormat; rlm@13: rlm@7: public class AudioSend { rlm@7: rlm@19: private final long deviceID; rlm@7: rlm@19: public AudioSend(long deviceID){ rlm@19: this.deviceID = deviceID; rlm@19: } rlm@7: rlm@19: /** This establishes the LWJGL context as the context which rlm@19: * will be copies to all other contexts. It must be called rlm@19: * before any calls to addListener(); rlm@19: */ rlm@19: public void initDevice(){ rlm@19: ninitDevice(this.deviceID);} rlm@19: public static native void ninitDevice(long device); rlm@7: rlm@19: /** rlm@19: * The send device does not automatically process sound. This rlm@19: * step function will cause the desired number of samples to rlm@19: * be processed for each listener. The results will then be rlm@19: * available via calls to getSamples() for each rlm@19: * listener. rlm@19: * @param samples rlm@19: */ rlm@19: public void step(int samples){ rlm@19: nstep(this.deviceID, samples);} rlm@19: public static native void nstep(long device, int samples); rlm@7: rlm@19: /** rlm@19: * Retrieve the final rendered sound for a particular rlm@19: * listener. contextNum == 0 is the main LWJGL rlm@19: * context. rlm@19: * @param buffer rlm@19: * @param samples rlm@19: * @param contextNum rlm@19: */ rlm@19: public void getSamples(ByteBuffer buffer, rlm@19: int samples, int contextNum){ rlm@19: ngetSamples(this.deviceID, buffer, rlm@19: buffer.position(), samples, contextNum);} rlm@19: public static native void rlm@19: ngetSamples(long device, ByteBuffer buffer, rlm@19: int position, int samples, int contextNum); rlm@7: rlm@19: /** rlm@19: * Create an additional listener on the recorder device. The rlm@19: * device itself will manage this listener and synchronize it rlm@19: * with the main LWJGL context. Processed sound samples for rlm@19: * this listener will be available via a call to rlm@19: * getSamples() with contextNum rlm@19: * equal to the number of times this method has been called. rlm@19: */ rlm@19: public void addListener(){naddListener(this.deviceID);} rlm@19: public static native void naddListener(long device); rlm@7: rlm@19: /** rlm@19: * This will internally call alListener3f in the rlm@19: * appropriate slave context and update that context's rlm@19: * listener's parameters. Calling this for a number greater rlm@19: * than the current number of slave contexts will have no rlm@19: * effect. rlm@19: * @param pname rlm@19: * @param v1 rlm@19: * @param v2 rlm@19: * @param v3 rlm@19: * @param contextNum rlm@19: */ rlm@19: public void rlm@19: setNthListener3f(int pname, float v1, rlm@19: float v2, float v3, int contextNum){ rlm@19: nsetNthListener3f(pname, v1, v2, v3, rlm@19: this.deviceID, contextNum);} rlm@19: public static native void rlm@19: nsetNthListener3f(int pname, float v1, float v2, rlm@19: float v3, long device, int contextNum); rlm@19: rlm@19: /** rlm@19: * This will internally call alListenerf in the rlm@19: * appropriate slave context and update that context's rlm@19: * listener's parameters. Calling this for a number greater rlm@19: * than the current number of slave contexts will have no rlm@19: * effect. rlm@19: * @param pname rlm@19: * @param v1 rlm@19: * @param contextNum rlm@19: */ rlm@19: public void setNthListenerf(int pname, float v1, int contextNum){ rlm@19: nsetNthListenerf(pname, v1, this.deviceID, contextNum);} rlm@19: public static native void rlm@19: nsetNthListenerf(int pname, float v1, rlm@19: long device, int contextNum); rlm@19: rlm@19: /** rlm@19: * Retrieve the AudioFormat which the device is using. This rlm@19: * format is itself derived from the OpenAL config file under rlm@19: * the "format" variable. rlm@19: */ rlm@19: public AudioFormat getAudioFormat(){ rlm@19: return ngetAudioFormat(this.deviceID);} rlm@19: public static native AudioFormat ngetAudioFormat(long device); rlm@7: }