Initializing SDL_Mixer gives error "Can't setup PulseAudio stream" - c++

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

Related

How to fix "SDL_Init failed -1" in buildroot Raspberry image?

I'm trying to compile Navit for Raspberry Pi 3 with Buildroot image (WPE Framework included). There is only WPE Framework running on startup (no x server) therefore I would like to display Navit using framebuffer directly. I know there is support for this feature. I have configured Navit as follow:
https://i.stack.imgur.com/cDZ3O.png
but I'm not able to run it anyway. There is following error:
error:graphics_sdl:graphics_sdl_new:SDL_Init failed -1
I've installed SDL from buildroot. How to fix it or make SDL more verbose to find out what is the reason of this -1 error (missing dependencies, incompatible lib version, Navit configration problems, missing system variables pointing to specified dependencies)?
It turned out that Navit is very quiet about SDL error messages. -1 Error is just very general information... I had to recompile Navit sources and add SDL_GetError() function to code to find out what is a real reason.
The problem was missing mouse. I don't need it so I had to set up:
export SDL_NOMOUSE=1

SDL Mix_LoadMUS not loading .mp3

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/

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.

SDL2 Mixer: "No SoundFonts have been requested"

I can't open audio device, my code is very simple:
Mix_Init(...);
Mix_OpenAudio(44100, AUDIO_U16SYS, 1, 16);
And error from Mix_GetError():
No SoundFonts have been requested
Any ideas why? My OS is Linux Mint 17 x64, SDL2 come from repository.
Apparently, this is caused by a dependency on FluidSynth, which requires a sound font to be selected at startup.
From the patch:
Because the backend is determined when Mix_OpenAudio is called,
Mix_SetSoundFonts needs to be called before this.
It may be possible to disable MIDI in order to avoid having to specify a sound font.

EDSDK cpp error: 10 EDS_ERR_MISSING_SUBCOMPONENT

I am trying to get started with EDSDK to control my Canon 500D. I'm new to cpp, and windows XP apps and I'm using visual studio. After a great deal of blind trial and error I have finally managed to get the app to compile the basic sample code from the documentation. To do this I have the EDSDK.h, EDSDKTypes.h and EDSDKErrors.h headers in the right places and the EDSDK.dll and EDSDK.lib in the same folder as the code. It seems to be picking these up. I have got the 500D to be recognised by the PC so I believe the USB drivers are there.
The code is just trying to pick up the camera:
EdsError err=EDS_ERR_OK;
EdsCameraListRef cameraList=NULL;
err = EdsGetCameraList(&cameraList);
if(err == EDS_ERR_OK)
{...}
However, when I run this console app the error is picked up as 10 - which suggests, according to the document, that there is a missing subcomponent. This happens both if the camera is connected or not, so I'm thinking this is something missing from the compile. But I am getting nowhere with the documentation.
I have installed the edsdk 2.4 Windows version from a download not the official route, so this may be an issue.
Can anyone help? Specifically how can I find out what the missing subcomponent might be so I might include it. Is this a subcmponent of the build like a header file or something like a driver?
I know, old question but still it might help someone with the same problem.
From the documentation:
All DLLs are required in order to execute an EDSDK client application.
All of the modules in the DLL folder must be copied into the same folder where the EDSDK client application is in.
This means you'll have to have all DLLs beside your *.exe. Namely these DLLs:
DPPDLL.dll
DPPLibCom.dll
DPPRSC.dll
EDSDK.dll
EdsImage.dll
Mlib.dll
Ucs32P.dll