*AHEM*
I now have sound working on Windows using SDL. I plan on making a few changes to the code so that I can change the sampling rate with a single define, but other than that sound is a-OK.
I don't have *anything* working on Dreamcast. There were a couple of defines in the code for reading in the data files on Linux or DOS, neither of which will work right for KOS, so all of that has to be rewritten or modified. I think I sort of know how I'm going to do it, but ATM I'm in the middle of setting up my Linux box again so I haven't had a chance to try it. That shouldn't be too hard, except for maybe the saving stuff.
And, @BlackAura, I sort of tried what you were talking about, and it didn't work (probably because I misunderstood you, or just did something wrong - I did like your way better, though). I just disabled the sound effects altogether temporarilly, and tried setting up my sound callback function to play what was in the buffer, and then call a function to fill the buffer with the next chunk of music. That didn't work too well - the sound seemed to get stuck in the same spot for a few seconds, and then I'd be given an invitation to report the error to Microsoft. I figured a simple workaround, though. I have a function that sort of resembles this:
Code: Select all
int SoundThread(void *data){
//Do some stuff to set up the software fm synth:
while (SD_Started){
if (bufferempty ==0){
// figure out what song we're playing
// send some info to the FM synth.
//generate some music.
if (/*we're playing a sound effect*/){
// generate any needed sound effects and mix the music in with them.
}else{
// if there are no sound effects, split the music into 'stereo.'
bufferempty = 1;
}
}
return 0;
}
Then, I just create a SDL_Thread.
Code: Select all
int SD_Startup (){
// Set up the SDL Audio stuff, and the FM synth stuff, etc...
hSoundThread = SDL_CreateThread(SoundThread, NULL);
SDL_PauseAudio(0);
}
Then, my audio callback function is like this:
Code: Select all
int soundcallback(void *userdata, Uint8 *stream, int len){
memcpy(stream, userdata, len)
bufferempty = 0;
}
That fixes the problem I was having before, which was basically that the sound thread looped too fast, so the sound was getting a bit garbled. It's now nice and smooth, although I think it makes more sense to have the music playing constantly, and just have the sound effects play on their own channels as needed.