这个问题已经解决了!非常感谢布拉德,丹尼斯和瘾君子!你是英雄!:)
这是工作代码.它连接到Zeemote并从中读取数据.
public class ZeeTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { for (int i = 0; i < 3; i++) { test(); } } catch (Exception e) { e.printStackTrace(); } } private boolean connected = false; private BluetoothSocket sock; private InputStream in; public void test() throws Exception { if (connected) { return; } BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter(). getRemoteDevice("00:1C:4D:02:A6:55"); Method m = zee.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); sock = (BluetoothSocket)m.invoke(zee, Integer.valueOf(1)); Log.d("ZeeTest", …
我正在使用SoundPool 在我的应用程序中播放音频剪辑.一切都很好,但我需要知道剪辑播放何时结束.
目前,我通过使用MediaPlayer实例获取每个剪辑的持续时间来在我的应用中跟踪它.这工作正常,但加载每个文件两次看起来很浪费,只是为了得到持续时间.我可以自己知道文件的长度(可从AssetFileDescriptor获得)粗略计算持续时间,但我仍然需要知道采样率和通道数.
我看到了这个问题的两种可能解决方案:
有什么建议?
谢谢,马克斯
我目前正在使用的代码(工作正常,但为此目的而言相当沉重):
String[] fileNames = ...
MediaPlayer mp = new MediaPlayer();
for (String fileName : fileNames) {
AssetFileDescriptor d = context.getAssets().openFd(fileName);
mp.reset();
mp.setDataSource(d.getFileDescriptor(), d.getStartOffset(), d.getLength());
mp.prepare();
int duration = mp.getDuration();
// ...
}
Run Code Online (Sandbox Code Playgroud)
在旁注中,这个问题已被提出但没有得到答案.
我的代码以前从未用于处理有符号值,因此字节 - >短转换错误地处理了符号位.正确地解决了这个问题.
我正在尝试更改PCM数据流的音量.我可以从立体声文件中提取单通道数据,通过跳过/复制它们/插入零/等对样本做各种愚蠢的实验效果但我似乎找不到以任何方式修改实际样本值的方法并得到一个合理的产出.
我的尝试非常简单: http://i.imgur.com/FZ1BP.png
(value = -value工作正常 - 反转波并听起来相同)
执行此操作的代码同样简单(I/O使用0-65535范围内的无符号值) < - 这就是问题,读取正确签名的值可以解决问题:
// NOTE: INVALID CODE
int sample = ...read unsigned 16 bit value from a stream...
sample -= 32768;
sample = (int)(sample * 0.9f);
sample += 32768;
...write unsigned 16 bit value to a stream...
// NOTE: VALID CODE
int sample = ...read *signed* 16 bit value from a stream...
sample = (int)(sample * …
Run Code Online (Sandbox Code Playgroud)