1

I have been searching the web for some help on this for some time but could not find help on this specific problem: I intend to play the wav file "click.wav" with SDL Mixer. For reasons I could not figure out so far, SDL Mixer fails to load it properly.

The thing I don't understand is, that exactly the same code executes as it should on a different machine. Everything else compiles and executes perfectly except for loading and playing the sound file:

Mix_Chunk *sound = NULL;

sound = Mix_LoadWAV("click.wav");
if(sound == NULL) {
   fprintf(framelog, "Unable to load WAV file: %s\n"; 
   Mix_GetError());
}

Mix_LoadWAV returns NULL but unfortunately Mix_GetError() does not return an error code. I even started to have a look at the SDL source code, but I didn't get far. In SDL_mixer.h: #define Mix_LoadWAV(file) Mix_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1) , that is Mix_LoadWAV gets replaced by the Mix_LoadWAV_RW call that reads the file from a RWOPS strucutre. It mainly delegates to SDL_RWFromFile(file, "rb") to actually open the file and generate the strucutre. Maybe this is where the error originates from.

Both computers use a Windows 7 64-Bit operating system, Visual Studio 2008 and SDL2. I installed and checked all the files: Header files: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\gl 32-bit lib files: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib 32-bit dll files: C:\WINDOWS\SysWOW64 64-bit lib files: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Windows\VC\libs\amd64 64-bit dll files: C:\WINDOWS\System32

I set the following additional dependencies for the linker: SDL2.lib, SDL2main.lib, opengl32.lib, odbc32.lib, odbccp32.lib, SDL_mixer.lib

Below you will find the code that I use. Even though SDL Mixer fails to load the wave file, this file can be played on this computer without any problems from other programs.

I would really appreciate it if there would be some advice on how to fix this stupid problem. I am not an expert programmer and started only very recently with SDL.

#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <SDL/SDL.h>    // SDL2 input
#include <SDL/SDL_mixer.h>
#include <GL/freeglut.h>
#include <ctime>        // get time() function for date
#include <algorithm>    // std::random_shuffle
#include <string.h> 

#include <stdlib.h>
#include "randomc.h"                   // define classes for random number generators
//#include "userintf.cpp"                // define system specific user interface
#include "mersenne.cpp"                // members of class TRandomMersenne


int main(int argc, char *argv[])
{
    // Initialize certain SDL units
    if (SDL_Init( SDL_INIT_EVERYTHING ) < 0) {
        printf("Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );  
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, BPP ); 
    SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1); //1 bit for the stencil

    screen = SDL_CreateWindow(
        "SDL2 window",                  // window title
        SDL_WINDOWPOS_UNDEFINED,           // initial x position
        SDL_WINDOWPOS_UNDEFINED,           // initial y position
        XMAX,                               // width, in pixels
        YMAX,                               // height, in pixels
        SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN           
    );

    // Create an OpenGL context associated with the window.
    screencontext = SDL_GL_CreateContext(screen);

    if (screen == NULL) {
        printf("Unable to set specified video format!\n");
        exit(2);
    }

    glutInit(&argc, argv);
    int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16SYS;
int audio_channels = 2;
int audio_buffers = 1024;

if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
    fprintf(framelog, "Unable to initialize audio: %s\n", Mix_GetError());
    exit(1);
}

Mix_Chunk *sound = NULL;

sound = Mix_LoadWAV("click.wav");
if(sound == NULL) {
    fprintf(framelog, "Unable to load WAV file: %s\n", Mix_GetError());
    exit(1);
 }
}
rockhard85
  • 11
  • 3

0 Answers0