javascript - 如何在 AudioBufferSourceNode 中设置循环以精确匹配底层缓冲区中的特定偏移量?

标签 javascript html html5-audio web-audio-api

当使用 AudioBufferSourceNode 创建声音时,我可以设置偏移量和持续时间(以秒为单位)。

我有样本位置的偏移量和持续时间,我想我必须将其转换为时间,但我不知道从哪里开始。是否有可能获得精确匹配?

早期版本的 web-api 中似乎有示例偏移量和长度,但没有更多。

来自文档:( w3c )

Please note that as a low-level implementation detail, the AudioBuffer is at a specific sample-rate (usually the same as the AudioContext sample-rate), and that the loop times (in seconds) must be converted to the appropriate sample-frame positions in the buffer according to this sample-rate.

最佳答案

匹配应该是精确的,只需将样本位置除以采样率即可,

第二偏移量=样本偏移量/样本率

第二持续时间 = 样本持续时间/样本率

关于javascript - 如何在 AudioBufferSourceNode 中设置循环以精确匹配底层缓冲区中的特定偏移量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14882994/

相关文章:

javascript - 在函数中使用时为 "process is not defined"(Vue/Quasar)

javascript - 如何在等待函数结束的Javascript中创建加载器?

html - CSS 标签定位

javascript - 如何应用 EXIF 方向

javascript - 使用由 JavaScript 控制的 HTML5 音频时,某些轨道不可搜索

javascript - 构建 HTML5 音频流 Chrome 扩展 - 如何停止缓冲流

javascript - 从下拉菜单重定向

javascript - 在表中显示多对多关系的额外字段

jquery - 样式 <select/> 元素的 IE 问题

用于连续语音识别的 HTML5 语音输入 API