ref: a20cc2d81463696a759b130f2d68f0d2f641075b
dir: /Game/src/audiolib/fx_man.c/
/* Copyright (C) 1994-1995 Apogee Software, Ltd. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of 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 of MERCHANTABILITY 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 License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /********************************************************************** module: FX_MAN.C author: James R. Dose date: March 17, 1994 Device independant sound effect routines. (c) Copyright 1994 James R. Dose. All Rights Reserved. **********************************************************************/ #include "dsl.h" #include "fx_man.h" #include "sndcards.h" #include "multivoc.h" #define TRUE ( 1 == 1 ) #define FALSE ( !TRUE ) int FX_SoundDevice = -1; int FX_ErrorCode = FX_Ok; int FX_Installed = FALSE; #define FX_SetErrorCode( status ) \ FX_ErrorCode = ( status ); /*--------------------------------------------------------------------- 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(int ErrorNumber) { char *ErrorString; switch( ErrorNumber ) { case FX_Warning : case FX_Error : ErrorString = FX_ErrorString( FX_ErrorCode ); break; case FX_Ok : ErrorString = "Fx ok\n"; break; case FX_SoundCardError : ErrorString = DSL_ErrorString( DSL_Error ); break; case FX_InvalidCard : ErrorString = "Invalid Sound Fx device.\n"; break; case FX_MultiVocError : ErrorString = MV_ErrorString( MV_Error ); break; case FX_DPMI_Error : ErrorString = "DPMI Error in FX_MAN.\n"; break; default : ErrorString = "Unknown Fx error code.\n"; break; } return( ErrorString ); } /*--------------------------------------------------------------------- Function: FX_Init Selects which sound device to use. ---------------------------------------------------------------------*/ int FX_Init ( int SoundCard, int numvoices, int numchannels, int samplebits, int mixrate ) { int status; int devicestatus; if ( FX_Installed ) { FX_Shutdown(); } status = FX_Ok; FX_SoundDevice = SoundCard; switch( SoundCard ) { case SC_SoundScape : devicestatus = MV_Init( SoundCard, mixrate, numvoices, numchannels, samplebits ); if ( devicestatus != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); status = FX_Error; } break; default : FX_SetErrorCode( FX_InvalidCard ); status = FX_Error; } if ( status == FX_Ok ) { FX_Installed = TRUE; } return( status ); } /*--------------------------------------------------------------------- Function: FX_Shutdown Terminates use of sound device. ---------------------------------------------------------------------*/ int FX_Shutdown ( void ) { int status; if ( !FX_Installed ) { return( FX_Ok ); } status = FX_Ok; switch( FX_SoundDevice ) { case SC_SoundScape : status = MV_Shutdown(); if ( status != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); status = FX_Error; } break; default : FX_SetErrorCode( FX_InvalidCard ); status = FX_Error; } FX_Installed = FALSE; return( status ); } /*--------------------------------------------------------------------- Function: FX_SetCallback Sets the function to call when a voice is done. ---------------------------------------------------------------------*/ int FX_SetCallBack(void ( *function )( int32_t )) { int status; status = FX_Ok; switch( FX_SoundDevice ) { case SC_SoundScape : MV_SetCallBack( function ); break; default : FX_SetErrorCode( FX_InvalidCard ); status = FX_Error; } return( status ); } /*--------------------------------------------------------------------- Function: FX_SetVolume Sets the volume of the current sound device. ---------------------------------------------------------------------*/ void FX_SetVolume(int volume) { MV_SetVolume( volume ); } /*--------------------------------------------------------------------- Function: FX_SetReverseStereo Set the orientation of the left and right channels. ---------------------------------------------------------------------*/ void FX_SetReverseStereo(int setting) { MV_SetReverseStereo( setting ); } /*--------------------------------------------------------------------- Function: FX_GetReverseStereo Returns the orientation of the left and right channels. ---------------------------------------------------------------------*/ int FX_GetReverseStereo(void) { return MV_GetReverseStereo(); } /*--------------------------------------------------------------------- Function: FX_SetReverb Sets the reverb level. ---------------------------------------------------------------------*/ void FX_SetReverb ( int reverb ) { MV_SetReverb( reverb ); } /*--------------------------------------------------------------------- Function: FX_SetReverbDelay Sets the delay level of reverb to add to mix. ---------------------------------------------------------------------*/ void FX_SetReverbDelay ( int delay ) { MV_SetReverbDelay( delay ); } /*--------------------------------------------------------------------- Function: FX_VoiceAvailable Checks if a voice can be play at the specified priority. ---------------------------------------------------------------------*/ int FX_VoiceAvailable ( int priority ) { return MV_VoiceAvailable( priority ); } /*--------------------------------------------------------------------- Function: FX_PlayLoopedVOC Begin playback of sound data with the given volume and priority. ---------------------------------------------------------------------*/ int FX_PlayLoopedVOC ( uint8_t *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 ) { int handle; handle = MV_PlayLoopedVOC( ptr, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval ); if ( handle < MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); handle = FX_Warning; } return( handle ); } /*--------------------------------------------------------------------- Function: FX_PlayWAV Begin playback of sound data with the given volume and priority. ---------------------------------------------------------------------*/ int FX_PlayLoopedWAV ( uint8_t *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 ) { int32_t handle; handle = MV_PlayLoopedWAV( ptr, loopstart, loopend, pitchoffset, vol, left, right, priority, callbackval ); if ( handle < MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); handle = FX_Warning; } return( handle ); } /*--------------------------------------------------------------------- Function: FX_PlayVOC3D Begin playback of sound data at specified angle and distance from listener. ---------------------------------------------------------------------*/ int FX_PlayVOC3D ( uint8_t *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval ) { int handle; handle = MV_PlayVOC3D( ptr, pitchoffset, angle, distance, priority, callbackval ); if ( handle < MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); handle = FX_Warning; } return( handle ); } /*--------------------------------------------------------------------- Function: FX_PlayWAV3D Begin playback of sound data at specified angle and distance from listener. ---------------------------------------------------------------------*/ int FX_PlayWAV3D ( uint8_t *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval ) { int handle; handle = MV_PlayWAV3D( ptr, pitchoffset, angle, distance, priority, callbackval ); if ( handle < MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); handle = FX_Warning; } return( handle ); } /*--------------------------------------------------------------------- Function: FX_Pan3D Set the angle and distance from the listener of the voice associated with the specified handle. ---------------------------------------------------------------------*/ int FX_Pan3D ( int handle, int angle, int distance ) { int status; status = MV_Pan3D( handle, angle, distance ); if ( status != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); status = FX_Warning; } return( status ); } /*--------------------------------------------------------------------- Function: FX_StopSound Halts playback of a specific voice ---------------------------------------------------------------------*/ int FX_StopSound ( int handle ) { int status; status = MV_Kill( handle ); if ( status != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); return( FX_Warning ); } return( FX_Ok ); } /*--------------------------------------------------------------------- Function: FX_StopAllSounds Halts playback of all sounds. ---------------------------------------------------------------------*/ int FX_StopAllSounds ( void ) { int status; status = MV_KillAllVoices(); if ( status != MV_Ok ) { FX_SetErrorCode( FX_MultiVocError ); return( FX_Warning ); } return( FX_Ok ); }