SDL_mixer plays static instead of .wav file

651 Views Asked by At

I'm making a version of Tetris in SDL 2 that has sounds. I have background music, which works fine. However, the sound effects (move, rotate, etc.) play static instead of what they're supposed to play.

Some code:

Definitions:

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

At the beginning:

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;
...

Play sound code:

Mix_PlayChannel(-1, move, 0);

Close:

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();

Miscellaneous info:

  • Using C++ in VS 2013
  • Using SDL_mixer 2.0.0, downloaded yesterday
  • Sounds are ~11kB, music is 94,675kB
  • The sounds play fine in Windows Media Player

Let me know if you need any other info, and thanks in advance!

0

There are 0 best solutions below