From 45a9203d8160ccf0c045568fa4b5b93cba1d6191 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Tue, 17 Oct 2023 09:04:16 +0200 Subject: [PATCH] let SDL_Mixer do the actual sound mixing (#43) * add a dummy fx_mixer.c template * let SDL_Mixer do the actual sound mixing * fixes * more fixes * next fix * add a SDL_Mixer version guard * provide an alternative per-channel FX_SetVolume() implementation for SDL_Mixer < 2.6.0 * cosmetics * immediately stop music on Windows in CP_Quit() Instead of fading it out, that is, because on Windows changing the music channel volume affects the sfx channels as well. Fixes #8 --- configure.ac | 2 +- rott/Makefile.am | 5 +- rott/_rt_soun.h | 1 + rott/audiolib/Makefile.am | 13 - rott/audiolib/_multivc.h | 234 --- rott/audiolib/debugio.h | 30 - rott/audiolib/dma.h | 83 - rott/audiolib/dpmi.h | 80 - rott/audiolib/dsl.c | 234 --- rott/audiolib/dsl.h | 28 - rott/audiolib/fx_man.c | 1070 ------------- rott/audiolib/fx_man.h | 135 -- rott/audiolib/interrup.h | 37 - rott/audiolib/linklist.h | 118 -- rott/audiolib/ll_man.c | 173 --- rott/audiolib/ll_man.h | 76 - rott/audiolib/multivoc.c | 3064 ------------------------------------- rott/audiolib/multivoc.h | 123 -- rott/audiolib/mv_mix.c | 293 ---- rott/audiolib/mvreverb.c | 58 - rott/audiolib/nodpmi.c | 179 --- rott/audiolib/pitch.c | 258 ---- rott/audiolib/pitch.h | 45 - rott/audiolib/platform.h | 30 - rott/audiolib/sndcards.h | 55 - rott/audiolib/standard.h | 72 - rott/audiolib/user.c | 67 - rott/audiolib/user.h | 38 - rott/audiolib/usrhooks.c | 84 - rott/audiolib/usrhooks.h | 55 - rott/audiolib/util.h | 13 - rott/fx_man.h | 41 +- rott/fx_mixer.c | 421 +++++ rott/rt_dmand.c | 8 +- rott/rt_menu.c | 4 + rott/rt_sound.c | 33 +- 36 files changed, 447 insertions(+), 6813 deletions(-) delete mode 100644 rott/audiolib/Makefile.am delete mode 100644 rott/audiolib/_multivc.h delete mode 100644 rott/audiolib/debugio.h delete mode 100644 rott/audiolib/dma.h delete mode 100644 rott/audiolib/dpmi.h delete mode 100644 rott/audiolib/dsl.c delete mode 100644 rott/audiolib/dsl.h delete mode 100644 rott/audiolib/fx_man.c delete mode 100644 rott/audiolib/fx_man.h delete mode 100644 rott/audiolib/interrup.h delete mode 100644 rott/audiolib/linklist.h delete mode 100644 rott/audiolib/ll_man.c delete mode 100644 rott/audiolib/ll_man.h delete mode 100644 rott/audiolib/multivoc.c delete mode 100644 rott/audiolib/multivoc.h delete mode 100644 rott/audiolib/mv_mix.c delete mode 100644 rott/audiolib/mvreverb.c delete mode 100644 rott/audiolib/nodpmi.c delete mode 100644 rott/audiolib/pitch.c delete mode 100644 rott/audiolib/pitch.h delete mode 100644 rott/audiolib/platform.h delete mode 100644 rott/audiolib/sndcards.h delete mode 100644 rott/audiolib/standard.h delete mode 100644 rott/audiolib/user.c delete mode 100644 rott/audiolib/user.h delete mode 100644 rott/audiolib/usrhooks.c delete mode 100644 rott/audiolib/usrhooks.h delete mode 100644 rott/audiolib/util.h create mode 100644 rott/fx_mixer.c diff --git a/configure.ac b/configure.ac index ec9f2fd..033ad41 100644 --- a/configure.ac +++ b/configure.ac @@ -88,5 +88,5 @@ AC_ARG_ENABLE([werror], AS_IF([test "x$enable_werror" = "xyes"], [CFLAGS="$CFLAGS -Werror"]) -AC_CONFIG_FILES([Makefile rott/Makefile rott/audiolib/Makefile]) +AC_CONFIG_FILES([Makefile rott/Makefile]) AC_OUTPUT diff --git a/rott/Makefile.am b/rott/Makefile.am index 189e0ca..1d36a4c 100644 --- a/rott/Makefile.am +++ b/rott/Makefile.am @@ -1,5 +1,3 @@ -SUBDIRS = audiolib - bin_PROGRAMS = rott@SUFFIX@ rott@SUFFIX@_SOURCES = \ byteordr.c \ @@ -12,6 +10,7 @@ rott@SUFFIX@_SOURCES = \ dosutil.c \ dukemusc.c \ engine.c \ + fx_mixer.c \ isr.c \ m_misc2.c \ modexlib.c \ @@ -53,4 +52,4 @@ rott@SUFFIX@_SOURCES = \ w_wad.c \ z_zone.c rott@SUFFIX@_CFLAGS = @SDL_CFLAGS@ @SDL_mixer_CFLAGS@ -rott@SUFFIX@_LDADD = audiolib/libaudiolib.a @SDL_LIBS@ @SDL_mixer_LIBS@ +rott@SUFFIX@_LDADD = @SDL_LIBS@ @SDL_mixer_LIBS@ diff --git a/rott/_rt_soun.h b/rott/_rt_soun.h index 98c66de..cbec35b 100644 --- a/rott/_rt_soun.h +++ b/rott/_rt_soun.h @@ -30,6 +30,7 @@ typedef struct byte count; int prevhandle; int prevdistance; + void *chunk; } sound_t; #define SD_OVERWRITE 0x01 diff --git a/rott/audiolib/Makefile.am b/rott/audiolib/Makefile.am deleted file mode 100644 index c3a2a84..0000000 --- a/rott/audiolib/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -noinst_LIBRARIES = libaudiolib.a -libaudiolib_a_SOURCES = \ - dsl.c \ - fx_man.c \ - ll_man.c \ - multivoc.c \ - mv_mix.c \ - mvreverb.c \ - nodpmi.c \ - pitch.c \ - user.c \ - usrhooks.c -libaudiolib_a_CFLAGS = @SDL_CFLAGS@ diff --git a/rott/audiolib/_multivc.h b/rott/audiolib/_multivc.h deleted file mode 100644 index 08e3ea9..0000000 --- a/rott/audiolib/_multivc.h +++ /dev/null @@ -1,234 +0,0 @@ -/* -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. - -*/ -/********************************************************************** - file: _MULTIVC.H - - author: James R. Dose - date: December 20, 1993 - - Private header for MULTIVOC.C - - (c) Copyright 1993 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef ___MULTIVC_H -#define ___MULTIVC_H - -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) - -#define VOC_8BIT 0x0 -#define VOC_CT4_ADPCM 0x1 -#define VOC_CT3_ADPCM 0x2 -#define VOC_CT2_ADPCM 0x3 -#define VOC_16BIT 0x4 -#define VOC_ALAW 0x6 -#define VOC_MULAW 0x7 -#define VOC_CREATIVE_ADPCM 0x200 - -#define T_SIXTEENBIT_STEREO 0 -#define T_8BITS 1 -#define T_MONO 2 -#define T_16BITSOURCE 4 -#define T_LEFTQUIET 8 -#define T_RIGHTQUIET 16 -#define T_DEFAULT T_SIXTEENBIT_STEREO - -#define MV_MaxPanPosition 31 -#define MV_NumPanPositions ( MV_MaxPanPosition + 1 ) -#define MV_MaxTotalVolume 255 -//#define MV_MaxVolume 63 -#define MV_NumVoices 8 - -#define MIX_VOLUME( volume ) \ - ( ( max( 0, min( ( volume ), 255 ) ) * ( MV_MaxVolume + 1 ) ) >> 8 ) -// ( ( max( 0, min( ( volume ), 255 ) ) ) >> 2 ) - -//#define SILENCE_16BIT 0x80008000 -#define SILENCE_16BIT 0 -#define SILENCE_8BIT 0x80808080 -//#define SILENCE_16BIT_PAS 0 - -#define MixBufferSize 256 - -#define NumberOfBuffers 16 -#define TotalBufferSize ( MixBufferSize * NumberOfBuffers ) - -#define PI 3.1415926536 - -typedef enum - { - Raw, - VOC, - DemandFeed, - WAV - } wavedata; - -typedef enum - { - NoMoreData, - KeepPlaying - } playbackstatus; - - -typedef struct VoiceNode - { - struct VoiceNode *next; - struct VoiceNode *prev; - - wavedata wavetype; - char bits; - - playbackstatus ( *GetSound )( struct VoiceNode *voice ); - - void ( *mix )( unsigned long position, unsigned long rate, - const char *start, unsigned long length ); - - char *NextBlock; - char *LoopStart; - char *LoopEnd; - unsigned LoopCount; - unsigned long LoopSize; - unsigned long BlockLength; - - unsigned long PitchScale; - unsigned long FixedPointBufferSize; - - char *sound; - unsigned long length; - unsigned long SamplingRate; - unsigned long RateScale; - unsigned long position; - int Playing; - - int handle; - int priority; - - void ( *DemandFeed )( char **ptr, unsigned long *length ); - - short *LeftVolume; - short *RightVolume; - - unsigned long callbackval; - - } VoiceNode; - -typedef struct - { - VoiceNode *start; - VoiceNode *end; - } VList; - -typedef struct - { - unsigned char left; - unsigned char right; - } Pan; - -typedef signed short MONO16; -typedef signed char MONO8; - -typedef struct - { - MONO16 left; - MONO16 right; -// unsigned short left; -// unsigned short right; - } STEREO16; - -typedef struct - { - MONO16 left; - MONO16 right; - } SIGNEDSTEREO16; - -typedef struct - { -// MONO8 left; -// MONO8 right; - char left; - char right; - } STEREO8; - -typedef struct - { - char RIFF[ 4 ]; - unsigned long file_size; - char WAVE[ 4 ]; - char fmt[ 4 ]; - unsigned long format_size; - } riff_header; - -typedef struct - { - unsigned short wFormatTag; - unsigned short nChannels; - unsigned long nSamplesPerSec; - unsigned long nAvgBytesPerSec; - unsigned short nBlockAlign; - unsigned short nBitsPerSample; - } format_header; - -typedef struct - { - char DATA[ 4 ]; - unsigned long size; - } data_header; - -typedef MONO8 VOLUME8[ 256 ]; -typedef MONO16 VOLUME16[ 256 ]; - -typedef char HARSH_CLIP_TABLE_8[ MV_NumVoices * 256 ]; - -void ClearBuffer_DW( void *ptr, unsigned data, int length ); - -void MV_Mix8BitMono( unsigned long position, unsigned long rate, - const char *start, unsigned long length ); - -void MV_Mix8BitStereo( unsigned long position, - unsigned long rate, const char *start, unsigned long length ); - -void MV_Mix16BitMono( unsigned long position, - unsigned long rate, const char *start, unsigned long length ); - -void MV_Mix16BitStereo( unsigned long position, - unsigned long rate, const char *start, unsigned long length ); - -void MV_Mix16BitMono16( unsigned long position, - unsigned long rate, const char *start, unsigned long length ); - -void MV_Mix8BitMono16( unsigned long position, unsigned long rate, - const char *start, unsigned long length ); - -void MV_Mix8BitStereo16( unsigned long position, - unsigned long rate, const char *start, unsigned long length ); - -void MV_Mix16BitStereo16( unsigned long position, - unsigned long rate, const char *start, unsigned long length ); - -void MV_16BitReverb( const char *src, char *dest, const VOLUME16 *volume, int count ); - -void MV_8BitReverb( const char *src, char *dest, const VOLUME16 *volume, int count ); - -void MV_16BitReverbFast( const char *src, char *dest, int count, int shift ); - -void MV_8BitReverbFast( const char *src, char *dest, int count, int shift ); - -#endif diff --git a/rott/audiolib/debugio.h b/rott/audiolib/debugio.h deleted file mode 100644 index a6510ba..0000000 --- a/rott/audiolib/debugio.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -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. - -*/ -#ifndef __DEBUGIO_H -#define __DEBUGIO_H - -void DB_SetXY( int x, int y ); -void DB_PutChar( char ch ); -int DB_PrintString( char *string ); -int DB_PrintNum( int number ); -int DB_PrintUnsigned( unsigned long number, int radix ); -int DB_printf( char *fmt, ... ); - -#endif diff --git a/rott/audiolib/dma.h b/rott/audiolib/dma.h deleted file mode 100644 index f68d4ea..0000000 --- a/rott/audiolib/dma.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -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. - -*/ -/********************************************************************** - file: DMA.H - - author: James R. Dose - date: February 4, 1994 - - Public header file for DMA.C - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __DMA_H -#define __DMA_H - -enum DMA_ERRORS - { - DMA_Error = -1, - DMA_Ok = 0, - DMA_ChannelOutOfRange, - DMA_InvalidChannel - }; - -enum DMA_Modes - { - DMA_SingleShotRead, - DMA_SingleShotWrite, - DMA_AutoInitRead, - DMA_AutoInitWrite - }; - -char *DMA_ErrorString - ( - int ErrorNumber - ); - -int DMA_VerifyChannel - ( - int channel - ); - -int DMA_SetupTransfer - ( - int channel, - char *address, - int length, - int mode - ); - -int DMA_EndTransfer - ( - int channel - ); - -char *DMA_GetCurrentPos - ( - int channel - ); - -int DMA_GetTransferCount - ( - int channel - ); - -#endif diff --git a/rott/audiolib/dpmi.h b/rott/audiolib/dpmi.h deleted file mode 100644 index c8c4bbb..0000000 --- a/rott/audiolib/dpmi.h +++ /dev/null @@ -1,80 +0,0 @@ -/* -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: DPMI.H - - author: James R. Dose - date: March 31, 1994 - - Inline functions for performing DPMI calls. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __DPMI_H -#define __DPMI_H - -#include - -enum DPMI_Errors - { - DPMI_Warning = -2, - DPMI_Error = -1, - DPMI_Ok = 0 - }; - -typedef struct - { - unsigned long EDI; - unsigned long ESI; - unsigned long EBP; - unsigned long Reserved; - unsigned long EBX; - unsigned long EDX; - unsigned long ECX; - unsigned long EAX; - unsigned short Flags; - unsigned short ES; - unsigned short DS; - unsigned short FS; - unsigned short GS; - unsigned short IP; - unsigned short CS; - unsigned short SP; - unsigned short SS; - } dpmi_regs; - -unsigned long DPMI_GetRealModeVector( int num ); -void DPMI_SetRealModeVector( int num, unsigned long vector ); -int DPMI_CallRealModeFunction( dpmi_regs *callregs ); -int DPMI_GetDOSMemory( void **ptr, intptr_t *descriptor, unsigned length ); -int DPMI_FreeDOSMemory( intptr_t descriptor ); -int DPMI_LockMemory( void *address, unsigned length ); -int DPMI_LockMemoryRegion( void *start, void *end ); -int DPMI_UnlockMemory( void *address, unsigned length ); -int DPMI_UnlockMemoryRegion( void *start, void *end ); - -#define DPMI_Lock( variable ) \ - ( DPMI_LockMemory( (void *) &( variable ), sizeof( variable ) ) ) - -#define DPMI_Unlock( variable ) \ - ( DPMI_UnlockMemory( (void *) &( variable ), sizeof( variable ) ) ) - -#endif diff --git a/rott/audiolib/dsl.c b/rott/audiolib/dsl.c deleted file mode 100644 index f9cc7b1..0000000 --- a/rott/audiolib/dsl.c +++ /dev/null @@ -1,234 +0,0 @@ -#include -#include - -#include "dsl.h" -#include "util.h" - -#include "SDL.h" -#include "SDL_mixer.h" - -extern volatile int MV_MixPage; - -static int DSL_ErrorCode = DSL_Ok; - -static int mixer_initialized; - -static void ( *_CallBackFunc )( void ); -static volatile char *_BufferStart; -static int _BufferSize; -static int _NumDivisions; -static int _SampleRate; -static int _remainder; - -static Mix_Chunk *blank; -static unsigned char *blank_buf; - -/* -possible todo ideas: cache sdl/sdl mixer error messages. -*/ - -char *DSL_ErrorString( int ErrorNumber ) -{ - char *ErrorString; - - switch (ErrorNumber) { - case DSL_Warning: - case DSL_Error: - ErrorString = DSL_ErrorString(DSL_ErrorCode); - break; - - case DSL_Ok: - ErrorString = "SDL Driver ok."; - break; - - case DSL_SDLInitFailure: - ErrorString = "SDL Audio initialization failed."; - break; - - case DSL_MixerActive: - ErrorString = "SDL Mixer already initialized."; - break; - - case DSL_MixerInitFailure: - ErrorString = "SDL Mixer initialization failed."; - break; - - default: - ErrorString = "Unknown SDL Driver error."; - break; - } - - return ErrorString; -} - -static void DSL_SetErrorCode(int ErrorCode) -{ - DSL_ErrorCode = ErrorCode; -} - -int DSL_Init( void ) -{ - DSL_SetErrorCode(DSL_Ok); - - if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { - DSL_SetErrorCode(DSL_SDLInitFailure); - - return DSL_Error; - } - - return DSL_Ok; -} - -void DSL_Shutdown( void ) -{ - DSL_StopPlayback(); -} - -static void mixer_callback(int chan, void *stream, int len, void *udata) -{ - Uint8 *stptr; - Uint8 *fxptr; - int copysize; - - /* len should equal _BufferSize, else this is screwed up */ - - stptr = (Uint8 *)stream; - - if (_remainder > 0) { - copysize = min(len, _remainder); - - fxptr = (Uint8 *)(&_BufferStart[MV_MixPage * - _BufferSize]); - - memcpy(stptr, fxptr+(_BufferSize-_remainder), copysize); - - len -= copysize; - _remainder -= copysize; - - stptr += copysize; - } - - while (len > 0) { - /* new buffer */ - - _CallBackFunc(); - - fxptr = (Uint8 *)(&_BufferStart[MV_MixPage * - _BufferSize]); - - copysize = min(len, _BufferSize); - - memcpy(stptr, fxptr, copysize); - - len -= copysize; - - stptr += copysize; - } - - _remainder = len; -} - -int DSL_BeginBufferedPlayback( char *BufferStart, - int BufferSize, int NumDivisions, unsigned SampleRate, - int MixMode, void ( *CallBackFunc )( void ) ) -{ - Uint16 format; - int channels; - int chunksize; - - if (mixer_initialized) { - DSL_SetErrorCode(DSL_MixerActive); - - return DSL_Error; - } - - _CallBackFunc = CallBackFunc; - _BufferStart = BufferStart; - _BufferSize = (BufferSize / NumDivisions); - _NumDivisions = NumDivisions; - _SampleRate = SampleRate; - - _remainder = 0; - - format = (MixMode & SIXTEEN_BIT) ? AUDIO_S16SYS : AUDIO_U8; - channels = (MixMode & STEREO) ? 2 : 1; - -/* - 23ms is typically ideal (11025,22050,44100) - 46ms isn't bad -*/ - - chunksize = 512; - - if (SampleRate >= 16000) chunksize *= 2; - if (SampleRate >= 32000) chunksize *= 2; - -/* -// SDL mixer does this already - if (MixMode & SIXTEEN_BIT) chunksize *= 2; - if (MixMode & STEREO) chunksize *= 2; -*/ - - if (Mix_OpenAudio(SampleRate, format, channels, chunksize) < 0) { - DSL_SetErrorCode(DSL_MixerInitFailure); - - return DSL_Error; - } - -/* - Mix_SetPostMix(mixer_callback, NULL); -*/ - /* have to use a channel because postmix will overwrite the music... */ - Mix_RegisterEffect(0, mixer_callback, NULL, NULL); - - /* create a dummy sample just to allocate that channel */ - blank_buf = (Uint8 *)malloc(4096); - memset(blank_buf, 0, 4096); - - blank = Mix_QuickLoad_RAW(blank_buf, 4096); - - Mix_PlayChannel(0, blank, -1); - - mixer_initialized = 1; - - return DSL_Ok; -} - -void DSL_StopPlayback( void ) -{ - if (mixer_initialized) { - Mix_HaltChannel(0); - } - - if (blank != NULL) { - Mix_FreeChunk(blank); - } - - blank = NULL; - - if (blank_buf != NULL) { - free(blank_buf); - } - - blank_buf = NULL; - - if (mixer_initialized) { - Mix_CloseAudio(); - } - - mixer_initialized = 0; -} - -unsigned DSL_GetPlaybackRate( void ) -{ - return _SampleRate; -} - -unsigned long DisableInterrupts( void ) -{ - return 0; -} - -void RestoreInterrupts( unsigned long flags ) -{ -} diff --git a/rott/audiolib/dsl.h b/rott/audiolib/dsl.h deleted file mode 100644 index 1067052..0000000 --- a/rott/audiolib/dsl.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef AUDIOLIB__DSL_H -#define AUDIOLIB__DSL_H - -#define MONO_8BIT 0 -#define STEREO 1 -#define SIXTEEN_BIT 2 -#define STEREO_16BIT ( STEREO | SIXTEEN_BIT ) - -enum DSL_ERRORS - { - DSL_Warning = -2, - DSL_Error = -1, - DSL_Ok = 0, - DSL_SDLInitFailure, - DSL_MixerActive, - DSL_MixerInitFailure - }; - -char *DSL_ErrorString( int ErrorNumber ); -int DSL_Init( void ); -void DSL_StopPlayback( void ); -unsigned DSL_GetPlaybackRate( void ); -int DSL_BeginBufferedPlayback( char *BufferStart, - int BufferSize, int NumDivisions, unsigned SampleRate, - int MixMode, void ( *CallBackFunc )( void ) ); -void DSL_Shutdown( void ); - -#endif diff --git a/rott/audiolib/fx_man.c b/rott/audiolib/fx_man.c deleted file mode 100644 index bb2c009..0000000 --- a/rott/audiolib/fx_man.c +++ /dev/null @@ -1,1070 +0,0 @@ -/* -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 -#include -#include "sndcards.h" -#include "multivoc.h" - -#include "dsl.h" - -#include "ll_man.h" -#include "user.h" -#include "fx_man.h" - -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) - -static unsigned FX_MixRate; - -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."; - break; - - case FX_ASSVersion : - ErrorString = "Apogee Sound System Version " ASS_VERSION_STRING " " - "Programmed by Jim Dose\n" - "(c) Copyright 1995 James R. Dose. All Rights Reserved.\n"; - break; - - case FX_SoundCardError : - ErrorString = DSL_ErrorString( DSL_Error ); - break; - - case FX_InvalidCard : - ErrorString = "Invalid Sound Fx device."; - break; - - case FX_MultiVocError : - ErrorString = MV_ErrorString( MV_Error ); - break; - - case FX_DPMI_Error : - ErrorString = "DPMI Error in FX_MAN."; - break; - - default : - ErrorString = "Unknown Fx error code."; - break; - } - - return( ErrorString ); - } - - -/*--------------------------------------------------------------------- - Function: FX_SetupCard - - Sets the configuration of a sound device. ----------------------------------------------------------------------*/ - -int FX_SetupCard - ( - int SoundCard, - fx_device *device - ) - - { - int status; - int DeviceStatus; - - if ( USER_CheckParameter( "ASSVER" ) ) - { - FX_SetErrorCode( FX_ASSVersion ); - return( FX_Error ); - } - - FX_SoundDevice = SoundCard; - - status = FX_Ok; - FX_SetErrorCode( FX_Ok ); - - DeviceStatus = DSL_Init(); - if ( DeviceStatus != DSL_Ok ) - { - FX_SetErrorCode( FX_SoundCardError ); - status = FX_Error; - } - else - { - device->MaxVoices = 32; - device->MaxSampleBits = 0; - device->MaxChannels = 0; - } - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: FX_GetBlasterSettings - - Returns the current BLASTER environment variable settings. ----------------------------------------------------------------------*/ - -int FX_GetBlasterSettings - ( - fx_blaster_config *blaster - ) - - { - - return( FX_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: FX_SetupSoundBlaster - - Handles manual setup of the Sound Blaster information. ----------------------------------------------------------------------*/ - -int FX_SetupSoundBlaster - ( - fx_blaster_config blaster, - int *MaxVoices, - int *MaxSampleBits, - int *MaxChannels - ) - - { - - return( FX_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: FX_Init - - Selects which sound device to use. ----------------------------------------------------------------------*/ - -int FX_Init - ( - int SoundCard, - int numvoices, - int numchannels, - int samplebits, - unsigned mixrate - ) - - { - int status; - int devicestatus; - - if ( FX_Installed ) - { - FX_Shutdown(); - } - - if ( USER_CheckParameter( "ASSVER" ) ) - { - FX_SetErrorCode( FX_ASSVersion ); - return( FX_Error ); - } - - status = LL_LockMemory(); - if ( status != LL_Ok ) - { - FX_SetErrorCode( FX_DPMI_Error ); - return( FX_Error ); - } - - FX_MixRate = mixrate; - - status = FX_Ok; - FX_SoundDevice = SoundCard; - switch( SoundCard ) - { - case SoundBlaster : - case Awe32 : - case ProAudioSpectrum : - case SoundMan16 : - case SoundScape : - case SoundSource : - case TandySoundSource : - case UltraSound : - devicestatus = MV_Init( SoundCard, FX_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 ) - { - LL_UnlockMemory(); - } - else - { - 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 SoundBlaster : - case Awe32 : - case ProAudioSpectrum : - case SoundMan16 : - case SoundScape : - case SoundSource : - case TandySoundSource : - case UltraSound : - 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; - LL_UnlockMemory(); - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: FX_SetCallback - - Sets the function to call when a voice is done. ----------------------------------------------------------------------*/ - -int FX_SetCallBack - ( - void ( *function )( unsigned long ) - ) - - { - int status; - - status = FX_Ok; - - switch( FX_SoundDevice ) - { - case SoundBlaster : - case Awe32 : - case ProAudioSpectrum : - case SoundMan16 : - case SoundScape : - case SoundSource : - case TandySoundSource : - case UltraSound : - 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_GetVolume - - Returns the volume of the current sound device. ----------------------------------------------------------------------*/ - -int FX_GetVolume - ( - void - ) - - { - int volume; - - volume = MV_GetVolume(); - - return( 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_SetFastReverb - - Sets the reverb level. ----------------------------------------------------------------------*/ - -void FX_SetFastReverb - ( - int reverb - ) - - { - MV_SetFastReverb( reverb ); - } - - -/*--------------------------------------------------------------------- - Function: FX_GetMaxReverbDelay - - Returns the maximum delay time for reverb. ----------------------------------------------------------------------*/ - -int FX_GetMaxReverbDelay - ( - void - ) - - { - return MV_GetMaxReverbDelay(); - } - - -/*--------------------------------------------------------------------- - Function: FX_GetReverbDelay - - Returns the current delay time for reverb. ----------------------------------------------------------------------*/ - -int FX_GetReverbDelay - ( - void - ) - - { - return MV_GetReverbDelay(); - } - - -/*--------------------------------------------------------------------- - 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_EndLooping - - Stops the voice associated with the specified handle from looping - without stoping the sound. ----------------------------------------------------------------------*/ - -int FX_EndLooping - ( - int handle - ) - - { - int status; - - status = MV_EndLooping( handle ); - if ( status == MV_Error ) - { - FX_SetErrorCode( FX_MultiVocError ); - status = FX_Warning; - } - - return( status ); - } - -/*--------------------------------------------------------------------- - Function: FX_SetPan - - Sets the stereo and mono volume level of the voice associated - with the specified handle. ----------------------------------------------------------------------*/ - -int FX_SetPan - ( - int handle, - int vol, - int left, - int right - ) - - { - int status; - - status = MV_SetPan( handle, vol, left, right ); - if ( status == MV_Error ) - { - FX_SetErrorCode( FX_MultiVocError ); - status = FX_Warning; - } - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: FX_SetPitch - - Sets the pitch of the voice associated with the specified handle. ----------------------------------------------------------------------*/ - -int FX_SetPitch - ( - int handle, - int pitchoffset - ) - - { - int status; - - status = MV_SetPitch( handle, pitchoffset ); - if ( status == MV_Error ) - { - FX_SetErrorCode( FX_MultiVocError ); - status = FX_Warning; - } - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: FX_SetFrequency - - Sets the frequency of the voice associated with the specified handle. ----------------------------------------------------------------------*/ - -int FX_SetFrequency - ( - int handle, - int frequency - ) - - { - int status; - - status = MV_SetFrequency( handle, frequency ); - if ( status == MV_Error ) - { - FX_SetErrorCode( FX_MultiVocError ); - status = FX_Warning; - } - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: FX_PlayVOC - - Begin playback of sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int FX_PlayVOC - ( - char *ptr, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int handle; - - handle = MV_PlayVOC( ptr, pitchoffset, vol, left, right, - priority, callbackval ); - if ( handle < MV_Ok ) - { - FX_SetErrorCode( FX_MultiVocError ); - handle = FX_Warning; - } - - return( handle ); - } - - -/*--------------------------------------------------------------------- - Function: FX_PlayLoopedVOC - - Begin playback of sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int FX_PlayLoopedVOC - ( - char *ptr, - long loopstart, - long loopend, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long 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_PlayWAV - ( - char *ptr, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int handle; - - handle = MV_PlayWAV( ptr, 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 - ( - char *ptr, - long loopstart, - long loopend, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int 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 - ( - char *ptr, - int pitchoffset, - int angle, - int distance, - int priority, - unsigned long 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 - ( - char *ptr, - int pitchoffset, - int angle, - int distance, - int priority, - unsigned long 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_PlayRaw - - Begin playback of raw sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int FX_PlayRaw - ( - char *ptr, - unsigned long length, - unsigned rate, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int handle; - - handle = MV_PlayRaw( ptr, length, rate, pitchoffset, - vol, left, right, priority, callbackval ); - if ( handle < MV_Ok ) - { - FX_SetErrorCode( FX_MultiVocError ); - handle = FX_Warning; - } - - return( handle ); - } - - -/*--------------------------------------------------------------------- - Function: FX_PlayLoopedRaw - - Begin playback of raw sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int FX_PlayLoopedRaw - ( - char *ptr, - unsigned long length, - char *loopstart, - char *loopend, - unsigned rate, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int handle; - - handle = MV_PlayLoopedRaw( ptr, length, loopstart, loopend, - rate, pitchoffset, vol, left, right, 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_SoundActive - - Tests if the specified sound is currently playing. ----------------------------------------------------------------------*/ - -int FX_SoundActive - ( - int handle - ) - - { - return( MV_VoicePlaying( handle ) ); - } - - -/*--------------------------------------------------------------------- - Function: FX_SoundsPlaying - - Reports the number of voices playing. ----------------------------------------------------------------------*/ - -int FX_SoundsPlaying - ( - void - ) - - { - return( MV_VoicesPlaying() ); - } - - -/*--------------------------------------------------------------------- - 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 ); - } - - -/*--------------------------------------------------------------------- - Function: FX_StartDemandFeedPlayback - - Plays a digitized sound from a user controlled buffering system. ----------------------------------------------------------------------*/ - -int FX_StartDemandFeedPlayback - ( - void ( *function )( char **ptr, unsigned long *length ), - int rate, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int handle; - - handle = MV_StartDemandFeedPlayback( function, rate, - pitchoffset, vol, left, right, priority, callbackval ); - if ( handle < MV_Ok ) - { - FX_SetErrorCode( FX_MultiVocError ); - handle = FX_Warning; - } - - return( handle ); - } - - -/*--------------------------------------------------------------------- - Function: FX_StartRecording - - Starts the sound recording engine. ----------------------------------------------------------------------*/ - -int FX_StartRecording - ( - int MixRate, - void ( *function )( char *ptr, int length ) - ) - - { - int status; - - FX_SetErrorCode( FX_InvalidCard ); - status = FX_Warning; - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: FX_StopRecord - - Stops the sound record engine. ----------------------------------------------------------------------*/ - -void FX_StopRecord - ( - void - ) - - { - } diff --git a/rott/audiolib/fx_man.h b/rott/audiolib/fx_man.h deleted file mode 100644 index cdbb5a1..0000000 --- a/rott/audiolib/fx_man.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -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.H - - author: James R. Dose - date: March 17, 1994 - - Public header for FX_MAN.C - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __FX_MAN_H -#define __FX_MAN_H - -#include "sndcards.h" - -typedef struct - { - int MaxVoices; - int MaxSampleBits; - int MaxChannels; - } fx_device; - -#define MonoFx 1 -#define StereoFx 2 - -typedef struct - { - unsigned long Address; - unsigned long Type; - unsigned long Interrupt; - unsigned long Dma8; - unsigned long Dma16; - unsigned long Midi; - unsigned long Emu; - } fx_blaster_config; - -enum FX_ERRORS - { - FX_Warning = -2, - FX_Error = -1, - FX_Ok = 0, - FX_ASSVersion, - FX_BlasterError, - FX_SoundCardError, - FX_InvalidCard, - FX_MultiVocError, - FX_DPMI_Error - }; - -enum fx_BLASTER_Types - { - fx_SB = 1, - fx_SBPro = 2, - fx_SB20 = 3, - fx_SBPro2 = 4, - fx_SB16 = 6 - }; - - -char *FX_ErrorString( int ErrorNumber ); -int FX_SetupCard( int SoundCard, fx_device *device ); -int FX_GetBlasterSettings( fx_blaster_config *blaster ); -int FX_SetupSoundBlaster( fx_blaster_config blaster, int *MaxVoices, int *MaxSampleBits, int *MaxChannels ); -int FX_Init( int SoundCard, int numvoices, int numchannels, int samplebits, unsigned mixrate ); -int FX_Shutdown( void ); -int FX_SetCallBack( void ( *function )( unsigned long ) ); -void FX_SetVolume( int volume ); -int FX_GetVolume( void ); - -void FX_SetReverseStereo( int setting ); -int FX_GetReverseStereo( void ); -void FX_SetReverb( int reverb ); -void FX_SetFastReverb( int reverb ); -int FX_GetMaxReverbDelay( void ); -int FX_GetReverbDelay( void ); -void FX_SetReverbDelay( int delay ); - -int FX_VoiceAvailable( int priority ); -int FX_EndLooping( int handle ); -int FX_SetPan( int handle, int vol, int left, int right ); -int FX_SetPitch( int handle, int pitchoffset ); -int FX_SetFrequency( int handle, int frequency ); - -int FX_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int FX_PlayLoopedVOC( char *ptr, long loopstart, long loopend, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int FX_PlayWAV( char *ptr, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int FX_PlayLoopedWAV( char *ptr, long loopstart, long loopend, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int FX_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int FX_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int FX_PlayRaw( char *ptr, unsigned long length, unsigned rate, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int FX_PlayLoopedRaw( char *ptr, unsigned long length, char *loopstart, - char *loopend, unsigned rate, int pitchoffset, int vol, int left, - int right, int priority, unsigned long callbackval ); -int FX_Pan3D( int handle, int angle, int distance ); -int FX_SoundActive( int handle ); -int FX_SoundsPlaying( void ); -int FX_StopSound( int handle ); -int FX_StopAllSounds( void ); -int FX_StartDemandFeedPlayback( void ( *function )( char **ptr, unsigned long *length ), - int rate, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int FX_StartRecording( int MixRate, void ( *function )( char *ptr, int length ) ); -void FX_StopRecord( void ); - -#endif diff --git a/rott/audiolib/interrup.h b/rott/audiolib/interrup.h deleted file mode 100644 index f052efb..0000000 --- a/rott/audiolib/interrup.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -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: INTERRUP.H - - author: James R. Dose - date: March 31, 1994 - - Inline functions for disabling and restoring the interrupt flag. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __INTERRUPT_H -#define __INTERRUPT_H - -unsigned long DisableInterrupts( void ); -void RestoreInterrupts( unsigned long flags ); - -#endif diff --git a/rott/audiolib/linklist.h b/rott/audiolib/linklist.h deleted file mode 100644 index a0a581f..0000000 --- a/rott/audiolib/linklist.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -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. - -*/ -#ifndef __linklist_h -#define __linklist_h -#ifdef __cplusplus -extern "C" { -#endif - - -#define NewNode(type) ((type*)SafeMalloc(sizeof(type))) - - -#define LL_CreateNewLinkedList(rootnode,type,next,prev) \ - { \ - (rootnode) = NewNode(type); \ - (rootnode)->prev = (rootnode); \ - (rootnode)->next = (rootnode); \ - } - - - -#define LL_AddNode(rootnode, newnode, next, prev) \ - { \ - (newnode)->next = (rootnode); \ - (newnode)->prev = (rootnode)->prev; \ - (rootnode)->prev->next = (newnode); \ - (rootnode)->prev = (newnode); \ - } - -#define LL_TransferList(oldroot,newroot,next,prev) \ - { \ - if ((oldroot)->prev != (oldroot)) \ - { \ - (oldroot)->prev->next = (newroot); \ - (oldroot)->next->prev = (newroot)->prev; \ - (newroot)->prev->next = (oldroot)->next; \ - (newroot)->prev = (oldroot)->prev; \ - (oldroot)->next = (oldroot); \ - (oldroot)->prev = (oldroot); \ - } \ - } - -#define LL_ReverseList(root,type,next,prev) \ - { \ - type *newend,*trav,*tprev; \ - \ - newend = (root)->next; \ - for(trav = (root)->prev; trav != newend; trav = tprev) \ - { \ - tprev = trav->prev; \ - LL_MoveNode(trav,newend,next,prev); \ - } \ - } - - -#define LL_RemoveNode(node,next,prev) \ - { \ - (node)->prev->next = (node)->next; \ - (node)->next->prev = (node)->prev; \ - (node)->next = (node); \ - (node)->prev = (node); \ - } - - -#define LL_SortedInsertion(rootnode,insertnode,next,prev,type,sortparm) \ - { \ - type *hoya; \ - \ - hoya = (rootnode)->next; \ - while((hoya != (rootnode)) && ((insertnode)->sortparm > hoya->sortparm)) \ - { \ - hoya = hoya->next; \ - } \ - LL_AddNode(hoya,(insertnode),next,prev); \ - } - -#define LL_MoveNode(node,newroot,next,prev) \ - { \ - LL_RemoveNode((node),next,prev); \ - LL_AddNode((newroot),(node),next,prev); \ - } - -#define LL_ListEmpty(list,next,prev) \ - ( \ - ((list)->next == (list)) && \ - ((list)->prev == (list)) \ - ) - -#define LL_Free(list) SafeFree(list) -#define LL_Reset(list,next,prev) (list)->next = (list)->prev = (list) -#define LL_New LL_CreateNewLinkedList -#define LL_Remove LL_RemoveNode -#define LL_Add LL_AddNode -#define LL_Empty LL_ListEmpty -#define LL_Move LL_MoveNode - - -#ifdef __cplusplus -}; -#endif -#endif diff --git a/rott/audiolib/ll_man.c b/rott/audiolib/ll_man.c deleted file mode 100644 index 56e97da..0000000 --- a/rott/audiolib/ll_man.c +++ /dev/null @@ -1,173 +0,0 @@ -/* -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: LL_MAN.C - - author: James R. Dose - date: January 1, 1994 - - Linked list management routines. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#define LOCKMEMORY - -#include -#include "ll_man.h" - -#ifdef LOCKMEMORY -#include "dpmi.h" -#endif - -#define OFFSET( structure, offset ) \ - ( *( ( char ** )&( structure )[ offset ] ) ) - - -/********************************************************************** - - Memory locked functions: - -**********************************************************************/ - - -#define LL_LockStart LL_AddNode - - -void LL_AddNode - ( - char *item, - char **head, - char **tail, - int next, - int prev - ) - - { - OFFSET( item, prev ) = NULL; - OFFSET( item, next ) = *head; - - if ( *head ) - { - OFFSET( *head, prev ) = item; - } - else - { - *tail = item; - } - - *head = item; - } - -void LL_RemoveNode - ( - char *item, - char **head, - char **tail, - int next, - int prev - ) - - { - if ( OFFSET( item, prev ) == NULL ) - { - *head = OFFSET( item, next ); - } - else - { - OFFSET( OFFSET( item, prev ), next ) = OFFSET( item, next ); - } - - if ( OFFSET( item, next ) == NULL ) - { - *tail = OFFSET( item, prev ); - } - else - { - OFFSET( OFFSET( item, next ), prev ) = OFFSET( item, prev ); - } - - OFFSET( item, next ) = NULL; - OFFSET( item, prev ) = NULL; - } - - -/*--------------------------------------------------------------------- - Function: LL_LockEnd - - Used for determining the length of the functions to lock in memory. ----------------------------------------------------------------------*/ - -static void LL_LockEnd - ( - void - ) - - { - } - - -/*--------------------------------------------------------------------- - Function: LL_UnlockMemory - - Unlocks all neccessary data. ----------------------------------------------------------------------*/ - -void LL_UnlockMemory - ( - void - ) - - { -#ifdef LOCKMEMORY - - DPMI_UnlockMemoryRegion( LL_LockStart, LL_LockEnd ); - -#endif - } - - -/*--------------------------------------------------------------------- - Function: LL_LockMemory - - Locks all neccessary data. ----------------------------------------------------------------------*/ - -int LL_LockMemory - ( - void - ) - - { - -#ifdef LOCKMEMORY - - int status; - - status = DPMI_LockMemoryRegion( LL_LockStart, LL_LockEnd ); - if ( status != DPMI_Ok ) - { - return( LL_Error ); - } - -#endif - - return( LL_Ok ); - } diff --git a/rott/audiolib/ll_man.h b/rott/audiolib/ll_man.h deleted file mode 100644 index 375b1e1..0000000 --- a/rott/audiolib/ll_man.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -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: LL_MAN.H - - author: James R. Dose - date: February 4, 1994 - - Public header for LL_MAN.C. Linked list management routines. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __LL_MAN_H -#define __LL_MAN_H - -enum LL_Errors - { - LL_Warning = -2, - LL_Error = -1, - LL_Ok = 0 - }; - -typedef struct list - { - void *start; - void *end; - } list; - -void LL_AddNode( char *node, char **head, char **tail, int next, int prev ); -void LL_RemoveNode( char *node, char **head, char **tail, int next, int prev ); -void LL_UnlockMemory( void ); -int LL_LockMemory( void ); - -#define LL_AddToHead( type, listhead, node ) \ - LL_AddNode( ( char * )( node ), \ - ( char ** )&( ( listhead )->start ), \ - ( char ** )&( ( listhead )->end ), \ - ( int )&( ( type * ) 0 )->next, \ - ( int )&( ( type * ) 0 )->prev ) - -#define LL_AddToTail( type, listhead, node ) \ - LL_AddNode( ( char * )( node ), \ - ( char ** )&( ( listhead )->end ), \ - ( char ** )&( ( listhead )->start ), \ - ( int )&( ( type * ) 0 )->prev, \ - ( int )&( ( type * ) 0 )->next ) - -#define LL_Remove( type, listhead, node ) \ - LL_RemoveNode( ( char * )( node ), \ - ( char ** )&( ( listhead )->start ), \ - ( char ** )&( ( listhead )->end ), \ - ( int )&( ( type * ) 0 )->next, \ - ( int )&( ( type * ) 0 )->prev ) - -#define LL_NextNode( node ) ( ( node )->next ) -#define LL_PreviousNode( node ) ( ( node )->prev ) - -#endif diff --git a/rott/audiolib/multivoc.c b/rott/audiolib/multivoc.c deleted file mode 100644 index 782405f..0000000 --- a/rott/audiolib/multivoc.c +++ /dev/null @@ -1,3064 +0,0 @@ -/* -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: MULTIVOC.C - - author: James R. Dose - date: December 20, 1993 - - Routines to provide multichannel digitized sound playback for - Sound Blaster compatible sound cards. - - (c) Copyright 1993 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include -#include -#include -#include - -#include "util.h" -#include "dpmi.h" -#include "usrhooks.h" -#include "interrup.h" -#include "dma.h" -#include "linklist.h" -#include "sndcards.h" - -#include "dsl.h" - -#include "pitch.h" -#include "multivoc.h" -#include "_multivc.h" -#include "debugio.h" - -#define RoundFixed( fixedval, bits ) \ - ( \ - ( \ - (fixedval) + ( 1 << ( (bits) - 1 ) )\ - ) >> (bits) \ - ) - -#define IS_QUIET( ptr ) ( ( void * )( ptr ) == ( void * )&MV_VolumeTable[ 0 ] ) - -static int MV_ReverbLevel; -static int MV_ReverbDelay; -static VOLUME16 *MV_ReverbTable = NULL; - -//static signed short MV_VolumeTable[ MV_MaxVolume + 1 ][ 256 ]; -static signed short MV_VolumeTable[ 63 + 1 ][ 256 ]; - -//static Pan MV_PanTable[ MV_NumPanPositions ][ MV_MaxVolume + 1 ]; -static Pan MV_PanTable[ MV_NumPanPositions ][ 63 + 1 ]; - -static int MV_Installed = FALSE; -static int MV_SoundCard = SoundBlaster; -static int MV_TotalVolume = MV_MaxTotalVolume; -static int MV_MaxVoices = 1; -static int MV_Recording; - -static int MV_BufferSize = MixBufferSize; -static int MV_BufferLength; - -static int MV_NumberOfBuffers = NumberOfBuffers; - -static int MV_MixMode = MONO_8BIT; -static int MV_Channels = 1; -static int MV_Bits = 8; - -static int MV_Silence = SILENCE_8BIT; -static int MV_SwapLeftRight = FALSE; - -static int MV_RequestedMixRate; -static int MV_MixRate; - -static int MV_DMAChannel = -1; -static int MV_BuffShift; - -static int MV_TotalMemory; - -static intptr_t MV_BufferDescriptor; -static int MV_BufferEmpty[ NumberOfBuffers ]; -char *MV_MixBuffer[ NumberOfBuffers + 1 ]; - -static VoiceNode *MV_Voices = NULL; - -static volatile VoiceNode VoiceList; -static volatile VoiceNode VoicePool; - -/*static*/ int MV_MixPage = 0; -static int MV_VoiceHandle = MV_MinVoiceHandle; - -static void ( *MV_CallBackFunc )( unsigned long ) = NULL; -static void ( *MV_RecordFunc )( char *ptr, int length ) = NULL; -static void ( *MV_MixFunction )( VoiceNode *voice, int buffer ); - -static int MV_MaxVolume = 63; - -unsigned char *MV_HarshClipTable; -char *MV_MixDestination; -short *MV_LeftVolume; -short *MV_RightVolume; -int MV_SampleSize = 1; -int MV_RightChannelOffset; - -unsigned long MV_MixPosition; - -int MV_ErrorCode = MV_Ok; - -#define MV_SetErrorCode( status ) \ - MV_ErrorCode = ( status ); - - -/*--------------------------------------------------------------------- - Function: MV_ErrorString - - Returns a pointer to the error message associated with an error - number. A -1 returns a pointer the current error. ----------------------------------------------------------------------*/ - -char *MV_ErrorString - ( - int ErrorNumber - ) - - { - char *ErrorString; - - switch( ErrorNumber ) - { - case MV_Warning : - case MV_Error : - ErrorString = MV_ErrorString( MV_ErrorCode ); - break; - - case MV_Ok : - ErrorString = "Multivoc ok."; - break; - - case MV_UnsupportedCard : - ErrorString = "Selected sound card is not supported by Multivoc."; - break; - - case MV_NotInstalled : - ErrorString = "Multivoc not installed."; - break; - - case MV_NoVoices : - ErrorString = "No free voices available to Multivoc."; - break; - - case MV_NoMem : - ErrorString = "Out of memory in Multivoc."; - break; - - case MV_VoiceNotFound : - ErrorString = "No voice with matching handle found."; - break; - - case MV_DPMI_Error : - ErrorString = "DPMI Error in Multivoc."; - break; - - case MV_InvalidVOCFile : - ErrorString = "Invalid VOC file passed in to Multivoc."; - break; - - case MV_InvalidWAVFile : - ErrorString = "Invalid WAV file passed in to Multivoc."; - break; - - case MV_InvalidMixMode : - ErrorString = "Invalid mix mode request in Multivoc."; - break; - - case MV_SoundSourceFailure : - ErrorString = "Sound Source playback failed."; - break; - - case MV_IrqFailure : - ErrorString = "Playback failed, possibly due to an invalid or conflicting IRQ."; - break; - - case MV_DMAFailure : - ErrorString = "Playback failed, possibly due to an invalid or conflicting DMA channel."; - break; - - case MV_DMA16Failure : - ErrorString = "Playback failed, possibly due to an invalid or conflicting DMA channel. \n" - "Make sure the 16-bit DMA channel is correct."; - break; - - case MV_NullRecordFunction : - ErrorString = "Null record function passed to MV_StartRecording."; - break; - - default : - ErrorString = "Unknown Multivoc error code."; - break; - } - - return( ErrorString ); - } - - -/********************************************************************** - - Memory locked functions: - -**********************************************************************/ - - -#define MV_LockStart MV_Mix - - -/*--------------------------------------------------------------------- - Function: MV_Mix - - Mixes the sound into the buffer. ----------------------------------------------------------------------*/ - -static void MV_Mix - ( - VoiceNode *voice, - int buffer - ) - - { - char *start; - int length; - long voclength; - unsigned long position; - unsigned long rate; - unsigned long FixedPointBufferSize; - - if (voice == NULL || voice->GetSound == NULL) - return; - - if ( ( voice->length == 0 ) && - ( voice->GetSound( voice ) != KeepPlaying ) ) - { - return; - } - - length = MixBufferSize; - FixedPointBufferSize = voice->FixedPointBufferSize; - - MV_MixDestination = MV_MixBuffer[ buffer ]; - MV_LeftVolume = voice->LeftVolume; - MV_RightVolume = voice->RightVolume; - - if ( ( MV_Channels == 2 ) && ( IS_QUIET( MV_LeftVolume ) ) ) - { - MV_LeftVolume = MV_RightVolume; - MV_MixDestination += MV_RightChannelOffset; - } - - // Add this voice to the mix - while( length > 0 ) - { - start = voice->sound; - rate = voice->RateScale; - position = voice->position; - - // Check if the last sample in this buffer would be - // beyond the length of the sample block - if ( ( position + FixedPointBufferSize ) >= voice->length ) - { - if ( position < voice->length ) - { - voclength = ( voice->length - position + rate - 1 ) / rate; - } - else - { - voice->GetSound( voice ); - return; - } - } - else - { - voclength = length; - } - - voice->mix( position, rate, start, voclength ); - - if ( voclength & 1 ) - { - MV_MixPosition += rate; - voclength -= 1; - } - voice->position = MV_MixPosition; - - length -= voclength; - - if ( voice->position >= voice->length ) - { - // Get the next block of sound - if ( voice->GetSound( voice ) != KeepPlaying ) - { - return; - } - - if ( length > 0 ) - { - // Get the position of the last sample in the buffer - FixedPointBufferSize = voice->RateScale * ( length - 1 ); - } - } - } - } - - -/*--------------------------------------------------------------------- - Function: MV_PlayVoice - - Adds a voice to the play list. ----------------------------------------------------------------------*/ - -void MV_PlayVoice - ( - VoiceNode *voice - ) - - { - unsigned flags; - - flags = DisableInterrupts(); - LL_SortedInsertion( &VoiceList, voice, prev, next, VoiceNode, priority ); - - RestoreInterrupts( flags ); - } - - -/*--------------------------------------------------------------------- - Function: MV_StopVoice - - Removes the voice from the play list and adds it to the free list. ----------------------------------------------------------------------*/ - -void MV_StopVoice - ( - VoiceNode *voice - ) - - { - unsigned flags; - - flags = DisableInterrupts(); - - // move the voice from the play list to the free list - LL_Remove( voice, next, prev ); - LL_Add( (VoiceNode *)&VoicePool, voice, next, prev ); - - RestoreInterrupts( flags ); - } - - -/*--------------------------------------------------------------------- - Function: MV_ServiceVoc - - Starts playback of the waiting buffer and mixes the next one. ----------------------------------------------------------------------*/ - -// static int backcolor = 1; - -void MV_ServiceVoc - ( - void - ) - - { - VoiceNode *voice; - VoiceNode *next; - - // Toggle which buffer we'll mix next - MV_MixPage++; - if ( MV_MixPage >= MV_NumberOfBuffers ) - { - MV_MixPage -= MV_NumberOfBuffers; - } - - if ( MV_ReverbLevel == 0 ) - { - // Initialize buffer - //Commented out so that the buffer is always cleared. - //This is so the guys at Echo Speech can mix into the - //buffer even when no sounds are playing. - //if ( !MV_BufferEmpty[ MV_MixPage ] ) - { - ClearBuffer_DW( MV_MixBuffer[ MV_MixPage ], MV_Silence, MV_BufferSize >> 2 ); - if ( ( MV_SoundCard == UltraSound ) && ( MV_Channels == 2 ) ) - { - ClearBuffer_DW( MV_MixBuffer[ MV_MixPage ] + MV_RightChannelOffset, - MV_Silence, MV_BufferSize >> 2 ); - } - MV_BufferEmpty[ MV_MixPage ] = TRUE; - } - } - else - { - char *end; - char *source; - char *dest; - int count; - int length; - - end = MV_MixBuffer[ 0 ] + MV_BufferLength;; - dest = MV_MixBuffer[ MV_MixPage ]; - source = MV_MixBuffer[ MV_MixPage ] - MV_ReverbDelay; - if ( source < MV_MixBuffer[ 0 ] ) - { - source += MV_BufferLength; - } - - length = MV_BufferSize; - while( length > 0 ) - { - count = length; - if ( source + count > end ) - { - count = end - source; - } - - if ( MV_Bits == 16 ) - { - if ( MV_ReverbTable != NULL ) - { - MV_16BitReverb( source, dest, (const VOLUME16 *)MV_ReverbTable, count / 2 ); - if ( ( MV_SoundCard == UltraSound ) && ( MV_Channels == 2 ) ) - { - MV_16BitReverb( source + MV_RightChannelOffset, - dest + MV_RightChannelOffset, (const VOLUME16 *)MV_ReverbTable, count / 2 ); - } - } - else - { - MV_16BitReverbFast( source, dest, count / 2, MV_ReverbLevel ); - if ( ( MV_SoundCard == UltraSound ) && ( MV_Channels == 2 ) ) - { - MV_16BitReverbFast( source + MV_RightChannelOffset, - dest + MV_RightChannelOffset, count / 2, MV_ReverbLevel ); - } - } - } - else - { - if ( MV_ReverbTable != NULL ) - { - MV_8BitReverb( source, dest, (const VOLUME16 *)MV_ReverbTable, count ); - if ( ( MV_SoundCard == UltraSound ) && ( MV_Channels == 2 ) ) - { - MV_8BitReverb( source + MV_RightChannelOffset, - dest + MV_RightChannelOffset, (const VOLUME16 *)MV_ReverbTable, count ); - } - } - else - { - MV_8BitReverbFast( source, dest, count, MV_ReverbLevel ); - if ( ( MV_SoundCard == UltraSound ) && ( MV_Channels == 2 ) ) - { - MV_8BitReverbFast( source + MV_RightChannelOffset, - dest + MV_RightChannelOffset, count, MV_ReverbLevel ); - } - } - } - - // if we go through the loop again, it means that we've wrapped around the buffer - source = MV_MixBuffer[ 0 ]; - dest += count; - length -= count; - } - } - - // Play any waiting voices - for( voice = VoiceList.next; voice != &VoiceList; voice = next ) - { -// if ( ( voice < &MV_Voices[ 0 ] ) || ( voice > &MV_Voices[ 8 ] ) ) -// { -// SetBorderColor(backcolor++); -// break; -// } - - MV_BufferEmpty[ MV_MixPage ] = FALSE; - - MV_MixFunction( voice, MV_MixPage ); - - next = voice->next; - - // Is this voice done? - if ( !voice->Playing ) - { - MV_StopVoice( voice ); - - if ( MV_CallBackFunc ) - { - MV_CallBackFunc( voice->callbackval ); - } - } - } - } - - -int leftpage = -1; -int rightpage = -1; - -void MV_ServiceGus( char **ptr, unsigned long *length ) - { - if ( leftpage == MV_MixPage ) - { - MV_ServiceVoc(); - } - - leftpage = MV_MixPage; - - *ptr = MV_MixBuffer[ MV_MixPage ]; - *length = MV_BufferSize; - } - -void MV_ServiceRightGus( char **ptr, unsigned long *length ) - { - if ( rightpage == MV_MixPage ) - { - MV_ServiceVoc(); - } - - rightpage = MV_MixPage; - - *ptr = MV_MixBuffer[ MV_MixPage ] + MV_RightChannelOffset; - *length = MV_BufferSize; - } - -/*--------------------------------------------------------------------- - Function: MV_GetNextVOCBlock - - Interperate the information of a VOC format sound file. ----------------------------------------------------------------------*/ -static __inline unsigned int get_le32(void *p0) -{ - unsigned int val = *((unsigned int *) p0); - return(BUILDSWAP_INTEL32(val)); -} - -static __inline unsigned int get_le16(void *p0) -{ - unsigned short val = *((unsigned short *) p0); - return( (unsigned int) (BUILDSWAP_INTEL16(val)) ); -} - -static void MV_SetVoiceMixMode (VoiceNode *voice); - -playbackstatus MV_GetNextVOCBlock - ( - VoiceNode *voice - ) - - { - unsigned char *ptr; - int blocktype=0; - int lastblocktype=0; - uintptr_t blocklength=0l; - unsigned long samplespeed=0l; - unsigned int tc=0; - int packtype=0; - int voicemode=0; - int done=0; - unsigned BitsPerSample; - unsigned Channels; - unsigned Format; - - if ( voice->BlockLength > 0 ) - { - voice->position -= voice->length; - voice->sound += voice->length >> 16; - if ( voice->bits == 16 ) - { - voice->sound += voice->length >> 16; - } - voice->length = min( voice->BlockLength, 0x8000 ); - voice->BlockLength -= voice->length; - voice->length <<= 16; - return( KeepPlaying ); - } - - if ( ( voice->length > 0 ) && ( voice->LoopEnd != NULL ) && - ( voice->LoopStart != NULL ) ) - { - voice->BlockLength = voice->LoopSize; - voice->sound = voice->LoopStart; - voice->position = 0; - voice->length = min( voice->BlockLength, 0x8000 ); - voice->BlockLength -= voice->length; - voice->length <<= 16; - return( KeepPlaying ); - } - - ptr = ( unsigned char * )voice->NextBlock; - - voice->Playing = TRUE; - - voicemode = 0; - lastblocktype = 0; - packtype = 0; - - done = FALSE; - while( !done ) - { - // Stop playing if we get a NULL pointer - if ( ptr == NULL ) - { - voice->Playing = FALSE; - done = TRUE; - break; - } - - { - unsigned tmp = get_le32(ptr); - blocktype = tmp&255; - blocklength = tmp>>8; - } - ptr += 4; - - switch( blocktype ) - { - case 0 : - // End of data - if ( ( voice->LoopStart == NULL ) || - ( (unsigned char *)voice->LoopStart >= ( ptr - 4 ) ) ) - { - voice->Playing = FALSE; - done = TRUE; - } - else - { - voice->BlockLength = ( ptr - 4 ) - (unsigned char *)voice->LoopStart; - voice->sound = voice->LoopStart; - voice->position = 0; - voice->length = min( voice->BlockLength, 0x8000 ); - voice->BlockLength -= voice->length; - voice->length <<= 16; - return( KeepPlaying ); - } - break; - - case 1 : - // Sound data block - voice->bits = 8; - if ( lastblocktype != 8 ) - { - tc = ( unsigned int )*ptr << 8; - packtype = *( ptr + 1 ); - } - - ptr += 2; - blocklength -= 2; - - samplespeed = 256000000L / ( 65536 - tc ); - - // Skip packed or stereo data - if ( ( packtype != 0 ) || ( voicemode != 0 ) ) - { - ptr += blocklength; - } - else - { - done = TRUE; - } - voicemode = 0; - break; - - case 2 : - // Sound continuation block - samplespeed = voice->SamplingRate; - done = TRUE; - break; - - case 3 : - // Silence - // Not implimented. - ptr += blocklength; - break; - - case 4 : - // Marker - // Not implimented. - ptr += blocklength; - break; - - case 5 : - // ASCII string - // Not implimented. - ptr += blocklength; - break; - - case 6 : - // Repeat begin - if ( voice->LoopEnd == NULL ) - { - voice->LoopCount = get_le16(ptr); - voice->LoopStart = (char *)ptr + blocklength; - } - ptr += blocklength; - break; - - case 7 : - // Repeat end - ptr += blocklength; - if ( lastblocktype == 6 ) - { - voice->LoopCount = 0; - } - else - { - if ( ( voice->LoopCount > 0 ) && ( voice->LoopStart != NULL ) ) - { - ptr = (unsigned char *)voice->LoopStart; - if ( voice->LoopCount < 0xffff ) - { - voice->LoopCount--; - if ( voice->LoopCount == 0 ) - { - voice->LoopStart = NULL; - } - } - } - } - break; - - case 8 : - // Extended block - voice->bits = 8; - tc = get_le16(ptr); - packtype = *( ptr + 2 ); - voicemode = *( ptr + 3 ); - ptr += blocklength; - break; - - case 9 : - // New sound data block - samplespeed = get_le32(ptr); - BitsPerSample = ptr[4]; - Channels = ptr[5]; - Format = get_le16(ptr+6); - - if ( ( BitsPerSample == 8 ) && ( Channels == 1 ) && - ( Format == VOC_8BIT ) ) - { - ptr += 12; - blocklength -= 12; - voice->bits = 8; - done = TRUE; - } - else if ( ( BitsPerSample == 16 ) && ( Channels == 1 ) && - ( Format == VOC_16BIT ) ) - { - ptr += 12; - blocklength -= 12; - voice->bits = 16; - done = TRUE; - } - else - { - ptr += blocklength; - } - break; - - default : - // Unknown data. Probably not a VOC file. - voice->Playing = FALSE; - done = TRUE; - break; - } - - lastblocktype = blocktype; - } - - if ( voice->Playing ) - { - voice->NextBlock = (char *)ptr + blocklength; - voice->sound = (char *)ptr; - - voice->SamplingRate = samplespeed; - voice->RateScale = ( voice->SamplingRate * voice->PitchScale ) / MV_MixRate; - - // Multiply by MixBufferSize - 1 - voice->FixedPointBufferSize = ( voice->RateScale * MixBufferSize ) - - voice->RateScale; - - if ( voice->LoopEnd != NULL ) - { - if ( blocklength > (uintptr_t)voice->LoopEnd ) - { - blocklength = (uintptr_t)voice->LoopEnd; - } - else - { - voice->LoopEnd = (char *)blocklength; - } - - voice->LoopStart = voice->sound + (uintptr_t)voice->LoopStart; - voice->LoopEnd = voice->sound + (uintptr_t)voice->LoopEnd; - voice->LoopSize = voice->LoopEnd - voice->LoopStart; - } - - if ( voice->bits == 16 ) - { - blocklength /= 2; - } - - voice->position = 0; - voice->length = min( blocklength, 0x8000 ); - voice->BlockLength = blocklength - voice->length; - voice->length <<= 16; - - MV_SetVoiceMixMode( voice ); - - return( KeepPlaying ); - } - - return( NoMoreData ); - } - - -/*--------------------------------------------------------------------- - Function: MV_GetNextDemandFeedBlock - - Controls playback of demand fed data. ----------------------------------------------------------------------*/ - -playbackstatus MV_GetNextDemandFeedBlock - ( - VoiceNode *voice - ) - - { - if ( voice->BlockLength > 0 ) - { - voice->position -= voice->length; - voice->sound += voice->length >> 16; - voice->length = min( voice->BlockLength, 0x8000 ); - voice->BlockLength -= voice->length; - voice->length <<= 16; - - return( KeepPlaying ); - } - - if ( voice->DemandFeed == NULL ) - { - return( NoMoreData ); - } - - voice->position = 0; - ( voice->DemandFeed )( &voice->sound, &voice->BlockLength ); - voice->length = min( voice->BlockLength, 0x8000 ); - voice->BlockLength -= voice->length; - voice->length <<= 16; - - if ( ( voice->length > 0 ) && ( voice->sound != NULL ) ) - { - return( KeepPlaying ); - } - return( NoMoreData ); - } - - -/*--------------------------------------------------------------------- - Function: MV_GetNextRawBlock - - Controls playback of demand fed data. ----------------------------------------------------------------------*/ - -playbackstatus MV_GetNextRawBlock - ( - VoiceNode *voice - ) - - { - if ( voice->BlockLength <= 0 ) - { - if ( voice->LoopStart == NULL ) - { - voice->Playing = FALSE; - return( NoMoreData ); - } - - voice->BlockLength = voice->LoopSize; - voice->NextBlock = voice->LoopStart; - voice->length = 0; - voice->position = 0; - } - - voice->sound = voice->NextBlock; - voice->position -= voice->length; - voice->length = min( voice->BlockLength, 0x8000 ); - voice->NextBlock += voice->length; - if ( voice->bits == 16 ) - { - voice->NextBlock += voice->length; - } - voice->BlockLength -= voice->length; - voice->length <<= 16; - - return( KeepPlaying ); - } - - -/*--------------------------------------------------------------------- - Function: MV_GetNextWAVBlock - - Controls playback of demand fed data. ----------------------------------------------------------------------*/ - -playbackstatus MV_GetNextWAVBlock - ( - VoiceNode *voice - ) - - { - if ( voice->BlockLength <= 0 ) - { - if ( voice->LoopStart == NULL ) - { - voice->Playing = FALSE; - return( NoMoreData ); - } - - voice->BlockLength = voice->LoopSize; - voice->NextBlock = voice->LoopStart; - voice->length = 0; - voice->position = 0; - } - - voice->sound = voice->NextBlock; - voice->position -= voice->length; - voice->length = min( voice->BlockLength, 0x8000 ); - voice->NextBlock += voice->length; - if ( voice->bits == 16 ) - { - voice->NextBlock += voice->length; - } - voice->BlockLength -= voice->length; - voice->length <<= 16; - - return( KeepPlaying ); - } - - - -/*--------------------------------------------------------------------- - Function: MV_GetVoice - - Locates the voice with the specified handle. ----------------------------------------------------------------------*/ - -VoiceNode *MV_GetVoice - ( - int handle - ) - - { - VoiceNode *voice; - unsigned flags; - - flags = DisableInterrupts(); - - for( voice = VoiceList.next; voice != &VoiceList; voice = voice->next ) - { - if ( handle == voice->handle ) - { - break; - } - } - - RestoreInterrupts( flags ); - - if ( voice == &VoiceList ) - { - MV_SetErrorCode( MV_VoiceNotFound ); - - // SBF - should this return null? - return NULL; - } - - return( voice ); - } - - -/*--------------------------------------------------------------------- - Function: MV_VoicePlaying - - Checks if the voice associated with the specified handle is - playing. ----------------------------------------------------------------------*/ - -int MV_VoicePlaying - ( - int handle - ) - - { - VoiceNode *voice; - - if ( !MV_Installed ) - { - MV_SetErrorCode( MV_NotInstalled ); - return( FALSE ); - } - - voice = MV_GetVoice( handle ); - - if ( voice == NULL ) - { - return( FALSE ); - } - - return( TRUE ); - } - - -/*--------------------------------------------------------------------- - Function: MV_KillAllVoices - - Stops output of all currently active voices. ----------------------------------------------------------------------*/ - -int MV_KillAllVoices - ( - void - ) - - { - if ( !MV_Installed ) - { - MV_SetErrorCode( MV_NotInstalled ); - return( MV_Error ); - } - - // Remove all the voices from the list - while( VoiceList.next != &VoiceList ) - { - MV_Kill( VoiceList.next->handle ); - } - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_Kill - - Stops output of the voice associated with the specified handle. ----------------------------------------------------------------------*/ - -int MV_Kill - ( - int handle - ) - - { - VoiceNode *voice; - unsigned flags; - unsigned long callbackval; - - if ( !MV_Installed ) - { - MV_SetErrorCode( MV_NotInstalled ); - return( MV_Error ); - } - - flags = DisableInterrupts(); - - voice = MV_GetVoice( handle ); - if ( voice == NULL ) - { - RestoreInterrupts( flags ); - MV_SetErrorCode( MV_VoiceNotFound ); - return( MV_Error ); - } - - callbackval = voice->callbackval; - - MV_StopVoice( voice ); - - RestoreInterrupts( flags ); - - if ( MV_CallBackFunc ) - { - MV_CallBackFunc( callbackval ); - } - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_VoicesPlaying - - Determines the number of currently active voices. ----------------------------------------------------------------------*/ - -int MV_VoicesPlaying - ( - void - ) - - { - VoiceNode *voice; - int NumVoices = 0; - unsigned flags; - - if ( !MV_Installed ) - { - MV_SetErrorCode( MV_NotInstalled ); - return( 0 ); - } - - flags = DisableInterrupts(); - - for( voice = VoiceList.next; voice != &VoiceList; voice = voice->next ) - { - NumVoices++; - } - - RestoreInterrupts( flags ); - - return( NumVoices ); - } - - -/*--------------------------------------------------------------------- - Function: MV_AllocVoice - - Retrieve an inactive or lower priority voice for output. ----------------------------------------------------------------------*/ - -VoiceNode *MV_AllocVoice - ( - int priority - ) - - { - VoiceNode *voice; - VoiceNode *node; - unsigned flags; - -//return( NULL ); - if ( MV_Recording ) - { - return( NULL ); - } - - flags = DisableInterrupts(); - - // Check if we have any free voices - if ( LL_Empty( &VoicePool, next, prev ) ) - { - // check if we have a higher priority than a voice that is playing. - voice = VoiceList.next; - for( node = voice->next; node != &VoiceList; node = node->next ) - { - if ( node->priority < voice->priority ) - { - voice = node; - } - } - - if ( priority >= voice->priority ) - { - MV_Kill( voice->handle ); - } - } - - // Check if any voices are in the voice pool - if ( LL_Empty( &VoicePool, next, prev ) ) - { - // No free voices - RestoreInterrupts( flags ); - return( NULL ); - } - - voice = VoicePool.next; - LL_Remove( voice, next, prev ); - RestoreInterrupts( flags ); - - // Find a free voice handle - do - { - MV_VoiceHandle++; - if ( MV_VoiceHandle < MV_MinVoiceHandle ) - { - MV_VoiceHandle = MV_MinVoiceHandle; - } - } - while( MV_VoicePlaying( MV_VoiceHandle ) ); - - voice->handle = MV_VoiceHandle; - - return( voice ); - } - - -/*--------------------------------------------------------------------- - Function: MV_VoiceAvailable - - Checks if a voice can be play at the specified priority. ----------------------------------------------------------------------*/ - -int MV_VoiceAvailable - ( - int priority - ) - - { - VoiceNode *voice; - VoiceNode *node; - unsigned flags; - - // Check if we have any free voices - if ( !LL_Empty( &VoicePool, next, prev ) ) - { - return( TRUE ); - } - - flags = DisableInterrupts(); - - // check if we have a higher priority than a voice that is playing. - voice = VoiceList.next; - for( node = VoiceList.next; node != &VoiceList; node = node->next ) - { - if ( node->priority < voice->priority ) - { - voice = node; - } - } - - RestoreInterrupts( flags ); - - if ( ( voice != &VoiceList ) && ( priority >= voice->priority ) ) - { - return( TRUE ); - } - - return( FALSE ); - } - - -/*--------------------------------------------------------------------- - Function: MV_SetVoicePitch - - Sets the pitch for the specified voice. ----------------------------------------------------------------------*/ - -void MV_SetVoicePitch - ( - VoiceNode *voice, - unsigned long rate, - int pitchoffset - ) - - { - voice->SamplingRate = rate; - voice->PitchScale = PITCH_GetScale( pitchoffset ); - voice->RateScale = ( rate * voice->PitchScale ) / MV_MixRate; - - // Multiply by MixBufferSize - 1 - voice->FixedPointBufferSize = ( voice->RateScale * MixBufferSize ) - - voice->RateScale; - } - - -/*--------------------------------------------------------------------- - Function: MV_SetPitch - - Sets the pitch for the voice associated with the specified handle. ----------------------------------------------------------------------*/ - -int MV_SetPitch - ( - int handle, - int pitchoffset - ) - - { - 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_Error ); - } - - MV_SetVoicePitch( voice, voice->SamplingRate, pitchoffset ); - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_SetFrequency - - Sets the frequency for the voice associated with the specified handle. ----------------------------------------------------------------------*/ - -int MV_SetFrequency - ( - int handle, - int frequency - ) - - { - 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_Error ); - } - - MV_SetVoicePitch( voice, frequency, 0 ); - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_GetVolumeTable - - Returns a pointer to the volume table associated with the specified - volume. ----------------------------------------------------------------------*/ - -static short *MV_GetVolumeTable - ( - int vol - ) - - { - int volume; - short *table; - - volume = MIX_VOLUME( vol ); - - table = (short *)&MV_VolumeTable[ volume ]; - - return( table ); - } - - -/*--------------------------------------------------------------------- - Function: MV_SetVoiceMixMode - - Selects which method should be used to mix the voice. ----------------------------------------------------------------------*/ - -static void MV_SetVoiceMixMode - ( - VoiceNode *voice - ) - - { - unsigned flags; - int test; - - flags = DisableInterrupts(); - - test = T_DEFAULT; - if ( MV_Bits == 8 ) - { - test |= T_8BITS; - } - - if ( voice->bits == 16 ) - { - test |= T_16BITSOURCE; - } - - if ( MV_Channels == 1 ) - { - test |= T_MONO; - } - else - { - if ( IS_QUIET( voice->RightVolume ) ) - { - test |= T_RIGHTQUIET; - } - else if ( IS_QUIET( voice->LeftVolume ) ) - { - test |= T_LEFTQUIET; - } - } - - // Default case - voice->mix = MV_Mix8BitMono; - - switch( test ) - { - case T_8BITS | T_MONO | T_16BITSOURCE : - voice->mix = MV_Mix8BitMono16; - break; - - case T_8BITS | T_MONO : - voice->mix = MV_Mix8BitMono; - break; - - case T_8BITS | T_16BITSOURCE | T_LEFTQUIET : - MV_LeftVolume = MV_RightVolume; - voice->mix = MV_Mix8BitMono16; - break; - - case T_8BITS | T_LEFTQUIET : - MV_LeftVolume = MV_RightVolume; - voice->mix = MV_Mix8BitMono; - break; - - case T_8BITS | T_16BITSOURCE | T_RIGHTQUIET : - voice->mix = MV_Mix8BitMono16; - break; - - case T_8BITS | T_RIGHTQUIET : - voice->mix = MV_Mix8BitMono; - break; - - case T_8BITS | T_16BITSOURCE : - voice->mix = MV_Mix8BitStereo16; - break; - - case T_8BITS : - voice->mix = MV_Mix8BitStereo; - break; - - case T_MONO | T_16BITSOURCE : - voice->mix = MV_Mix16BitMono16; - break; - - case T_MONO : - voice->mix = MV_Mix16BitMono; - break; - - case T_16BITSOURCE | T_LEFTQUIET : - MV_LeftVolume = MV_RightVolume; - voice->mix = MV_Mix16BitMono16; - break; - - case T_LEFTQUIET : - MV_LeftVolume = MV_RightVolume; - voice->mix = MV_Mix16BitMono; - break; - - case T_16BITSOURCE | T_RIGHTQUIET : - voice->mix = MV_Mix16BitMono16; - break; - - case T_RIGHTQUIET : - voice->mix = MV_Mix16BitMono; - break; - - case T_16BITSOURCE : - voice->mix = MV_Mix16BitStereo16; - break; - - case T_SIXTEENBIT_STEREO : - voice->mix = MV_Mix16BitStereo; - break; - - default : - voice->mix = MV_Mix8BitMono; - } - - RestoreInterrupts( flags ); - } - - -/*--------------------------------------------------------------------- - Function: MV_SetVoiceVolume - - Sets the stereo and mono volume level of the voice associated - with the specified handle. ----------------------------------------------------------------------*/ - -void MV_SetVoiceVolume - ( - VoiceNode *voice, - int vol, - int left, - int right - ) - - { - if ( MV_Channels == 1 ) - { - left = vol; - right = vol; - } - - if ( MV_SwapLeftRight ) - { - // SBPro uses reversed panning - voice->LeftVolume = MV_GetVolumeTable( right ); - voice->RightVolume = MV_GetVolumeTable( left ); - } - else - { - voice->LeftVolume = MV_GetVolumeTable( left ); - voice->RightVolume = MV_GetVolumeTable( right ); - } - - MV_SetVoiceMixMode( voice ); - } - - -/*--------------------------------------------------------------------- - Function: MV_EndLooping - - Stops the voice associated with the specified handle from looping - without stoping the sound. ----------------------------------------------------------------------*/ - -int MV_EndLooping - ( - int handle - ) - - { - VoiceNode *voice; - unsigned flags; - - if ( !MV_Installed ) - { - MV_SetErrorCode( MV_NotInstalled ); - return( MV_Error ); - } - - flags = DisableInterrupts(); - - voice = MV_GetVoice( handle ); - if ( voice == NULL ) - { - RestoreInterrupts( flags ); - MV_SetErrorCode( MV_VoiceNotFound ); - return( MV_Warning ); - } - - voice->LoopCount = 0; - voice->LoopStart = NULL; - voice->LoopEnd = NULL; - - RestoreInterrupts( flags ); - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_SetPan - - Sets the stereo and mono volume level of the voice associated - with the specified handle. ----------------------------------------------------------------------*/ - -int MV_SetPan - ( - int handle, - int vol, - int left, - int 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. ----------------------------------------------------------------------*/ - -int MV_Pan3D - ( - int handle, - int angle, - int distance - ) - - { - int left; - int right; - int mid; - int volume; - int 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 - ( - int 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 - ( - int reverb - ) - - { - MV_ReverbLevel = max( 0, min( 16, reverb ) ); - MV_ReverbTable = NULL; - } - - -/*--------------------------------------------------------------------- - Function: MV_GetMaxReverbDelay - - Returns the maximum delay time for reverb. ----------------------------------------------------------------------*/ - -int MV_GetMaxReverbDelay - ( - void - ) - - { - int maxdelay; - - maxdelay = MixBufferSize * MV_NumberOfBuffers; - - return maxdelay; - } - - -/*--------------------------------------------------------------------- - Function: MV_GetReverbDelay - - Returns the current delay time for reverb. ----------------------------------------------------------------------*/ - -int MV_GetReverbDelay - ( - void - ) - - { - return MV_ReverbDelay / MV_SampleSize; - } - - -/*--------------------------------------------------------------------- - Function: MV_SetReverbDelay - - Sets the delay level of reverb to add to mix. ----------------------------------------------------------------------*/ - -void MV_SetReverbDelay - ( - int delay - ) - - { - int maxdelay; - - maxdelay = MV_GetMaxReverbDelay(); - MV_ReverbDelay = max( MixBufferSize, min( delay, maxdelay ) ); - MV_ReverbDelay *= MV_SampleSize; - } - - -/*--------------------------------------------------------------------- - Function: MV_SetMixMode - - Prepares Multivoc to play stereo of mono digitized sounds. ----------------------------------------------------------------------*/ - -int MV_SetMixMode - ( - int numchannels, - int samplebits - ) - - { - int mode; - - if ( !MV_Installed ) - { - MV_SetErrorCode( MV_NotInstalled ); - return( MV_Error ); - } - - mode = 0; - if ( numchannels == 2 ) - { - mode |= STEREO; - } - if ( samplebits == 16 ) - { - mode |= SIXTEEN_BIT; - } - - MV_MixMode = mode; - - 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; - if ( ( MV_SoundCard == UltraSound ) && ( MV_Channels == 2 ) ) - { - MV_SampleSize /= 2; - MV_BufferSize /= 2; - MV_RightChannelOffset = MV_BufferSize * MV_NumberOfBuffers; - MV_BufferLength /= 2; - } - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_StartPlayback - - Starts the sound playback engine. ----------------------------------------------------------------------*/ - -int MV_StartPlayback - ( - void - ) - - { - int status; - int buffer; - - // 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; - -//JIM -// MV_MixRate = MV_RequestedMixRate; -// return( MV_Ok ); - - // Start playback - status = DSL_BeginBufferedPlayback( MV_MixBuffer[ 0 ], - TotalBufferSize, MV_NumberOfBuffers, - MV_RequestedMixRate, MV_MixMode, MV_ServiceVoc ); - - if ( status != DSL_Ok ) - { - MV_SetErrorCode( MV_BlasterError ); - return( MV_Error ); - } - - MV_MixRate = DSL_GetPlaybackRate(); - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_StopPlayback - - Stops the sound playback engine. ----------------------------------------------------------------------*/ - -void MV_StopPlayback - ( - void - ) - - { - VoiceNode *voice; - VoiceNode *next; - unsigned flags; - - DSL_StopPlayback(); - - // 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 ); - } - - -/*--------------------------------------------------------------------- - Function: MV_StartRecording - - Starts the sound recording engine. ----------------------------------------------------------------------*/ - -int MV_StartRecording - ( - int MixRate, - void ( *function )( char *ptr, int length ) - ) - - { - MV_SetErrorCode( MV_UnsupportedCard ); - return( MV_Error ); - } - - -/*--------------------------------------------------------------------- - Function: MV_StopRecord - - Stops the sound record engine. ----------------------------------------------------------------------*/ - -void MV_StopRecord - ( - void - ) - - { - } - - -/*--------------------------------------------------------------------- - Function: MV_StartDemandFeedPlayback - - Plays a digitized sound from a user controlled buffering system. ----------------------------------------------------------------------*/ - -int MV_StartDemandFeedPlayback - ( - void ( *function )( char **ptr, unsigned long *length ), - int rate, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long 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. ----------------------------------------------------------------------*/ - -int MV_PlayRaw - ( - char *ptr, - unsigned long length, - unsigned rate, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int 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. ----------------------------------------------------------------------*/ - -int MV_PlayLoopedRaw - ( - char *ptr, - unsigned long length, - char *loopstart, - char *loopend, - unsigned rate, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long 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; - 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. ----------------------------------------------------------------------*/ - -int MV_PlayWAV - ( - char *ptr, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int status; - - status = MV_PlayLoopedWAV( ptr, -1, -1, pitchoffset, vol, left, right, - priority, callbackval ); - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: MV_PlayWAV3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int MV_PlayWAV3D - ( - char *ptr, - int pitchoffset, - int angle, - int distance, - int priority, - unsigned long callbackval - ) - - { - int left; - int right; - int mid; - int volume; - int 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. ----------------------------------------------------------------------*/ - -int MV_PlayLoopedWAV - ( - char *ptr, - long loopstart, - long loopend, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - riff_header *riff; - format_header *format; - data_header *data; - VoiceNode *voice; - int length; - int absloopend; - int 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( 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, (long)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 >= (long)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. ----------------------------------------------------------------------*/ - -int MV_PlayVOC3D - ( - char *ptr, - int pitchoffset, - int angle, - int distance, - int priority, - unsigned long callbackval - ) - - { - int left; - int right; - int mid; - int volume; - int 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. ----------------------------------------------------------------------*/ - -int MV_PlayVOC - ( - char *ptr, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - int status; - - status = MV_PlayLoopedVOC( ptr, -1, -1, pitchoffset, vol, left, right, - priority, callbackval ); - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: MV_PlayLoopedVOC - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int MV_PlayLoopedVOC - ( - char *ptr, - intptr_t loopstart, - intptr_t loopend, - int pitchoffset, - int vol, - int left, - int right, - int priority, - unsigned long callbackval - ) - - { - VoiceNode *voice; - int status; - unsigned short nextpos; - - 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; - - nextpos = *( unsigned short * )( ptr + 0x14 ); - voice->NextBlock = ptr + BUILDSWAP_INTEL16(nextpos); - - 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_LockEnd - - Used for determining the length of the functions to lock in memory. ----------------------------------------------------------------------*/ - -static void MV_LockEnd - ( - void - ) - - { - } - - -/*--------------------------------------------------------------------- - Function: MV_CreateVolumeTable - - Create the table used to convert sound data to a specific volume - level. ----------------------------------------------------------------------*/ - -void MV_CreateVolumeTable - ( - int index, - int volume, - int MaxVolume - ) - - { - int val; - int level; - int 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 ] = val; - } - } - } - - -/*--------------------------------------------------------------------- - Function: MV_CalcVolume - - Create the table used to convert sound data to a specific volume - level. ----------------------------------------------------------------------*/ - -void MV_CalcVolume - ( - int MaxVolume - ) - - { - int volume; - - for( volume = 0; volume < 128; volume++ ) - { - MV_HarshClipTable[ volume ] = 0; - MV_HarshClipTable[ volume + 384 ] = 255; - } - for( volume = 0; volume < 256; volume++ ) - { - MV_HarshClipTable[ volume + 128 ] = volume; - } - - // For each volume level, create a translation table with the - // appropriate volume calculated. - for( volume = 0; volume <= MV_MaxVolume; volume++ ) - { - MV_CreateVolumeTable( volume, volume, MaxVolume ); - } - } - - -/*--------------------------------------------------------------------- - Function: MV_CalcPanTable - - Create the table used to determine the stereo volume level of - a sound located at a specific angle and distance from the listener. ----------------------------------------------------------------------*/ - -void MV_CalcPanTable - ( - void - ) - - { - int level; - int angle; - int distance; - int HalfAngle; - int ramp; - - HalfAngle = ( MV_NumPanPositions / 2 ); - - for( distance = 0; distance <= MV_MaxVolume; distance++ ) - { - level = ( 255 * ( MV_MaxVolume - distance ) ) / MV_MaxVolume; - for( angle = 0; angle <= HalfAngle / 2; angle++ ) - { - ramp = level - ( ( level * angle ) / - ( MV_NumPanPositions / 4 ) ); - - MV_PanTable[ angle ][ distance ].left = ramp; - MV_PanTable[ HalfAngle - angle ][ distance ].left = ramp; - MV_PanTable[ HalfAngle + angle ][ distance ].left = level; - MV_PanTable[ MV_MaxPanPosition - angle ][ distance ].left = level; - - MV_PanTable[ angle ][ distance ].right = level; - MV_PanTable[ HalfAngle - angle ][ distance ].right = level; - MV_PanTable[ HalfAngle + angle ][ distance ].right = ramp; - MV_PanTable[ MV_MaxPanPosition - angle ][ distance ].right = ramp; - } - } - } - - -/*--------------------------------------------------------------------- - Function: MV_SetVolume - - Sets the volume of digitized sound playback. ----------------------------------------------------------------------*/ - -void MV_SetVolume - ( - int volume - ) - - { - volume = max( 0, volume ); - volume = min( volume, MV_MaxTotalVolume ); - - MV_TotalVolume = volume; - - // Calculate volume table - MV_CalcVolume( volume ); - } - - -/*--------------------------------------------------------------------- - Function: MV_GetVolume - - Returns the volume of digitized sound playback. ----------------------------------------------------------------------*/ - -int MV_GetVolume - ( - void - ) - - { - return( MV_TotalVolume ); - } - - -/*--------------------------------------------------------------------- - Function: MV_SetCallBack - - Set the function to call when a voice stops. ----------------------------------------------------------------------*/ - -void MV_SetCallBack - ( - void ( *function )( unsigned long ) - ) - - { - MV_CallBackFunc = function; - } - - -/*--------------------------------------------------------------------- - Function: MV_SetReverseStereo - - Set the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -void MV_SetReverseStereo - ( - int setting - ) - - { - MV_SwapLeftRight = setting; - } - - -/*--------------------------------------------------------------------- - Function: MV_GetReverseStereo - - Returns the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -int MV_GetReverseStereo - ( - void - ) - - { - return( MV_SwapLeftRight ); - } - - -/*--------------------------------------------------------------------- - Function: MV_TestPlayback - - Checks if playback has started. ----------------------------------------------------------------------*/ - -int MV_TestPlayback - ( - void - ) - - { - return MV_Ok; - } - - -/*--------------------------------------------------------------------- - Function: MV_Init - - Perform the initialization of variables and memory used by - Multivoc. ----------------------------------------------------------------------*/ - -int MV_Init - ( - int soundcard, - int MixRate, - int Voices, - int numchannels, - int samplebits - ) - - { - char *ptr; - int status; - int buffer; - int index; - - if ( MV_Installed ) - { - MV_Shutdown(); - } - - MV_SetErrorCode( MV_Ok ); - - status = MV_LockMemory(); - if ( status != MV_Ok ) - { - return( status ); - } - - MV_TotalMemory = Voices * sizeof( VoiceNode ) + sizeof( HARSH_CLIP_TABLE_8 ); - status = USRHOOKS_GetMem( ( void ** )&ptr, MV_TotalMemory ); - if ( status != USRHOOKS_Ok ) - { - MV_UnlockMemory(); - MV_SetErrorCode( MV_NoMem ); - return( MV_Error ); - } - - status = DPMI_LockMemory( ptr, MV_TotalMemory ); - if ( status != DPMI_Ok ) - { - USRHOOKS_FreeMem( ptr ); - MV_UnlockMemory(); - MV_SetErrorCode( MV_DPMI_Error ); - return( MV_Error ); - } - - MV_Voices = ( VoiceNode * )ptr; - MV_HarshClipTable = (unsigned char *) ptr + ( MV_TotalMemory - sizeof( HARSH_CLIP_TABLE_8 ) ); - - // Set number of voices before calculating volume table - MV_MaxVoices = Voices; - - LL_Reset( (VoiceNode *)&VoiceList, next, prev ); - LL_Reset( (VoiceNode *)&VoicePool, next, prev ); - - for( index = 0; index < Voices; index++ ) - { - LL_Add( (VoiceNode *)&VoicePool, &MV_Voices[ index ], next, prev ); - } - - // Allocate mix buffer within 1st megabyte - status = DPMI_GetDOSMemory( ( void ** )&ptr, &MV_BufferDescriptor, - 2 * TotalBufferSize ); - - if ( status ) - { - DPMI_UnlockMemory( MV_Voices, MV_TotalMemory ); - USRHOOKS_FreeMem( MV_Voices ); - MV_Voices = NULL; - MV_TotalMemory = 0; - MV_UnlockMemory(); - - MV_SetErrorCode( MV_NoMem ); - return( MV_Error ); - } - - MV_SetReverseStereo( FALSE ); - - // Initialize the sound card - status = DSL_Init(); - if ( status != DSL_Ok ) - { - MV_SetErrorCode( MV_BlasterError ); - } - - if ( MV_ErrorCode != MV_Ok ) - { - status = MV_ErrorCode; - - DPMI_UnlockMemory( MV_Voices, MV_TotalMemory ); - USRHOOKS_FreeMem( MV_Voices ); - MV_Voices = NULL; - MV_TotalMemory = 0; - - DPMI_FreeDOSMemory( MV_BufferDescriptor ); - MV_UnlockMemory(); - - MV_SetErrorCode( status ); - return( MV_Error ); - } - - MV_SoundCard = soundcard; - MV_Installed = TRUE; - MV_CallBackFunc = NULL; - MV_RecordFunc = NULL; - MV_Recording = FALSE; - MV_ReverbLevel = 0; - MV_ReverbTable = NULL; - - // Set the sampling rate - MV_RequestedMixRate = MixRate; - - // Set Mixer to play stereo digitized sound - MV_SetMixMode( numchannels, samplebits ); - MV_ReverbDelay = MV_BufferSize * 3; - - MV_MixBuffer[ MV_NumberOfBuffers ] = ptr; - for( buffer = 0; buffer < MV_NumberOfBuffers; buffer++ ) - { - MV_MixBuffer[ buffer ] = ptr; - ptr += MV_BufferSize; - } - - // Calculate pan table - MV_CalcPanTable(); - - MV_SetVolume( MV_MaxTotalVolume ); - - // Start the playback engine - status = MV_StartPlayback(); - if ( status != MV_Ok ) - { - // Preserve error code while we shutdown. - status = MV_ErrorCode; - MV_Shutdown(); - MV_SetErrorCode( status ); - return( MV_Error ); - } - - if ( MV_TestPlayback() != MV_Ok ) - { - status = MV_ErrorCode; - MV_Shutdown(); - MV_SetErrorCode( status ); - return( MV_Error ); - } - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_Shutdown - - Restore any resources allocated by Multivoc back to the system. ----------------------------------------------------------------------*/ - -int MV_Shutdown - ( - void - ) - - { - int buffer; - unsigned flags; - - if ( !MV_Installed ) - { - return( MV_Ok ); - } - - flags = DisableInterrupts(); - - MV_KillAllVoices(); - - MV_Installed = FALSE; - - // Stop the sound recording engine - if ( MV_Recording ) - { - MV_StopRecord(); - } - - // Stop the sound playback engine - MV_StopPlayback(); - - // Shutdown the sound card - DSL_Shutdown(); - - RestoreInterrupts( flags ); - - // Free any voices we allocated - DPMI_UnlockMemory( MV_Voices, MV_TotalMemory ); - USRHOOKS_FreeMem( MV_Voices ); - MV_Voices = NULL; - MV_TotalMemory = 0; - - LL_Reset( (VoiceNode *)&VoiceList, next, prev ); - LL_Reset( (VoiceNode *)&VoicePool, next, prev ); - - MV_MaxVoices = 1; - - // Release the descriptor from our mix buffer - DPMI_FreeDOSMemory( MV_BufferDescriptor ); - for( buffer = 0; buffer < NumberOfBuffers; buffer++ ) - { - MV_MixBuffer[ buffer ] = NULL; - } - - return( MV_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: MV_UnlockMemory - - Unlocks all neccessary data. ----------------------------------------------------------------------*/ - -void MV_UnlockMemory - ( - void - ) - - { - PITCH_UnlockMemory(); - - DPMI_UnlockMemoryRegion( MV_LockStart, MV_LockEnd ); - DPMI_Unlock( MV_VolumeTable ); - DPMI_Unlock( MV_PanTable ); - DPMI_Unlock( MV_Installed ); - DPMI_Unlock( MV_SoundCard ); - DPMI_Unlock( MV_TotalVolume ); - DPMI_Unlock( MV_MaxVoices ); - DPMI_Unlock( MV_BufferSize ); - DPMI_Unlock( MV_BufferLength ); - DPMI_Unlock( MV_SampleSize ); - DPMI_Unlock( MV_NumberOfBuffers ); - DPMI_Unlock( MV_MixMode ); - DPMI_Unlock( MV_Channels ); - DPMI_Unlock( MV_Bits ); - DPMI_Unlock( MV_Silence ); - DPMI_Unlock( MV_SwapLeftRight ); - DPMI_Unlock( MV_RequestedMixRate ); - DPMI_Unlock( MV_MixRate ); - DPMI_Unlock( MV_BufferDescriptor ); - DPMI_Unlock( MV_MixBuffer ); - DPMI_Unlock( MV_BufferEmpty ); - DPMI_Unlock( MV_Voices ); - DPMI_Unlock( VoiceList ); - DPMI_Unlock( VoicePool ); - DPMI_Unlock( MV_MixPage ); - DPMI_Unlock( MV_VoiceHandle ); - DPMI_Unlock( MV_CallBackFunc ); - DPMI_Unlock( MV_RecordFunc ); - DPMI_Unlock( MV_Recording ); - DPMI_Unlock( MV_MixFunction ); - DPMI_Unlock( MV_HarshClipTable ); - DPMI_Unlock( MV_MixDestination ); - DPMI_Unlock( MV_LeftVolume ); - DPMI_Unlock( MV_RightVolume ); - DPMI_Unlock( MV_MixPosition ); - DPMI_Unlock( MV_ErrorCode ); - DPMI_Unlock( MV_DMAChannel ); - DPMI_Unlock( MV_BuffShift ); - DPMI_Unlock( MV_ReverbLevel ); - DPMI_Unlock( MV_ReverbDelay ); - DPMI_Unlock( MV_ReverbTable ); - } - - -/*--------------------------------------------------------------------- - Function: MV_LockMemory - - Locks all neccessary data. ----------------------------------------------------------------------*/ - -int MV_LockMemory - ( - void - ) - - { - int status; - int pitchstatus; - - status = DPMI_LockMemoryRegion( MV_LockStart, MV_LockEnd ); - status |= DPMI_Lock( MV_VolumeTable ); - status |= DPMI_Lock( MV_PanTable ); - status |= DPMI_Lock( MV_Installed ); - status |= DPMI_Lock( MV_SoundCard ); - status |= DPMI_Lock( MV_TotalVolume ); - status |= DPMI_Lock( MV_MaxVoices ); - status |= DPMI_Lock( MV_BufferSize ); - status |= DPMI_Lock( MV_BufferLength ); - status |= DPMI_Lock( MV_SampleSize ); - status |= DPMI_Lock( MV_NumberOfBuffers ); - status |= DPMI_Lock( MV_MixMode ); - status |= DPMI_Lock( MV_Channels ); - status |= DPMI_Lock( MV_Bits ); - status |= DPMI_Lock( MV_Silence ); - status |= DPMI_Lock( MV_SwapLeftRight ); - status |= DPMI_Lock( MV_RequestedMixRate ); - status |= DPMI_Lock( MV_MixRate ); - status |= DPMI_Lock( MV_BufferDescriptor ); - status |= DPMI_Lock( MV_MixBuffer ); - status |= DPMI_Lock( MV_BufferEmpty ); - status |= DPMI_Lock( MV_Voices ); - status |= DPMI_Lock( VoiceList ); - status |= DPMI_Lock( VoicePool ); - status |= DPMI_Lock( MV_MixPage ); - status |= DPMI_Lock( MV_VoiceHandle ); - status |= DPMI_Lock( MV_CallBackFunc ); - status |= DPMI_Lock( MV_RecordFunc ); - status |= DPMI_Lock( MV_Recording ); - status |= DPMI_Lock( MV_MixFunction ); - status |= DPMI_Lock( MV_HarshClipTable ); - status |= DPMI_Lock( MV_MixDestination ); - status |= DPMI_Lock( MV_LeftVolume ); - status |= DPMI_Lock( MV_RightVolume ); - status |= DPMI_Lock( MV_MixPosition ); - status |= DPMI_Lock( MV_ErrorCode ); - status |= DPMI_Lock( MV_DMAChannel ); - status |= DPMI_Lock( MV_BuffShift ); - status |= DPMI_Lock( MV_ReverbLevel ); - status |= DPMI_Lock( MV_ReverbDelay ); - status |= DPMI_Lock( MV_ReverbTable ); - - pitchstatus = PITCH_LockMemory(); - if ( ( pitchstatus != PITCH_Ok ) || ( status != DPMI_Ok ) ) - { - MV_UnlockMemory(); - MV_SetErrorCode( MV_DPMI_Error ); - return( MV_Error ); - } - - return( MV_Ok ); - } - -void ClearBuffer_DW( void *ptr, unsigned data, int length ) -{ - unsigned *d = (unsigned *)ptr; - - while (length--) { - *d = data; - - d++; - } -} diff --git a/rott/audiolib/multivoc.h b/rott/audiolib/multivoc.h deleted file mode 100644 index 1548000..0000000 --- a/rott/audiolib/multivoc.h +++ /dev/null @@ -1,123 +0,0 @@ -/* -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. - -*/ -/********************************************************************** - file: MULTIVOC.H - - author: James R. Dose - date: December 20, 1993 - - Public header for MULTIVOC.C - - (c) Copyright 1993 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __MULTIVOC_H -#define __MULTIVOC_H - -// platform.h is in buildengine, but I need the byteswapping macros... --ryan. -#include "platform.h" - -#define MV_MinVoiceHandle 1 - -extern int MV_ErrorCode; - -enum MV_Errors - { - MV_Warning = -2, - MV_Error = -1, - MV_Ok = 0, - MV_UnsupportedCard, - MV_NotInstalled, - MV_NoVoices, - MV_NoMem, - MV_VoiceNotFound, - MV_BlasterError, - MV_PasError, - MV_SoundScapeError, - MV_SoundSourceError, - MV_DPMI_Error, - MV_InvalidVOCFile, - MV_InvalidWAVFile, - MV_InvalidMixMode, - MV_SoundSourceFailure, - MV_IrqFailure, - MV_DMAFailure, - MV_DMA16Failure, - MV_NullRecordFunction - }; - -char *MV_ErrorString( int ErrorNumber ); -int MV_VoicePlaying( int handle ); -int MV_KillAllVoices( void ); -int MV_Kill( int handle ); -int MV_VoicesPlaying( void ); -int MV_VoiceAvailable( int priority ); -int MV_SetPitch( int handle, int pitchoffset ); -int MV_SetFrequency( int handle, int frequency ); -int MV_EndLooping( int handle ); -int MV_SetPan( int handle, int vol, int left, int right ); -int MV_Pan3D( int handle, int angle, int distance ); -void MV_SetReverb( int reverb ); -void MV_SetFastReverb( int reverb ); -int MV_GetMaxReverbDelay( void ); -int MV_GetReverbDelay( void ); -void MV_SetReverbDelay( int delay ); -int MV_SetMixMode( int numchannels, int samplebits ); -int MV_StartPlayback( void ); -void MV_StopPlayback( void ); -int MV_StartRecording( int MixRate, void ( *function )( char *ptr, int length ) ); -void MV_StopRecord( void ); -int MV_StartDemandFeedPlayback( void ( *function )( char **ptr, unsigned long *length ), - int rate, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int MV_PlayRaw( char *ptr, unsigned long length, - unsigned rate, int pitchoffset, int vol, int left, - int right, int priority, unsigned long callbackval ); -int MV_PlayLoopedRaw( char *ptr, unsigned long length, - char *loopstart, char *loopend, unsigned rate, int pitchoffset, - int vol, int left, int right, int priority, - unsigned long callbackval ); -int MV_PlayWAV( char *ptr, int pitchoffset, int vol, int left, - int right, int priority, unsigned long callbackval ); -int MV_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int MV_PlayLoopedWAV( char *ptr, long loopstart, long loopend, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int MV_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int MV_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int MV_PlayLoopedVOC( char *ptr, intptr_t loopstart, intptr_t loopend, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -void MV_CreateVolumeTable( int index, int volume, int MaxVolume ); -void MV_SetVolume( int volume ); -int MV_GetVolume( void ); -void MV_SetCallBack( void ( *function )( unsigned long ) ); -void MV_SetReverseStereo( int setting ); -int MV_GetReverseStereo( void ); -int MV_Init( int soundcard, int MixRate, int Voices, int numchannels, - int samplebits ); -int MV_Shutdown( void ); -void MV_UnlockMemory( void ); -int MV_LockMemory( void ); - -#endif diff --git a/rott/audiolib/mv_mix.c b/rott/audiolib/mv_mix.c deleted file mode 100644 index 75a0691..0000000 --- a/rott/audiolib/mv_mix.c +++ /dev/null @@ -1,293 +0,0 @@ -#include "multivoc.h" - -extern char *MV_MixDestination; -extern unsigned long MV_MixPosition; - -extern char *MV_LeftVolume; -extern char *MV_RightVolume; - -extern unsigned char *MV_HarshClipTable; - -extern int MV_RightChannelOffset; -extern int MV_SampleSize; - -void MV_Mix8BitMono( unsigned long position, unsigned long rate, - const char *start, unsigned long length ) -{ - const unsigned char *src; - unsigned char *dest; - unsigned int i; - - src = (const unsigned char *)start; - dest = (unsigned char *)MV_MixDestination; - - for (i = 0; i < length; i++) { - int s = src[position >> 16]; - int d = *dest; - - s = MV_LeftVolume[s * 2]; - - s += d; - - s = MV_HarshClipTable[s + 0x80]; - - *dest = (s & 0xff); - - position += rate; - dest += MV_SampleSize; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix8BitStereo( unsigned long position, - unsigned long rate, const char *start, unsigned long length ) -{ - const unsigned char *src; - unsigned char *dest; - unsigned int i; - - src = (const unsigned char *)start; - dest = (unsigned char *)MV_MixDestination; - - for (i = 0; i < length; i++) { - int s = src[(position >> 16)]; - int dl = dest[0]; - int dr = dest[MV_RightChannelOffset]; - - dl += MV_LeftVolume[s * 2]; - dr += MV_RightVolume[s * 2]; - - dl = MV_HarshClipTable[dl + 0x80]; - dr = MV_HarshClipTable[dr + 0x80]; - - dest[0] = (dl & 0xff); - dest[MV_RightChannelOffset] = (dr & 0xff); - - position += rate; - dest += MV_SampleSize; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix16BitMono( unsigned long position, - unsigned long rate, const char *start, unsigned long length ) -{ - const short *MV_LeftVolumeS; - const unsigned char *src; - short *dest; - unsigned int i; - - src = (const unsigned char *)start; - dest = (short *)MV_MixDestination; - - MV_LeftVolumeS = (const short *)MV_LeftVolume; - - for (i = 0; i < length; i++) { - int s = src[position >> 16]; - int d = dest[0]; - - s = MV_LeftVolumeS[s]; - - s += d; - - if (s < -32768) s = -32768; - if (s > 32767) s = 32767; - - *dest = (short) s; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix16BitStereo( unsigned long position, - unsigned long rate, const char *start, unsigned long length ) -{ - const short *MV_LeftVolumeS; - const short *MV_RightVolumeS; - const unsigned char *src; - short *dest; - unsigned int i; - - src = (unsigned char *)start; - dest = (short *)MV_MixDestination; - - MV_LeftVolumeS = (const short *)MV_LeftVolume; - MV_RightVolumeS = (const short *)MV_RightVolume; - - for (i = 0; i < length; i++) { - int s = src[position >> 16]; - int dl = dest[0]; - int dr = dest[MV_RightChannelOffset/2]; - - dl += MV_LeftVolumeS[s]; - dr += MV_RightVolumeS[s]; - - if (dl < -32768) dl = -32768; - if (dl > 32767) dl = 32767; - if (dr < -32768) dr = -32768; - if (dr > 32767) dr = 32767; - - dest[0] = (short) dl; - dest[MV_RightChannelOffset/2] = (short) dr; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix8BitMono16( unsigned long position, unsigned long rate, - const char *start, unsigned long length ) -{ - const char *src; - unsigned char *dest; - unsigned int i; - - src = (const char *)start + 1; - dest = (unsigned char *)MV_MixDestination; - - for (i = 0; i < length; i++) { - int s = (int)src[(position >> 16) * 2] + 0x80; - int d = *dest; - - s = MV_LeftVolume[s * 2]; - - s += d; - - s = MV_HarshClipTable[s + 0x80]; - - *dest = (s & 0xff); - - position += rate; - dest += MV_SampleSize; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix8BitStereo16( unsigned long position, - unsigned long rate, const char *start, unsigned long length ) -{ - const char *src; - unsigned char *dest; - unsigned int i; - - src = (const char *)start + 1; - dest = (unsigned char *)MV_MixDestination; - - for (i = 0; i < length; i++) { - int s = src[(position >> 16) * 2] + 0x80; - int dl = dest[0]; - int dr = dest[MV_RightChannelOffset]; - - dl += MV_LeftVolume[s * 2]; - dr += MV_RightVolume[s * 2]; - - dl = MV_HarshClipTable[dl + 0x80]; - dr = MV_HarshClipTable[dr + 0x80]; - - dest[0] = (dl & 0xff); - dest[MV_RightChannelOffset] = (dr & 0xff); - - position += rate; - dest += MV_SampleSize; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix16BitMono16( unsigned long position, - unsigned long rate, const char *start, unsigned long length ) -{ - const short *MV_LeftVolumeS; - const unsigned char *src; - short *dest; - unsigned int i; - - src = (const unsigned char *)start; - dest = (short *)MV_MixDestination; - - MV_LeftVolumeS = (const short *)MV_LeftVolume; - - for (i = 0; i < length; i++) { - int sl = src[(position >> 16) * 2 + 0]; - int sh = src[(position >> 16) * 2 + 1] ^ 0x80; - - int d = *dest; - - sl = MV_LeftVolume[sl * 2 + 1]; - sh = MV_LeftVolumeS[sh]; - - d = sl + sh + 0x80 + d; - - if (d < -32768) d = -32768; - if (d > 32767) d = 32767; - - *dest = (short) d; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix16BitStereo16( unsigned long position, - unsigned long rate, const char *start, unsigned long length ) -{ - const short *MV_LeftVolumeS; - const short *MV_RightVolumeS; - const unsigned char *src; - short *dest; - unsigned int i; - - src = (const unsigned char *)start; - dest = (short *)MV_MixDestination; - - MV_LeftVolumeS = (const short *)MV_LeftVolume; - MV_RightVolumeS = (const short *)MV_RightVolume; - - for (i = 0; i < length; i++) { - int sl = src[(position >> 16) * 2 + 0]; - int sh = src[(position >> 16) * 2 + 1] ^ 0x80; - - int dl = dest[0]; - int dr = dest[MV_RightChannelOffset/2]; - - int sll = MV_LeftVolume[sl * 2 + 1]; - int slh = MV_LeftVolumeS[sh]; - - int srl = MV_RightVolume[sl * 2 + 1]; - int srh = MV_RightVolumeS[sh]; - - dl = sll + slh + 0x80 + dl; - dr = srl + srh + 0x80 + dr; - - if (dl < -32768) dl = -32768; - if (dl > 32767) dl = 32767; - if (dr < -32768) dr = -32768; - if (dr > 32767) dr = 32767; - - dest[0] = (short) dl; - dest[MV_RightChannelOffset/2] = (short) dr; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} diff --git a/rott/audiolib/mvreverb.c b/rott/audiolib/mvreverb.c deleted file mode 100644 index f228ffd..0000000 --- a/rott/audiolib/mvreverb.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "multivoc.h" -#include "_multivc.h" - -void MV_16BitReverb( const char *src, char *dest, const VOLUME16 *volume, int count ) -{ - int i; - - short *pdest = (short *)dest; - - for (i = 0; i < count; i++) { - int sl = src[i*2+0]; - int sh = src[i*2+1] ^ 0x80; - - sl = (*volume)[sl] >> 8; - sh = (*volume)[sh]; - - pdest[i] = (short)(sl + sh + 0x80); - } -} - -void MV_8BitReverb( const char *src, char *dest, const VOLUME16 *volume, int count ) -{ - int i; - - for (i = 0; i < count; i++) { - unsigned char s = (unsigned char) src[i]; - - s = (*volume)[s] & 0xff; - - dest[i] = (char)(s + 0x80); - } -} - -void MV_16BitReverbFast( const char *src, char *dest, int count, int shift ) -{ - int i; - - short *pdest = (short *)dest; - const short *psrc = (const short *)src; - - for (i = 0; i < count; i++) { - pdest[i] = psrc[i] >> shift; - } -} - -void MV_8BitReverbFast( const char *src, char *dest, int count, int shift ) -{ - int i; - - unsigned char sh = 0x80 - (0x80 >> shift); - - for (i = 0; i < count; i++) { - unsigned char a = ((unsigned char) src[i]) >> shift; - unsigned char c = (((unsigned char) src[i]) ^ 0x80) >> 7; - - dest[i] = (signed char) (a + sh + c); - } -} diff --git a/rott/audiolib/nodpmi.c b/rott/audiolib/nodpmi.c deleted file mode 100644 index c5cbc53..0000000 --- a/rott/audiolib/nodpmi.c +++ /dev/null @@ -1,179 +0,0 @@ -/* -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: DPMI.C - - author: James R. Dose - date: April 8, 1994 - - Functions for performing DPMI calls. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include -#include -#include "dpmi.h" - -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) - -/*--------------------------------------------------------------------- - Function: DPMI_GetRealModeVector - - Returns the vector of a real mode interrupt. ----------------------------------------------------------------------*/ - -unsigned long DPMI_GetRealModeVector - ( - int num - ) - - { - return 0; - } - - -/*--------------------------------------------------------------------- - Function: DPMI_SetRealModeVector - - Sets the vector of a real mode interrupt. ----------------------------------------------------------------------*/ - -void DPMI_SetRealModeVector - ( - int num, - unsigned long vector - ) - - { - } - - -/*--------------------------------------------------------------------- - Function: DPMI_CallRealModeFunction - - Performs a call to a real mode function. ----------------------------------------------------------------------*/ - -int DPMI_CallRealModeFunction - ( - dpmi_regs *callregs - ) - - { - return( DPMI_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: DPMI_LockMemory - - Locks a region of memory to keep the virtual memory manager from - paging the region out. ----------------------------------------------------------------------*/ - -int DPMI_LockMemory - ( - void *address, - unsigned length - ) - - { - return ( DPMI_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: DPMI_LockMemoryRegion - - Locks a region of memory to keep the virtual memory manager from - paging the region out. ----------------------------------------------------------------------*/ - -int DPMI_LockMemoryRegion - ( - void *start, - void *end - ) - - { - int status; - - status = DPMI_LockMemory( start, ( char * )end - ( char * )start ); - - return( status ); - } - - -/*--------------------------------------------------------------------- - Function: DPMI_UnlockMemory - - Unlocks a region of memory that was previously locked. ----------------------------------------------------------------------*/ - -int DPMI_UnlockMemory - ( - void *address, - unsigned length - ) - - { - return ( DPMI_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: DPMI_UnlockMemoryRegion - - Unlocks a region of memory that was previously locked. ----------------------------------------------------------------------*/ - -int DPMI_UnlockMemoryRegion - ( - void *start, - void *end - ) - - { - int status; - - status = DPMI_UnlockMemory( start, ( char * )end - ( char * )start ); - - return( status ); - } - -int DPMI_GetDOSMemory( void **ptr, intptr_t *descriptor, unsigned length ) -{ - /* Lovely... */ - - *ptr = (void *)malloc(length); - - *descriptor = (intptr_t) *ptr; - - return (descriptor == 0) ? DPMI_Error : DPMI_Ok; -} - -int DPMI_FreeDOSMemory( intptr_t descriptor ) -{ - free((void *)descriptor); - - return (descriptor == 0) ? DPMI_Error : DPMI_Ok; -} diff --git a/rott/audiolib/pitch.c b/rott/audiolib/pitch.c deleted file mode 100644 index dc63828..0000000 --- a/rott/audiolib/pitch.c +++ /dev/null @@ -1,258 +0,0 @@ -/* -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: PITCH.C - - author: James R. Dose - date: June 14, 1993 - - Routines for pitch scaling. - - (c) Copyright 1993 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include -//#include -#include "dpmi.h" -#include "standard.h" -#include "pitch.h" - -#define MAXDETUNE 25 - -static unsigned long PitchTable[ 12 ][ MAXDETUNE ] = - { - { 0x10000, 0x10097, 0x1012f, 0x101c7, 0x10260, 0x102f9, 0x10392, 0x1042c, - 0x104c6, 0x10561, 0x105fb, 0x10696, 0x10732, 0x107ce, 0x1086a, 0x10907, - 0x109a4, 0x10a41, 0x10adf, 0x10b7d, 0x10c1b, 0x10cba, 0x10d59, 0x10df8, - 0x10e98 }, - { 0x10f38, 0x10fd9, 0x1107a, 0x1111b, 0x111bd, 0x1125f, 0x11302, 0x113a5, - 0x11448, 0x114eb, 0x1158f, 0x11634, 0x116d8, 0x1177e, 0x11823, 0x118c9, - 0x1196f, 0x11a16, 0x11abd, 0x11b64, 0x11c0c, 0x11cb4, 0x11d5d, 0x11e06, - 0x11eaf }, - { 0x11f59, 0x12003, 0x120ae, 0x12159, 0x12204, 0x122b0, 0x1235c, 0x12409, - 0x124b6, 0x12563, 0x12611, 0x126bf, 0x1276d, 0x1281c, 0x128cc, 0x1297b, - 0x12a2b, 0x12adc, 0x12b8d, 0x12c3e, 0x12cf0, 0x12da2, 0x12e55, 0x12f08, - 0x12fbc }, - { 0x1306f, 0x13124, 0x131d8, 0x1328d, 0x13343, 0x133f9, 0x134af, 0x13566, - 0x1361d, 0x136d5, 0x1378d, 0x13846, 0x138fe, 0x139b8, 0x13a72, 0x13b2c, - 0x13be6, 0x13ca1, 0x13d5d, 0x13e19, 0x13ed5, 0x13f92, 0x1404f, 0x1410d, - 0x141cb }, - { 0x1428a, 0x14349, 0x14408, 0x144c8, 0x14588, 0x14649, 0x1470a, 0x147cc, - 0x1488e, 0x14951, 0x14a14, 0x14ad7, 0x14b9b, 0x14c5f, 0x14d24, 0x14dea, - 0x14eaf, 0x14f75, 0x1503c, 0x15103, 0x151cb, 0x15293, 0x1535b, 0x15424, - 0x154ee }, - { 0x155b8, 0x15682, 0x1574d, 0x15818, 0x158e4, 0x159b0, 0x15a7d, 0x15b4a, - 0x15c18, 0x15ce6, 0x15db4, 0x15e83, 0x15f53, 0x16023, 0x160f4, 0x161c5, - 0x16296, 0x16368, 0x1643a, 0x1650d, 0x165e1, 0x166b5, 0x16789, 0x1685e, - 0x16934 }, - { 0x16a09, 0x16ae0, 0x16bb7, 0x16c8e, 0x16d66, 0x16e3e, 0x16f17, 0x16ff1, - 0x170ca, 0x171a5, 0x17280, 0x1735b, 0x17437, 0x17513, 0x175f0, 0x176ce, - 0x177ac, 0x1788a, 0x17969, 0x17a49, 0x17b29, 0x17c09, 0x17cea, 0x17dcc, - 0x17eae }, - { 0x17f91, 0x18074, 0x18157, 0x1823c, 0x18320, 0x18406, 0x184eb, 0x185d2, - 0x186b8, 0x187a0, 0x18888, 0x18970, 0x18a59, 0x18b43, 0x18c2d, 0x18d17, - 0x18e02, 0x18eee, 0x18fda, 0x190c7, 0x191b5, 0x192a2, 0x19391, 0x19480, - 0x1956f }, - { 0x1965f, 0x19750, 0x19841, 0x19933, 0x19a25, 0x19b18, 0x19c0c, 0x19d00, - 0x19df4, 0x19ee9, 0x19fdf, 0x1a0d5, 0x1a1cc, 0x1a2c4, 0x1a3bc, 0x1a4b4, - 0x1a5ad, 0x1a6a7, 0x1a7a1, 0x1a89c, 0x1a998, 0x1aa94, 0x1ab90, 0x1ac8d, - 0x1ad8b }, - { 0x1ae89, 0x1af88, 0x1b088, 0x1b188, 0x1b289, 0x1b38a, 0x1b48c, 0x1b58f, - 0x1b692, 0x1b795, 0x1b89a, 0x1b99f, 0x1baa4, 0x1bbaa, 0x1bcb1, 0x1bdb8, - 0x1bec0, 0x1bfc9, 0x1c0d2, 0x1c1dc, 0x1c2e6, 0x1c3f1, 0x1c4fd, 0x1c609, - 0x1c716 }, - { 0x1c823, 0x1c931, 0x1ca40, 0x1cb50, 0x1cc60, 0x1cd70, 0x1ce81, 0x1cf93, - 0x1d0a6, 0x1d1b9, 0x1d2cd, 0x1d3e1, 0x1d4f6, 0x1d60c, 0x1d722, 0x1d839, - 0x1d951, 0x1da69, 0x1db82, 0x1dc9c, 0x1ddb6, 0x1ded1, 0x1dfec, 0x1e109, - 0x1e225 }, - { 0x1e343, 0x1e461, 0x1e580, 0x1e6a0, 0x1e7c0, 0x1e8e0, 0x1ea02, 0x1eb24, - 0x1ec47, 0x1ed6b, 0x1ee8f, 0x1efb4, 0x1f0d9, 0x1f1ff, 0x1f326, 0x1f44e, - 0x1f576, 0x1f69f, 0x1f7c9, 0x1f8f3, 0x1fa1e, 0x1fb4a, 0x1fc76, 0x1fda3, - 0x1fed1 } - }; - - -//static int PITCH_Installed = FALSE; - - -/*--------------------------------------------------------------------- - Function: PITCH_Init - - Initializes pitch table. ----------------------------------------------------------------------*/ -/* -void PITCH_Init - ( - void - ) - - { - int note; - int detune; - - if ( !PITCH_Installed ) - { - for( note = 0; note < 12; note++ ) - { - for( detune = 0; detune < MAXDETUNE; detune++ ) - { - PitchTable[ note ][ detune ] = 0x10000 * - pow( 2, ( note * MAXDETUNE + detune ) / ( 12.0 * MAXDETUNE ) ); - } - } - - PITCH_Installed = TRUE; - } - } -*/ - -/********************************************************************** - - Memory locked functions: - -**********************************************************************/ - - -#define PITCH_LockStart PITCH_GetScale - - -/*--------------------------------------------------------------------- - Function: PITCH_GetScale - - Returns a fixed-point value to scale number the specified amount. ----------------------------------------------------------------------*/ - -unsigned long PITCH_GetScale - ( - int pitchoffset - ) - - { - unsigned long scale; - int octaveshift; - int noteshift; - int note; - int detune; - -// if ( !PITCH_Installed ) -// { -// PITCH_Init(); -// } - - if ( pitchoffset == 0 ) - { - return( PitchTable[ 0 ][ 0 ] ); - } - - noteshift = pitchoffset % 1200; - if ( noteshift < 0 ) - { - noteshift += 1200; - } - - note = noteshift / 100; - detune = ( noteshift % 100 ) / ( 100 / MAXDETUNE ); - octaveshift = ( pitchoffset - noteshift ) / 1200; - - if ( detune < 0 ) - { - detune += ( 100 / MAXDETUNE ); - note--; - if ( note < 0 ) - { - note += 12; - octaveshift--; - } - } - - scale = PitchTable[ note ][ detune ]; - - if ( octaveshift < 0 ) - { - scale >>= -octaveshift; - } - else - { - scale <<= octaveshift; - } - - return( scale ); - } - - -/*--------------------------------------------------------------------- - Function: PITCH_LockEnd - - Used for determining the length of the functions to lock in memory. ----------------------------------------------------------------------*/ - -static void PITCH_LockEnd - ( - void - ) - - { - } - - -/*--------------------------------------------------------------------- - Function: PITCH_UnlockMemory - - Unlocks all neccessary data. ----------------------------------------------------------------------*/ - -void PITCH_UnlockMemory - ( - void - ) - - { - DPMI_UnlockMemoryRegion( PITCH_LockStart, PITCH_LockEnd ); - DPMI_Unlock( PitchTable ); -// DPMI_Unlock( PITCH_Installed ); - } - - -/*--------------------------------------------------------------------- - Function: PITCH_LockMemory - - Unlocks all neccessary data. ----------------------------------------------------------------------*/ - -int PITCH_LockMemory - ( - void - ) - - { - int status; - - status = DPMI_LockMemoryRegion( PITCH_LockStart, PITCH_LockEnd ); - status |= DPMI_Lock( PitchTable ); -// status |= DPMI_Lock( PITCH_Installed ); - - if ( status != DPMI_Ok ) - { - PITCH_UnlockMemory(); - return( PITCH_Error ); - } - - return( PITCH_Ok ); - } diff --git a/rott/audiolib/pitch.h b/rott/audiolib/pitch.h deleted file mode 100644 index f4f5c63..0000000 --- a/rott/audiolib/pitch.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -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: PITCH.H - - author: James R. Dose - date: June 14, 1994 - - Public header for PITCH.C - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __PITCH_H -#define __PITCH_H - -enum PITCH_ERRORS - { - PITCH_Warning = -2, - PITCH_Error = -1, - PITCH_Ok = 0, - }; - -//void PITCH_Init( void ); -unsigned long PITCH_GetScale( int pitchoffset ); -void PITCH_UnlockMemory( void ); -int PITCH_LockMemory( void ); -#endif diff --git a/rott/audiolib/platform.h b/rott/audiolib/platform.h deleted file mode 100644 index 4b74e6a..0000000 --- a/rott/audiolib/platform.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _INCLUDE_PLATFORM_H_ -#define _INCLUDE_PLATFORM_H_ - -#include - -static __inline unsigned short _swap16(unsigned short D) -{ - return((D<<8)|(D>>8)); -} - -static __inline unsigned int _swap32(unsigned int D) -{ - return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); -} - -#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -#define PLATFORM_BIGENDIAN 1 -#define BUILDSWAP_INTEL16(x) _swap16(x) -#define BUILDSWAP_INTEL32(x) _swap32(x) -#else -#define PLATFORM_LITTLEENDIAN 1 -#define BUILDSWAP_INTEL16(x) (x) -#define BUILDSWAP_INTEL32(x) (x) -#endif - -#endif /* !defined _INCLUDE_PLATFORM_H_ */ - -/* end of platform.h ... */ - - diff --git a/rott/audiolib/sndcards.h b/rott/audiolib/sndcards.h deleted file mode 100644 index 39878b7..0000000 --- a/rott/audiolib/sndcards.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -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: SNDCARDS.H - - author: James R. Dose - date: March 31, 1994 - - Contains enumerated type definitions for sound cards. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __SNDCARDS_H -#define __SNDCARDS_H - -#define ASS_VERSION_STRING "1.12" - -typedef enum - { -// ASS_NoSound, - SoundBlaster, - ProAudioSpectrum, - SoundMan16, - Adlib, - GenMidi, - SoundCanvas, - Awe32, - WaveBlaster, - SoundScape, - UltraSound, - SoundSource, - TandySoundSource, - PC, - NumSoundCards - } soundcardnames; - -#endif diff --git a/rott/audiolib/standard.h b/rott/audiolib/standard.h deleted file mode 100644 index e9344e3..0000000 --- a/rott/audiolib/standard.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -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: STANDARD.H - - author: James R. Dose - date: May 25, 1994 - - Header containing standard definitions. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __STANDARD_H -#define __STANDARD_H - -typedef int boolean; -typedef int errorcode; - -#ifndef TRUE - #define TRUE ( 1 == 1 ) - #define FALSE ( !TRUE ) -#endif - -enum STANDARD_ERRORS - { - Warning = -2, - FatalError = -1, - Success = 0 - }; - -#define BITSET( data, bit ) \ - ( ( ( data ) & ( bit ) ) == ( bit ) ) - -#define ARRAY_LENGTH( array ) \ - ( sizeof( array ) / sizeof( ( array )[ 0 ] ) ) - -#define WITHIN_BOUNDS( array, index ) \ - ( ( 0 <= ( index ) ) && ( ( index ) < ARRAY_LENGTH( array ) ) ) - -#define FOREVER for( ; ; ) - -#ifdef NDEBUG - #define DEBUGGING 0 -#else - #define DEBUGGING 1 -#endif - -#define DEBUG_CODE \ - if ( DEBUGGING == 0 ) \ - { \ - } \ - else - -#endif diff --git a/rott/audiolib/user.c b/rott/audiolib/user.c deleted file mode 100644 index c60d511..0000000 --- a/rott/audiolib/user.c +++ /dev/null @@ -1,67 +0,0 @@ -/* -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: USER.C - - author: James R. Dose - date: April 26, 1994 - - Routines to parse command line options. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include -#include "user.h" - -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) - -/*--------------------------------------------------------------------- - Function: USER_CheckParameter - - Checks if the specified string is present in the command line. ----------------------------------------------------------------------*/ - -int USER_CheckParameter - ( - const char *parameter - ) - - { - return FALSE; - } - - -/*--------------------------------------------------------------------- - Function: USER_GetText - - Checks if the specified string is present in the command line - and returns a pointer to the text following it. ----------------------------------------------------------------------*/ - -char *USER_GetText - ( - const char *parameter - ) - - { - return NULL; - } diff --git a/rott/audiolib/user.h b/rott/audiolib/user.h deleted file mode 100644 index b81b3cf..0000000 --- a/rott/audiolib/user.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -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: USER.H - - author: James R. Dose - phone: (214)-271-1365 Ext #221 - date: April 26, 1994 - - Public header for USER.C - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __USER_H -#define __USER_H - -int USER_CheckParameter( const char *parameter ); -char *USER_GetText( const char *parameter ); - -#endif diff --git a/rott/audiolib/usrhooks.c b/rott/audiolib/usrhooks.c deleted file mode 100644 index e012dc4..0000000 --- a/rott/audiolib/usrhooks.c +++ /dev/null @@ -1,84 +0,0 @@ -/* -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: USRHOOKS.C - - author: James R. Dose - date: July 26, 1994 - - This module contains cover functions for operations the library - needs that may be restricted by the calling program. This code - is left public for you to modify. -**********************************************************************/ - -#include -#include "usrhooks.h" - - -/*--------------------------------------------------------------------- - Function: USRHOOKS_GetMem - - Allocates the requested amount of memory and returns a pointer to - its location, or NULL if an error occurs. NOTE: pointer is assumed - to be dword aligned. ----------------------------------------------------------------------*/ - -int USRHOOKS_GetMem - ( - void **ptr, - unsigned long size - ) - - { - void *memory; - - memory = malloc( size ); - if ( memory == NULL ) - { - return( USRHOOKS_Error ); - } - - *ptr = memory; - - return( USRHOOKS_Ok ); - } - - -/*--------------------------------------------------------------------- - Function: USRHOOKS_FreeMem - - Deallocates the memory associated with the specified pointer. ----------------------------------------------------------------------*/ - -int USRHOOKS_FreeMem - ( - void *ptr - ) - - { - if ( ptr == NULL ) - { - return( USRHOOKS_Error ); - } - - free( ptr ); - - return( USRHOOKS_Ok ); - } diff --git a/rott/audiolib/usrhooks.h b/rott/audiolib/usrhooks.h deleted file mode 100644 index 8dc2e0e..0000000 --- a/rott/audiolib/usrhooks.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -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: USRHOOKS.H - - author: James R. Dose - date: July 26, 1994 - - Public header file for USRHOOKS.C. - - This module contains cover functions for operations the library - needs that may be restricted by the calling program. The function - prototypes in this header should not be modified. -**********************************************************************/ - -#ifndef __USRHOOKS_H -#define __USRHOOKS_H - -/*--------------------------------------------------------------------- - Error definitions ----------------------------------------------------------------------*/ - -enum USRHOOKS_Errors - { - USRHOOKS_Warning = -2, - USRHOOKS_Error = -1, - USRHOOKS_Ok = 0 - }; - - -/*--------------------------------------------------------------------- - Function Prototypes ----------------------------------------------------------------------*/ - -int USRHOOKS_GetMem( void **ptr, unsigned long size ); -int USRHOOKS_FreeMem( void *ptr ); - -#endif diff --git a/rott/audiolib/util.h b/rott/audiolib/util.h deleted file mode 100644 index 2960501..0000000 --- a/rott/audiolib/util.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef AUDIOLIB__UTIL_H -#define AUDIOLIB__UTIL_H - -#ifndef min -#define min(a, b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef max -#define max(a, b) ((a) > (b) ? (a) : (b)) -#endif - -#endif - diff --git a/rott/fx_man.h b/rott/fx_man.h index a65b6fd..70e7751 100644 --- a/rott/fx_man.h +++ b/rott/fx_man.h @@ -1,6 +1,7 @@ /* Copyright (C) 1994-1995 Apogee Software, Ltd. +Copyright (C) 2023 Fabian Greffrath This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -63,58 +64,28 @@ int FX_Init( int SoundCard, int numvoices, int numchannels, int samplebits, un int FX_Shutdown( void ); int FX_SetCallBack( void ( *function )( unsigned long ) ); void FX_SetVolume( int volume ); -int FX_GetVolume( void ); void FX_SetReverseStereo( int setting ); int FX_GetReverseStereo( void ); void FX_SetReverb( int reverb ); -void FX_SetFastReverb( int reverb ); -int FX_GetMaxReverbDelay( void ); -int FX_GetReverbDelay( void ); -void FX_SetReverbDelay( int delay ); int FX_VoiceAvailable( int priority ); -int FX_EndLooping( int handle ); int FX_SetPan( int handle, int vol, int left, int right ); int FX_SetPitch( int handle, int pitchoffset ); -int FX_SetFrequency( int handle, int frequency ); -int FX_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int FX_PlayLoopedVOC( char *ptr, long loopstart, long loopend, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int FX_PlayWAV( char *ptr, int pitchoffset, int vol, int left, int right, - int priority, unsigned long callbackval ); -int FX_PlayLoopedWAV( char *ptr, long loopstart, long loopend, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int FX_PlayVOC3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int FX_PlayWAV3D( char *ptr, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int FX_PlayRaw( char *ptr, unsigned long length, unsigned rate, - int pitchoffset, int vol, int left, int right, int priority, - unsigned long callbackval ); -int FX_PlayLoopedRaw( char *ptr, unsigned long length, char *loopstart, - char *loopend, unsigned rate, int pitchoffset, int vol, int left, - int right, int priority, unsigned long callbackval ); +int FX_Play ( int handle, int sndnum, int pitchoffset, int angle, int distance, int priority ); + int FX_Pan3D( int handle, int angle, int distance ); int FX_SoundActive( int handle ); -int FX_SoundsPlaying( void ); int FX_StopSound( int handle ); int FX_StopAllSounds( void ); + +#if 0 int FX_StartDemandFeedPlayback( void ( *function )( char **ptr, unsigned long *length ), int rate, int pitchoffset, int vol, int left, int right, int priority, unsigned long callbackval ); int FX_StartRecording( int MixRate, void ( *function )( char *ptr, int length ) ); void FX_StopRecord( void ); - -// ROTT Special - SBF -int FX_PlayVOC3D_ROTT( char *ptr, int size, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -int FX_PlayWAV3D_ROTT( char *ptr, int size, int pitchoffset, int angle, int distance, - int priority, unsigned long callbackval ); -// End ROTT hacks +#endif #endif diff --git a/rott/fx_mixer.c b/rott/fx_mixer.c new file mode 100644 index 0000000..4d3e1ea --- /dev/null +++ b/rott/fx_mixer.c @@ -0,0 +1,421 @@ +/* +Copyright (C) 1994-1995 Apogee Software, Ltd. +Copyright (C) 2023 Fabian Greffrath + +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. +*/ + +#include "SDL.h" +#include "SDL_mixer.h" + +#include "rt_def.h" +#include "w_wad.h" +#include "z_zone.h" + +#include "fx_man.h" +#include "_rt_soun.h" +#include "rt_sound.h" + +#if (SHAREWARE == 0) +#include "snd_reg.h" +#else +#include "snd_shar.h" +#endif + +#define MAX_CHANNELS 8 + +static struct +{ + sound_t *sfx; +} channels[MAX_CHANNELS]; + +static int FX_Installed = 0; + +/********************************************************************** + module: MULTIVOC.C + + author: James R. Dose + date: December 20, 1993 + + Routines to provide multichannel digitized sound playback for + Sound Blaster compatible sound cards. + + (c) Copyright 1993 James R. Dose. All Rights Reserved. +**********************************************************************/ + +#define MV_MaxPanPosition 31 +#define MV_NumPanPositions (MV_MaxPanPosition + 1) + +#define MIX_VOLUME(volume) \ + ((max(0, min((volume), 255)) * (MV_MaxVolume + 1)) >> 8) + +typedef struct +{ + unsigned char left; + unsigned char right; +} Pan; + +static Pan MV_PanTable[MV_NumPanPositions][63 + 1]; +static int MV_MaxVolume = 63; + +/*--------------------------------------------------------------------- + Function: MV_CalcPanTable + + Create the table used to determine the stereo volume level of + a sound located at a specific angle and distance from the listener. +---------------------------------------------------------------------*/ + +static void MV_CalcPanTable(void) +{ + int level; + int angle; + int distance; + int HalfAngle; + int ramp; + + HalfAngle = (MV_NumPanPositions / 2); + + for (distance = 0; distance <= MV_MaxVolume; distance++) + { + level = (255 * (MV_MaxVolume - distance)) / MV_MaxVolume; + for (angle = 0; angle <= HalfAngle / 2; angle++) + { + ramp = level - ((level * angle) / (MV_NumPanPositions / 4)); + + MV_PanTable[angle][distance].left = ramp; + MV_PanTable[HalfAngle - angle][distance].left = ramp; + MV_PanTable[HalfAngle + angle][distance].left = level; + MV_PanTable[MV_MaxPanPosition - angle][distance].left = level; + + MV_PanTable[angle][distance].right = level; + MV_PanTable[HalfAngle - angle][distance].right = level; + MV_PanTable[HalfAngle + angle][distance].right = ramp; + MV_PanTable[MV_MaxPanPosition - angle][distance].right = ramp; + } + } +} + +/*--------------------------------------------------------------------- + Function: MV_SetPan + + Sets the stereo and mono volume level of the voice associated + with the specified handle. +---------------------------------------------------------------------*/ + +static int MV_SetPan(int handle, int vol, int left, int right) +{ + Mix_SetPanning(handle, left, right); + + return FX_Ok; +} + +/*--------------------------------------------------------------------- + Function: MV_Pan3D + + Set the angle and distance from the listener of the voice associated + with the specified handle. +---------------------------------------------------------------------*/ + +static int MV_Pan3D(int handle, int angle, int distance) +{ + int left; + int right; + int mid; + int volume; + + 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); + + return MV_SetPan(handle, mid, left, right); +} + +/********************************************************************** + 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. +**********************************************************************/ + +void FX_SetReverb(int reverb) +{ +} + +void FX_SetVolume(int volume) +{ +#if SDL_MIXER_VERSION_ATLEAST(2, 6, 0) + Mix_MasterVolume(volume >> 1); +#else + int i; + + for (i = 0; i < MAX_CHANNELS; i++) + { + Mix_Volume(i, volume >> 1); + } +#endif +} + +char *FX_ErrorString(int ErrorNumber) +{ + return (char *) SDL_GetError(); +} + +int FX_StopSound(int handle) +{ + if (handle >= 0 && channels[handle].sfx) + { + Mix_HaltChannel(handle); + + if (channels[handle].sfx->count) + { + channels[handle].sfx->count--; + } + + channels[handle].sfx = NULL; + } + + return FX_Ok; +} + +// Calculate slice size, the result must be a power of two. + +static int snd_samplerate = 44100; + +static int GetSliceSize(void) +{ + int limit; + int n; + + limit = snd_samplerate / 35; // VBLCOUNTER + + // Try all powers of two, not exceeding the limit. + + for (n = 0;; ++n) + { + // 2^n <= limit < 2^n+1 ? + + if ((1 << (n + 1)) > limit) + { + return (1 << n); + } + } + + // Should never happen? + + return 1024; +} + +int FX_SetupCard(int SoundCard, fx_device *device) +{ + Uint16 mix_format; + int mix_channels; + + if (SDL_Init(SDL_INIT_AUDIO) < 0) + { + fprintf(stderr, "\n Couldn't initialize SDL audio: %s", SDL_GetError()); + return FX_Error; + } + + if (Mix_OpenAudioDevice(snd_samplerate, AUDIO_S16SYS, 2, GetSliceSize(), + NULL, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE) < 0) + { + fprintf(stderr, "\n Couldn't open audio with desired format."); + return FX_Error; + } + + // [FG] feed actual sample frequency back into config variable + Mix_QuerySpec(&snd_samplerate, &mix_format, &mix_channels); + + printf("\n Configured audio device with %.1f kHz (%s%d%s), %d channels.", + (float) snd_samplerate / 1000, + SDL_AUDIO_ISFLOAT(mix_format) ? "F" + : SDL_AUDIO_ISSIGNED(mix_format) ? "S" + : "U", + (int) SDL_AUDIO_BITSIZE(mix_format), + SDL_AUDIO_BITSIZE(mix_format) > 8 + ? (SDL_AUDIO_ISBIGENDIAN(mix_format) ? "MSB" : "LSB") + : "", + mix_channels); + + // [FG] let SDL_Mixer do the actual sound mixing + Mix_AllocateChannels(MAX_CHANNELS); + + FX_Installed = true; + + return FX_Ok; +} + +int FX_Shutdown(void) +{ + if (FX_Installed) + { + Mix_CloseAudio(); + FX_Installed = 0; + } + + return FX_Ok; +} + +extern int SoundNumber(int x); + +int FX_Init(int SoundCard, int numvoices, int numchannels, int samplebits, + unsigned mixrate) +{ + int i; + + printf("\n Precaching all sound effects... "); + for (i = 0; i < SD_LASTSOUND; i++) + { + int snd = SoundNumber(i); + + if (snd >= 0) + { + char *data; + int size; + SDL_RWops *rw; + + data = W_CacheLumpNum(snd, PU_STATIC, CvtNull, 1); + size = W_LumpLength(snd); + + rw = SDL_RWFromMem(data, size); + + if (!(sounds[i].chunk = Mix_LoadWAV_RW(rw, 1))) + { + fprintf(stderr, "FX_Init: %s (%s)\n", SDL_GetError(), + W_GetNameForNum(snd)); + } + + Z_Free(data); + } + } + printf("done."); + + printf("\n Calculating stereo panning... "); + MV_CalcPanTable(); + printf("done."); + + return FX_Ok; +} + +int FX_SetCallBack(void (*function)(unsigned long)) +{ + return FX_Ok; +} + +static int reverse_stereo; + +void FX_SetReverseStereo(int setting) +{ + reverse_stereo = setting; +} + +int FX_GetReverseStereo(void) +{ + return reverse_stereo; +} + +int FX_SoundActive(int handle) +{ + return Mix_Playing(handle); +} + +int FX_VoiceAvailable(int priority) +{ + int i; + int min_prio = 255, min_chan = -1; + + for (i = 0; i < MAX_CHANNELS; i++) + { + if (!channels[i].sfx || !FX_SoundActive(i)) + { + return i; + } + + if (channels[i].sfx->priority < min_prio) + { + min_prio = channels[i].sfx->priority; + min_chan = i; + } + } + + if (priority > min_prio) + { + return min_chan; + } + + return -1; +} + +int FX_Play(int handle, int sndnum, int pitchoffset, int angle, int distance, + int priority) +{ + FX_StopSound(handle); + + if (sounds[sndnum].chunk) + { + sounds[sndnum].count++; + channels[handle].sfx = &sounds[sndnum]; + + Mix_PlayChannelTimed(handle, sounds[sndnum].chunk, 0, -1); + FX_Pan3D(handle, angle, distance); + + return handle; + } + + return -1; +} + +int FX_SetPitch(int handle, int pitchoffset) +{ + return FX_Ok; +} + +int FX_Pan3D(int handle, int angle, int distance) +{ + return MV_Pan3D(handle, angle, distance); +} + +int FX_SetPan(int handle, int vol, int left, int right) +{ + return MV_SetPan(handle, vol, left, right); +} + +int FX_StopAllSounds(void) +{ + int i; + + for (i = 0; i < MAX_CHANNELS; i++) + { + FX_StopSound(i); + } + + return FX_Ok; +} diff --git a/rott/rt_dmand.c b/rott/rt_dmand.c index 676cef3..064588d 100644 --- a/rott/rt_dmand.c +++ b/rott/rt_dmand.c @@ -107,9 +107,11 @@ void SD_StartIncomingSound ( void ) PlayingPointer = -1; PlaybackPointer = 0; +#if 0 Playingvoice = FX_StartDemandFeedPlayback ( SD_UpdatePlaybackSound, RECORDINGSAMPLERATE, 0, 255, 255, 255, 255, -1); +#endif if (Playingvoice==0) { SafeFree(PlaybackBuffer); @@ -234,7 +236,7 @@ void SD_UpdateRecordingSound ( char * ptr, int length ) boolean SD_StartRecordingSound ( void ) { - int status; + int status=FX_Ok; if (SD_Started==false) return false; @@ -250,7 +252,9 @@ boolean SD_StartRecordingSound ( void ) FeederPointer = -1; RecordingPointer = 0; +#if 0 status=FX_StartRecording( RECORDINGSAMPLERATE, SD_UpdateRecordingSound); +#endif if (status!=FX_Ok) { @@ -274,7 +278,9 @@ void SD_StopRecordingSound ( void ) return; if (Recording == true) { +#if 0 FX_StopRecord(); +#endif Recording=false; } } diff --git a/rott/rt_menu.c b/rott/rt_menu.c index 7a91827..774179f 100644 --- a/rott/rt_menu.c +++ b/rott/rt_menu.c @@ -2668,7 +2668,11 @@ void CP_Quit ( int which ) { int handle; +#ifdef _WIN32 + MU_StopSong(); +#else MU_FadeOut(310); +#endif handle=SD_Play(SD_QUIT1SND+num); VL_FadeOut (0, 255, 0, 0, 0, 10); CleanUpControlPanel(); diff --git a/rott/rt_sound.c b/rott/rt_sound.c index a272c14..1f7acca 100644 --- a/rott/rt_sound.c +++ b/rott/rt_sound.c @@ -55,7 +55,6 @@ static int soundstart; static int soundtype; int SD_Started=false; static boolean PositionStored=false; -static int NumBadSounds=0; static int remotestart; static boolean SoundsRemapped = false; @@ -223,6 +222,8 @@ int SD_Startup ( boolean bombonerror ) bits = 8; } + remotestart=W_GetNumForName("remostrt")+1; + status=FX_Init( card, voices, channels, bits, 11025 ); if (status != FX_Ok) @@ -243,7 +244,6 @@ int SD_Startup ( boolean bombonerror ) FX_SetCallBack( SD_MakeCacheable ); - remotestart=W_GetNumForName("remostrt")+1; SD_Started=true; @@ -287,7 +287,6 @@ boolean SD_SoundOkay ( int sndnum ) int SD_PlayIt ( int sndnum, int angle, int distance, int pitch ) { int voice; - char * snd; if (!(sounds[sndnum].flags & SD_WRITE)) { @@ -300,36 +299,14 @@ int SD_PlayIt ( int sndnum, int angle, int distance, int pitch ) } } - if ( !FX_VoiceAvailable( sounds[sndnum].priority ) ) + if ((voice = FX_VoiceAvailable(sounds[sndnum].priority)) == -1) { return( 0 ); } - sounds[sndnum].count++; + voice = FX_Play(voice, sndnum, pitch, angle, distance, sounds[sndnum].priority); - snd=W_CacheLumpNum(SoundNumber(sndnum),PU_STATIC, CvtNull, 1); - - if ( *snd == 'C' ) - { - voice = FX_PlayVOC3D( snd, pitch, angle, distance, - sounds[sndnum].priority, (unsigned long) sndnum ); - } - else - { - voice = FX_PlayWAV3D( snd, pitch, angle, distance, - sounds[sndnum].priority, (unsigned long) sndnum ); - } - - if ( voice < FX_Ok ) - { - SD_MakeCacheable( sndnum ); - - return 0; - } - - NumBadSounds=0; - - if (!(sounds[sndnum].flags & SD_WRITE)) + if (voice >= 0 && !(sounds[sndnum].flags & SD_WRITE)) { sounds[sndnum].prevhandle=voice; sounds[sndnum].prevdistance=distance;