--- np2/sound/sound.c 2003/10/21 16:27:54 1.5 +++ np2/sound/sound.c 2003/12/08 00:55:33 1.10 @@ -1,6 +1,6 @@ #include "compiler.h" #include "soundmng.h" -#include "i286.h" +#include "cpucore.h" #include "pccore.h" #include "iocore.h" #include "sound.h" @@ -33,9 +33,11 @@ static SNDSTREAM sndstream; static void streamreset(void) { + SNDCSEC_ENTER; sndstream.ptr = sndstream.buffer; sndstream.remain = sndstream.samples + sndstream.reserve; sndstream.cbreg = sndstream.cb; + SNDCSEC_LEAVE; } static void streamprepare(UINT samples) { @@ -95,9 +97,9 @@ BOOL sound_create(UINT rate, UINT ms) { } sndstream.samples = samples; sndstream.reserve = reserve; - streamreset(); SNDCSEC_INIT; + streamreset(); return(SUCCESS); scre_err2: @@ -110,10 +112,10 @@ scre_err1: void sound_destroy(void) { if (sndstream.buffer) { - SNDCSEC_TERM; - soundmng_stop(); + streamreset(); soundmng_destroy(); + SNDCSEC_TERM; _MFREE(sndstream.buffer); sndstream.buffer = NULL; } @@ -124,7 +126,7 @@ void sound_reset(void) { if (sndstream.buffer) { soundmng_reset(); streamreset(); - soundcfg.lastclock = I286_CLOCK; + soundcfg.lastclock = CPU_CLOCK; beep_eventreset(); } } @@ -152,7 +154,7 @@ void sound_changeclock(void) { soundcfg.hzbase = hz; soundcfg.clockbase = clock; soundcfg.minclock = 2 * clock / hz; - soundcfg.lastclock = I286_CLOCK; + soundcfg.lastclock = CPU_CLOCK; } void sound_streamregist(void *hdl, SOUNDCB cbfn) { @@ -178,7 +180,7 @@ void sound_sync(void) { return; } - length = I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK - soundcfg.lastclock; + length = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK - soundcfg.lastclock; if (length < soundcfg.minclock) { return; } @@ -188,30 +190,40 @@ void sound_sync(void) { } SNDCSEC_ENTER; streamprepare(length); - SNDCSEC_LEAVE; - soundcfg.writecount += length; soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase; beep_eventreset(); + SNDCSEC_LEAVE; + soundcfg.writecount += length; if (soundcfg.writecount >= 100) { soundcfg.writecount = 0; soundmng_sync(); } } +static volatile int locks = 0; + const SINT32 *sound_pcmlock(void) { const SINT32 *ret; + if (locks) { + TRACEOUT(("sound pcm lock: already locked")); + return(NULL); + } + locks++; ret = sndstream.buffer; if (ret) { SNDCSEC_ENTER; if (sndstream.remain > sndstream.reserve) { streamprepare(sndstream.remain - sndstream.reserve); - soundcfg.lastclock = I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK; + soundcfg.lastclock = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK; beep_eventreset(); } } + else { + locks--; + } return(ret); } @@ -223,12 +235,14 @@ void sound_pcmunlock(const SINT32 *hdl) leng = sndstream.reserve - sndstream.remain; if (leng > 0) { CopyMemory(sndstream.buffer, - sndstream.buffer + sndstream.samples * 2, + sndstream.buffer + (sndstream.samples * 2), leng * 2 * sizeof(SINT32)); } sndstream.ptr = sndstream.buffer + (leng * 2); - sndstream.remain += sndstream.samples; + sndstream.remain = sndstream.samples + sndstream.reserve - leng; +// sndstream.remain += sndstream.samples; SNDCSEC_LEAVE; + locks--; } }