obtain sample frame offset corresponding to certai

2019-09-01 23:53发布

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

1条回答
\"骚年 ilove
2楼-- · 2019-09-02 00:20

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);
查看更多
登录 后发表回答