如何在OpenAL中获取具有单个缓冲区的源的长度(持续时间)?

时间:2011-11-02 10:33:49

标签: c++ openal fmod

我正在从 FMOD 迁移到 OpenAL ,我找不到 FSOUND_Sample_GetLength()函数的模拟,它返回样本中的样本长度(考虑不考虑频率)...我从 alutLoadMemoryFromFileImage()获得 OpenAL 缓冲区名称,所以我不能用这种方式得到波形数据。

请帮忙!

1 个答案:

答案 0 :(得分:11)

您需要使用alGetBufferi()自行拼凑:

ALint sizeInBytes;
ALint channels;
ALint bits;

alGetBufferi(bufferID, AL_SIZE, &sizeInBytes);
alGetBufferi(bufferID, AL_CHANNELS, &channels);
alGetBufferi(bufferID, AL_BITS, &bits);

lengthInSamples = sizeInBytes * 8 / (channels * bits);

以秒为单位的持续时间:

ALint frequency;

alGetBufferi(bufferID, AL_FREQUENCY, &frequency);

durationInSeconds = (float)lengthInSamples / (float)frequency;