我正在使用 Android,试图让我的 AudioTrack 应用程序播放 Windows .wav 文件 (Tada.wav)。坦率地说,这不应该这么难,但我听到了很多奇怪的事情。该文件保存在我手机的迷你 SD 卡上,读取内容似乎不是问题,但是当我播放该文件时(参数我非常确定是正确的),我收到几秒钟的白噪音在声音似乎自行分解为可能正确的东西之前。
我已成功录制并在电话上播放自己的声音 - 我根据本示例中的说明创建了一个 .pcm 文件:
http://emeadev.blogspot.com/2009/09/raw-audio-manipulation-in-android.html http://emeadev.blogspot.com/2009/09/raw-audio-manipulation-in-android.html
(没有向后掩蔽)...
有人对网络上在 Android 上播放 .wav 文件的示例有一些建议或了解吗?
谢谢,
R。
我偶然发现了答案(坦率地说,通过尝试 &^@!我认为不会起作用),以防有人感兴趣......在我的原始代码中(源自原始帖子链接中的示例),从文件中读取数据如下:
InputStream is = new FileInputStream (file);
BufferedInputStream bis = new BufferedInputStream (is, 8000);
DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file
int i = 0; // Read the file into the "music" array
while (dis.available() > 0)
{
music[i] = dis.readShort(); // This assignment does not reverse the order
i++;
}
dis.close(); // Close the input stream
在此版本中,music[] 是 SHORTS 数组。因此,readShort() 方法在这里似乎有意义,因为数据是 16 位 PCM...但是,在 Android 上这似乎是问题所在。我将该代码更改为以下内容:
music=new byte[(int) file.length()];//size & length of the file
InputStream is = new FileInputStream (file);
BufferedInputStream bis = new BufferedInputStream (is, 8000);
DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file
int i = 0; // Read the file into the "music" array
while (dis.available() > 0)
{
music[i] = dis.readByte(); // This assignment does not reverse the order
i++;
}
dis.close(); // Close the input stream
在此版本中,music[] 是一个 BYTES 数组。我仍然告诉AudioTrack它是16位PCM数据,而我的Android似乎在将字节数组写入如此配置的AudioTrack中没有问题......无论如何,它最终听起来是对的,所以如果有人其他人想在 Android 上播放 Windows 声音,出于某种原因,这就是解决方案。啊,字节序……
R.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)