obtain sample frame offset corresponding to certain time in audio file-iPhone

烈酒焚心 提交于 2019-12-25 01:32:24

问题


Given an audio file of duration 10s, if I want to seek to 2s, how do I obtain the sample frame offset?


回答1:


if it's LPCM (e.g. not compressed), then use the sample rate.

in pseudocode:

double sampleRate = audioFile.getSampleRate();
size_t offsetInSeconds = 2;
size_t sampleToRead = sampleRate * offsetInSeconds * audioFile.getChannelCount();
AudioSample sample = audioFile.getSampleAt(sampleToRead);


来源:https://stackoverflow.com/questions/4896472/obtain-sample-frame-offset-corresponding-to-certain-time-in-audio-file-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!