changeset 38:adeb88787645

fixed all problems for 16 bit mono output
author Robert McIntyre <rlm@mit.edu>
date Mon, 31 Oct 2011 07:43:44 -0700
parents 094a92b556a2
children 784a3f4e6202
files divergence/results.txt src/com/aurellem/capture/audio/AudioSendRenderer.java src/com/aurellem/capture/examples/AdvancedAudio.java
diffstat 3 files changed, 33 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/divergence/results.txt	Mon Oct 31 02:35:35 2011 -0700
     1.2 +++ b/divergence/results.txt	Mon Oct 31 07:43:44 2011 -0700
     1.3 @@ -5,7 +5,6 @@
     1.4  sqr-100Hz also diverges at 10.
     1.5  
     1.6  
     1.7 -
     1.8  calling audioRenderer.updateSourceParams in main update loop doesn't
     1.9  change output
    1.10  
    1.11 @@ -33,7 +32,6 @@
    1.12  Divergence gets worse the longer things run.
    1.13  
    1.14  
    1.15 -
    1.16  As the sound source moves about the listener in a circle, the sound
    1.17  should be at a constant volume, since the distance between the source
    1.18  and listener is constant. Instead, the sound varies depending on where
     2.1 --- a/src/com/aurellem/capture/audio/AudioSendRenderer.java	Mon Oct 31 02:35:35 2011 -0700
     2.2 +++ b/src/com/aurellem/capture/audio/AudioSendRenderer.java	Mon Oct 31 07:43:44 2011 -0700
     2.3 @@ -27,7 +27,7 @@
     2.4  	extends LwjglAudioRenderer implements MultiListener {
     2.5  
     2.6  	private AudioSend audioSend;
     2.7 -	private static final AudioFormat outFormat =  new AudioFormat(44100.0f, 32, 1, true, false);
     2.8 +	private AudioFormat outFormat;// =  new AudioFormat(44100.0f, 32, 1, true, false);
     2.9  	
    2.10  	/**
    2.11  	 * Keeps track of all the listeners which have been registered so far.
    2.12 @@ -106,7 +106,7 @@
    2.13  	public void initInThread(){
    2.14  		try{
    2.15              if (!AL.isCreated()){
    2.16 -                AL.create("Multiple Audio Send", (int) outFormat.getSampleRate(), 60, false);
    2.17 +                AL.create("Multiple Audio Send", 44100, 60, false);
    2.18              }
    2.19          }catch (OpenALException ex){
    2.20              logger.log(Level.SEVERE, "Failed to load audio library", ex);
    2.21 @@ -134,6 +134,9 @@
    2.22  		catch (NoSuchFieldException e) {e.printStackTrace();}
    2.23  		
    2.24  		this.audioSend = new AudioSend(this.deviceID);
    2.25 +		this.outFormat = audioSend.getAudioFormat();
    2.26 +		initBuffer();
    2.27 +		System.out.println(outFormat);
    2.28  		
    2.29  		// The LWJGL context must be established as the master context before 
    2.30  		// any other listeners can be created on this device.
    2.31 @@ -171,15 +174,29 @@
    2.32  	
    2.33  	
    2.34  	//public final static int BYTES_PER_SAMPLE = 4;
    2.35 -	private ByteBuffer buffer = BufferUtils.createByteBuffer(4096); 
    2.36  	
    2.37 -	private byte[] debug0 = new byte[4096];
    2.38 -	private byte[] debug1 = new byte[4096];
    2.39  	
    2.40 +	private ByteBuffer buffer;;
    2.41 +	private byte[] debug0;
    2.42 +	private byte[] debug1;
    2.43  	
    2.44 +	public static final int MIN_FRAMERATE = 10;
    2.45 +	
    2.46 +	private void initBuffer(){
    2.47 +		int bufferSize = (int)(this.outFormat.getSampleRate() / ((float)MIN_FRAMERATE)) * 
    2.48 +					this.outFormat.getFrameSize();
    2.49 +		this.buffer = BufferUtils.createByteBuffer(bufferSize);
    2.50 +		debug0 = new byte[4096];
    2.51 +		debug1 = new byte[4096];
    2.52 +			
    2.53 +	}
    2.54 +	/*
    2.55 +	
    2.56 +	*/
    2.57  	public void dispatchAudio(float tpf){
    2.58  		
    2.59  		int samplesToGet = (int) (tpf * outFormat.getSampleRate());
    2.60 +		System.out.println("want " + samplesToGet + " samples");
    2.61  		try {latch.await();} 
    2.62  		catch (InterruptedException e) {e.printStackTrace();}
    2.63  		audioSend.step(samplesToGet);
     3.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Mon Oct 31 02:35:35 2011 -0700
     3.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Mon Oct 31 07:43:44 2011 -0700
     3.3 @@ -208,16 +208,16 @@
     3.4  	music = new AudioNode(assetManager, "Sound/Environment/sqr-1kHz.wav", false);
     3.5  	
     3.6      rootNode.attachChild(music);
     3.7 -    //audioRenderer.playSource(music);
     3.8 -    //music.setPositional(true);
     3.9 -    //music.setVolume(1f);
    3.10 -    //music.setReverbEnabled(false);
    3.11 -    //music.setDirectional(false);
    3.12 -    //music.setMaxDistance(200.0f);
    3.13 -    //music.setRefDistance(1f);
    3.14 -    //music.setRolloffFactor(1f);
    3.15 -    //music.setLooping(false);
    3.16 -    //audioRenderer.pauseSource(music); 
    3.17 +    audioRenderer.playSource(music);
    3.18 +    music.setPositional(true);
    3.19 +    music.setVolume(1f);
    3.20 +    music.setReverbEnabled(false);
    3.21 +    music.setDirectional(false);
    3.22 +    music.setMaxDistance(200.0f);
    3.23 +    music.setRefDistance(1f);
    3.24 +    music.setRolloffFactor(1f);
    3.25 +    music.setLooping(false);
    3.26 +    audioRenderer.pauseSource(music); 
    3.27      
    3.28    }
    3.29  
    3.30 @@ -358,7 +358,7 @@
    3.31      
    3.32      System.out.println(countdown);
    3.33      
    3.34 -    if (countdown++ == 700) { this.requestClose(false);}
    3.35 +    if (countdown++ == 300) { this.requestClose(false);}
    3.36      
    3.37      //System.out.println("channel "+ music.getChannel());
    3.38      //listener.setLocation(cam.getLocation());