Working on a 3DS Port

We already have a cache system for graphic in cache.cpp btw. Maybe it can be used as some type of inspiration.

I think your solution is a bit too low level. You are thinking in C, not in C++11. We are using reference counting everywhere because it makes handling memory so much easier. And this will even work for linearAlloc/linearFree because you can provide custom (de)allocator.

So e.g. for cache.cpp we store the file references in std::map<std::string, Bitmap> where the filename is associated with a Bitmap reference.

So for this case you could use some std::map<std::string, std::shared_ptr<uint8_t*>> and your shared_ptr uses a custom allocator and custom deleter (see stackoverflow) that calls linearAlloc/linearFree for memory management. Your custom allocator/deleter could also count the amount of bytes that are already allocated. And when they reach a certain value you delete the oldest (time of usage) sound effect from the cache. Now the cache element is removed but you changed your 3ds_audio class in a way that it holds a shared_ptr reference to currently played sound, so it will not get deleted immediately. And when cSnd is finished it will be deleted :slight_smile:

You probably couldn’t follow me, because this is complex C++11 stuff. You can also stick to your memory buffer by now and when I find time during next weekend I can show you a more “modern” cache. :smiley:

And I don’t have much time in the week to write a longer, detailed article because I’m too busy :slight_smile:

I’ll probably wait you for a “better-looking” solution. I’ll probably start now working on OGG sounds to see if ivorbisfile is good on 3ds and if it’s fast enough.

As for the C thinking, you’re completely right. I usually write C code even if i know a bit of modern C++ syntax cause i feel much more comfortable with standard C syntax :stuck_out_tongue:

Yepp, when you are finished with the code I will take a look how much taste of C++ I can add ;). If it works it’s of course also fine to use your C code. Because it’s a port we are (or at least I’m) just happy that somebody is working on them :). Looking forward to play some games on my Old 3ds next weekend. :smiley:

Speaking about cached bitmap, is it normal that when i end a game i get on console “possible leak in cached bitmap” for two bitmaps?

Yes. When returning to the title the Cache is flushed and two bitmaps (system and title) still have a strong reference because they are used on the title screen. So this is not really a leak because they will get deleted when the title scene shuts down.

To use ogg sounds instead of wav, i just need to convert them and remove the wav ones with the same filename?

Yepp. Same name, different extension. Because the file finder prefers WAV over OGG over MP3 (no idea why that order, somebody decided this :D).

Lets hope Tremor works with hard float…

Seems there are some problem with the audiobuf detection. It says me the PCM16 audiobuffer is 0 bytes :confused:

That’s how i calculate audiobuf size (same code used in my lua interpreter):

EDIT: I’ve pushed a commit about it since i’m going to bed, if you want to take it a look, here it is: github.com/Rinnegatamante/easyr … 0cedcd4166

No idea. Looks okay according to the docs. Did you try running a minimal example native at your PC?

You could also check SDL2 mixer code. They use ov_pcm_total.
github.com/davidsiaw/SDL2_mixer … ogg.c#L113

And that exploit looks unreliable according to your GBATemp beta testers. We use the same strategy to find Bugs in our Player btw, by using Android users as beta testers :wink:

libsvchax is not updated to latest commits by aliaspider (the one who found the exploit). I’m going to update it nad then re-try to see if that increase reliability (thecnically it should boot like 80% times so it’s quite good).

Ps i’ve fixxed the audio buffer length by modiying the size calculation with this (probably what caused the problem is ov_time_total returning 0?)

Sound->audiobuf_size = ov_pcm_total(vf,-1)<<audiotype;

But now, no sound is played. I wonder if the problem is in vorbisidec or not. Going to double check the code just to be sure everything it’s fine.

EDIT: Added a simple audio dumper for the decoded sound and it saves me a fully blank audiofile:

FILE* test = fopen("sdmc:/sound.bin","w"); fwrite(Sound->audiobuf,Sound->audiobuf_size>>1,1,test); fclose(test);

Fixxed, OGG decoder working perfectly now :wink: - github.com/Rinnegatamante/easyr … 2c929f2b09

Awesome. If you should be bored I could also provide you with a portlib of mpg123 for mp3 support :wink:

Could be great but i’ll need a lot of time for MP3 support (since i used to work with vorbisfile and normal wav decoding but i never touched mp3 files <.< ).

Added mpg123 to the portlibs archive linked some posts above. Had to patch it because it wants socket headers for some reason even though I disabled http support o.O.
Please test if you get linker errors.

Here is some sample code for inspiration by one of our devs :slight_smile: (uses SDL2 for streaming, but the decoding uses mpg123)
github.com/EasyRPG/Player/issue … -198092588

I guess the linker line is -lmpg123 -lout123

EDIT: Because vorbisidec worked you also have a working hard float OGG lib now for your lua player 3ds :slight_smile:

Via mpg123_format you tell the internal resampler of mpg123 that you want audio as PCM in that format (in the example 44.1k with stereo). Maybe is better to use the cSnd hardware resampler (samplerate argument) but is a good start.

[quote=“Ghabry”]Added mpg123 to the portlibs archive linked some posts above. Had to patch it because it wants socket headers for some reason even though I disabled http support o.O.
Please test if you get linker errors.

Here is some sample code for inspiration by one of our devs :slight_smile: (uses SDL2 for streaming, but the decoding uses mpg123)
github.com/EasyRPG/Player/issue … -198092588

I guess the linker line is -lmpg123 -lout123

EDIT: Because vorbisidec worked you also have a working hard float OGG lib now for your lua player 3ds :)[/quote]

I’ll probably use vorbisidec even on lpp-3ds since i noticed it’s much more faster then standard vorbisfile.

As for the BGM, does the test game have some bgm background? If so, what’s the file format?

Yepp vorbisidec is designed for embedded hardware. So it is much faster then the normal version.

Yes it has background music. But it is MIDI :(. (Music folder). Is probably easier for you to replace the MIDI with some arbitrary WAV/OGG/MP3 files for testing.

If you really want MIDI: unhaut.x10host.com/fmmidi/
Though, no idea how to use that lib (has no installer, just copy paste all the cpp and h files into the player src folder, except program.h iirc)

[quote=“Ghabry”]Yepp vorbisidec is designed for embedded hardware. So it is much faster then the normal version.

Yes it has background music. But it is MIDI :(. (Music folder). Is probably easier for you to replace the MIDI with some arbitrary WAV/OGG/MP3 files for testing.

If you really want MIDI: unhaut.x10host.com/fmmidi/
Though, no idea how to use that lib (has no installer, just copy paste all the cpp and h files into the player src folder, except program.h iirc)[/quote]

Going to use a wav file for now. What file should i replace to edit the Main Menu BGM?

Music/Opening if I remember correctly.

I also updated the portlibs. mpg123 is now compiled with NEON instructions and integer truncation mode (faster)

There is no Opening file, i’ll assume it is Opening2?

P.S. Am i correct assuming only one BGM can be played at the same time?