|
|
| version 1.3, 2003/10/19 16:54:51 | version 1.4, 2003/10/20 06:36:33 |
|---|---|
| Line 8 | Line 8 |
| #include "beep.h" | #include "beep.h" |
| UINT32 opna_rate = 22050; | SOUNDCFG soundcfg; |
| static int writebytes = 0; | |
| UINT32 ratebase200 = 110; | |
| UINT32 dsound_lastclock = 0; | |
| #define STREAM_CBMAX 16 | #define STREAM_CBMAX 16 |
| Line 69 BOOL sound_create(UINT rate, UINT ms) { | Line 63 BOOL sound_create(UINT rate, UINT ms) { |
| UINT samples; | UINT samples; |
| ZeroMemory(&sndstream, sizeof(sndstream)); | ZeroMemory(&sndstream, sizeof(sndstream)); |
| if (rate == 0) { | |
| return(SUCCESS); | |
| } | |
| switch(rate) { | switch(rate) { |
| case 11025: | case 11025: |
| opna_rate = 11025; | |
| break; | |
| case 22050: | case 22050: |
| opna_rate = 22050; | |
| break; | |
| case 44100: | case 44100: |
| opna_rate = 44100; | |
| break; | break; |
| default: | default: |
| Line 94 BOOL sound_create(UINT rate, UINT ms) { | Line 78 BOOL sound_create(UINT rate, UINT ms) { |
| } | } |
| soundmng_reset(); | soundmng_reset(); |
| soundcfg.rate = rate; | |
| sound_changeclock(); | |
| sndstream.buffer = (SINT32 *)_MALLOC(samples * 2 * sizeof(SINT32), | sndstream.buffer = (SINT32 *)_MALLOC(samples * 2 * sizeof(SINT32), |
| "stream"); | "stream"); |
| if (sndstream.buffer == NULL) { | if (sndstream.buffer == NULL) { |
| Line 101 BOOL sound_create(UINT rate, UINT ms) { | Line 88 BOOL sound_create(UINT rate, UINT ms) { |
| } | } |
| sndstream.samples = samples; | sndstream.samples = samples; |
| streamreset(); | streamreset(); |
| ratebase200 = (rate + 199) / 200; | |
| SNDCSEC_INIT; | SNDCSEC_INIT; |
| return(SUCCESS); | return(SUCCESS); |
| Line 130 void sound_reset(void) { | Line 116 void sound_reset(void) { |
| if (sndstream.buffer) { | if (sndstream.buffer) { |
| soundmng_reset(); | soundmng_reset(); |
| streamreset(); | streamreset(); |
| dsound_lastclock = I286_CLOCK; | soundcfg.lastclock = I286_CLOCK; |
| beep_eventreset(); | beep_eventreset(); |
| } | } |
| } | } |
| void sound_changeclock(void) { | |
| UINT32 clock; | |
| UINT hz; | |
| UINT hzmax; | |
| if (sndstream.buffer == NULL) { | |
| return; | |
| } | |
| // とりあえず 25で割り切れる。 | |
| clock = pc.realclock / 25; | |
| hz = soundcfg.rate / 25; | |
| // で、クロック数に合せて調整。(64bit演算しろよな的) | |
| hzmax = (1 << (32 - 8)) / (clock >> 8); | |
| while(hzmax < hz) { | |
| clock = (clock + 1) >> 1; | |
| hz = (hz + 1) >> 1; | |
| } | |
| soundcfg.hzbase = hz; | |
| soundcfg.clockbase = clock; | |
| soundcfg.minclock = 2 * clock / hz; | |
| soundcfg.lastclock = I286_CLOCK; | |
| } | |
| void sound_streamregist(void *hdl, SOUNDCB cbfn) { | void sound_streamregist(void *hdl, SOUNDCB cbfn) { |
| if (sndstream.buffer) { | if (sndstream.buffer) { |
| Line 152 void sound_streamregist(void *hdl, SOUND | Line 164 void sound_streamregist(void *hdl, SOUND |
| void sound_sync(void) { | void sound_sync(void) { |
| UINT length; | UINT32 length; |
| if (sndstream.buffer == NULL) { | if (sndstream.buffer == NULL) { |
| return; | return; |
| } | } |
| length = (I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK | length = I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK - soundcfg.lastclock; |
| - dsound_lastclock) * ratebase200; | if (length < soundcfg.minclock) { |
| if (length < pc.dsoundclock2) { | |
| return; | return; |
| } | } |
| length /= pc.dsoundclock; | length = (length * soundcfg.hzbase) / soundcfg.clockbase; |
| if (length) { | if (length == 0) { |
| SNDCSEC_ENTER; | return; |
| streamprepare(length); | |
| SNDCSEC_LEAVE; | |
| writebytes += length; | |
| dsound_lastclock += (length * pc.dsoundclock / ratebase200); | |
| beep_eventreset(); | |
| } | } |
| SNDCSEC_ENTER; | |
| streamprepare(length); | |
| SNDCSEC_LEAVE; | |
| soundcfg.writecount += length; | |
| soundcfg.lastclock += length * soundcfg.clockbase / soundcfg.hzbase; | |
| beep_eventreset(); | |
| if (writebytes >= 100) { | if (soundcfg.writecount >= 100) { |
| writebytes = 0; | soundcfg.writecount = 0; |
| soundmng_sync(); | soundmng_sync(); |
| } | } |
| } | } |
| Line 188 const SINT32 *ret; | Line 200 const SINT32 *ret; |
| SNDCSEC_ENTER; | SNDCSEC_ENTER; |
| if (sndstream.remain) { | if (sndstream.remain) { |
| streamprepare(sndstream.remain); | streamprepare(sndstream.remain); |
| dsound_lastclock = I286_CLOCK; | soundcfg.lastclock = I286_CLOCK + I286_BASECLOCK - I286_REMCLOCK; |
| beep_eventreset(); | beep_eventreset(); |
| } | } |
| } | } |