📄 multivoc.c
字号:
/*--------------------------------------------------------------------- Function: MV_SetPan Sets the stereo and mono volume level of the voice associated with the specified handle.---------------------------------------------------------------------*/int32_t MV_SetPan(int32_t handle, int32_t vol, int32_t left, int32_t right){ VoiceNode *voice; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } voice = MV_GetVoice(handle); if (voice == NULL) { MV_SetErrorCode(MV_VoiceNotFound); return(MV_Warning); } MV_SetVoiceVolume(voice, vol, left, right); return(MV_Ok);}/*--------------------------------------------------------------------- Function: MV_Pan3D Set the angle and distance from the listener of the voice associated with the specified handle.---------------------------------------------------------------------*/int32_t MV_Pan3D(int32_t handle, int32_t angle, int32_t distance){ int32_t left; int32_t right; int32_t mid; int32_t volume; int32_t status; if (distance < 0) { distance = -distance; angle += MV_NumPanPositions / 2; } volume = MIX_VOLUME(distance); // Ensure angle is within 0 - 31 angle &= MV_MaxPanPosition; left = MV_PanTable[ angle ][ volume ].left; right = MV_PanTable[ angle ][ volume ].right; mid = max(0, 255 - distance); status = MV_SetPan(handle, mid, left, right); return(status);}/*--------------------------------------------------------------------- Function: MV_SetReverb Sets the level of reverb to add to mix.---------------------------------------------------------------------*/void MV_SetReverb(int32_t reverb){ MV_ReverbLevel = MIX_VOLUME(reverb); MV_ReverbTable = &MV_VolumeTable[ MV_ReverbLevel ];}/*--------------------------------------------------------------------- Function: MV_SetFastReverb Sets the level of reverb to add to mix.---------------------------------------------------------------------*/void MV_SetFastReverb(int32_t reverb){ MV_ReverbLevel = max(0, min(16, reverb)); MV_ReverbTable = NULL;}/*--------------------------------------------------------------------- Function: MV_GetMaxReverbDelay Returns the maximum delay time for reverb.---------------------------------------------------------------------*/int32_t MV_GetMaxReverbDelay(void){ int32_t maxdelay; maxdelay = MixBufferSize * MV_NumberOfBuffers; return maxdelay;}/*--------------------------------------------------------------------- Function: MV_GetReverbDelay Returns the current delay time for reverb.---------------------------------------------------------------------*/int32_t MV_GetReverbDelay(void){ return MV_ReverbDelay / MV_SampleSize;}/*--------------------------------------------------------------------- Function: MV_SetReverbDelay Sets the delay level of reverb to add to mix.---------------------------------------------------------------------*/void MV_SetReverbDelay(int32_t delay){ int32_t maxdelay; maxdelay = MV_GetMaxReverbDelay(); MV_ReverbDelay = max((signed)MixBufferSize, min(delay, maxdelay)); MV_ReverbDelay *= MV_SampleSize;}/*--------------------------------------------------------------------- Function: MV_SetMixMode Prepares Multivoc to play stereo of mono digitized sounds.---------------------------------------------------------------------*/int32_t MV_SetMixMode(int32_t numchannels, int32_t samplebits){ int32_t mode; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } mode = 0; if (numchannels == 2) { mode |= STEREO; } if (samplebits == 16) { mode |= SIXTEEN_BIT; }//#if defined(_WIN32)// MV_MixMode = DSOUND_SetMixMode(mode);//#else MV_MixMode = mode;//#endif MV_Channels = 1; if (MV_MixMode & STEREO) { MV_Channels = 2; } MV_Bits = 8; if (MV_MixMode & SIXTEEN_BIT) { MV_Bits = 16; } MV_BuffShift = 7 + MV_Channels; MV_SampleSize = sizeof(MONO8) * MV_Channels; if (MV_Bits == 8) { MV_Silence = SILENCE_8BIT; } else { MV_Silence = SILENCE_16BIT; MV_BuffShift += 1; MV_SampleSize *= 2; } MV_BufferSize = MixBufferSize * MV_SampleSize; MV_NumberOfBuffers = TotalBufferSize / MV_BufferSize; MV_BufferLength = TotalBufferSize; MV_RightChannelOffset = MV_SampleSize / 2; return(MV_Ok);}// ---------------------------------------------------------------------// OGG file// ---------------------------------------------------------------------ov_callbacks cb;size_t ReadOgg(void *ptr, size_t size1, size_t nmemb, void *datasource){ sounddef *d=(sounddef *)datasource; size1*=nmemb; /* if (d->pos>=d->size) return 0;*/ if (d->pos+size1>=d->size) size1=d->size-d->pos; Bmemcpy(ptr,(d->ptrsnd+d->pos),size1); d->pos+=size1; return size1;}int32_t SeekOgg(void *datasource,ogg_int64_t offset,int32_t whence){ sounddef *d=(sounddef *)datasource; switch (whence) { case SEEK_SET: whence=offset; break; case SEEK_CUR: whence=d->pos+offset; break; case SEEK_END: whence=d->size-offset; break; default: return -1; } /* if (whence>=(int32_t)d->size||whence<0) return -1;*/ d->pos=whence; return 0;}intptr_t TellOgg(void *datasource){ sounddef *d=(sounddef *)datasource; return d->pos;}int32_t CloseOgg(void *datasource){ UNREFERENCED_PARAMETER(datasource); return 0;}/*--------------------------------------------------------------------- Function: MV_StartPlayback Starts the sound playback engine.---------------------------------------------------------------------*/int32_t MV_StartPlayback(void){ int32_t status; int32_t buffer; cb.close_func=CloseOgg; cb.read_func =ReadOgg; cb.seek_func =SeekOgg; cb.tell_func =(void *)TellOgg; // Initialize the buffers ClearBuffer_DW(MV_MixBuffer[ 0 ], MV_Silence, TotalBufferSize >> 2); for (buffer = 0; buffer < MV_NumberOfBuffers; buffer++) { MV_BufferEmpty[ buffer ] = TRUE; } // Set the mix buffer variables MV_MixPage = 1; MV_MixFunction = MV_Mix; MV_MixRate = MV_RequestedMixRate; // Start playback#if defined(_WIN32) status = DSOUND_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers);#else status = DSL_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers);#endif if (status != 0) { MV_SetErrorCode(MV_BlasterError); return(MV_Error); } return(MV_Ok);}/*--------------------------------------------------------------------- Function: MV_StopPlayback Stops the sound playback engine.---------------------------------------------------------------------*/void MV_StopPlayback(void){ VoiceNode *voice; VoiceNode *next; unsigned flags; // Stop sound playback#if defined(_WIN32) DSOUND_StopPlayback();#else DSL_StopPlayback();#endif // Make sure all callbacks are done. flags = DisableInterrupts(); for (voice = VoiceList.next; voice != &VoiceList; voice = next) { next = voice->next; MV_StopVoice(voice); if (MV_CallBackFunc) { MV_CallBackFunc(voice->callbackval); } } RestoreInterrupts(flags);}#if 0/*--------------------------------------------------------------------- Function: MV_StartRecording Starts the sound recording engine.---------------------------------------------------------------------*/int32_t MV_StartRecording(int32_t MixRate, void(*function)(char *ptr, int32_t length)){ int32_t status; switch (MV_SoundCard) { case SoundBlaster : break; default : MV_SetErrorCode(MV_UnsupportedCard); return(MV_Error); break; } if (function == NULL) { MV_SetErrorCode(MV_NullRecordFunction); return(MV_Error); } MV_StopPlayback(); // Initialize the buffers ClearBuffer_DW(MV_MixBuffer[ 0 ], SILENCE_8BIT, TotalBufferSize >> 2); // Set the mix buffer variables MV_MixPage = 0; MV_RecordFunc = function; // Start playback switch (MV_SoundCard) { case SoundBlaster : status = BLASTER_BeginBufferedRecord(MV_MixBuffer[ 0 ], TotalBufferSize, NumberOfBuffers, MixRate, MONO_8BIT, MV_ServiceRecord); if (status != BLASTER_Ok) { MV_SetErrorCode(MV_BlasterError); return(MV_Error); } break; } MV_Recording = TRUE; return(MV_Ok);}#endif#if 0/*--------------------------------------------------------------------- Function: MV_StopRecord Stops the sound record engine.---------------------------------------------------------------------*/void MV_StopRecord(void){ // Stop sound playback switch (MV_SoundCard) { case SoundBlaster : BLASTER_StopPlayback(); break; } MV_Recording = FALSE; MV_StartPlayback();}#endif/*--------------------------------------------------------------------- Function: MV_StartDemandFeedPlayback Plays a digitized sound from a user controlled buffering system.---------------------------------------------------------------------*/int32_t MV_StartDemandFeedPlayback(void(*function)(char **ptr, uint32_t *length), int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ VoiceNode *voice; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } // Request a voice from the voice pool voice = MV_AllocVoice(priority); if (voice == NULL) { MV_SetErrorCode(MV_NoVoices); return(MV_Error); } voice->wavetype = DemandFeed; voice->bits = 8; voice->GetSound = MV_GetNextDemandFeedBlock; voice->NextBlock = NULL; voice->DemandFeed = function; voice->LoopStart = NULL; voice->LoopCount = 0; voice->BlockLength = 0; voice->position = 0; voice->sound = NULL; voice->length = 0; voice->BlockLength = 0; voice->Playing = TRUE; voice->next = NULL; voice->prev = NULL; voice->priority = priority; voice->callbackval = callbackval; MV_SetVoicePitch(voice, rate, pitchoffset); MV_SetVoiceVolume(voice, vol, left, right); MV_PlayVoice(voice); return(voice->handle);}/*--------------------------------------------------------------------- Function: MV_PlayRaw Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayRaw(char *ptr, uint32_t length, unsigned rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ int32_t status; status = MV_PlayLoopedRaw(ptr, length, NULL, NULL, rate, pitchoffset, vol, left, right, priority, callbackval); return(status);}/*--------------------------------------------------------------------- Function: MV_PlayLoopedRaw Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayLoopedRaw(char *ptr, int32_t length, char *loopstart, char *loopend, unsigned rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ VoiceNode *voice; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } // Request a voice from the voice pool voice = MV_AllocVoice(priority); if (voice == NULL) { MV_SetErrorCode(MV_NoVoices); return(MV_Error); } voice->wavetype = Raw; voice->bits = 8; voice->GetSound = MV_GetNextRawBlock; voice->Playing = TRUE; voice->NextBlock = ptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -