SDL_mixer播放静态而不是.wav文件

时间:2015-05-20 22:24:33

标签: c++ audio sdl sdl-2 sdl-mixer

我在SDL 2中制作了一个有声音的俄罗斯方块版本。我有背景音乐,效果很好。但是,声音效果(移动,旋转等)会播放静态而不是它们应该播放的声音。

一些代码:

说明:

Mix_Music *music;
Mix_Chunk *move, *rotate, *clear, *difficult, *gameOver;

一开始:

if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 4, 2048) != 0) {
    printf("Error: Failed to initiate Mixer subsystem. SDL_Mixer Error: %s\n", Mix_GetError());
    return false;
}

music = Mix_LoadMUS("music.wav");
if (music == NULL) {
    printf("Failed to load Music. SDL_Mixer Error: %s\n", Mix_GetError());
}

move = Mix_LoadWAV("move.wav");
if (move == NULL) {
    printf("Failed to load sound \"move\". SDL_Mixer Error: %s\n", Mix_GetError());
}

rotate = Mix_LoadWAV("rotate.wav");
if (rotate == NULL) {
    printf("Failed to load sound \"rotate\". SDL_Mixer Error: %s\n", Mix_GetError());
}
...
Mix_VolumeMusic((128 * options[0].currentOption * options[1].currentOption) / 10000); // (128 * 20 * 100) / 10000 = 25;
Mix_VolumeChunk(move, (128 * options[0].currentOption * options[2].currentOption) / 10000); // (128 * 20 * 100) / 10000 = 25;
Mix_VolumeChunk(rotate, (128 * options[0].currentOption * options[2].currentOption) / 10000); // (128 * 20 * 100) / 10000 = 25;
...

播放声音代码:

Mix_PlayChannel(-1, move, 0);

关闭:

Mix_FreeMusic(music);
music = NULL;
Mix_FreeChunk(move);
Mix_FreeChunk(rotate);
Mix_FreeChunk(clear);
Mix_FreeChunk(difficult);
Mix_FreeChunk(gameOver);
move = NULL;
rotate = NULL;
clear = NULL;
difficult = NULL;
gameOver = NULL;

Mix_Quit();

其他信息:

  • 在VS 2013中使用C ++
  • 使用昨天下载的SDL_mixer 2.0.0
  • 声音约为11kB,音乐为94,675kB
  • Windows Media Player中的声音播放正常

如果您需要任何其他信息,请告诉我,并提前致谢!

0 个答案:

没有答案