SDL port for Android SDK/NDK 1.6

Quickly share your Android Code Snippets here...

Re: SDL port for Android SDK/NDK 1.6

Postby shishanjiu » Sun Apr 28, 2013 4:22 am

pelya wrote:
shishanjiu wrote:On my android phone, when return from suspend, my app's screen is splitted to two frames

I've fixed a similar bug few months ago, it was caused by screen orientation not changing immediately to landscape during suspend, and it happened only during initialization.
Are you using latest Git revision of the SDL? On what device did you test it? Are you using software SDL screen surface or OpenGL? Can you reproduce the bug with some minimal application, Ballfield for example?
Can you add some logs to the MainActivity.onResume(), and check that isCurrentOrientationHorizontal() returns true?


I'm not similiar with Git.I always get the whole of it and this will use too much time. How can I get only the changes of git? Any instructions or parameters can do this with git? Thanks a lot.

I'm using xiaomi phone and software SDL screen. Ballfield doesn't reproduce the bug, but I think it's due to SDL_Flip(SDL_GetVideoSurface()) in while(1) loop. In my app there're not SDL_Flip every second. After EACH return from suspend, the screen is splitted to two same parts, which are both the left half of normal screen.

pelya wrote:
shishanjiu wrote:Another question. An apk may have some entries or functions to execute different works, and may have some icons created on desktop to launch different functions after it's installed, just like settings of Android.

SDL does not support that. If you want to add that functionality, you'll need to edit Java files and AndroidManifest.xml/AndroidManifestTemplate.xml by yourself.


I know I need to edit Jave files and AndroidManifest.xml to implement this. But how can I link java funtion to SDL function, for example, to call a SDL's subfuntion after clicking one icon of desktop or call main function with different parameters?
shishanjiu
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Sep 20, 2012 3:41 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Sun Apr 28, 2013 12:30 pm

In my app there're not SDL_Flip every second.
That may be the cause, I'll try to reproduce it myself.

shishanjiu wrote:But how can I link java funtion to SDL function, for example, to call a SDL's subfuntion after clicking one icon of desktop or call main function with different parameters?

You'll need to use JNI. There's a simple example in your NDK directory, in samples/hello-jni. You may also look at SDL sources, in files project/java/Audio.java and project/jni/sdl-1.2/src/audio/android/SDL_androidaudio.c.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby protomank » Mon Apr 29, 2013 2:28 pm

Hellow pelya. I want to thank you for your po9rt of SDL 1.2, with it, i was able to port my game project http://rockbot.upperland.net in three days (it took me more time to find some instructions than actually porting, that needed only two ifdefs).
Here is a screenshot of the game running: https://www.facebook.com/photo.php?fbid=10151193844063039&set=a.10151193843878039.1073741828.232478063038&type=1&relevant_count=1

One question I have is about speed, is using HW surfaces faster than SW in the Android's SDL port? I'm starting video with HW currently and getting around 15 fts on my i5800 phone (Samsung Galaxy 3) that have a 670Mhz CPU but a really bad GPU and 50 fps on the Samsung Galaxy Tab 10.1.
Also, my game uses 8 bits color, and I didn't find any references about it, only 16/24 bits, could this slow down the video?

Thanks a lot for your effort, it made my day :)
protomank
Freshman
Freshman
 
Posts: 5
Joined: Mon Apr 29, 2013 2:18 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Apr 29, 2013 4:51 pm

If you're not using OpenGL directly, you should set SwVideoMode=y inside AndroidAppSettings.cfg, this will be the fastest. 8-bit video surface is converted to 16/24 bit surface every frame, so I suggest also setting VideoDepthBpp=16, because it will be faster.
BTW there was a bug in the on-screen keyboard configuration, which I've fixed this Friday, it's seen in your screenshot (Ab button should be at top-left). Please update your SDL repository, uninstall and reinstall the game.
If you don't want SDL startup menu being shown, set StartupMenuButtonTimeout=0 inside AndroidAppSettings.cfg (you don't need to configure mouse).
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby protomank » Wed May 01, 2013 4:37 pm

pelya, thanks for the tips on speed, I got 10-20 fps with those :)

But I'm having one issue, when I set SdlVideoResizeKeepAspect, part of the screen, on the right side is just blank (as it is not being used by tha game); the problem is that the on-screen keys that should appear there aren't being drawn by SDL, so I have to disable keep aspect to use the on-screen keyboard... Is there a way to fix that?
Also, is there a way to center the game image when keep aspect is false? (I probally can hack it, if needed, but if there is already a way for doing so, it won't be needed to change the SDL code by myself).

Thanks a lot! :)
protomank
Freshman
Freshman
 
