开发者

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

开发者 https://www.devze.com 2023-02-09 01:53 出处:网络
Given an audio file of duration 10s, if I want to seek to 2s, how do I obtain the s开发者_StackOverflow社区ample frame offset?if it\'s LPCM (e.g. not compressed), then use the sample rate.

Given an audio file of duration 10s, if I want to seek to 2s, how do I obtain the s开发者_StackOverflow社区ample frame offset?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号