please share a SDL MIXER example working..!!!

497 views
Skip to first unread message

colombian developers

unread,
Nov 1, 2013, 12:43:33 PM11/1/13
to native-cli...@googlegroups.com
please share a  SDL MIXER  example working..!!!

thanks

Ben Smith

unread,
Nov 1, 2013, 1:01:17 PM11/1/13
to native-cli...@googlegroups.com
On Friday, November 1, 2013 9:43:33 AM UTC-7, colombian developers wrote:
please share a  SDL MIXER  example working..!!!

thanks

Take a look at the DROD example game in naclports (examples/games/drod).

You can take a look at the source for the NaCl port here: https://github.com/binji/drod/tree/nacl, and see the diff from upstream here: https://github.com/binji/drod/compare/nacl.

DevelopDaily

unread,
Nov 1, 2013, 7:33:59 PM11/1/13
to native-cli...@googlegroups.com
You may go to the Chrome Web Store to search "RI-LI".

That is a railroad game based on NaCl and SDL.

BL

unread,
Nov 22, 2013, 7:01:41 PM11/22/13
to native-cli...@googlegroups.com
SDL_mixer was built for PNaCL. 
Can you tell me why I already included SDL_mixer.a, but still get the undefined link errors on using:
Mix_OpenAudio
Mix_CloseAudio

the link ordesr: I used and initializedSDL_Init() both VIDEO and AUDIO
SDL SDLmain SDL_image SDL_mixer ppapi ppapi_cpp ppapi_gles2 pthread ...

Thanks

Ben Smith

unread,
Nov 25, 2013, 1:34:07 PM11/25/13
to native-cli...@googlegroups.com
Hi BL,

My guess is that you are getting undefined symbol errors for SDL_OpenAudio from the Mix_OpenAudio function, correct?

Because SDL_mixer references symbols from SDL, it needs to come before SDL on the link line. Same with SDL_image.

... -lSDL_mixer -lSDL_image -lSDL ...

Here's a good blog post describing link order with static linking: http://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking/

-Ben

BL

unread,
Nov 29, 2013, 2:14:12 PM11/29/13
to native-cli...@googlegroups.com
Thanks Ben, 
further succeeded with SDL_Init(SDL_INIT_AUDIO) and Mix_OpenAudio() 
I try to load a "sample.wav" file and get error:
==> Mix_LoadWAV() failed. common.js:299
Mix_LoadWAV_RW with NULL src 
I put the "sample.wav" file in the same folder with the my audio.pexe
Seems the sample.wav could not be found or loaded. Where should the wav file be put ?

audio.pexe load wav api call:
    sample = Mix_LoadWAV("sample.wav");    
    if (sample == NULL)  {
       PostMessage("==> Mix_LoadWAV() failed.");
       PostMessage(Mix_GetError());

Ben Smith

unread,
Dec 2, 2013, 1:23:10 PM12/2/13
to native-cli...@googlegroups.com
Native Client runs in a sandbox, so it doesn't have access to your local filesystem directly.

In this case, you want to read a file from the same path on your web server. You have two options to make this work:

1) Use the nacl_io library. This will allow you to use fopen/fread/fwrite etc. normally. You can mount an "httpfs" filesystem to allow reading from the server:

From the nacl_io_demo example in the NaCl SDK:

  mount("",       /* source. Use relative URL */
        "/http",  /* target */
        "httpfs", /* filesystemtype */
        0,        /* mountflags */
        "");      /* data */

Now you can open the file by reading from "/http/<filename>":

  FILE* file = fopen("/http/sample.wav", "r");
  ...

2) You can use the URLLoader PPAPI interface directly. You won't be able use Mix_LoadWAV (because it relies on fopen). Looking at SDL_Mixer, it seems that Mix_LoadWav is a #define that calls Mix_LoadWav_RW, and takes as its first parameter a pointer to SDL_RWops. You could read from the server into a buffer, then use SDL_RWFromMem to create a SDL_RWops you can pass to Mix_LoadWav_RW.

In general, for porting existing code, using nacl_io will be much easier.

BL

unread,
Dec 7, 2013, 2:44:41 PM12/7/13
to native-cli...@googlegroups.com
Thanks Ben. I had sound works now. One more question:
Why the SDL callback is repeating non stop even I stop/pause audio playing (SDL_PauseAudio(1) ?

Ben Smith

unread,
Dec 9, 2013, 12:45:18 PM12/9/13
to native-cli...@googlegroups.com
This seems to be a bug in the NaCl SDL audio code. I've filed https://code.google.com/p/naclports/issues/detail?id=96 to track it.

Basically, the SDL audio code is ignoring the SDL audio thread and calling the user callback directly to fill its audio buffer. This means that none of the standard SDL audio code is called (e.g. pausing audio, frequency conversion, etc.)

To work around this, you can do what SDL_PauseAudio does: in your audio callback, fill the buffer with 0 when the audio is paused. It looks like you can call SDL_GetAudioStatus to see if the audio is currently paused.

DEBALINA MALLICK

unread,
Dec 23, 2013, 4:16:57 AM12/23/13
to native-cli...@googlegroups.com
Hi All,
Can you please share me a SDL_Mixer example which plays mp3 file in NACL. As my requirement is to play an mp3 file in NACL.
Reply all
Reply to author
Forward
0 new messages