|
|
| version 1.1, 2003/10/23 07:20:43 | version 1.5, 2003/11/21 06:51:11 |
|---|---|
| Line 6 | Line 6 |
| #include "soundmng.h" | #include "soundmng.h" |
| #include "sound.h" | #include "sound.h" |
| #if defined(VERMOUTH_LIB) | #if defined(VERMOUTH_LIB) |
| #include "vermouth.h" | #include "commng.h" |
| #include "cmver.h" | |
| #endif | #endif |
| #define SOUNDBUFFERS 2 | #define SOUNDBUFFERS 2 |
| typedef struct { | typedef struct { |
| SndChannelPtr hdl; | SndChannelPtr hdl; |
| SndCallBackUPP cb; | SndCallBackUPP cb; |
| UINT rate; | UINT rate; |
| UINT samples; | UINT samples; |
| UINT buffersize; | UINT buffersize; |
| #if !defined(SOUND_CRITICAL) | |
| SINT16 *indata; | |
| SINT16 *extendbuffer; | |
| #endif | |
| ExtSoundHeader *buf[SOUNDBUFFERS]; | ExtSoundHeader *buf[SOUNDBUFFERS]; |
| SndCommand cmd[SOUNDBUFFERS]; | SndCommand cmd[SOUNDBUFFERS]; |
| SndCommand cbcmd[SOUNDBUFFERS]; | SndCommand cbcmd[SOUNDBUFFERS]; |
| Line 27 static BOOL QS_Avail = FALSE; | Line 33 static BOOL QS_Avail = FALSE; |
| static _QSOUND QSound; | static _QSOUND QSound; |
| static BOOL QSound_Playing = FALSE; | static BOOL QSound_Playing = FALSE; |
| #if defined(VERMOUTH_LIB) | |
| MIDIMOD vermouth_module = NULL; | |
| #endif | |
| static pascal void QSoundCallback(SndChannelPtr inCh, SndCommand *inCmd) { | static pascal void QSoundCallback(SndChannelPtr inCh, SndCommand *inCmd) { |
| QSOUND qs; | QSOUND qs; |
| int nextbuf; | int nextbuf; |
| void *dst; | void *dst; |
| #if defined(SOUND_CRITICAL) | |
| const SINT32 *src; | const SINT32 *src; |
| #endif | |
| if (QS_Avail) { | if (QS_Avail) { |
| qs = &QSound; | qs = &QSound; |
| nextbuf = inCmd->param1; | nextbuf = inCmd->param1; |
| dst = qs->buf[nextbuf]->sampleArea; | dst = qs->buf[nextbuf]->sampleArea; |
| #if !defined(SOUND_CRITICAL) | |
| if (qs->indata) { | |
| CopyMemory((SINT16 *)dst, qs->indata, qs->buffersize); | |
| qs->indata = NULL; | |
| } | |
| #else | |
| src = NULL; | src = NULL; |
| if (QSound_Playing) { | if (QSound_Playing) { |
| src = sound_pcmlock(); | src = sound_pcmlock(); |
| Line 51 const SINT32 *src; | Line 61 const SINT32 *src; |
| satuation_s16((SINT16 *)dst, src, qs->buffersize); | satuation_s16((SINT16 *)dst, src, qs->buffersize); |
| sound_pcmunlock(src); | sound_pcmunlock(src); |
| } | } |
| #endif | |
| else { | else { |
| ZeroMemory(dst, qs->buffersize); | ZeroMemory(dst, qs->buffersize); |
| } | } |
| Line 117 static BOOL SoundBuffer_Init(UINT rate, | Line 128 static BOOL SoundBuffer_Init(UINT rate, |
| qs->buffersize = buffersize; | qs->buffersize = buffersize; |
| drate = rate; | drate = rate; |
| dtox80(&drate, &extFreq); | dtox80(&drate, &extFreq); |
| #if !defined(SOUND_CRITICAL) | |
| qs->extendbuffer = (SINT16 *)_MALLOC(buffersize, "Extend buffer"); | |
| if (qs->extendbuffer == NULL) { | |
| goto sbinit_err; | |
| } | |
| #endif | |
| buffersize += sizeof(ExtSoundHeader); | buffersize += sizeof(ExtSoundHeader); |
| for (i=0; i<SOUNDBUFFERS; i++) { | for (i=0; i<SOUNDBUFFERS; i++) { |
| buf = (ExtSoundHeader *)_MALLOC(buffersize, "ExtSoundHeader"); | buf = (ExtSoundHeader *)_MALLOC(buffersize, "ExtSoundHeader"); |
| Line 161 static void SoundBuffer_Term(void) { | Line 180 static void SoundBuffer_Term(void) { |
| buf[i] = NULL; | buf[i] = NULL; |
| } | } |
| } | } |
| #if !defined(SOUND_CRITICAL) | |
| qs->indata = NULL; | |
| if (qs->extendbuffer) { | |
| _MFREE(qs->extendbuffer); | |
| qs->extendbuffer = NULL; | |
| } | |
| #endif | |
| } | } |
| UINT soundmng_create(UINT rate, UINT ms) { | UINT soundmng_create(UINT rate, UINT ms) { |
| UINT samples; | UINT samples; |
| #if defined(VERMOUTH_LIB) | |
| UINT num; | |
| #endif | |
| QSound_Playing = FALSE; | QSound_Playing = FALSE; |
| Line 182 UINT soundmng_create(UINT rate, UINT ms) | Line 205 UINT soundmng_create(UINT rate, UINT ms) |
| if (SoundChannel_Init()) { | if (SoundChannel_Init()) { |
| goto qsinit_err; | goto qsinit_err; |
| } | } |
| samples = (rate / 3) & (~3); | #if !defined(SOUND_CRITICAL) |
| samples = rate * ms / (SOUNDBUFFERS * 1000); | |
| samples = (samples + 3) & (~3); | |
| #else | |
| samples = rate * ms / 1000; | |
| samples = (samples + 255) & (~255); | |
| #endif | |
| if (SoundBuffer_Init(rate, samples)) { | if (SoundBuffer_Init(rate, samples)) { |
| goto qsinit_err; | goto qsinit_err; |
| } | } |
| #if defined(VERMOUTH_LIB) | #if defined(VERMOUTH_LIB) |
| vermouth_module = midimod_create(rate); | cmvermouth_load(rate); |
| for (num=0; num<128; num++) { | |
| midimod_loadprogram(vermouth_module, num); | |
| midimod_loadrhythm(vermouth_module, num); | |
| } | |
| #endif | #endif |
| return(samples); | return(samples); |
| qsinit_err: | qsinit_err: |
| soundmng_destroy(); | soundmng_destroy(); |
| (void)ms; | |
| return(0); | return(0); |
| } | } |
| void soundmng_destroy(void) { | void soundmng_destroy(void) { |
| if (QS_Avail) { | if (QS_Avail) { |
| #if defined(VERMOUTH_LIB) | |
| midimod_destroy(vermouth_module); | |
| vermouth_module = NULL; | |
| #endif | |
| QS_Avail = FALSE; | QS_Avail = FALSE; |
| SoundBuffer_Term(); | SoundBuffer_Term(); |
| SoundChannel_Term(); | SoundChannel_Term(); |
| #if defined(VERMOUTH_LIB) | |
| cmvermouth_unload(); | |
| #endif | |
| } | } |
| } | } |
| Line 224 void soundmng_stop(void) { | Line 247 void soundmng_stop(void) { |
| QSound_Playing = FALSE; | QSound_Playing = FALSE; |
| } | } |
| #if !defined(SOUND_CRITICAL) | |
| void soundmng_sync(void) { | |
| QSOUND qs; | |
| const SINT32 *src; | |
| qs = &QSound; | |
| if ((QSound_Playing) && (qs->indata == NULL)) { | |
| src = sound_pcmlock(); | |
| if (src) { | |
| satuation_s16(qs->extendbuffer, src, qs->buffersize); | |
| sound_pcmunlock(src); | |
| qs->indata = qs->extendbuffer; | |
| } | |
| } | |
| } | |
| #endif | |