SDL基准声音

SDL Benchmark Sound

本文关键字:声音 基准 SDL      更新时间:2023-10-16

我正在为我的最后一个cs项目在两个图形库(SDL、SFML)之间进行一个基准测试项目。我几乎完成了,然而,当我对播放声音的速度进行基准测试时,无论他做了多少循环,它总是返回0所花费的时间。你知道我的代码出了什么问题吗?声音确实在播放,但我可能应该做一些其他算法。

void playSound()
{
    Mix_PlayChannel(-1, sound, 0);
}
void soundBenchmark(int numOfCycles)
{
    int time = SDL_GetTicks(), timeRequired;
    for(int i = 0; i < numOfCycles; i++) playSound();
    timeRequired = SDL_GetTicks() - time;
    cout << "Time required for " << numOfCycles << " cycles: " <<  timeRequired << " seconds.n";
}

函数Mix_PlayChannel()不会阻止代码的执行。该函数只需将数据发送到声卡(或等效设备)并返回。

您必须记住使用Mix_PlayChannel()的频道,然后定期使用Mix_Playing()检查该频道是否正在播放,并查看时间。