Posts: 5
Joined: Mon Apr 29, 2013 2:18 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Wed May 01, 2013 5:46 pm

I hope I'll fix that aspect ratio setting in the next two weeks.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby protomank » Wed May 01, 2013 6:43 pm

Thanks. I'm glad to know that you are still working on the SDL port :)
protomank
Freshman
Freshman
 
Posts: 5
Joined: Mon Apr 29, 2013 2:18 pm

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Sun May 19, 2013 8:23 pm

Hi pelya! I'm back :P

Have you fixed the Aspect Ratio Issue?
I've got the videos working, but now I can't use sndfile, it kills the app in this line:

Code: Select all
sFile1 = sf_open(getFilename(AID_Stage03Do).c_str(), SFM_READ, &sInfo1);


I'm using this code for initializing the files and so on:

Code: Select all
int BUFFLEN = 1600000;
   int BUFFLENMINI = 70000;

   SF_INFO sInfo1;
   SF_INFO sInfo2;
   SF_INFO sInfo3;
   SF_INFO sInfo4;
   SF_INFO sInfo5;

   SNDFILE *sFile1 = NULL;
   SNDFILE *sFile2 = NULL;
   SNDFILE *sFile3 = NULL;
   SNDFILE *sFile4 = NULL;
   SNDFILE *sFile5 = NULL;

   double *buffDo;
   double *buffFa;
   double *buffSol;
   double *buffSong;
   double *buffOutput;

   sf_count_t countDo = 0;
   sf_count_t countFa = 0;
   sf_count_t countSol = 0;
   sf_count_t countSong = 0;
   sf_count_t countOutput = 0;

   buffDo = (double*)malloc(BUFFLEN*sizeof(double));
   buffFa = (double*)malloc(BUFFLEN*sizeof(double));
   buffSol = (double*)malloc(BUFFLEN*sizeof(double));
   buffSong = (double*)malloc(BUFFLEN*sizeof(double));
   buffOutput = (double*)malloc(BUFFLEN*sizeof(double));

   sInfo1.format = 0;
   sInfo2.format = 0;
   sInfo3.format = 0;
   sInfo4.format = 0;

   logcat("Opening files...\n");

   logcat(getFilename(AID_Stage03Do).c_str());
   sFile1 = sf_open(getFilename(AID_Stage03Do).c_str(), SFM_READ, &sInfo1); // IT CRASHES HERE!!!
   logcat(getFilename(AID_Stage03Fa).c_str());
   sFile2 = sf_open(getFilename(AID_Stage03Fa).c_str(), SFM_READ, &sInfo2);
   logcat(getFilename(AID_Stage03Sol).c_str());
   sFile3 = sf_open(getFilename(AID_Stage03Sol).c_str(), SFM_READ, &sInfo3);
   logcat(getFilenameMusic(cancion).c_str());
   sFile4 = sf_open(getFilenameMusic(cancion).c_str(), SFM_READ, &sInfo4);
   
   float sampleRateMS = 1./float(sInfo1.samplerate) * 1000.;


   logcat("Opening file with SNDFILE...\n");

   sInfo5 = sInfo4;
   sFile5 = sf_open(generateOutputFile(cancion).c_str(), SFM_WRITE, &sInfo5);


   if (!sFile1 || !sFile2 || !sFile3 || !sFile4 || !sFile5) {
      return false;
   }

   logcat("SNDFILE reading ...\n");

   countDo = sf_read_double(sFile1, buffDo, BUFFLENMINI);
   countFa = sf_read_double(sFile2, buffFa, BUFFLENMINI);
   countSol = sf_read_double(sFile3, buffSol, BUFFLENMINI);
   countSong = sf_read_double(sFile4, buffSong, BUFFLEN);



