如何转换ShortBuffer到缓冲器[]? [英] How to convert ShortBuffer to Buffer[]?

查看:419
本文介绍了如何转换ShortBuffer到缓冲器[]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上使用JavaCV,而我这个样的活动一起以下。
的https://$c$c.google.com /p/javacv/source/browse/samples/RecordActivity.java

不过是我遇到麻烦了行

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

但我发现了异常该行,因为它是期待一个缓冲区[]。但是读入缓冲区和ShortBuffer,我不知道为什么它不会接受它。

有关记录的声明()

 公共无效记录(com.google code.javacv.cpp.opencv_core.IplImage图像)抛出com.google code.javacv.FrameRecorder.Exception {/ *编译code * /}公共无效记录(com.google code.javacv.cpp.opencv_core.IplImage形象,诠释的PixelFormat)抛出com.google code.javacv.FrameRecorder.Exception {/ *编译code * /}公共无效的记录(java.nio.Buffer中的[]样本)抛出com.google code.javacv.FrameRecorder.Exception {/ *编译code * /}

这是使用缓冲班我第一次,所以我有点糊涂了,他们是如何工作的。


解决方案

 缓冲区[] = barray新的缓冲区[1];
barray [0] = ShortBuffer.wrap(audioData,0,bufferReadResult);
recorder.record(barray);

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.

解决方案

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

这篇关于如何转换ShortBuffer到缓冲器[]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