如何使用 Sound.loadPCMFromByteArray() 加载 WAV 文件?
基于此处的资源(定义 WAV 文件的结构),我能够获取第 44 个字节和文件末尾附近的音频数据(末尾存在一些额外的元数据,这是不必要的)。
但我在使用 Flash Player 11 中提供的新 Sound.loadPCMFromByteArray()
方法加载它时遇到了问题。
如果我传递样本数,我会收到此错误:
_sound.loadPCMFromByteArray(pcm, pcm.length, "float", wav.isStereo, wav.sampleRate);
- [Fault] 异常, information=ArgumentError: Error #2084: 参数的 AMF 编码不能超过 40K
但是,如果我将 pcm.length
除以四 (4),它似乎会播放“某些内容”但根本不是我最初通过的样本。另外,听起来它会永远循环,这是预期的行为吗? (我当然希望不会!)
//Dividing by 4 (# >> 2 is the same) is playable, but incorrect!
_sound.loadPCMFromByteArray(pcm, pcm.length >> 2, "float", wav.isStereo, wav.sampleRate);
WAV 数据的 ByteArray 是否需要以某种方式进行处理才能符合可读的 PCM 格式?我是否需要在末尾插入 EOF 字符以便它知道何时停止声音文件?
我应该使用“float”以外的其他格式吗?支持哪些?
Based on the resource here (defining the structure of a WAV file), I was able to get the audio data between the 44th byte and near the end of the file (some extra meta-data exists at the end which is not necessary).
But I'm having trouble loading it with the new Sound.loadPCMFromByteArray()
method available in Flash Player 11.
I get this error if I pass the number of samples:
_sound.loadPCMFromByteArray(pcm, pcm.length, "float", wav.isStereo, wav.sampleRate);
- [Fault] exception, information=ArgumentError: Error #2084: The AMF encoding of the arguments cannot exceed 40K
However, if I divide the pcm.length
by four (4), it seems to play "something" but isn't at all the sample that I passed it originally. Plus, it sounds like it's looping forever, is this the intended behavior? (I sure hope not!)
//Dividing by 4 (# >> 2 is the same) is playable, but incorrect!
_sound.loadPCMFromByteArray(pcm, pcm.length >> 2, "float", wav.isStereo, wav.sampleRate);
Does the ByteArray of WAV data need to be processed a certain way to conform to a readable PCM format? Do I need to insert an EOF character at the end so it knows when to stop the Sound file?
Should I use another format than "float"? Which ones are supported?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论