johannes-fetz / joengine

Jo Engine is an open source 2D and 3D game engine for the Sega Saturn written in C under MIT license
http://jo-engine.org/
MIT License
208 stars 32 forks source link

PCM: Jo Engine Doesn't Set Sample Rate #36

Closed slinga-homebrew closed 3 years ago

slinga-homebrew commented 4 years ago

Hi Johannes,

I don't expect you to change anything, just wanted to document. Jo Engine doesn't appear to support setting the sample rate for PCM files. As per your comments in "demo - audio\main.c" the Saturn can support both 8000 and 44100 sample rates. However there does not appear to be a place to change the sample rates anywhere.

jo_audio_load_pcm() does not take a sample rate, the jo_sound struct does not contain the sample rate, and jo_audio_play_sound_on_channel() takes an index into the PCM _jo_internal_pcm[JO_SOUND_MAX_CHANNEL] array. This structure contains the sample rate (via some computation in pitch, see Ponut's code: https://github.com/ponut64/68k/blob/47e56ede2ee5bb4979ce85dffc5446ec44f81dd7/jo_demo/pcmsys.c#L207). The pitch doesn't appear to ever be set.

So here are the issues that should be considered: 1) What does a pitch of 0 mean? Since it isn't set, what sample rate it is? 2) Since the user cannot specify the sample rate it doesn't make sense to list multiple supported sample rates. 3) Maybe change the jo_audio_play_sound_on_channel() prototype to take a PCM* as an input. That way the user could specify everything.

Thanks as always.

johannes-fetz commented 3 years ago

@slinga-homebrew For Flicks-Flock you just have to do this:

void loadPCMAssets(void) { jo_audio_load_pcm("DEATH.PCM", JoSoundMono8Bit, &g_Assets.deathPCM); g_Assets.deathPCM.sample_rate = 27086; jo_audio_load_pcm("GRAVITY.PCM", JoSoundMono8Bit, &g_Assets.reverseGravityPCM); g_Assets.reverseGravityPCM.sample_rate = 27086; jo_audio_load_pcm("LIGHT.PCM", JoSoundMono8Bit, &g_Assets.lightningPCM); g_Assets.lightningPCM.sample_rate = 27086; jo_audio_load_pcm("STONE.PCM", JoSoundMono8Bit, &g_Assets.stoneSneakersPCM); g_Assets.stoneSneakersPCM.sample_rate = 27086; }

then replace my_jo_audio_play_sound by jo_audio_play_sound

slinga-homebrew commented 3 years ago

Thanks, fixed.