Question

I capture song in real-time with TargetDataLine:

line.read(buffer, 0, buffer.length);

But this buffer have to be byte array. I need capture to buffer which is long array or float array. I try to convert from byte to long or float but these data are not correct.

How Can I capture with another type or covert byte to float/long in correct way?

Was it helpful?

Solution

You could try this approach:

byte[] buffer = new byte[2048];
float[] fBuffer = new float[buffer.length >> 2];

ByteBuffer bb = ByteBuffer.wrap(buffer);
FloatBuffer fb = bb.asFloatBuffer();
fb.get(fBuffer, 0, fBuffer.length);

This does the conversion for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top