LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: [CLOSED] OpenAL missing alcCaptureSamples number of samples  (Read 488 times)

Evan407

  • Newbie
  • *
  • Offline Offline
  • Posts: 40

from https://www.openal.org/documentation/OpenAL_Programmers_Guide.pdf
Code: [Select]
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?

Code: [Select]
  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);
}
  }

Quote
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]
8189
java.nio.DirectByteBuffer[pos=0 lim=0 cap=8192]
Logged

Evan407

  • Newbie
  • *
  • Offline Offline
  • Posts: 40
Re: OpenAL missing alcCaptureSamples number of samples
« Reply #1 on: January 14, 2017, 00:17:12 »

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.
Code: [Select]
  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.
Logged

Evan407

  • Newbie
  • *
  • Offline Offline
  • Posts: 40
Re: [CLOSED] OpenAL missing alcCaptureSamples number of samples
« Reply #2 on: January 17, 2017, 22:32:39 »

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