SDL Mix_LoadMUS not loading .mp3 - c++

So Apparently i've been trying to load an .mp3 using SDL_mixer. However, this does not work, as opposed to the libsdl wiki: SDL_mixer Mix_LoadMUS
I was hoping for it to work, but when loading and playing the file, the following errors popped in my console app:
Mix_LoadMUS: Unrecognized audio format
Mix_PlayMusic: music parameter was NULL
To my extent, i've been trying to load test.mp3 the following way:
Mix_Music * m_mainMusic;
m_mainMusic = Mix_LoadMUS("test.mp3");
if (m_mainMusic != nullptr)
printf("Loaded the file\n");
else
printf("Mix_LoadMUS: %s\n", Mix_GetError());
if (Mix_PlayMusic(m_mainMusic, -1) == -1)
printf("Mix_PlayMusic: %s\n", Mix_GetError());
I have obviously initialized the SDL subsystem.

With the help of the above explanations I tried to reproduce your issue, and the only thing that caused something similar was the lack of runtime libraries. Make sure that all the necessary libraries are available during runtime (copy them in the folder of your executable or set an environment variable or use static linking.) The runtime libraries distributed with SDL_mixer are the following ones: libmpg123-0, libmodplug-1, libFLAC-8, libogg-0, libopus-0, libopusfile-0, libvorbis-0, libvorbisfile-3 and SDL2_mixer.
These can be acquired here: https://www.libsdl.org/projects/SDL_mixer/

Related

Failing to load a png image in SDL2

I am trying to load PNG image, but it always ends in an error. I was first trying to use SDL's SDL_LoadBMP, but since that dind't work, I downloaded SDL2_image.h, did all the setup, but it still isn't working. The image is in the same directory as the cpp file. When I run my program, it runs, but prints error. Here is the function to load the image:
void loadImage()
{
image = IMG_Load("Untitled.png");
if (image == NULL)
std::cout << "error: " << SDL_GetError();
}
The error message from SDL_GetError is Failed loading libpng16-16.dll: The specified module could not be found. I tried passing the full path, but it gives an error and I don't know how to get around that problem since I am a beginner. Thanks.
Edit: After reading through the article linked in the answer to the tagged-duplicate question and making some changes(particularly installing the missing dll file and putting it in the same directory as the main cpp flie), I am getting this error message in a pop-up window: The procedure entry point inflateValidate could not be located in the dynamic link library, and the path to libpng16-16.dll is given after that.

SDL2_image not initializing

