KOS snd_sfx_play problem

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

KOS snd_sfx_play problem

Post by Orion_ »

Hello,
I'm just starting Dreamcast development, and after some hours trying to compile a recent GCC and KOS 2.0.0 (I can provide recent cygwin gcc binaries for those who wants)
I finally got something to show up on the dreamcast.
My problem is sound.
I tried OGG streaming, but the stream is buggy, and also you cannot preload multiple ogg files in memory.
So I tried to use "snd_sfx" API, using ADPCM to reduce memory cost.
I use snd_init, snd_sfx_load, then snd_sfx_play
The sound starts playing for 1 or 2 seconds, then stops, for unknown reason.
The sound I load should last at least 1min (it's a music)
Also, there is no "loop" flag, where as in the kos source, you can set a loop flag, but it's always set to 0.

So, I would like to know, is this behavior normal ? (is there a time limit for sfx ???)
how can I handle music with preloading in memory ?

Thank you
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS snd_sfx_play problem

Post by BlueCrab »

The entire set of snd_sfx_* functions are not designed necessarily for playing music, hence why there is no loop setting for them. That piece of code is designed for sound effects (hence the sfx in the function names), which are generally "play once then be done with it" types of things.

While I can't necessarily comment on your particular problem without seeing the code (and possibly the wav file you're trying to play), I'd suggest looking at alternate means for playing music (the snd_stream stuff is where you would want to look, and the ogg stuff does show how this works, if you look at the code of those libraries).

What (other than the not being able to have multiple Ogg files in memory) were you having issues with in regard to the vorbis library (and were you using libtremor or liboggvorbisplay)?
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: KOS snd_sfx_play problem

Post by Orion_ »

The problem I had with ogg is that the stream was not flawless, it was like the song had hiccups.
I tried with both libtremor & liboggvorbisplay, on nullDC and real dreamcast on a CD.
Maybe there is a bitrate limit for ogg on dreamcast ? the ogg I use can go up to 166kbps (stereo 44khz)

EDIT: I tried with an ogg file in a romdisk and it seems to be ok this way. (at least on the real Dreamcast, nullDC seems to have problem playing ogg)
Now I need to modify my sound manager so it will preload the ogg file in a ramdisk so then stream it from there.

What library is preferred ? oggvorbisplay or tremor ?
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS snd_sfx_play problem

Post by BlueCrab »

I'm not sure what the max bitrate is for smooth streaming, but yeah, cacheing it in /ram will probably make things go a lot more smoothly, since then you aren't having to wait for the disc drive to seek and such. That's a relatively easy fix, I should think. :)

Either library should work fine, although tremor may be more CPU friendly. The difference between the two is that the oggvorbisplay is the full floating-point library, whereas tremor should only be doing integer arithmetic to do the decoding.
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: KOS snd_sfx_play problem

Post by Orion_ »

Bump on this thread.

I tried to delete the "65534" sample length limitation of the function "snd_sfx_play" but it doesn't change anything.
So I assume the hardware limitation is no sample length more than 65534.
Regardless of stereo mode, this means:
Sfx can be maximum length of: seconds = 65534 / Sfx Frequency in Hz
1,486 seconds at 44kHz
2,972 seconds at 22kHz
5,944 seconds at 11kHz

Seems like ADPCM mode is worse!
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: KOS snd_sfx_play problem

Post by Newbie »

This is not possible to use "KOS fx sound system" to play background music.

The only way is using "KOS stream system".

The replay is perfect if all sound is in memory cache.

You can use MP3, OGG, ADX stream replay routines in KOS PORTS.

Using MP3 or OGG take time, ADX is faster ( around 1% CPU time).

But ADX compress rate is far less from MP3 or OGG so it takes RAM and ADX compression tool produce some time strange results as i think there was a problem of filter in the tool code.

You can also make your own decoding system with your own sound format : the only thing is that your decoding routine must provide bytes to play to the streaming system buffer at time.

And all must be used in a separate thread from main execution point.

Hope it helps.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KOS snd_sfx_play problem

Post by BlueCrab »

Orion_ wrote:Bump on this thread.

I tried to delete the "65534" sample length limitation of the function "snd_sfx_play" but it doesn't change anything.
So I assume the hardware limitation is no sample length more than 65534.
Regardless of stereo mode, this means:
Sfx can be maximum length of: seconds = 65534 / Sfx Frequency in Hz
1,486 seconds at 44kHz
2,972 seconds at 22kHz
5,944 seconds at 11kHz

Seems like ADPCM mode is worse!
It is a hardware limitation, as you suspect. The registers that control the sample length (the loop start/loop end registers) are only 16-bits, so the max value is right there around the 65534 that the code has...

ADPCM mode is not "worse", as this value is in samples. ADPCM samples are smaller (4 bits vs 8 or 16 bits) so they take up less space in the sound RAM, but that's irrelevant -- you're only worried about the number of samples in-use if you're worried about the time of the sound effect being played.

Unfortunately, if you want anything more complex, you'll have to work with the streaming system yourself. That said, the sfxmgr code should provide a good starting point that you can work with to build up a streaming sound effect system. As I said before, the sfxmgr is meant for short one-shots, specifically those that don't require any sort of control from the SH4 after being started (so those that the registers can be set for and forgotten about).
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: KOS snd_sfx_play problem

Post by SWAT »

You can play any size of PCM data, for it you have 3 methods:

1) Dinamically upload new data to SPU memory after playing previous data. Separate buffer to 2 and upload data to #1 while playing #2 and vice versa (channel loop setup for all buffer). I use this technique for playing CDDA tracks.
2) Upload all data to memory before playing, but at playing change loop start/stop positions. But this will not work good, as it is necessary to stop playback at a fraction of a second, which can lead to distortion in the sound. But I think with good code, the problem will not be noticeable to the ear.
3) Use more channels for playback one big buffer. Disable looping on all and start play second channel at end of previous channel. Can have sound problems as in method #2.

For 2 and 3 methods you need use aica interrupts for most smooth playback.
For the first method it's can be ignored, because not need to stop/start channels in very small time interval. It's playing by loop automatically.
Image
Post Reply