📄 audiolib_fx_fmod.c
字号:
//-------------------------------------------------------------------------/*Duke Nukem Copyright (C) 1996, 2003 3D Realms EntertainmentThis file is part of Duke Nukem 3D version 1.5 - Atomic EditionDuke Nukem 3D is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. FMOD AudioLib implementation by Jonathon Fowler (jonof@edgenetwk.com)*///-------------------------------------------------------------------------#include "fx_man_fmod.h"#include "duke3d.h"#include "fmod.h"#define TRUE (1==1)#define FALSE (1==0)#define dprintOSD(...)#ifdef WINDOWSextern int32_t hWindow;#endifvoid(*FX_CallBackFunc)(uint32_t) = NULL;int32_t FX_ErrorCode = FX_Ok;#define FX_SetErrorCode( status ) \ FX_ErrorCode = ( status );FSOUND_SAMPLE * FX_Samples[MAXSOUNDS + 11]; // 11 remote ridiculesint32_t FX_NumVoices = 0;static char chtoggle=0;static char *chstates=NULL, *chstatesa, *chstatesb;static int32_t *chcallvals=NULL;int32_t FX_ReadVOCInfo(char *data, int32_t size, int32_t *samplerate, int32_t *channels, int32_t *samplesize, int32_t *datalen);int32_t FX_ReadVOCData(char *data, char *buf, int32_t bufferlen, char eightbit);int32_t FX_SimulateCallbacks(void);/*--------------------------------------------------------------------- Function: FX_ErrorString Returns a pointer to the error message associated with an error number. A -1 returns a pointer the current error.---------------------------------------------------------------------*/char *FX_ErrorString(int32_t ErrorNumber){ char *ErrorString; switch (ErrorNumber) { case FX_Warning : case FX_Error : ErrorString = FX_ErrorString(FX_ErrorCode); break; case FX_Ok : ErrorString = "Fx ok."; break; case FX_ASSVersion : ErrorString = "Apogee Sound System Version WinMM " "Programmed by Jim Dose, Ported by Jonathon Fowler\n" "(c) Copyright 1995 James R. Dose. All Rights Reserved.\n"; break; case FX_FMODInit : ErrorString = "Failed initializing FMOD."; break; default : ErrorString = "Unknown Fx error code."; break; } return(ErrorString);}/*--------------------------------------------------------------------- Function: FX_Init Selects which sound device to use.---------------------------------------------------------------------*/static char *OutputType(int32_t a){ switch (a) { case FSOUND_OUTPUT_NOSOUND: return "no-sound"; case FSOUND_OUTPUT_WINMM: return "WinMM"; case FSOUND_OUTPUT_DSOUND: return "DirectSound"; case FSOUND_OUTPUT_A3D: return "Aureal3D"; case FSOUND_OUTPUT_OSS: return "OSS"; case FSOUND_OUTPUT_ESD: return "ESD"; case FSOUND_OUTPUT_ALSA: return "ALSA"; case FSOUND_OUTPUT_ASIO: return "ASIO"; case FSOUND_OUTPUT_XBOX: return "Xbox"; case FSOUND_OUTPUT_PS2: return "Playstation2"; case FSOUND_OUTPUT_MAC: return "Macintosh Sound Manager"; default: return "unknown"; }}int32_t FX_Init(int32_t SoundCard, int32_t numvoices, int32_t numchannels, int32_t samplebits, unsigned mixrate){ FSOUND_Close(); memset(FX_Samples, 0, sizeof(FX_Samples));#ifdef WINDOWS if (hWindow) { //FSOUND_SetHWND(&hWindow); }#endif if (!FSOUND_Init(mixrate, numvoices, FSOUND_INIT_GLOBALFOCUS)) { FX_SetErrorCode(FX_FMODInit); return FX_Error; } printOSD("FX_Init(): %d voices, %d channels, %dHz samplerate\n", numvoices,numchannels,FSOUND_GetOutputRate()); printOSD("FX_Init(): FMOD is using the %s output driver\n", OutputType(FSOUND_GetOutput())); chtoggle=0; if (chstates) free(chstates); chstates = (char*)malloc(numvoices*2 + sizeof(int32_t)*numvoices); memset(chstates,0,numvoices*2 + sizeof(int32_t)*numvoices); chcallvals = (int32_t*)(chstates + numvoices*2); chstatesa = chstates; chstatesb = chstates + numvoices; FX_NumVoices = numvoices; FX_SetErrorCode(FX_Ok); return FX_Ok;}/*--------------------------------------------------------------------- Function: FX_Shutdown Terminates use of sound device.---------------------------------------------------------------------*/int32_t FX_Shutdown(void){ uint32_t curalloced, maxalloced; if (chstates) { FSOUND_GetMemoryStats(&curalloced, &maxalloced); printOSD("FX_Shutdown(): allocation stats - currently %d bytes, maximum %d bytes\n",curalloced,maxalloced); } FSOUND_Close(); if (chstates) free(chstates); chstates=chstatesa=chstatesb=0; FX_SetErrorCode(FX_Ok); return FX_Ok;}/*--------------------------------------------------------------------- Function: FX_SetCallback Sets the function to call when a voice is done.---------------------------------------------------------------------*/int32_t FX_SetCallBack(void(*function)(uint32_t)){ FX_CallBackFunc = function; FX_SetErrorCode(FX_Ok); return FX_Ok;}/*--------------------------------------------------------------------- Function: FX_SetVolume Sets the volume of the current sound device.---------------------------------------------------------------------*/void FX_SetVolume(int32_t volume){ FSOUND_SetSFXMasterVolume(volume);}/*--------------------------------------------------------------------- Function: FX_SetReverseStereo Set the orientation of the left and right channels.---------------------------------------------------------------------*/void FX_SetReverseStereo(int32_t setting){}/*--------------------------------------------------------------------- Function: FX_GetReverseStereo Returns the orientation of the left and right channels.---------------------------------------------------------------------*/int32_t FX_GetReverseStereo(void){ return 0;}/*--------------------------------------------------------------------- Function: FX_SetReverb Sets the reverb level.---------------------------------------------------------------------*/void FX_SetReverb(int32_t reverb){}/*--------------------------------------------------------------------- Function: FX_SetReverbDelay Sets the delay level of reverb to add to mix.---------------------------------------------------------------------*/void FX_SetReverbDelay(int32_t delay){}/*--------------------------------------------------------------------- Function: FX_VoiceAvailable Checks if a voice can be play at the specified priority.---------------------------------------------------------------------*/int32_t FX_VoiceAvailable(int32_t priority){ FX_SimulateCallbacks(); return 1;}/*--------------------------------------------------------------------- Function: FX_PlayLoopedVOC Begin playback of sound data with the given volume and priority. JBF: As a hack, since Duke3D passes the sound/sample number as the callbackval parameter, we can use this as an index into the FX_Samples array to access samples if they've already been loaded. RemoteRidicule sounds have negative callback values, so they take up residence at the end of FX_Samples.---------------------------------------------------------------------*/int32_t FX_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){ return FX_PlayLoopedSound(pitchoffset, vol, callbackval);}/*--------------------------------------------------------------------- Function: FX_PlayWAV Begin playback of sound data with the given volume and priority.---------------------------------------------------------------------*/int32_t FX_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){ return FX_PlayLoopedSound(pitchoffset, vol, callbackval);}/*--------------------------------------------------------------------- Function: FX_PlayVOC3D Begin playback of sound data at specified angle and distance from listener.---------------------------------------------------------------------*/int32_t FX_PlayVOC3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval){ return FX_PlayPositionedSound(pitchoffset, angle, distance, callbackval);}/*--------------------------------------------------------------------- Function: FX_PlayWAV3D Begin playback of sound data at specified angle and distance from listener.---------------------------------------------------------------------*/int32_t FX_PlayWAV3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval){ return FX_PlayPositionedSound(pitchoffset, angle, distance, callbackval);}/*--------------------------------------------------------------------- Function: FX_Pan3D Set the angle and distance from the listener of the voice associated with the specified handle.---------------------------------------------------------------------*/int32_t FX_Pan3D( int32_t handle, int32_t angle, int32_t distance){ return FX_Ok;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -