What's new

Sound using SDL

AamirM

New member
Hi,

I am porting my sega genesis emu to linux but I am having problems with sound. I am used to DSound in which I just call something like update_snd(buffer, buf_len) when audio was available while in SDL, it calls a callback for more sound which I can't get working. Could someone simplify how the hell does this really works? How can make it work like DSound?

stay safe,

AamirM
 

Exophase

Emulator Developer
Hi,

I am porting my sega genesis emu to linux but I am having problems with sound. I am used to DSound in which I just call something like update_snd(buffer, buf_len) when audio was available while in SDL, it calls a callback for more sound which I can't get working. Could someone simplify how the hell does this really works? How can make it work like DSound?

stay safe,

AamirM

Works like you said, a callback is called telling you it needs N bytes of sound and you have to write those bytes to a buffer, and it has to not take too long or sound will skip. If you want to make it like the method you're using in DSound then you can do this:

- Have a function like update_snd which copies the audio to a global buffer, and make it stall if it fills up the buffer (you can do this with condition variables with the other part or a yield loop, I wouldn't spin on it - if it's full that should mean you have lots of audio left over, make the buffer big)
- Have the callback take audio off this buffer and if there isn't enough audio make it wait on the update for more, that'll happen if the game is being emulated too slowly.
- Use synchronization primitives between the two.
 
OP
A

AamirM

New member
Hi,

Well after a bit of trying I got it working. Thanks to all. Now all that is left is some frontend(which I hate) work and my Genesis emu will be ready for both windows and linux. Thanks again.

stay safe,

AamirM
 

Top