SDL Benchmark Sound

时间:2013-11-25 12:53:49

标签: c++ audio sdl benchmarking

我正在为我的最终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";
}

1 个答案:

答案 0 :(得分:3)

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

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