[CLOSED] OpenAL missing alcCaptureSamples number of samples

Started by Evan407, January 13, 2017, 03:21:52

Previous topic - Next topic

Evan407

from https://www.openal.org/documentation/OpenAL_Programmers_Guide.pdf
void alcCaptureSamples(
 ALCdevice *device,
 ALCvoid *buffer,
 ALCsizei samples
);


AL11.alcCaptureSamples(long device, java.nio.ByteBuffer buffer) isn't filling the buffer at all. Maybe its using 0 as an argument for samples?

  static long micDevice;
  static ByteBuffer captureBuffer = BufferUtils.createByteBuffer(8192);
  static boolean capturing = false;
  static void captureStart(){
	if(!capturing){
	  capturing = true;
	  micDevice = alcCaptureOpenDevice((ByteBuffer)null,44100,AL_FORMAT_MONO16,8192);
	  alcCaptureStart(micDevice);
	}
  }
  static void captureSamples(){//called repeatedly
	if(capturing){///test
	  System.out.println(alcGetInteger(micDevice,ALC_CAPTURE_SAMPLES));// retrieve the number of samples currently available
	  alcCaptureSamples(micDevice,captureBuffer);
	  System.out.println(captureBuffer.mark());
	  captureBuffer.flip();
	}
  }
  static void captureEnd(){
	if(capturing){
	  capturing = false;
	  alcCaptureCloseDevice(micDevice);
	}
  }


Quote8189
java.nio.DirectByteBuffer[pos=0 lim=0 cap=8192]
8189
java.nio.DirectByteBuffer[pos=0 lim=0 cap=8192]
8189
java.nio.DirectByteBuffer[pos=0 lim=0 cap=8192]
8189
java.nio.DirectByteBuffer[pos=0 lim=0 cap=8192]
8189
java.nio.DirectByteBuffer[pos=0 lim=0 cap=8192]

Evan407

After looking into the source code I discovered it uses buffer.remaining() for the number of samples parameter!
Here is the working code that fills the buffer.
  static long micDevice;
  static ByteBuffer captureBuffer = BufferUtils.createByteBuffer(8192);
  static boolean capturing = false;
  static void captureStart(){
	if(!capturing){
	  capturing = true;
	  micDevice = alcCaptureOpenDevice((ByteBuffer)null,44100,AL_FORMAT_MONO16,8192);
	  alcCaptureStart(micDevice);
	}
  }
  static void captureSamples(){//called repeatedly
	if(capturing){///test
	  int numSamples = alcGetInteger(micDevice,ALC_CAPTURE_SAMPLES);
	  captureBuffer.limit(numSamples);//!! you have to do this 
	  alcCaptureSamples(micDevice,captureBuffer);
for(int i = 0; i < numSamples;i++)System.out.println(captureBuffer.get());////test
	  captureBuffer.clear();
	}
  }
  static void captureEnd(){
	if(capturing){
	  capturing = false;
	  alcCaptureCloseDevice(micDevice);
	}
  }


It uses limit() to set the remaining for the buffer.

Evan407

If anybody is reading this an error in the code is that each sample is 2 bytes not 1 byte.