And the app dies with this message on DDMS:
Code: Select all
05-19 21:21:14.049: I/MusicBox(32553): Opening files...
05-19 21:21:14.049: I/MusicBox(32553): resources/stage03/ACORDE_DO.ogg
05-19 21:21:14.244: I/WindowState(391): WIN DEATH: Window{41af78d0 u0 SurfaceView}
05-19 21:21:14.244: I/ActivityManager(391): Process org.funbox.musicboxtablet (pid 32553) has died.
05-19 21:21:14.252: W/InputDispatcher(391): channel '41ac1568 org.funbox.musicboxtablet/org.funbox.musicboxtablet.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
05-19 21:21:14.252: E/InputDispatcher(391): channel '41ac1568 org.funbox.musicboxtablet/org.funbox.musicboxtablet.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
05-19 21:21:14.252: W/InputDispatcher(391): Attempted to unregister already unregistered input channel '41ac1568 org.funbox.musicboxtablet/org.funbox.musicboxtablet.MainActivity (server)'
05-19 21:21:14.252: W/ActivityManager(391): Force removing ActivityRecord{419be2f0 u0 org.funbox.musicboxtablet/.MainActivity}: app died, no saved state
05-19 21:21:14.252: I/WindowState(391): WIN DEATH: Window{41ac1568 u0 org.funbox.musicboxtablet/org.funbox.musicboxtablet.MainActivity}
05-19 21:21:14.377: D/Zygote(130): Process 32553 exited cleanly (1)
05-19 21:21:14.384: I/ActivityManager(391): Config changes=1480 {1.0 214mcc4mnc en_US ldltr sw360dp w360dp h567dp 320dpi nrml port finger -keyb/v/h -nav/h s.18}
05-19 21:21:14.384: I/InputReader(391): Reconfiguring input devices.  changes=0x00000004
05-19 21:21:14.384: I/InputReader(391): Device reconfigured: id=6, name='Melfas MMSxxx Touchscreen', size 720x1280, orientation 0, mode 1, display id 0
05-19 21:21:14.392: I/InputReader(391): Reconfiguring input devices.  changes=0x00000004
05-19 21:21:14.392: I/InputReader(391): Device reconfigured: id=6, name='Melfas MMSxxx Touchscreen', size 720x1280, orientation 0, mode 1, display id 0
05-19 21:21:14.830: W/InputMethodManagerService(391): Got RemoteException sending setActive(false) notification to pid 32553 uid 10099
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Sun May 19, 2013 8:31 pm

I've fixed aspect ratio. I did not look into sndfile error yet, and I'm busy currently with my job, so I won't be able to touch SDL for at least a month, sorry.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Sun May 19, 2013 9:00 pm

About the aspect ratio I get two vertical black bands :/
Whatever I put in

# Application resizing will keep 4:3 aspect ratio, with black bars at sides (y)/(n)
SdlVideoResizeKeepAspect=n

I get the two black bars on my galaxy nexus (btw, my screen on SDL is 1024x552), and the image is stretched.

Edit: I changed the resolution on SDL_androidvideo-1.2.c:

Code: Select all
/* Modes sorted largest to smallest */
   SDL_modelist[0]->w = SDL_ANDROID_sWindowWidth; SDL_modelist[0]->h = SDL_ANDROID_sWindowHeight;
   SDL_modelist[1]->w = 1024; SDL_modelist[1]->h = 552; // Widely used on PC
   SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480; // Widely used on PC
   SDL_modelist[3]->w = 640; SDL_modelist[3]->h = 400; // Widely used on PC


Edit2: Oh... I'm stupid xD
I was just issuing adb install -r the generated apk, and once I uninstalled the app from the device and installed again from start the black bands were gone!

I have to finally present the app on 1st of June, couldn't you take a quick look to sndfile at least, please?
I know you don't want donations, but I'd be very glad to :)
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon May 20, 2013 1:23 pm

You can try to use sdl_sound library instead of libsndfile. Or you can try to debug libsndfile itself, unfortunately it does not print any stacktrace, so you can try using ndk-gdb (you'll probably need to insert 10-second sleep in the beginning of your code, because ndk-gdb isn't very fast).
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Mon May 20, 2013 2:35 pm

I can't use sdl_sound because it can't join audio files (at least that I know). I need to mix some small sounds on different times into a big song.
Could it be that like with ffmpeg, libsndfile is compiled without codecs?
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon May 20, 2013 2:45 pm

It is compiled with codecs, as far as I can tell. could you try running it in emulator, so maybe you'll get stacktrace in ADB logcat? Or create a minimal test app, for me to debug.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby protomank » Mon May 20, 2013 2:47 pm

Mixu wrote:I can't use sdl_sound because it can't join audio files (at least that I know). I need to mix some small sounds on different times into a big song.
Could it be that like with ffmpeg, libsndfile is compiled without codecs?


What about using sdl_mixer? I believe it can do what you want.
protomank
Freshman
Freshman
 
Posts: 5
Joined: Mon Apr 29, 2013 2:18 pm

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Mon May 20, 2013 3:26 pm

I already use sdl_mixer for playing sounds, but it can't save or generate music/sounds :(
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 8 guests