Im trying to load a .png file with SDL2 and SDL2_image. SDL2 initializes properly while SDL2_image just fails for no apparent reason, please help.
IMG_Init() returns 0
IMG_GetError() returns nothing
I'm using SDL2 2.0.10 and SDL2_image 2.0.5 (latest versions afaik)
I do have all needed dll files in the same folder as my executable (SDL2.dll, SDL2_image.dll, libpng16-16.dll, zlib1.dll as I'm only using png files right now)
I have no idea why this isn't working and I have been trying to find an answer for at least 2 hours now
My code:
if(IMG_Init(IMG_INIT_PNG) != 0) {
std::cout << "Failed to init sdl_image"<<IMG_GetError()<<std::endl;
return 0;
}
As HolyBlackCat pointed out, it should be IMG_INIT(IMG_INIT_PNG) != IMG_INIT_PNG instead of IMG_INIT(IMG_INIT_PNG) != 0

How to debug MagickReadImage fail when no Exception occurs

I have some MagickWand code where the MagickReadImage() fails (returns MagickFalse) on one system where it works on the other.
Now there is no exception occuring, MagickGetException() returns an empty string which means no exception if I understood the documentation correctly.
The file I want to open is there, I can open it with other tools under the same user, and the magick_wand I use is not NULL.
The code around the call is essentially this:
// read image
MagickBooleanType status = MagickReadImage(magick_wand, fn_selector);
// make sure it worked
if (status == MagickFalse)
{
char *description;
ExceptionType severity;
description=MagickGetException(magick_wand,&severity);
fprintf(stderr,"%s %s %lu :%s: %u\n",GetMagickModule(),description,severity);
description=(char *) MagickRelinquishMemory(description);
fprintf(stderr, "magickwand couldn't read file %s\n", fn_selector);
exit(1);
}
Is there any way to find out why the function call fails? MagickReadImage() seems to call an internal function which is not easily debuggable, and I don't want to build the MagickWand library myself with added debug stuff if not absolutely necessary.
Using MagickWand version 6.8.9.9 (debian jessie)
Turns out (after going through an strace) the PDF reading part of ImageMagick requires the ghostscript executable (/usr/bin/gs) to be installed on the system. Now when installing ImageMagick via the Debian apt package manager, ghostscript is not a dependency, only a recommend of the Magick library. Unfortunately Magick does not think it's necessary to inform you in any way that a library component is missing when the read call fails.
After installing the ghostscript package, everything works as expected.

Initializing SDL_Mixer gives error "Can't setup PulseAudio stream"

I'm coding an app on my raspberry-pi 3 running on Ubuntu-MATE.
I use C++ on code::blocks with SDL and SDL_Mixer to play mp3 files (I'm still using the v1.2 of the SDL libs).
I get no error when I init SDL, but when I init SDL_Mixer with this line :
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024)
It returns -1, so I get the error message with the Mix_GetError() method, and it gives me a "Can't setup PulseAudio stream" message.
I'm not aware of what PulseAudio is, so after some research I understood it's used for network streaming audio streams.
Why this module is needed at the init of the lib, and is there a way to go around it ? I don't intend to use network features in my app.
Also, I checked with a "sudo apt-get install pulseaudio" to make sure I wasn't missing some libs, but my packet manager seems to indicate that I have the latest update...
Any clues would really help me a lot !
Thanks
I finally resolved it myself... it was a fricking typo.
I wrote 444100 instead of 44100 for the frequency init parameter :/
Everything now load correctly (for SDL, I just used SDL_INIT_EVERYTHING for the ones who asked).
By the way, I only use SDL to use SDL_Mixer; I suppose SDL_Mixer can't run as standalone, so which module can I load in SDL to only init the basics ?
Also, now I'm curious : why does SDL_Mixer needs PulseAudio to init ?
Thanks

SDL - TTF - font not loading

I am having Problem loading SDL_TTF font.
my program is so big, so there's a piece of code which is creating problem.
TTF_Font *font = NULL;
SDL_Color textColor = {255, 255, 255};
if(SDL_Init() == -1 || TTF_Init() == -1)
return 0;
font = TTF_OpenFont("calibri.ttf", 28);
if(font == NULL)
return 0;
Now please tell me why the funtion TTF_OpenFont is not working.
font remains NULL after the funtion and the program exits...
EDIT:
I cannot cout or printf TTF_GetError() but i used breakpoints to see which function is not working correctly and found the function TTF_OpenFont() returning null every time.
(BTW if there any way to print the Erroe on screen the tell please).
TTF_Init() is working correctly.
FOR PEOPLE WHO ARE ASKING TO INSTALL SDL_TTF SEPARATELY:
I have written the link below from which i am learning SDL in first tutorial it guides how to install SDL and integrate it which project, In 3rd lesson comes the SDL_IMAGE extension library which is to be needed to install separately (which i did and used all image functions easily), In 7th lesson it didn't teach how to install SDL_TFF rather says to do the same steps as for SDL_IMAGE but this time for SDL_TTf so i downloaded SDL_TTF and intalled and you know the rest after....
Windows 8.1, CodeBlocks, MinGW32, SDL1
Here's the link i am learning SDL from
SDL Tutorials
This is how i installed the Extension Library(SDL_TTF)
Setting Up Extention Library
If font is NULL you should use TTF_GetError to know what went wrong.
If the error message is opaque you may want then to take a look at TTF_OpenFont source.
Suggestions:
1) substitute this code for TTF_Init():
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
2) Make sure you call it before any other SDL_ttf functions.
If you're still having problems, please specify
your platform (Windows? Linux?)
how you installed your TTF fonts.
3) See also: https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html
===================================================================
I'm sorry you're still having problems displaying fonts. A few additional suggestions:
1) I'm sure the tutorial you're using is very good. But you can't assume that just because you followed all the steps, you didn't inadvertantly miss something. To resolve the problem, you're going to have to "look beyond" the tutorial.
2) For starters, we need to confirm whether or not TTF_Init() succeeded. We must be able to see TTF_Init() return status, and TTF_GetError() messages.
Q: What is the return value of TTF_Init?
There are several ways you can display "TTF_GetError":
Start your program from a command prompt ("cmd"):printf("TTF_Init: %s\n", TTF_GetError());
Copy the error to a string and look at it under a debugger: char[80] msg; strcpy (msg, TTF_GetError());
Use a Win32 MessageBox to display the error in a pop-up: MSDN - MessageBox function
3) Make sure you have these .dll's on your filesystem:
libfreetype*.dll
SDL2_ttf*.dll
zlib*.dll
4) Look at the fonts you have installed on your filesystem, for example: C:\Windows\Fonts\*.ttf
See also SDL_ttf - Font directory/Where do fonts go?
PROBLEM SOLVED.
Thanks EveryOne for giving your time...
the problem was program was not recognizing font(candara )
so it copy pasted in my project folder.
I know this was already answerd but i ran into a similar problem with SDL2_ttf under Visual Studio 2015 and want to share my solution to help maybe others in the future.
My problem was that when i started my SDLe application that used SDLe_ttf it could not load the font that was placed in the same directory. But when i executed the the build executable manualy from the command line everything was fine.
I think the problem is that Visual Studio 2015 executes the build executable from a different directory and since i used only the font file name(Sans.ttf) it could not load the font because it treats it as a relative path.
My soultion was to just prefix the font file name with the execution directory which can be optained by calling SDL_GetBasePath.