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
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.
And I don’t have much time in the week to write a longer, detailed article because I’m too busy
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
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.
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.
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
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).
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.
EDIT: Because vorbisidec worked you also have a working hard float OGG lib now for your lua player 3ds
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.
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?