How to convert ShortBuffer to Buffer[]?

僤鯓⒐⒋嵵緔 提交于 2019-12-13 07:03:15

问题


I'm using JavaCV on Android, and I'm following along with this sample activity. https://code.google.com/p/javacv/source/browse/samples/RecordActivity.java

However the line that i'm having trouble with is

 recorder.record( ShortBuffer.wrap(audioData, 0, bufferReadResult). );

But i'm getting exceptions for that line as it is expecting a Buffer[]. However reading into Buffer and ShortBuffer, I'm not sure why it wont take it.

Declarations for record()

public void record(com.googlecode.javacv.cpp.opencv_core.IplImage image) throws com.googlecode.javacv.FrameRecorder.Exception { /* compiled code */ }

public void record(com.googlecode.javacv.cpp.opencv_core.IplImage image, int pixelFormat) throws com.googlecode.javacv.FrameRecorder.Exception { /* compiled code */ }

public void record(java.nio.Buffer[] samples) throws com.googlecode.javacv.FrameRecorder.Exception { /* compiled code */ }

This is my first time using the Buffer classes, so I'm a bit confused how they work.


回答1:


Buffer[] barray = new Buffer[1];
barray[0] = ShortBuffer.wrap(audioData, 0, bufferReadResult);
recorder.record(barray);


来源:https://stackoverflow.com/questions/17764641/how-to-convert-shortbuffer-to-buffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!