## Recommended Posts

KuroKitten    151
I've been having troubles with SDL Mixer, namely, Mix_LoadMUS() fails repeatedly. I'm currently using an engine developed by another person. (his tutorial on it can be found here: http://gpwiki.org/index.php/SDL:Tutorials:Complete_2D_Engine_Overview ) The code itself is fairly simple, it's just been packaged in a nice OOP way. I've narrowed down the problem as well as I can - I currently have Mix_LoadMUS() attempt to load an mp3 file into a Mix_Music variable, and I have the game run as long as that variable isn't NULL. So the program will merely blip by for a second if Mix_LoadMUS() fails. All of his source code can be seen at the above linked Wiki. I've considered E-mailing him and asking, however, going over his code, it all looks fine and dandy, so I'm inclined to think it's something that I'm doing wrong, or specific to my computer. Here is my current game loop:
    Kore::cMusic bkgrndMusic("02.mp3");
g_SoundManager->SetMusicVolume(128);
bkgrndMusic.Play(-1);

bool isRunning = true;
while( bkgrndMusic.m_Music != NULL )
{
g_Timer->SetInterval(17);

isRunning = g_Input->Update(); // Update for any new Input. Set isRunning to False if the window has been closed.
//if(g_Input->IsKeyDown(KEY_UP))
//g_SoundManager->SetMusicVolume( g_SoundManager->GetMusicVolume() + 16 );
//if(g_Input->IsKeyDown(KEY_DOWN))
//g_SoundManager->SetMusicVolume( g_SoundManager->GetMusicVolume() - 16 );

g_Graphics->ClearScreen();

// Draw shit.

g_Graphics->SwapBuffers();

while( !(g_Timer->TimeUp()) )
{
// If the game is running faster than 60 frames a second, wait a little bit.
g_Timer->Sleep(1);
}

g_Timer->Sleep(1); // Prevent the game from hogging CPU.
}


Only a few things to note, I changed his source code a little bit: cInput now returns False instead of True on an SDL_Quit message (that just made more sense to me) and I moved m_Music up to public for testing purposes. The only thing I can come up with is that, for whatever reason, the program just isn't finding my mp3 file. Of course this doesn't make any sense... It's right there in the folder and it's named appropriately... But it's the only thing I can come up with. If anyone has any ideas, I would be more than grateful! If you need any more information, just ask. Huge thanks in advance to any and all help offered. Hopefully I can get this seemingly illogical error figured out >.< Meow!

##### Share on other sites
Kylotan    9865
The working directory you're running from is probably not the directory with the mp3 in it.

##### Share on other sites
KuroKitten    151
Quote:
 Original post by KylotanThe working directory you're running from is probably not the directory with the mp3 in it.

The mp3 is Indeed in the same directory I'm running from. In fact, I was even begging to grow a little unsure whether or not I had put it in the right directory (I have the Engine's source files in a folder within the main games folder.) and so I made a second copy of the song, and put one in each directory. Still to no avail.

If it helps, I can map out how I have files set up:

Solace/    Kore Engine/                02.mp3        cAnimation.cpp        cAnimation.h        cAnimationManager.cpp        cAnimationManager.h        cApp.cpp        cApp.h        cCamera.cpp        cCamera.h        cFontManager.cpp        cFontManager.h        cGraphics.cpp        cGraphics.h        cInput.cpp        cInput.h        cMusic.cpp        cMusic.h        cProcessManager.cpp        cProcessManager.h        cSound.cpp        cSound.h        cSoundManager.cpp        cSoundManager.h        cStateManager.cpp        cStateManager.h        cTextureManager.cpp        cTextureManager.h        cTimer.cpp        cTimer.h        Engine.cpp        Engine.h           ePurpose.h        globals.h        GraphicTypes.h        keys.h        kore.h        Singleton.h    02.mp3    jpeg62.dll    libpng12.dll    main.cpp    SDL.dll    SDL_image.dll    SDL_mixer.dll    Solace.cpp    Solace.dev    Solace.exe    Solace.h    tiff.dll    zlib1.dll

##### Share on other sites
Kylotan    9865
You misunderstand; the directory containing the executable is not necessarily the working directory. How are you running the executable? From within an IDE? If so, try it at a command prompt. If there's a difference, it's because the IDE is running from a debug directory or something like that. Basically relative file paths can be fragile unless you've set the working directory to something predictable.

##### Share on other sites
KuroKitten    151
Quote:
 Original post by KylotanYou misunderstand; the directory containing the executable is not necessarily the working directory. How are you running the executable? From within an IDE? If so, try it at a command prompt. If there's a difference, it's because the IDE is running from a debug directory or something like that. Basically relative file paths can be fragile unless you've set the working directory to something predictable.

