Working on a 3DS Port

At the moment i think using csnd with svchax is the best thing. For future firmwares wer can always distribute temp builds with sound disabled so at least it should work fine but without sound.
As for the DSP wrapper. I can work secondarely on it when at least a stable version with csnd is finished.

There still are some obscure parts to me, for example volume range is 0-255? (Since csnd assumes a float as volume with range 0.0-1.0).
Also sounds need to be played in loop till Stop is called? (or they’re just oneshot sounds?)

Music loops.

Sounds are one-shot. You can’t even cancel them from events. The SE_Stop is only for “return to title”.

Volume goes from 0 to 100.

MMhh that sounds a bit bad for how csnd works.

Is CtrAudio::Update() called at any frame?
I just need some workaround to correctly free audiobuffers when they finished playing.

Yes, Audio::Update is called 60 times per second (independend of the FPS, as long as the CPU is not totally overloaded)

What formats are used for sounds by Test Game? If there are some WAV files, i can easily add WAV support (since WAV files don’t need any kind of decode phase basically and a basic SE wrapper has been done: github.com/Rinnegatamante/easyr … io_3ds.cpp).

TestGame uses PCM WAV.
At least sound effects are (AD)PCM WAV in different formats (mono, stero, 44.1k, 48k…). I assume the 3DS has a hardware resampler.

Music is more chaotic :wink:

Noooo, why you mentioned ADPCM ç_ç. I had a really bad time trying to figure out how to properly play sounds in that audiocodec without any good result :frowning:

Anyway no, 3DS doesn’t have an hardware resampler for what i know (and even if it has such piece of hw, it has not been RE and included in libctru :frowning: ).

I’m going to add first PCM16 and PCM8 support.

Just wondered because I saw a sampleRate argument for cSndplaysound. This is not for the resampler? :confused:

Don’t worry. Only implement PCM WAV. The other devs can figure out the rest :). We just add a few more libraries :smiley:

Looks like i’m having some problem with FileFinder.

That’s what i do:

[code]int DecodeWav(std::string const& filename, DecodedSound* Sound){

// Opening file
FILE* stream = FileFinder::fopenUTF8(filename, "rb");
if (!stream) {
	Output::Warning("Couldn't open sound file %s", filename.c_str());
	return -1;
}

// other stuffs
[/code]

[code]void CtrAudio::SE_Play(std::string const& file, int volume, int /* pitch */) {

// Searching for the file
std::string const path = FileFinder::FindSound(file);
if (path.empty()) {
	Output::Debug("Sound not found: %s", file.c_str());
	return;
}

// Select an available audio channel
int i = 0;
while (i < num_channels){
	u8 isPlaying;
	csndIsPlaying(i+0x08, &isPlaying);
	if (!isPlaying) break;
	i++;
	if (i >= num_channels){
		Output::Warning("Cannot execute %s sound: audio-device is busy.\n",file.c_str());
		return;
	}
}
if (audiobuffers[i] != NULL){
	linearFree(audiobuffers[i]);
	audiobuffers[i] = NULL;
}

// Opening and decoding the file (TODO: Add other containers support like OGG and MIDI files)
bool isStereo = false;
int audiobuf_size;
int codec;
DecodedSound myFile;
if (DecodeWav(file, &myFile) < 0) return;[/code]

But i always get on screen the error from DecodeWav that it can’t open the requested file even if that file exists (cursor1)

EDIT: Solved

Ok wav files support correctly added and perfectly working (for SE_). ( github.com/Rinnegatamante/easyr … 6da592c099 )
Probably for OGG sounds it’s better to have something like a memory cache for sounds that get used multiple times cause even with wav files i noticed a low stuttering when the file gets loaded.

Is it possible to do all the Audio loading in an extra thread instead of the main one? Or does this have some side effects?

EDIT: Awesome that you already got it working btw.

Now we only need some streaming based approach for Music and everything is already fine :slight_smile:

[quote=“Ghabry”]Is it possible to do all the Audio loading in an extra thread instead of the main one? Or does this have some side effects?

EDIT: Awesome that you already got it working btw.

Now we only need some streaming based approach for Music and everything is already fine :)[/quote]

It should be possible but that thread should run on APPCORE i think cause i want to relegate SYSCORE only to BGM streaming in the future.

How much RAM does EasyRPG usually take? I can try to implement a memory cache like Quake Engine does. It should consistently reduce stuttering problem in most of the case. (For example for menu sound).
Even something like 4-5 MB of cache could be a good thing.

That depends on the game. Hero’s Realm takes 500 MB ;). Usually not more then 20 MB under Windows (3ds has maybe less footprint than a Windows thread).

I’m going to implement a little sound cache of about 5 mbs just for 3DS. If you feel it could be helpful for other ports, it will be easily portable to other devices.
I think for 3DS is a vital feature (since 3DS lacks of CPU power :frowning: ).

Btw, do you have IRC? We are idling in freenode, so this makes maybe the conversation a bit smoother :slight_smile:

I don’t use IRC to be honest, i usually chat on Skype if it can help.

Introduced a test cache just to be sure the logic i’m using it’s fine and it runs pretty smoother now.
I have to finish it since it’s almost bugged (I’ve to write the part that re-full the cache when it’s full).

I made it easy to enable/disable by adding a new flag (USE_CACHE) so making builds without it is pretty simple.

Sound cache added, it seems to work fine but it’s the first time i write a cache system so it could also be bugged in some part or it could be heavily improved.

Commit: github.com/Rinnegatamante/easyr … 61a02cdabe