diff src/com/aurellem/capture/audio/AudioSendRenderer.java @ 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 2a525e937d86
children 784a3f4e6202
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/audio/AudioSendRenderer.java	Mon Oct 31 02:35:35 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/audio/AudioSendRenderer.java	Mon Oct 31 07:43:44 2011 -0700
     1.3 @@ -27,7 +27,7 @@
     1.4  	extends LwjglAudioRenderer implements MultiListener {
     1.5  
     1.6  	private AudioSend audioSend;
     1.7 -	private static final AudioFormat outFormat =  new AudioFormat(44100.0f, 32, 1, true, false);
     1.8 +	private AudioFormat outFormat;// =  new AudioFormat(44100.0f, 32, 1, true, false);
     1.9  	
    1.10  	/**
    1.11  	 * Keeps track of all the listeners which have been registered so far.
    1.12 @@ -106,7 +106,7 @@
    1.13  	public void initInThread(){
    1.14  		try{
    1.15              if (!AL.isCreated()){
    1.16 -                AL.create("Multiple Audio Send", (int) outFormat.getSampleRate(), 60, false);
    1.17 +                AL.create("Multiple Audio Send", 44100, 60, false);
    1.18              }
    1.19          }catch (OpenALException ex){
    1.20              logger.log(Level.SEVERE, "Failed to load audio library", ex);
    1.21 @@ -134,6 +134,9 @@
    1.22  		catch (NoSuchFieldException e) {e.printStackTrace();}
    1.23  		
    1.24  		this.audioSend = new AudioSend(this.deviceID);
    1.25 +		this.outFormat = audioSend.getAudioFormat();
    1.26 +		initBuffer();
    1.27 +		System.out.println(outFormat);
    1.28  		
    1.29  		// The LWJGL context must be established as the master context before 
    1.30  		// any other listeners can be created on this device.
    1.31 @@ -171,15 +174,29 @@
    1.32  	
    1.33  	
    1.34  	//public final static int BYTES_PER_SAMPLE = 4;
    1.35 -	private ByteBuffer buffer = BufferUtils.createByteBuffer(4096); 
    1.36  	
    1.37 -	private byte[] debug0 = new byte[4096];
    1.38 -	private byte[] debug1 = new byte[4096];
    1.39  	
    1.40 +	private ByteBuffer buffer;;
    1.41 +	private byte[] debug0;
    1.42 +	private byte[] debug1;
    1.43  	
    1.44 +	public static final int MIN_FRAMERATE = 10;
    1.45 +	
    1.46 +	private void initBuffer(){
    1.47 +		int bufferSize = (int)(this.outFormat.getSampleRate() / ((float)MIN_FRAMERATE)) * 
    1.48 +					this.outFormat.getFrameSize();
    1.49 +		this.buffer = BufferUtils.createByteBuffer(bufferSize);
    1.50 +		debug0 = new byte[4096];
    1.51 +		debug1 = new byte[4096];
    1.52 +			
    1.53 +	}
    1.54 +	/*
    1.55 +	
    1.56 +	*/
    1.57  	public void dispatchAudio(float tpf){
    1.58  		
    1.59  		int samplesToGet = (int) (tpf * outFormat.getSampleRate());
    1.60 +		System.out.println("want " + samplesToGet + " samples");
    1.61  		try {latch.await();} 
    1.62  		catch (InterruptedException e) {e.printStackTrace();}
    1.63  		audioSend.step(samplesToGet);