我在播放 Mix_Chunk 时出现意外延迟
所以我正在尝试学习SDL并创建一个小游戏。 当用户按下空格键时,它应该播放声音。 这可行,但声音需要大约 0.5 秒才能播放...我该如何解决这个问题? 我检查了实际文件,看看延迟是否只是其中的一部分,结果并非如此。
Win Vista 上的 SDL 与 C++。
这是一些相关代码:
...
Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 )
...
main()
{
...
Mix_PlayMusic( BG_Music, 0 ); //background music
while( quit == false )
{
fps.start();
fire.handleInput( event, ship.get_x_pos() );
...
}
句柄输入函数:
void lasersC::handleInput( SDL_Event &event, int x )
{
Uint8 *keystates = SDL_GetKeyState( NULL );
if ( keystates[ SDLK_SPACE ] && delay == 0)
{
Mix_PlayChannel(-1, laser, 0);
fired * F = new fired( NULL, S_HEIGHT - 50, x + 20 );
F->shot = lasers;
F->y_pos = S_HEIGHT - 50;
F->x_pos = x + 20;
weps.push_back( F );
delay = 10;
}
}
如果需要更多,请告诉我。
So I am trying to learn SDL and creating a small game. When the user presses the space bar, it should play a sound. This works, but the sound takes about .5 seconds to play... How would I fix this? I've checked the actual file to see if the delay was just part of it, and that turned out to not be the case.
SDL with c++ on win vista.
Here's some relevant code:
...
Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 )
...
main()
{
...
Mix_PlayMusic( BG_Music, 0 ); //background music
while( quit == false )
{
fps.start();
fire.handleInput( event, ship.get_x_pos() );
...
}
the handle input function:
void lasersC::handleInput( SDL_Event &event, int x )
{
Uint8 *keystates = SDL_GetKeyState( NULL );
if ( keystates[ SDLK_SPACE ] && delay == 0)
{
Mix_PlayChannel(-1, laser, 0);
fired * F = new fired( NULL, S_HEIGHT - 50, x + 20 );
F->shot = lasers;
F->y_pos = S_HEIGHT - 50;
F->x_pos = x + 20;
weps.push_back( F );
delay = 10;
}
}
If more is needed, let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译 SDL 时通常会检查 DirectX 标头(显然)
您可以尝试使用 DirectX 支持重新编译吗?
另外,您在客户端执行了多少缓冲? 这可能是一个问题。
编辑 - 在下面的评论之后:
http://www.libsdl.org/extras/win32/common /directx-devel.tar.gz
There is usually a check for DirectX headers when compiling SDL (apparently)
Can you try to recompile with DirectX support?
Also, how much buffering are you enforcing at the client side? It may be a problem with that.
EDIT - After the comments below:
http://www.libsdl.org/extras/win32/common/directx-devel.tar.gz