on the fly WAV to PCM

vbt

Staff member
Would it be possible on Saturn ? When I compare the size of the WAV and the size of the PCM, it's almost the same, so there could have only a small difference like a header. It could be stupid, I didn't read PCM and WAV specs.
 
Wav is just a container format that (usually) holds raw pcm inside. Not counting extra tags like comments, the wav file is 44 bytes bigger (the header size).
 
vbt said:
Would it be possible on Saturn ? When I compare the size of the WAV and the size of the PCM, it's almost the same, so there could have only a small difference like a header. It could be stupid, I didn't read PCM and WAV specs.

Yes, it's possible. The conversion that has to be done is just sign-related and for stereo the channels are interleaved in wav files, while in PCM format it's two consecutive arrays. I guess the latter one suits better for DMA transfer...

Conversion from wav to pcm has already been done in the Saturn Sound Player. That Saturn app and the tool RB_SaturnPCM.EXE both use the same library RB_SaturnPCM.c. It performs the conversion in-place, meaning no additional memory is needed.

However, I think you want something different, like streaming. The PCM library of SBL performs streaming of AIFF files, so why don't you take these? In general on Saturn I think it's better to pre-convert all data stuff, rather than doing the conversion on the console. When providing the sound data on a low level, you could of course do the wav conversion on-the-fly.
 
At least in theory it should be possible to play interleaved audio, provided the sampling frequency is a multiple of 44100 Hz and you set the playback frequency to twice the sampling frequency. This should make the SCSP read exactly every other sample without the interpolation picking up data from the "other channel". If this works for eg. 11025 Hz and 22050 Hz sampling frequencies it might be useful for streaming audio.


Unfortunately neither the SH2's onboard DMA controller nor the SCU DMA controller seem to be flexible enough to do the deinterleaving for you (ie. add two transfer units to the source address but only one to the destination address) so preprocessing the audio data is far preferable to doing it at runtime.
 
RockinB said:
Conversion from wav to pcm has already been done in the Saturn Sound Player. That Saturn app and the tool RB_SaturnPCM.EXE both use the same library RB_SaturnPCM.c. It performs the conversion in-place, meaning no additional memory is needed.
I will check this 🙂

However, I think you want something different, like streaming. The PCM library of SBL performs streaming of AIFF files, so why don't you take these? In general on Saturn I think it's better to pre-convert all data stuff, rather than doing the conversion on the console. When providing the sound data on a low level, you could of course do the wav conversion on-the-fly.

I know but I have in mind to make game ports easier to do. So if there was just a header to remove, it could be done in a library.

antime said:
At least in theory it should be possible to play interleaved audio, provided the sampling frequency is a multiple of 44100 Hz and you set the playback frequency to twice the sampling frequency. This should make the SCSP read exactly every other sample without the interpolation picking up data from the "other channel". If this works for eg. 11025 Hz and 22050 Hz sampling frequencies it might be useful for streaming audio.

That's interesting.

Unfortunately neither the SH2's onboard DMA controller nor the SCU DMA controller seem to be flexible enough to do the deinterleaving for you (ie. add two transfer units to the source address but only one to the destination address) so preprocessing the audio data is far preferable to doing it at runtime.

Does it mean, setting frequency playback with twice the frequency like you said before cannot work at all ?
 
vbt said:
Does it mean, setting frequency playback with twice the frequency like you said before cannot work at all ?

Those are orthogonal issues. The frequency thing may coerce the SCSP into playing interleaved audio, while a more powerful DMA controller would have let you do the de-interleaving while transferring the audio data from main memory into SCSP RAM for almost no cost. As things are, if you want to convert interleaved audio into non-interleaved you have to do it manually with code, which of course takes time.
 
Back
Top