문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top