--- np2/sound/sound.c 2004/03/24 06:07:57 1.15 +++ np2/sound/sound.c 2005/04/01 15:35:49 1.20 @@ -98,7 +98,8 @@ static void streamfilewrite(UINT samples CBTBL *cb; UINT count; SINT32 buf32[2*512]; - BYTE buf[2*2*512]; + UINT8 buf[2*2*512]; + UINT r; UINT i; SINT32 samp; @@ -110,6 +111,12 @@ static void streamfilewrite(UINT samples cb->cbfn(cb->hdl, buf32, count); cb++; } + r = min(sndstream.remain, count); + if (r) { + CopyMemory(sndstream.ptr, buf32, r * 2 * sizeof(SINT32)); + sndstream.ptr += r * 2; + sndstream.remain -= r; + } for (i=0; i 32767) { @@ -119,13 +126,42 @@ static void streamfilewrite(UINT samples samp = -32768; } // little endianなので satuation_s16は使えない - buf[i*2+0] = (BYTE)samp; - buf[i*2+1] = (BYTE)(samp >> 8); + buf[i*2+0] = (UINT8)samp; + buf[i*2+1] = (UINT8)(samp >> 8); } wavewr_write(sndstream.rec, buf, count * 4); samples -= count; } } + +static void filltailsample(UINT count) { + + SINT32 *ptr; + UINT orgsize; + SINT32 sampl; + SINT32 sampr; + + count = min(sndstream.remain, count); + if (count) { + ptr = sndstream.ptr; + orgsize = (ptr - sndstream.buffer) / 2; + if (orgsize == 0) { + sampl = 0; + sampr = 0; + } + else { + sampl = *(ptr - 2); + sampr = *(ptr - 1); + } + sndstream.ptr += count * 2; + sndstream.remain -= count; + do { + ptr[0] = sampl; + ptr[1] = sampr; + ptr += 2; + } while(--count); + } +} #endif @@ -224,6 +260,7 @@ void sound_changeclock(void) { clock = (clock + 1) >> 1; hz = (hz + 1) >> 1; } + TRACEOUT(("hzbase/clockbase = %d/%d", hz, clock)); soundcfg.hzbase = hz; soundcfg.clockbase = clock; soundcfg.minclock = 2 * clock / hz; @@ -261,16 +298,14 @@ void sound_sync(void) { if (length == 0) { return; } + SNDCSEC_ENTER; #if defined(SUPPORT_WAVEREC) if (sndstream.rec) { streamfilewrite(length); - soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase; - beep_eventreset(); - return; } + else #endif - SNDCSEC_ENTER; - streamprepare(length); + streamprepare(length); soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase; beep_eventreset(); SNDCSEC_LEAVE; @@ -288,11 +323,6 @@ const SINT32 *sound_pcmlock(void) { const SINT32 *ret; -#if defined(SUPPORT_WAVEREC) - if (sndstream.rec) { - return(NULL); - } -#endif if (locks) { TRACEOUT(("sound pcm lock: already locked")); return(NULL); @@ -301,7 +331,14 @@ const SINT32 *ret; ret = sndstream.buffer; if (ret) { SNDCSEC_ENTER; - if (sndstream.remain > sndstream.reserve) { + if (sndstream.remain > sndstream.reserve) +#if defined(SUPPORT_WAVEREC) + if (sndstream.rec) { + filltailsample(sndstream.remain - sndstream.reserve); + } + else +#endif + { streamprepare(sndstream.remain - sndstream.reserve); soundcfg.lastclock = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK; beep_eventreset(); @@ -335,10 +372,10 @@ void sound_pcmunlock(const SINT32 *hdl) // ---- pcmmix -BOOL pcmmix_regist(PMIXDAT *dat, void *datptr, UINT datsize, UINT rate) { +BRESULT pcmmix_regist(PMIXDAT *dat, void *datptr, UINT datsize, UINT rate) { GETSND gs; - BYTE tmp[256]; + UINT8 tmp[256]; UINT size; UINT r; SINT16 *buf; @@ -384,12 +421,12 @@ pmr_err1: return(FAILURE); } -BOOL pcmmix_regfile(PMIXDAT *dat, const char *fname, UINT rate) { +BRESULT pcmmix_regfile(PMIXDAT *dat, const OEMCHAR *fname, UINT rate) { FILEH fh; UINT size; - BYTE *ptr; - BOOL r; + UINT8 *ptr; + BRESULT r; r = FAILURE; fh = file_open_rb(fname); @@ -400,7 +437,7 @@ BOOL pcmmix_regfile(PMIXDAT *dat, const if (size == 0) { goto pmrf_err2; } - ptr = (BYTE *)_MALLOC(size, fname); + ptr = (UINT8 *)_MALLOC(size, fname); if (ptr == NULL) { goto pmrf_err2; }