当移植用libsndfile编写的C ++代码时,我应该在Android中使用什么? [英] What should I use in Android when porting C++ code written with libsndfile?

查看:433
本文介绍了当移植用libsndfile编写的C ++代码时,我应该在Android中使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移植一个小的(<10类)C ++项目到Java。该项目操作声音文件,在C ++中使用 libsndfile 。该代码包括以下内容:

  const int channels = audioFileInfo.channels; 
...
sf_readf_double(audioFile,inputBuffer,MAX_ECHO);
...
sf_writef_double(outputAudioFile,& currentAudioBuffer [WINDOW_SIZE * channels],SEGMENTATION_LENGTH);

在Java中,在低级别操作声音文件的最好方法是什么?

进度报告

p>经过一番挖掘,我发现 javax.sound.sampled ,看起来它可能会做的工作。



编辑2 仔细检查后,它将无法工作(或至少没有任何可用的方式),因为它依赖于 com.sun.sound 包。



编辑3 com.sun.sound sun.misc 包是在GNU GPLv2下发布的,他们进我的项目。将 javax.sound.sampled 重命名为 imp.javax.sound.sampled 后,项目会编译,我可以创建 AudioFileFormat 对象,但没有抛出任何异常。



编辑4 确定,有些事情会出现在使用javax.sound.sampled,其他没有。例如,以下调用:

  AudioInputStream stream = AudioSystem.getAudioInputStream(waveFile)); 

不起作用,但我可以通过这样做:

  WaveFileReader wfr = new WaveFileReader(); 
AudioInputStream stream = wfr.getAudioInputStream(waveFile);

通常,调用 AudioSystem.getAudioFileTypes c $ c>返回空列表。我可以深入到这些包,看到它是与供应商,但我很失去如何补救这一点。有了我的对象它报告它的编码等正确,这是令人鼓舞的。



我的大问题这一刻正在创建一个Clip对象。这需要使用Line对象创建,这通常来自AudioSystem。可以使用Native开发工具包为Android编译libsndfile。可以使用Native开发工具包为Android编译libsndfile。一旦你为Android编译的库,你应该能够使用JNI从Java访问它。


I'm porting a small (<10 classes) C++ project to Java. The project manipulates sound files, and in C++ does this using libsndfile. The code includes stuff like:

const int channels = audioFileInfo.channels;
...
sf_readf_double( audioFile, inputBuffer, MAX_ECHO );
...
sf_writef_double( outputAudioFile, &currentAudioBuffer[WINDOW_SIZE * channels], SEGMENTATION_LENGTH );

In Java, what's the best way to manipulate sound files on a low level? I'm talking about stuff like normalizing, adding echoes etc.

Progress Report

After a bit of digging I've found javax.sound.sampled, which looks like it might do the job.

Edit 2 On closer inspection, it won't work (or at least not in any usable way), since it relies on the com.sun.sound package.

Edit 3 On even more inspection, and experimentation, the com.sun.sound and sun.misc packages are released under the GNU GPLv2, and I've downloaded them into my project. Having renamed javax.sound.sampled to imp.javax.sound.sampled, the project compiles, and I can create AudioFileFormat objects without any exceptions being thrown, yet. I haven't had a chance to play around much yet but I'll keep you updated.

Edit 4 Ok, Some things appear to work with javax.sound.sampled, others do not. For example, calls such as:

AudioInputStream stream = AudioSystem.getAudioInputStream(waveFile));

do not work, however I can get around this by doing:

WaveFileReader wfr = new WaveFileReader();
AudioInputStream stream = wfr.getAudioInputStream(waveFile);

In general, calls to things like AudioSystem.getAudioFileTypes() return empty lists. I can delve into the packages and see it's something to do with providers, but I'm at a loss how to remedy this. Having got my stream object it does report its encoding etc. correctly, which is encouraging.

My big problem at the moment is creating a Clip object. This needs to be created with a Line object, which would normally come from AudioSystem. Can anyone think of a way around this?

解决方案

libsndfile can be compiled for Android using the Native Development Kit. Once you have the library compiled for Android, you should be able to use JNI to access it from Java.

这篇关于当移植用libsndfile编写的C ++代码时,我应该在Android中使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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