📄 multivoc.c
字号:
voice->position = 0; voice->BlockLength = length; voice->length = 0; voice->next = NULL; voice->prev = NULL; voice->priority = priority; voice->callbackval = callbackval; voice->LoopStart = loopstart; voice->LoopEnd = loopend; voice->LoopSize = (voice->LoopEnd - voice->LoopStart) + 1; MV_SetVoicePitch(voice, rate, pitchoffset); MV_SetVoiceVolume(voice, vol, left, right); MV_PlayVoice(voice); return(voice->handle);}/*--------------------------------------------------------------------- Function: MV_PlayWAV Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayWAV(char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ int32_t status; status = MV_PlayLoopedWAV(ptr, -1, -1, pitchoffset, vol, left, right, priority, callbackval); if (status < MV_Ok) { Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); initprintf(tempbuf); } return(status);}/*--------------------------------------------------------------------- Function: MV_PlayWAV3D Begin playback of sound data at specified angle and distance from listener.---------------------------------------------------------------------*/int32_t MV_PlayWAV3D(char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval){ int32_t left; int32_t right; int32_t mid; int32_t volume; int32_t status; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } 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_PlayWAV(ptr, pitchoffset, mid, left, right, priority, callbackval); return(status);}/*--------------------------------------------------------------------- Function: MV_PlayLoopedWAV Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayLoopedWAV(char *ptr, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ riff_header *riff; format_header *format; data_header *data; VoiceNode *voice; int32_t length; int32_t absloopend; int32_t absloopstart; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } riff = (riff_header *)ptr; if ((strncmp(riff->RIFF, "RIFF", 4) != 0) || (strncmp(riff->WAVE, "WAVE", 4) != 0) || (strncmp(riff->fmt, "fmt ", 4) != 0)) { MV_SetErrorCode(MV_InvalidWAVFile); return(MV_Error); } format = (format_header *)(riff + 1); data = (data_header *)(((char *)format) + riff->format_size); // Check if it's PCM data. if (format->wFormatTag != 1) { MV_SetErrorCode(MV_InvalidWAVFile); return(MV_Error); } if (format->nChannels != 1) { MV_SetErrorCode(MV_InvalidWAVFile); return(MV_Error); } if ((format->nBitsPerSample != 8) && (format->nBitsPerSample != 16)) { MV_SetErrorCode(MV_InvalidWAVFile); return(MV_Error); } if (strncmp((char *)data->DATA, "data", 4) != 0) { MV_SetErrorCode(MV_InvalidWAVFile); 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 = WAV; voice->bits = format->nBitsPerSample; voice->GetSound = MV_GetNextWAVBlock; length = data->size; absloopstart = loopstart; absloopend = loopend; if (voice->bits == 16) { loopstart *= 2; data->size &= ~1; loopend *= 2; length /= 2; } loopend = min(loopend, (signed)data->size); absloopend = min(absloopend, length); voice->Playing = TRUE; voice->DemandFeed = NULL; voice->LoopStart = NULL; voice->LoopCount = 0; voice->position = 0; voice->length = 0; voice->BlockLength = absloopend; voice->NextBlock = (char *)(data + 1); voice->next = NULL; voice->prev = NULL; voice->priority = priority; voice->callbackval = callbackval; voice->LoopStart = voice->NextBlock + loopstart; voice->LoopEnd = voice->NextBlock + loopend; voice->LoopSize = absloopend - absloopstart; if ((loopstart >= (signed)data->size) || (loopstart < 0)) { voice->LoopStart = NULL; voice->LoopEnd = NULL; voice->BlockLength = length; } MV_SetVoicePitch(voice, format->nSamplesPerSec, pitchoffset); MV_SetVoiceVolume(voice, vol, left, right); MV_PlayVoice(voice); return(voice->handle);}/*--------------------------------------------------------------------- Function: MV_PlayVOC3D Begin playback of sound data at specified angle and distance from listener.---------------------------------------------------------------------*/int32_t MV_PlayVOC3D(char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval){ int32_t left; int32_t right; int32_t mid; int32_t volume; int32_t status; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } 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_PlayVOC(ptr, pitchoffset, mid, left, right, priority, callbackval); return(status);}/*--------------------------------------------------------------------- Function: MV_PlayVOC Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayVOC(char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ int32_t status; status = MV_PlayLoopedVOC(ptr, -1, -1, pitchoffset, vol, left, right, priority, callbackval); if (status < MV_Ok) { Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); initprintf(tempbuf); } return(status);}/*--------------------------------------------------------------------- Function: MV_PlayLoopedVOC Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayLoopedVOC(char *ptr, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ VoiceNode *voice; int32_t status; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } // Make sure it's a valid VOC file. status = strncmp(ptr, "Creative Voice File", 19); if (status != 0) { MV_SetErrorCode(MV_InvalidVOCFile); 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 = VOC; voice->bits = 8; voice->GetSound = MV_GetNextVOCBlock; voice->NextBlock = ptr + *(uint16_t *)(ptr + 0x14); voice->DemandFeed = NULL; voice->LoopStart = NULL; voice->LoopCount = 0; voice->BlockLength = 0; voice->PitchScale = PITCH_GetScale(pitchoffset); voice->length = 0; voice->next = NULL; voice->prev = NULL; voice->priority = priority; voice->callbackval = callbackval; voice->LoopStart = (char *)loopstart; voice->LoopEnd = (char *)loopend; voice->LoopSize = loopend - loopstart + 1; if (loopstart < 0) { voice->LoopStart = NULL; voice->LoopEnd = NULL; } MV_SetVoiceVolume(voice, vol, left, right); MV_PlayVoice(voice); return(voice->handle);}/*--------------------------------------------------------------------- Function: MV_PlayLoopedOGG Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/VoiceNode *voice;int32_t MV_PlayLoopedOGG(char *ptr, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ vorbis_info *vorbisInfo; int32_t length; 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->OGGstream.pos=0; voice->OGGstream.ptrsnd=ptr; voice->OGGstream.size=g_sounds[callbackval].soundsiz; voice->downsample=0; if (ov_open_callbacks(&voice->OGGstream,&voice->OGGstream.oggStream,0,0,cb)<0) { MV_SetErrorCode(MV_InvalidOGGFile); return(MV_Error); } vorbisInfo=ov_info(&voice->OGGstream.oggStream,-1); if (!vorbisInfo) { MV_SetErrorCode(MV_InvalidOGGFile); return(MV_Error); } while ((ogg_int64_t)(vorbisInfo->rate)/(1<<voice->downsample)*PITCH_GetScale(pitchoffset)/0x1000000/0x100) voice->downsample++; length=ov_pcm_total(&voice->OGGstream.oggStream,-1); if (!length) length=0xffffff; /* if (length == OV_EINVAL) { MV_SetErrorCode(MV_InvalidOGGFile); return(MV_Error); }*/ loopend=length=length>>voice->downsample; voice->wavetype = OGG; voice->bits = 16; voice->GetSound = MV_GetNextOGGBlock; voice->Playing = TRUE; voice->DemandFeed = NULL; voice->LoopStart = NULL; voice->LoopCount = 0; voice->position = 0; voice->length = 0; voice->BlockLength = loopend; voice->NextBlock = NULL; voice->next = NULL; voice->prev = NULL; voice->priority = priority; voice->callbackval = callbackval; voice->LoopStart = voice->NextBlock + loopstart+1; voice->LoopEnd = voice->NextBlock + loopend+1; voice->LoopSize = loopend - loopstart; if (loopstart < 0) { voice->LoopStart = NULL; voice->LoopEnd = NULL; voice->BlockLength = length; } MV_SetVoicePitch(voice, vorbisInfo->rate>>voice->downsample, pitchoffset); if (vorbisInfo->channels==2) voice->downsample++; MV_SetVoiceVolume(voice, vol, left, right); MV_PlayVoice(voice); return(voice->handle);}/*--------------------------------------------------------------------- Function: MV_PlayOGG Begin playback of sound data with the given sound levels and priority.---------------------------------------------------------------------*/int32_t MV_PlayOGG(char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval){ int32_t status; status = MV_PlayLoopedOGG(ptr, -1, -1, pitchoffset, vol, left, right, priority, callbackval); if (status < MV_Ok) { Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); initprintf(tempbuf); } return(status);}/*--------------------------------------------------------------------- Function: MV_PlayOGG3D Begin playback of sound data at specified angle and distance from listener.---------------------------------------------------------------------*/int32_t MV_PlayOGG3D(char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval){ int32_t left; int32_t right; int32_t mid; int32_t volume; int32_t status; if (!MV_Installed) { MV_SetErrorCode(MV_NotInstalled); return(MV_Error); } 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_PlayOGG(ptr, pitchoffset, mid, left, right, priority, callbackval); return(status);}/*--------------------------------------------------------------------- Function: MV_CreateVolumeTable Create the table used to convert sound data to a specific volume level.---------------------------------------------------------------------*/void MV_CreateVolumeTable(int32_t index, int32_t volume, int32_t MaxVolume){ int32_t val; int32_t level; int32_t i; level = (volume * MaxVolume) / MV_MaxTotalVolume; if (MV_Bits == 16) { for (i = 0; i < 65536; i += 256) { val = i - 0x8000; val *= level; val /= MV_MaxVolume; MV_VolumeTable[ index ][ i / 256 ] = val; } } else { for (i = 0; i < 256; i++) { val = i - 0x80; val *= level; val /= MV_MaxVolume; MV_VolumeTable[ volume ][ i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -