Working on a 3DS Port

Yeah, Opening2 then. And Map is Field1 (not 100% sure but should be Field1).

Yeah. Only one BGM. Playing another BGM kills the current.
BGMs Loop and can be adjusted in Volume and Faded in (as argument to BGM_Play) and Out (Fade function).
The player will also not care if you keep running the music after Fade Out with Volume 0 or kill the music.

Atm i’m going to leave stubbed the fade function and just trying to implement a simple audio streaming. If it works fine, adding fade function should be relatively easy.

Technically BGM should be implemented but i’m having issues with the streaming thread (like if it doesn’t work).
Going to try something different.

Looks like i’m having some problem with mono musics too (they are complete mute) :confused: . Going to check if mono sounds are working.

EDIT: Mono sounds are working fine :confused: That’s really strange!
EDIT2: Looks like Audacity when converting from Stereo to Mono gave me a mute audio file, nice to lose like 40 minutes trying everything when the problem is in the audio file :smiley:

Really don’t know why the BGM doesn’t work properly. It’s like if secondary thread doesn’t run at all (since i get first block of the song looped forever).

Here’s the commit about current state (streaming logic it’s pratically the same used in lpp-3ds): github.com/Rinnegatamante/easyr … 3e89a48a06

Found the problem and solved, mono WAV BGM support added :smiley: Now working on stereo too.

Looks like stereo files plays initially bad (like if the streaming function works in a bad way (like if it goes to write to too little portion of memory?)) but after a while (like 15 secs of playback?) they fix and play fine too.

If you want to take a look to the code (maybe there is some error in streaming logic) here you are latest commit: github.com/Rinnegatamante/easyr … ccf809e02a

Maybe file reading is slow, did you retry by adding more cpu time percentage to discard a performance related issue?

I’m quite sure the problem is not related to file reading speed since the same method is used in my lua interpreter and also if i change the argument of svcSleepThread, it produces same result. It’s probably something related to decoder logic (i’ve probably made some bad mistake when managing with buffer offsets or something similar).

Strange. If you can’t find the bug I will try to debug it this evening (in 8 hours ^^)

I think it’s a good idea (since it’s quite easy to understand what could cause the problem if you test it by your own i think.).
I’ve tried to patch it but still no success.

Oh there are also some other minor bugs like if you exit and re-open EasyRPG, it starts with garbage sounds (so this means BGM_Stop is not called when exiting?)

Yeah, will be probably not too hard to figure out…

The Ui class is responsible for cleaning up resources and you don’t use the default one (SDLUi).

Because audio_ is a scoped/unique pointer it will be automatically freed when the Ui is destroyed and invoke the CtrAudio destructor which is responsible for cleaning up the audio

EDIT:
The 3DS will probably need some call back handling because exiting the homebrew via the home menu button of the 3ds will not call any clean up code.
To do a proper shutdown you must set “Player::exit_flag” to true.

Home Menu button doesn’t work at all atm. (I was talking about the End Game button).

P.s. What’s the range for fadein / fade args? (And how they work? Something like fadein + 1 since fadein == volume and viceversa?)

Oh okay. Havn’t tested it native yet, have no 3DS. I will test it on the 3DS of my brother this weekend. (10.3 old 3DS)

The End Game button (in the title scene) does the described cleanup Player::Exit -> destroy ui -> destroy audio.
Concerning music changes during the game: The high level api (game_system) calls BGM_Stop before BGM_play.

The fade argument is the time in milliseconds for the fade.

And the fading is just a linear function (not completely sure, maybe it’s quadratic, but doesn’t really matter) over the volume.
So e.g. passing a volume of 50 and a fade of 1000 means:
at 100ms: Volume 5
at 500ms: Volume 25
at 1000ms: Volume 50
at 1001ms+: Volume 50

And the Fade function is exactly the same, just for the fade out case.

Fade effect should be working now (i don’t have a project to properly test it). ( github.com/Rinnegatamante/easyr … 60279081fb )

Just by staring at your PCM code without running it:

The mono code writes to (when replaced by variables):
buf + half_buf * half_check

The stereo code write to (per channel):
half_buf / 2 * half_check
Is that “half_chn_size” (half_buf / 2) required? (the only logical reason for a bug is the value of “z”)

[quote=“Ghabry”]Just by staring at your PCM code without running it:

The mono code writes to (when replaced by variables):
buf + half_buf * half_check

The stereo code write to (per channel):
half_buf / 2 * half_check
Is that “half_chn_size” (half_buf / 2) required? (the only logical reason for a bug is the value of “z”)[/quote]

The / 2 in a stereo file is needed cause csnd can’t play stereo files natively so we must separate left and right channel

It’s something like

MONO:

           first block         |          second block
|------------------------------|------------------------------| <-- buffer

STEREO:

         left channel          |            right channel
  first block | second block   | first block | second block
|------------------------------|------------------------------| <-- buffer

The streaming thread should update first block when second block is playing and viceversa.

Thanks. Now I understand how the buffer is written.
I start investigating now…

Could you do a quick test in the meanwhile? I read on gbatemp that the startup speed is horrible. My guess is that the filesystem code is very slow in parsing directories.
Please try if taking the EMSCRIPTEN codepath in filefinder
github.com/EasyRPG/Player/blob/ … er.cpp#L87
(lines 87 to 93) gives a speedup.
This will cause issues if the file system is case sensitive, but if that’s the cause we can work on a proper solution.

Btw, using “>> 1” instead of “/ 2” will not give any speedup at all. The compiler is smart enough and knows the trick, too.

Looks like it doesn’t change anything or it’s even slower (?)
There are two parts in startup where it “apparently freeze”: After BGM_Play is called once (don’t know what startup sequence goes to load after this) and when easyRPG checks for the encode (apparently).

Speaking about startup performances, do you think using FS service instead of stdio could speedup startup?
I’ve never tried to compare them for performances differences but i think the stdio wrapper should run slower since it needs to be “translated” to FS syscalls.

Here’s the related code about stdio implementation in ctrulib for SDMC: github.com/smealum/ctrulib/blob … sdmc_dev.c