Oh, that's very interesting. I am in fact running from an IDE (Dev-Cpp if it helps to know.)

I recompiled, and then tried running both from CMD, as well as just flat out running the .exe through GUI. In both cases the song wasn't being loaded. I also tried changing the code so that it points exactly to the file:

Kore::cMusic bkgrndMusic("F:/Dev-Cpp/Projects/Solace/02.mp3");

And still, the same results... I feel like it follows no logic!

##### Share on other sites
Kylotan    9865
Try a different MP3, or perhaps a different format entirely? (A tracker format, or an .OGG, or whatever else the library supports.)

##### Share on other sites
KuroKitten    151
Quote:
 Original post by KylotanTry a different MP3, or perhaps a different format entirely? (A tracker format, or an .OGG, or whatever else the library supports.)

I just tried using an .ogg file - same results.

My next guess was that, perhaps, it's an issue specific to my computer. I sent the files to a friend (I RARed them, so the file hierarchy was consistent) and still the same results.

Next I though that maybe it was the library I was using to compile was old or faulty for some reason. I went to download the official most recent release of SDL_mixer, and included in there were some DLL files I hadn't seen before:

libogg-0.dll
libvorbis-0.dll
libvorbisfile-3.dll
smpeg.dll

I threw those in with my program and tried running it again. Sure enough! The .ogg files played perfectly! I tested it again with the .mp3 file... but to no avail. Oddly, the .mp3 file still wont play.

Any ideas on why .mp3 files still refuse to play?

##### Share on other sites
furibund    122
Quote:
 Original post by KuroKittenI also tried changing the code so that it points exactly to the file:Kore::cMusic bkgrndMusic("F:/Dev-Cpp/Projects/Solace/02.mp3");

Shouldn't it be:
Kore::cMusic bkgrndMusic("F:\\Dev-Cpp\\Projects\\Solace\\02.mp3");
?

##### Share on other sites
SsjAngelous    122
Being a little bit lazy i didnt actually look at the full source code on the link, mainly cause i am currently just working on something and procrastinating but less said about that the better :) could you answer me a few questions.

1. Are you initialising the SDL_INIT_AUDIO in your SDL_Init?
2. Can you shove a folder into where your source code is called Music and place your .mp3 in there, then instead of F:/Dev-Cpp/Projects/Solace/02.mp3 you can just put Music/02.mp3

I believe that i had a few random problems with my project when i was using SDL_Mixer it wasnt loading my audio files aswel, it just randomly worked when i double checked i had included all the SDL_Mixer Include files and Libraries, it seems to be very tempramental. If you have already fixed the problem then could you tell me what the problem was? if not i'm willing to try and help, i'm learning aswel.

##### Share on other sites
KuroKitten    151
Quote:
 Original post by SsjAngelous1. Are you initialising the SDL_INIT_AUDIO in your SDL_Init?

Yes, I am. It's within the initialization of the Audio Manager. In other words, before I can even create a Music object, SDL_INIT_AUDIO is initialized.

Quote:
 Original post by SsjAngelous2. Can you shove a folder into where your source code is called Music and place your .mp3 in there, then instead of F:/Dev-Cpp/Projects/Solace/02.mp3 you can just put Music/02.mp3

I have actually done both. In fact, it runs just fine from within the main folder simply using "filename" or "../filename" (Runs fine is a bit of a misnomer though, more on that below)

Quote:
 Original post by SsjAngelousI believe that i had a few random problems with my project when i was using SDL_Mixer it wasnt loading my audio files aswel, it just randomly worked when i double checked i had included all the SDL_Mixer Include files and Libraries, it seems to be very tempramental. If you have already fixed the problem then could you tell me what the problem was? if not i'm willing to try and help, i'm learning aswel.

I haven't completely fixed the problem. Ogg files do run perfectly now, with no problem at all. However, mp3 files still refuse to play. As I mentioned above, the issue was with dll files. SDL_Mixer doesn't put up an error if you're not using a certain dell, and instead just doesn't set itself up for that file type. Once I included the dlls, ogg files ran fine. mp3 files, however, still wont play. I'm using smpeg.dll for mp3 files. As far as I'm aware, this should be the only dll I need to play mp3 files, however, I have a slight suspicion that I'm missing a file or two, being as ogg files required 3 dlls.

##### Share on other sites
SsjAngelous    122
It pains me SDL, as good as it is to learn with i cant help but feel a little bit 2nd rate when using it, maybe i'm being snobby lol.

but if you do find yourself having to just use .ogg files you can use "Audacity" to convert your .mp3 files to .ogg files, its a lazy way out but if it works and you dont get a headache then its worth it right?