Salem, the 85K include a ~100kb exe file (which packed goes down to ~50kb). That is not someone elses compressed source code. There is my source as well as the explanations and examples.
I see gurus like you complain when someone asks "please make my program" or "how do I do this" expecting someone else to solve it entirely... but I'm seeing complaints even with my case in which I have it almost working and need a push from someone who knows more than me...
Anyway I will definitely try your suggestion. Here it goes:
This is the problematic function:
Code:
static UINT AIAPI UpdateAudio(UINT nFrames)
// nFrames is 0 when this function is called
nFrames = 500;
// I am just "guessing" that value.
/* send PCM samples to the DSP audio device */
if (AC97.lpfnAudioWave != NULL) {
AC97.lpfnAudioWave(AC97.lpBuffer, nFrames);
}
//I think is while is one of my problems (too much delay to break for some reason)
while(1){
int d0 = w_get_watermark_status();
if(d0 == -1 || d0 == 0) break;
if(d0 == -2){
w_reset_watermark_ex(nFrames);
break;
}
}
//nFrames is the size of the buffer, it should be actual_sample_rate / clocks_per_second
//I don't know where to get the clocks_per_second from.
w_lock_mixing_buffer(nFrames);
//AC97.lpBuffer is the pointer to the wave data.
//It is 8 bits so that's why I call w_mixing8 instead of w_mixing
w_mixing8(AC97.lpBuffer, nFrames, 256, 256); // 256 is the volume on L/R channels
w_unlock_mixing_buffer();
return AUDIO_ERROR_NONE;
So:
a) My program calls this function every clock_per_second. I get clocks_per_second with this function:
Code:
a=clock();
gettime(&t);
while(secs!=2)
{
gettime(&t2);
if(t.ti_sec!=t2.ti_sec)
{
memcpy(&t,&t2,sizeof(struct time));
secs++;
}
}
b=clock()-a;
clocks_per_second=(clock_t)((double)b/2.0F);
b) Updateaudio locks the buffer, plays the wave, unlocks the buffer and via the while loop checks if the samples have been played, and if they did it breaks. If D0 is 0 it is OK with no latency, if it's -1 it is fine, if it's -2 there's been a buffer underrun.
c) I can't figure if I need to advance the AC97.lpBuffer pointer or SEAL does it automatically.
Hope this helps... thanks for the replies.
Marton