diff --git a/polymer/eduke32/source/jaudiolib/_midi.h b/polymer/eduke32/source/jaudiolib/_midi.h deleted file mode 100644 index 67139080c..000000000 --- a/polymer/eduke32/source/jaudiolib/_midi.h +++ /dev/null @@ -1,282 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) - -*/ -/********************************************************************** - module: _MIDI.H - - author: James R. Dose - date: May 25, 1994 - - Private header for MIDI.C. Midi song file playback routines. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef ___MIDI_H -#define ___MIDI_H -#include "compat.h" - -#define RELATIVE_BEAT( measure, beat, tick ) \ - ( ( tick ) + ( ( beat ) << 9 ) + ( ( measure ) << 16 ) ) - -//Bobby Prince thinks this may be 100 -//#define GENMIDI_DefaultVolume 100 -#define GENMIDI_DefaultVolume 90 - -#define MAX_FORMAT 1 - -#define NUM_MIDI_CHANNELS 16 - -#define TIME_PRECISION 16 - -#define MIDI_HEADER_SIGNATURE 0x6468544d // "MThd" -#define MIDI_TRACK_SIGNATURE 0x6b72544d // "MTrk" - -#define MIDI_VOLUME 7 -#define MIDI_PAN 10 -#define MIDI_DETUNE 94 -#define MIDI_RHYTHM_CHANNEL 9 -#define MIDI_RPN_MSB 100 -#define MIDI_RPN_LSB 101 -#define MIDI_DATAENTRY_MSB 6 -#define MIDI_DATAENTRY_LSB 38 -#define MIDI_PITCHBEND_MSB 0 -#define MIDI_PITCHBEND_LSB 0 -#define MIDI_RUNNING_STATUS 0x80 -#define MIDI_NOTE_OFF 0x8 -#define MIDI_NOTE_ON 0x9 -#define MIDI_POLY_AFTER_TCH 0xA -#define MIDI_CONTROL_CHANGE 0xB -#define MIDI_PROGRAM_CHANGE 0xC -#define MIDI_AFTER_TOUCH 0xD -#define MIDI_PITCH_BEND 0xE -#define MIDI_SPECIAL 0xF -#define MIDI_SYSEX 0xF0 -#define MIDI_SYSEX_CONTINUE 0xF7 -#define MIDI_META_EVENT 0xFF -#define MIDI_END_OF_TRACK 0x2F -#define MIDI_TEMPO_CHANGE 0x51 -#define MIDI_TIME_SIGNATURE 0x58 -#define MIDI_RESET_ALL_CONTROLLERS 0x79 -#define MIDI_ALL_NOTES_OFF 0x7b -#define MIDI_MONO_MODE_ON 0x7E -#define MIDI_SYSTEM_RESET 0xFF - -#define GET_NEXT_EVENT( track, data ) \ - ( data ) = *( track )->pos; \ - ( track )->pos += 1 - -#define GET_MIDI_CHANNEL( event ) ( ( event ) & 0xf ) -#define GET_MIDI_COMMAND( event ) ( ( event ) >> 4 ) - -#define EMIDI_INFINITE -1 -#define EMIDI_END_LOOP_VALUE 127 -#define EMIDI_ALL_CARDS 127 -#define EMIDI_INCLUDE_TRACK 110 -#define EMIDI_EXCLUDE_TRACK 111 -#define EMIDI_PROGRAM_CHANGE 112 -#define EMIDI_VOLUME_CHANGE 113 -#define EMIDI_CONTEXT_START 114 -#define EMIDI_CONTEXT_END 115 -#define EMIDI_LOOP_START 116 -#define EMIDI_LOOP_END 117 -#define EMIDI_SONG_LOOP_START 118 -#define EMIDI_SONG_LOOP_END 119 - -#define EMIDI_GeneralMIDI 0 - -#define EMIDI_AffectsCurrentCard( c, type ) \ - ( ( ( c ) == EMIDI_ALL_CARDS ) || ( ( c ) == ( type ) ) ) - - -#define EMIDI_NUM_CONTEXTS 7 -typedef struct - { - char *pos; - char *loopstart; - int16_t loopcount; - int16_t RunningStatus; - uint32_t time; - int32_t FPSecondsPerTick; - int16_t tick; - int16_t beat; - int16_t measure; - int16_t BeatsPerMeasure; - int16_t TicksPerBeat; - int16_t TimeBase; - int32_t delay; - int16_t active; - } songcontext; - -typedef struct - { - char *start; - char *pos; - - int32_t delay; - int16_t active; - int16_t RunningStatus; - - int16_t currentcontext; - songcontext context[ EMIDI_NUM_CONTEXTS ]; - - char EMIDI_IncludeTrack; - char EMIDI_ProgramChange; - char EMIDI_VolumeChange; - } track; - -static int32_t _MIDI_ReadNumber( void *from, size_t size ); -static int32_t _MIDI_ReadDelta( track *ptr ); -static void _MIDI_ResetTracks( void ); -static void _MIDI_AdvanceTick( void ); -static void _MIDI_MetaEvent( track *Track ); -static void _MIDI_SysEx( track *Track ); -static int32_t _MIDI_InterpretControllerInfo( track *Track, int32_t TimeSet, - int32_t channel, int32_t c1, int32_t c2 ); -static int32_t _MIDI_SendControlChange( int32_t channel, int32_t c1, int32_t c2 ); -static void _MIDI_SetChannelVolume( int32_t channel, int32_t volume ); -static void _MIDI_SendChannelVolumes( void ); -static int32_t _MIDI_ProcessNextTick( void ); -static void _MIDI_InitEMIDI( void ); - -/* - if ( c1 == EMIDI_LOOP_START ) - { - if ( c2 == 0 ) - { - Track->context[ 0 ].loopcount = EMIDI_INFINITE; - } - else - { - Track->context[ 0 ].loopcount = c2; - } - - Track->context[ 0 ].pos = Track->pos; - Track->context[ 0 ].loopstart = Track->pos; - Track->context[ 0 ].RunningStatus = Track->RunningStatus; - Track->context[ 0 ].time = _MIDI_Time; - Track->context[ 0 ].FPSecondsPerTick = _MIDI_FPSecondsPerTick; - Track->context[ 0 ].tick = _MIDI_Tick; - Track->context[ 0 ].beat = _MIDI_Beat; - Track->context[ 0 ].measure = _MIDI_Measure; - Track->context[ 0 ].BeatsPerMeasure = _MIDI_BeatsPerMeasure; - Track->context[ 0 ].TicksPerBeat = _MIDI_TicksPerBeat; - Track->context[ 0 ].TimeBase = _MIDI_TimeBase; - break; - } - - if ( ( c1 == EMIDI_LOOP_END ) && - ( c2 == EMIDI_END_LOOP_VALUE ) ) - { - if ( ( Track->context[ 0 ].loopstart != NULL ) && - ( Track->context[ 0 ].loopcount != 0 ) ) - { - if ( Track->context[ 0 ].loopcount != EMIDI_INFINITE ) - { - Track->context[ 0 ].loopcount--; - } - - Track->pos = Track->context[ 0 ].loopstart; - Track->RunningStatus = Track->context[ 0 ].RunningStatus; - - if ( !TimeSet ) - { - _MIDI_Time = Track->context[ 0 ].time; - _MIDI_FPSecondsPerTick = Track->context[ 0 ].FPSecondsPerTick; - _MIDI_Tick = Track->context[ 0 ].tick; - _MIDI_Beat = Track->context[ 0 ].beat; - _MIDI_Measure = Track->context[ 0 ].measure; - _MIDI_BeatsPerMeasure = Track->context[ 0 ].BeatsPerMeasure; - _MIDI_TicksPerBeat = Track->context[ 0 ].TicksPerBeat; - _MIDI_TimeBase = Track->context[ 0 ].TimeBase; - TimeSet = TRUE; - } - } - break; - } - - if ( c1 == MIDI_MONO_MODE_ON ) - { - Track->pos++; - } - - if ( ( c1 == MIDI_VOLUME ) && ( !Track->EMIDI_VolumeChange ) ) - { - _MIDI_SetChannelVolume( channel, c2 ); - break; - } - else if ( ( c1 == EMIDI_VOLUME_CHANGE ) && - ( Track->EMIDI_VolumeChange ) ) - { - _MIDI_SetChannelVolume( channel, c2 ); - break; - } - - if ( ( c1 == EMIDI_PROGRAM_CHANGE ) && - ( Track->EMIDI_ProgramChange ) ) - { - _MIDI_Funcs->ProgramChange( channel, MIDI_PatchMap[ c2 & 0x7f ] ); - break; - } - - if ( c1 == EMIDI_CONTEXT_START ) - { - break; - } - - if ( c1 == EMIDI_CONTEXT_END ) - { - if ( ( Track->currentcontext != _MIDI_Context ) || - ( Track->context[ _MIDI_Context ].pos == NULL ) - { - break; - } - - Track->currentcontext = _MIDI_Context; - Track->context[ 0 ].loopstart = Track->context[ _MIDI_Context ].loopstart; - Track->context[ 0 ].loopcount = Track->context[ _MIDI_Context ].loopcount; - Track->pos = Track->context[ _MIDI_Context ].pos; - Track->RunningStatus = Track->context[ _MIDI_Context ].RunningStatus; - - if ( TimeSet ) - { - break; - } - - _MIDI_Time = Track->context[ _MIDI_Context ].time; - _MIDI_FPSecondsPerTick = Track->context[ _MIDI_Context ].FPSecondsPerTick; - _MIDI_Tick = Track->context[ _MIDI_Context ].tick; - _MIDI_Beat = Track->context[ _MIDI_Context ].beat; - _MIDI_Measure = Track->context[ _MIDI_Context ].measure; - _MIDI_BeatsPerMeasure = Track->context[ _MIDI_Context ].BeatsPerMeasure; - _MIDI_TicksPerBeat = Track->context[ _MIDI_Context ].TicksPerBeat; - _MIDI_TimeBase = Track->context[ _MIDI_Context ].TimeBase; - TimeSet = TRUE; - break; - } - - if ( _MIDI_Funcs->ControlChange ) - { - _MIDI_Funcs->ControlChange( channel, c1, c2 ); - } - */ - -#endif diff --git a/polymer/eduke32/source/jaudiolib/_multivc.h b/polymer/eduke32/source/jaudiolib/_multivc.h deleted file mode 100644 index a41ae2c4d..000000000 --- a/polymer/eduke32/source/jaudiolib/_multivc.h +++ /dev/null @@ -1,277 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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 - -#include "openal.h" - -#ifndef TRUE -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) -#endif - -#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 127 -#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 - -#if defined(_WIN32) -#define MixBufferSize (MV_GetBufferSize(MV_RequestedMixRate)) -#else -#define MixBufferSize (512) -#endif - -#define NumberOfBuffers 16 -#define TotalBufferSize ( MixBufferSize * NumberOfBuffers ) - -#define PI 3.14159265358979323 - -typedef enum -{ - Raw, - VOC, - DemandFeed, - WAV, - OGG -} 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)(uint32_t position, uint32_t rate, - char *start, uint32_t length); - - char *NextBlock; - char *LoopStart; - char *LoopEnd; - uint32_t LoopCount; - uint32_t LoopSize; - uint32_t BlockLength; - - uint32_t PitchScale; - uint32_t FixedPointBufferSize; - - char *sound; - uint32_t length; - uint32_t SamplingRate; - uint32_t RateScale; - uint32_t position; - int32_t Playing; - - int32_t handle; - int32_t priority; - - void (*DemandFeed)(char **ptr, uint32_t *length); - - sounddef OGGstream; -// char *bufsnd; - char bufsnd[0x8000*4]; - int32_t downsample; - - int16_t *LeftVolume; - int16_t *RightVolume; - - uint32_t callbackval; - -} VoiceNode; - -typedef struct -{ - VoiceNode *start; - VoiceNode *end; -} VList; - -typedef struct -{ - char left; - char right; -} Pan; - -typedef struct -{ - MONO16 left; - MONO16 right; -} STEREO16; - -typedef struct -{ - MONO16 left; - MONO16 right; -} SIGNEDSTEREO16; - -typedef struct -{ - char left; - char right; -} STEREO8; - -typedef struct -{ - char RIFF[ 4 ]; - uint32_t file_size; - char WAVE[ 4 ]; - char fmt[ 4 ]; - uint32_t format_size; -} riff_header; - -typedef struct -{ - uint16_t wFormatTag; - uint16_t nChannels; - uint32_t nSamplesPerSec; - uint32_t nAvgBytesPerSec; - uint16_t nBlockAlign; - uint16_t nBitsPerSample; -} format_header; - -typedef struct -{ - char DATA[ 4 ]; - uint32_t size; -} data_header; - -typedef char HARSH_CLIP_TABLE_8[ MV_NumVoices * 256 ]; - -#if defined(_WIN32) -static uint32_t MV_GetBufferSize(uint32_t); -#endif -static void MV_Mix(VoiceNode *voice, int32_t buffer); -static void MV_PlayVoice(VoiceNode *voice); -static void MV_StopVoice(VoiceNode *voice); -static int32_t MV_ServiceVoc(int32_t); - -static playbackstatus MV_GetNextVOCBlock(VoiceNode *voice); -static playbackstatus MV_GetNextDemandFeedBlock(VoiceNode *voice); -static playbackstatus MV_GetNextRawBlock(VoiceNode *voice); -static playbackstatus MV_GetNextWAVBlock(VoiceNode *voice); - -// static void MV_ServiceRecord( void ); -static VoiceNode *MV_GetVoice(int32_t handle); -static VoiceNode *MV_AllocVoice(int32_t priority); - -static int16_t *MV_GetVolumeTable(int32_t vol); - -static void MV_SetVoiceMixMode(VoiceNode *voice); - -static void MV_SetVoicePitch(VoiceNode *voice, uint32_t rate, int32_t pitchoffset); -static void MV_CalcVolume(int32_t MaxLevel); -static void MV_CalcPanTable(void); - -static void ClearBuffer_DW(void *ptr, int32_t data, int32_t length); - -#if defined(_MSC_VER) - -#define CDEC _cdecl - -#elif defined(_WIN32) - -#define CDEC __cdecl - -#else - -#define CDEC - -#endif - - -void CDEC MV_Mix8BitMono(uint32_t position, uint32_t rate, - char *start, uint32_t length); - -void CDEC MV_Mix8BitStereo(uint32_t position, - uint32_t rate, char *start, uint32_t length); - -void CDEC MV_Mix16BitMono(uint32_t position, - uint32_t rate, char *start, uint32_t length); - -void CDEC MV_Mix16BitStereo(uint32_t position, - uint32_t rate, char *start, uint32_t length); - -void CDEC MV_Mix16BitMono16(uint32_t position, - uint32_t rate, char *start, uint32_t length); - -void CDEC MV_Mix8BitMono16(uint32_t position, uint32_t rate, - char *start, uint32_t length); - -void CDEC MV_Mix8BitStereo16(uint32_t position, - uint32_t rate, char *start, uint32_t length); - -void CDEC MV_Mix16BitStereo16(uint32_t position, - uint32_t rate, char *start, uint32_t length); - -void CDEC MV_16BitReverb(char *src, char *dest, VOLUME16 *volume, int32_t count); -void CDEC MV_8BitReverb(char *src, char *dest, VOLUME16 *volume, int32_t count); -void CDEC MV_16BitReverbFast(char *src, char *dest, int32_t count, int32_t shift); -void CDEC MV_8BitReverbFast(char *src, char *dest, int32_t count, int32_t shift); - -#undef CDEC - -#endif diff --git a/polymer/eduke32/source/jaudiolib/audiolib_fxstub.c b/polymer/eduke32/source/jaudiolib/audiolib_fxstub.c deleted file mode 100644 index 96b35b90b..000000000 --- a/polymer/eduke32/source/jaudiolib/audiolib_fxstub.c +++ /dev/null @@ -1,393 +0,0 @@ -//------------------------------------------------------------------------- -/* -Duke Nukem Copyright (C) 1996, 2003 3D Realms Entertainment - -This file is part of Duke Nukem 3D version 1.5 - Atomic Edition - -Duke Nukem 3D 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. - - Dummy AudioLib stub implementation by Jonathon Fowler (jonof@edgenetwk.com) -*/ -//------------------------------------------------------------------------- - -#include "fx_man.h" - - -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) - - -int32_t FX_ErrorCode = FX_Ok; - -#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 -( - int32_t ErrorNumber -) - -{ - char *ErrorString; - - switch (ErrorNumber) - { - case FX_Warning : - case FX_Error : - ErrorString = FX_ErrorString(FX_ErrorCode); - break; - - case FX_Ok : - ErrorString = "Fx ok."; - break; - - case FX_ASSVersion : - ErrorString = "Apogee Sound System Version 0 " - "Programmed by Jim Dose\n" - "(c) Copyright 1995 James R. Dose. All Rights Reserved.\n"; - break; - - default : - ErrorString = "Unknown Fx error code."; - break; - } - - return(ErrorString); -} - - -/*--------------------------------------------------------------------- - Function: FX_Init - - Selects which sound device to use. ----------------------------------------------------------------------*/ - -int32_t FX_Init -( - int32_t SoundCard, - int32_t numvoices, - int32_t numchannels, - int32_t samplebits, - uint32_t mixrate -) - -{ - return(FX_Ok); -} - - -/*--------------------------------------------------------------------- - Function: FX_Shutdown - - Terminates use of sound device. ----------------------------------------------------------------------*/ - -int32_t FX_Shutdown -( - void -) - -{ - return(FX_Ok); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetCallback - - Sets the function to call when a voice is done. ----------------------------------------------------------------------*/ - -int32_t FX_SetCallBack -( - void(*function)(uint32_t) -) - -{ - return(FX_Ok); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetVolume - - Sets the volume of the current sound device. ----------------------------------------------------------------------*/ - -void FX_SetVolume -( - int32_t volume -) - -{} - - -/*--------------------------------------------------------------------- - Function: FX_SetReverseStereo - - Set the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -void FX_SetReverseStereo -( - int32_t setting -) - -{} - - -/*--------------------------------------------------------------------- - Function: FX_GetReverseStereo - - Returns the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -int32_t FX_GetReverseStereo -( - void -) - -{ - return 0; -} - - -/*--------------------------------------------------------------------- - Function: FX_SetReverb - - Sets the reverb level. ----------------------------------------------------------------------*/ - -void FX_SetReverb -( - int32_t reverb -) - -{} - - -/*--------------------------------------------------------------------- - Function: FX_SetReverbDelay - - Sets the delay level of reverb to add to mix. ----------------------------------------------------------------------*/ - -void FX_SetReverbDelay -( - int32_t delay -) - -{} - - -/*--------------------------------------------------------------------- - Function: FX_VoiceAvailable - - Checks if a voice can be play at the specified priority. ----------------------------------------------------------------------*/ - -int32_t FX_VoiceAvailable -( - int32_t priority -) - -{ - return 0; -} - - -/*--------------------------------------------------------------------- - Function: FX_PlayLoopedVOC - - Begin playback of sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int32_t FX_PlayLoopedVOC -( - char *ptr, - int32_t loopstart, - int32_t loopend, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: FX_PlayWAV - - Begin playback of sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int32_t FX_PlayLoopedWAV -( - char *ptr, - int32_t loopstart, - int32_t loopend, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: FX_PlayVOC3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int32_t FX_PlayVOC3D -( - char *ptr, - int32_t pitchoffset, - int32_t angle, - int32_t distance, - int32_t priority, - uint32_t callbackval -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: FX_PlayWAV3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int32_t FX_PlayWAV3D -( - char *ptr, - int32_t pitchoffset, - int32_t angle, - int32_t distance, - int32_t priority, - uint32_t callbackval -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: FX_Pan3D - - Set the angle and distance from the listener of the voice associated - with the specified handle. ----------------------------------------------------------------------*/ - -int32_t FX_Pan3D -( - int32_t handle, - int32_t angle, - int32_t distance -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: FX_StopSound - - Halts playback of a specific voice ----------------------------------------------------------------------*/ - -int32_t FX_StopSound -( - int32_t handle -) - -{ - return(FX_Ok); -} - - -/*--------------------------------------------------------------------- - Function: FX_StopAllSounds - - Halts playback of all sounds. ----------------------------------------------------------------------*/ - -int32_t FX_StopAllSounds -( - void -) - -{ - return(FX_Ok); -} - - -void AudioUpdate(void) { } - -int32_t FX_PlayLoopedOGG -( - char *ptr, - int32_t loopstart, - int32_t loopend, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) -{ - return(0); -} - -int32_t FX_PlayOGG3D -( - char *ptr, - int32_t pitchoffset, - int32_t angle, - int32_t distance, - int32_t priority, - uint32_t callbackval -) -{ - return(0); -} \ No newline at end of file diff --git a/polymer/eduke32/source/jaudiolib/audiolib_musicstub.c b/polymer/eduke32/source/jaudiolib/audiolib_musicstub.c deleted file mode 100644 index 36e94ce62..000000000 --- a/polymer/eduke32/source/jaudiolib/audiolib_musicstub.c +++ /dev/null @@ -1,494 +0,0 @@ -//------------------------------------------------------------------------- -/* -Duke Nukem Copyright (C) 1996, 2003 3D Realms Entertainment - -This file is part of Duke Nukem 3D version 1.5 - Atomic Edition - -Duke Nukem 3D 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. - - Dummy AudioLib stub implementation by Jonathon Fowler (jonof@edgenetwk.com) -*/ -//------------------------------------------------------------------------- - -#include "music.h" - - -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) - - -int32_t MUSIC_ErrorCode = MUSIC_Ok; - - -/*--------------------------------------------------------------------- - Function: MUSIC_ErrorString - - Returns a pointer to the error message associated with an error - number. A -1 returns a pointer the current error. ----------------------------------------------------------------------*/ - -char *MUSIC_ErrorString -( - int32_t ErrorNumber -) - -{ - char *ErrorString; - - switch (ErrorNumber) - { - case MUSIC_Warning : - case MUSIC_Error : - ErrorString = MUSIC_ErrorString(MUSIC_ErrorCode); - break; - - case MUSIC_Ok : - ErrorString = "Music ok."; - break; - - case MUSIC_ASSVersion : - ErrorString = "Apogee Sound System Version " - "Programmed by Jim Dose\n" - "(c) Copyright 1996 James R. Dose. All Rights Reserved.\n"; - break; - - case MUSIC_SoundCardError : - break; - - case MUSIC_MPU401Error : - ErrorString = "Could not detect MPU-401."; - break; - - case MUSIC_InvalidCard : - ErrorString = "Invalid Music device."; - break; - - case MUSIC_MidiError : - ErrorString = "Error playing MIDI file."; - break; - - case MUSIC_TaskManError : - ErrorString = "TaskMan error."; - break; - - case MUSIC_DPMI_Error : - ErrorString = "DPMI Error in MUSIC."; - break; - - default : - ErrorString = "Unknown Music error code."; - break; - } - - return(ErrorString); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Init - - Selects which sound device to use. ----------------------------------------------------------------------*/ - -int32_t MUSIC_Init -( - int32_t SoundCard, - int32_t Address -) - -{ - int32_t i; - int32_t status; - - status = MUSIC_Ok; - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Shutdown - - Terminates use of sound device. ----------------------------------------------------------------------*/ - -int32_t MUSIC_Shutdown -( - void -) - -{ - int32_t status; - - status = MUSIC_Ok; - - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetMaxFMMidiChannel - - Sets the maximum MIDI channel that FM cards respond to. ----------------------------------------------------------------------*/ - -void MUSIC_SetMaxFMMidiChannel -( - int32_t channel -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetVolume - - Sets the volume of music playback. ----------------------------------------------------------------------*/ - -void MUSIC_SetVolume -( - int32_t volume -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetMidiChannelVolume - - Sets the volume of music playback on the specified MIDI channel. ----------------------------------------------------------------------*/ - -void MUSIC_SetMidiChannelVolume -( - int32_t channel, - int32_t volume -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_ResetMidiChannelVolumes - - Sets the volume of music playback on all MIDI channels to full volume. ----------------------------------------------------------------------*/ - -void MUSIC_ResetMidiChannelVolumes -( - void -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetVolume - - Returns the volume of music playback. ----------------------------------------------------------------------*/ - -int32_t MUSIC_GetVolume -( - void -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetLoopFlag - - Set whether the music will loop or end when it reaches the end of - the song. ----------------------------------------------------------------------*/ - -void MUSIC_SetLoopFlag -( - int32_t loopflag -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SongPlaying - - Returns whether there is a song playing. ----------------------------------------------------------------------*/ - -int32_t MUSIC_SongPlaying -( - void -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Continue - - Continues playback of a paused song. ----------------------------------------------------------------------*/ - -void MUSIC_Continue -( - void -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Pause - - Pauses playback of a song. ----------------------------------------------------------------------*/ - -void MUSIC_Pause -( - void -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_StopSong - - Stops playback of current song. ----------------------------------------------------------------------*/ - -int32_t MUSIC_StopSong -( - void -) - -{ - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_PlaySong - - Begins playback of MIDI song. ----------------------------------------------------------------------*/ - -int32_t MUSIC_PlaySong -( - char *song, - int32_t loopflag -) - -{ - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetContext - - Sets the song context. ----------------------------------------------------------------------*/ - -void MUSIC_SetContext -( - int32_t context -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetContext - - Returns the current song context. ----------------------------------------------------------------------*/ - -int32_t MUSIC_GetContext -( - void -) - -{ return 0; } - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongTick - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongTick -( - uint32_t PositionInTicks -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongTime - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongTime -( - uint32_t milliseconds -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongPosition - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongPosition -( - int32_t measure, - int32_t beat, - int32_t tick -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetSongPosition - - Returns the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_GetSongPosition -( - songposition *pos -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetSongLength - - Returns the length of the song. ----------------------------------------------------------------------*/ - -void MUSIC_GetSongLength -( - songposition *pos -) - -{} - - - - - - -/*--------------------------------------------------------------------- - Function: MUSIC_FadeVolume - - Fades music volume from current level to another over a specified - period of time. ----------------------------------------------------------------------*/ - -int32_t MUSIC_FadeVolume -( - int32_t tovolume, - int32_t milliseconds -) - -{ - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_FadeActive - - Returns whether the fade routine is active. ----------------------------------------------------------------------*/ - -int32_t MUSIC_FadeActive -( - void -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_StopFade - - Stops fading the music. ----------------------------------------------------------------------*/ - -void MUSIC_StopFade -( - void -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_RerouteMidiChannel - - Sets callback function to reroute MIDI commands from specified - function. ----------------------------------------------------------------------*/ - -void MUSIC_RerouteMidiChannel -( - int32_t channel, - int32_t(*function)(int32_t event, int32_t c1, int32_t c2) -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_RegisterTimbreBank - - Halts playback of all sounds. ----------------------------------------------------------------------*/ - -void MUSIC_RegisterTimbreBank -( - char *timbres -) - -{} - - -void MUSIC_Update(void) -{} - -void MUSIC_PlayMusic(char *_filename, int32_t loopflag) -{} diff --git a/polymer/eduke32/source/jaudiolib/debugio.h b/polymer/eduke32/source/jaudiolib/debugio.h deleted file mode 100644 index 59867970c..000000000 --- a/polymer/eduke32/source/jaudiolib/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( int32_t x, int32_t y ); -void DB_PutChar( char ch ); -int32_t DB_PrintString( char *string ); -int32_t DB_PrintNum( int32_t number ); -int32_t DB_PrintUnsigned( uint32_t number, int32_t radix ); -int32_t DB_printf( char *fmt, ... ); - -#endif diff --git a/polymer/eduke32/source/jaudiolib/dsl.c b/polymer/eduke32/source/jaudiolib/dsl.c deleted file mode 100644 index cb9b4ad0f..000000000 --- a/polymer/eduke32/source/jaudiolib/dsl.c +++ /dev/null @@ -1,280 +0,0 @@ -/* -Copyright (C) 2003-2004 Ryan C. Gordon. and James Bentler - -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. - -Originally written by Ryan C. Gordon. (icculus@clutteredmind.org) -Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu) - -*/ -#include -#include - -#include "compat.h" -#include "dsl.h" -#include "pragmas.h" - -#define _NEED_SDLMIXER 1 -#include "sdl_inc.h" - -extern int32_t MV_MixPage; - -int32_t DSL_ErrorCode = DSL_Ok; - -static int32_t mixer_initialized; -static int32_t interrupts_disabled = 0; - -static int32_t(*_DSL_CallBackFunc)(int32_t); -static volatile char *_DSL_BufferStart; -static int32_t _DSL_BufferSize; -static int32_t _DSL_SampleRate; -static int32_t _DSL_remainder; -static Uint16 _DSL_format; -static int32_t _DSL_channels; - - -static Mix_Chunk *blank; -static uint8_t *blank_buf; - -/* -possible todo ideas: cache sdl/sdl mixer error messages. -*/ - -char *DSL_ErrorString(int32_t 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(int32_t ErrorCode) -{ - DSL_ErrorCode = ErrorCode; -} - -int32_t DSL_Init(int32_t soundcard, int32_t mixrate, int32_t numchannels, int32_t samplebits, int32_t buffersize) -{ - /* FIXME: Do I need an SDL_mixer version check - * like that in sdlmusic.h here, too??? - */ - - UNREFERENCED_PARAMETER(soundcard); - UNREFERENCED_PARAMETER(buffersize); - - DSL_SetErrorCode(DSL_Ok); - - if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) - { - DSL_SetErrorCode(DSL_SDLInitFailure); - - return DSL_Error; - } - - _DSL_channels = numchannels; - _DSL_SampleRate = mixrate; - _DSL_format = (samplebits == 16) ? AUDIO_S16SYS : AUDIO_U8; - - return DSL_Ok; -} - -void DSL_Shutdown(void) -{ - DSL_StopPlayback(); -} - -static void mixer_callback(int32_t chan, void *stream, int32_t len, void *udata) -{ - Uint8 *stptr; - Uint8 *fxptr; - int32_t copysize; - UNREFERENCED_PARAMETER(chan); - UNREFERENCED_PARAMETER(udata); - /* len should equal _DSL_BufferSize, else this is screwed up */ - - stptr = (Uint8 *)stream; - - if (_DSL_remainder > 0) - { - copysize = min(len, _DSL_remainder); - - fxptr = (Uint8 *)(&_DSL_BufferStart[MV_MixPage * - _DSL_BufferSize]); - - Bmemcpy(stptr, fxptr+(_DSL_BufferSize-_DSL_remainder), copysize); - - len -= copysize; - _DSL_remainder -= copysize; - - stptr += copysize; - } - - while (len > 0) - { - /* new buffer */ - - _DSL_CallBackFunc(0); - - fxptr = (Uint8 *)(&_DSL_BufferStart[MV_MixPage * - _DSL_BufferSize]); - - copysize = min(len, _DSL_BufferSize); - - Bmemcpy(stptr, fxptr, copysize); - - len -= copysize; - - stptr += copysize; - } - - _DSL_remainder = len; -} - -//int32_t DSL_BeginBufferedPlayback(char *BufferStart, - // int32_t BufferSize, int32_t NumDivisions, uint32_t SampleRate, - // int32_t MixMode, void(*CallBackFunc)(void)) -int32_t DSL_BeginBufferedPlayback(char *BufferStart, int32_t(*CallBackFunc)(int32_t), int32_t BufferSize, int32_t NumDivisions) -{ - int32_t chunksize; - - if (mixer_initialized) - { - DSL_SetErrorCode(DSL_MixerActive); - - return DSL_Error; - } - - _DSL_CallBackFunc = CallBackFunc; - _DSL_BufferStart = BufferStart; - _DSL_BufferSize = (BufferSize / NumDivisions); - - _DSL_remainder = 0; - - /* - 23ms is typically ideal (11025,22050,44100) - 46ms isn't bad - */ - - chunksize = 512; - - if (_DSL_SampleRate >= 16000) chunksize *= 2; - if (_DSL_SampleRate >= 32000) chunksize *= 2; - - if (Mix_OpenAudio(_DSL_SampleRate, _DSL_format, _DSL_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; -} - -uint32_t DSL_GetPlaybackRate(void) -{ - return _DSL_SampleRate; -} - -int32_t DisableInterrupts(void) -{ - if (interrupts_disabled++) - return 0; -// interrupts_disabled = 1; - SDL_LockAudio(); - return(0); -} - -int32_t RestoreInterrupts(int32_t flags) -{ - UNREFERENCED_PARAMETER(flags); - if (--interrupts_disabled) - return 0; -// interrupts_disabled = 0; - SDL_UnlockAudio(); - return(0); -} diff --git a/polymer/eduke32/source/jaudiolib/dsl.h b/polymer/eduke32/source/jaudiolib/dsl.h deleted file mode 100644 index 64b942137..000000000 --- a/polymer/eduke32/source/jaudiolib/dsl.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright (C) 2003-2004 Ryan C. Gordon. and James Bentler - -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. - -Originally written by Ryan C. Gordon. (icculus@clutteredmind.org) -Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu) - -*/ -#ifndef AUDIOLIB__DSL_H -#define AUDIOLIB__DSL_H - -#define MONO_8BIT 0 -#define STEREO 1 -#define SIXTEEN_BIT 2 - -enum DSL_ERRORS - { - DSL_Warning = -2, - DSL_Error = -1, - DSL_Ok = 0, - DSL_SDLInitFailure, - DSL_MixerActive, - DSL_MixerInitFailure - }; - -extern int32_t DSL_ErrorCode; -char *DSL_ErrorString( int32_t ErrorNumber ); - -int32_t DisableInterrupts(void); // simulated using critical sections -int32_t RestoreInterrupts(int32_t); - -int32_t DSL_Init(int32_t soundcard, int32_t mixrate, int32_t numchannels, int32_t samplebits, int32_t buffersize); -void DSL_StopPlayback( void ); -uint32_t DSL_GetPlaybackRate( void ); -int32_t DSL_BeginBufferedPlayback(char *BufferStart, int32_t (*CallBackFunc)(int32_t), int32_t buffersize, int32_t numdivisions); -void DSL_Shutdown( void ); - -#endif diff --git a/polymer/eduke32/source/jaudiolib/dsoundout.c b/polymer/eduke32/source/jaudiolib/dsoundout.c deleted file mode 100644 index eab894c16..000000000 --- a/polymer/eduke32/source/jaudiolib/dsoundout.c +++ /dev/null @@ -1,639 +0,0 @@ -/* - * DirectSound output code for MultiVoc - * by Jonathon Fowler (jonof@edgenetwk.com) - */ -//------------------------------------------------------------------------- -/* -Duke Nukem Copyright (C) 1996, 2003 3D Realms Entertainment - -This file is part of Duke Nukem 3D version 1.5 - Atomic Edition - -Duke Nukem 3D 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 -#include "dsoundout.h" - -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#include - -#ifdef USE_OPENAL -#include "openal.h" -#endif -#include "compat.h" -#include "winlayer.h" - -#if defined(_MSC_VER) -#include -#endif - - -#ifndef RENDERTYPEWIN -#error The DirectSound output module for AudioLib only works with the Windows interface. -#endif - -static CRITICAL_SECTION mutex; -static int32_t _DSOUND_CriticalSectionAlloced = FALSE; -static HANDLE isrthread = NULL; -static HANDLE isrfinish = NULL; - -static HMODULE hDSoundDLL = NULL; -static LPDIRECTSOUND lpDS = NULL; -static LPDIRECTSOUNDBUFFER lpDSBPrimary = NULL; -static LPDIRECTSOUNDBUFFER lpDSBSecondary = NULL; -static LPDIRECTSOUNDNOTIFY lpDSNotify = NULL; -static HANDLE *hPosNotify = NULL; - -static int32_t(*_DSOUND_CallBack)(int32_t) = NULL; -static int32_t _DSOUND_BufferLength = 0; -static int32_t _DSOUND_NumBuffers = 0; -static char *_DSOUND_MixBuffer = NULL; - -static int32_t DSOUND_Installed = FALSE; - -int32_t DSOUND_ErrorCode = DSOUND_Ok; - -#define DSOUND_SetErrorCode( status ) \ - DSOUND_ErrorCode = ( status ); - - - -/* - * DisableInterrupts - * Enter the critical section. - */ -int32_t DisableInterrupts(void) -{ - if (!_DSOUND_CriticalSectionAlloced) return -1; - - EnterCriticalSection(&mutex); - - return 0; -} - - -/* - * RestoreInterrupts - * Leave the critical section. - */ -int32_t RestoreInterrupts(int32_t a) -{ - if (!_DSOUND_CriticalSectionAlloced) return -1; - - LeaveCriticalSection(&mutex); - - return 0; - a=a; -} - - -/* - * DSOUND_ErrorString - * Returns a description of an error code. - */ -char *DSOUND_ErrorString(int32_t errorcode) -{ - switch (errorcode) - { - case DSOUND_Warning: - case DSOUND_Error: - return DSOUND_ErrorString(DSOUND_ErrorCode); - - case DSOUND_Ok: - return "DirectSound ok."; - - case DSOUND_NoDLL: - return "Failed loading DSOUND.DLL."; - - case DSOUND_NoDirectSoundCreate: - return "Failed getting DirectSoundCreate entry point."; - - case DSOUND_FailedDSC: - return "DirectSoundCreate failed."; - - case DSOUND_FailedSetCoopLevel: - return "Failed setting cooperative level."; - - case DSOUND_FailedCreatePrimary: - return "Failed creating primary buffer."; - - case DSOUND_FailedSetFormat: - return "Failed setting primary buffer format."; - - case DSOUND_FailedCreateSecondary: - return "Failed creating secondary buffer."; - - case DSOUND_FailedCreateNotifyEvent: - return "Failed creating notification event object."; - - case DSOUND_FailedQueryNotify: - return "Failed querying notification interface."; - - case DSOUND_FailedSetNotify: - return "Failed setting notification positions."; - - case DSOUND_FailedCreateFinishEvent: - return "Failed creating finish event object."; - - case DSOUND_FailedCreateThread: - return "Failed creating playback thread."; - - case DSOUND_FailedPlaySecondary: - return "Failed playing secondary buffer."; - - case DSOUND_FailedGetExitCode: - return "GetExitCodeThread failed."; - - default: - return "Unknown DirectSound error code."; - } -} - - -/* - * DSOUND_Init - * Initializes the DirectSound objects. - */ -int32_t DSOUND_Init(int32_t soundcard, int32_t mixrate, int32_t numchannels, int32_t samplebits, int32_t buffersize) -{ - HRESULT(WINAPI *aDirectSoundCreate)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN); - HRESULT hr; - DSBUFFERDESC dsbuf; - WAVEFORMATEX wfex; - DSBPOSITIONNOTIFY posn; - - UNREFERENCED_PARAMETER(soundcard); - - if (DSOUND_Installed) - { - DSOUND_Shutdown(); - } - - initprintf("Initializing DirectSound...\n"); - - if (!_DSOUND_CriticalSectionAlloced) - { - // initialize the critical section object we'll use to - // simulate (dis|en)abling interrupts - InitializeCriticalSection(&mutex); - _DSOUND_CriticalSectionAlloced = TRUE; - } - -// initprintf(" - Loading DSOUND.DLL\n"); - hDSoundDLL = LoadLibrary("DSOUND.DLL"); - if (!hDSoundDLL) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_NoDLL); - return DSOUND_Error; - } - - aDirectSoundCreate = (void *)GetProcAddress(hDSoundDLL, "DirectSoundCreate"); - if (!aDirectSoundCreate) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_NoDirectSoundCreate); - return DSOUND_Error; - } - -// initprintf(" - Creating DirectSound object\n"); - hr = aDirectSoundCreate(NULL, &lpDS, NULL); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedDSC); - return DSOUND_Error; - } - - hr = IDirectSound_SetCooperativeLevel(lpDS, (HWND)win_gethwnd(), DSSCL_EXCLUSIVE); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedSetCoopLevel); - return DSOUND_Error; - } - -// initprintf(" - Creating primary buffer\n"); - ZeroMemory(&dsbuf, sizeof(dsbuf)); - dsbuf.dwSize = sizeof(DSBUFFERDESC); - dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER; - hr = IDirectSound_CreateSoundBuffer(lpDS, &dsbuf, &lpDSBPrimary, NULL); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedCreatePrimary); - return DSOUND_Error; - } - -/* initprintf(" - Setting primary buffer format\n" - " Channels: %d\n" - " Sample rate: %dHz\n" - " Sample size: %d bits\n", - numchannels, mixrate, samplebits); */ - initprintf(" - Primary buffer format: %d ch, %dHz, %d bits\n", - numchannels, mixrate, samplebits); - ZeroMemory(&wfex, sizeof(wfex)); - wfex.wFormatTag = WAVE_FORMAT_PCM; - wfex.nChannels = numchannels; - wfex.nSamplesPerSec = mixrate; - wfex.wBitsPerSample = samplebits; - wfex.nBlockAlign = (wfex.wBitsPerSample / 8) * wfex.nChannels; - wfex.nAvgBytesPerSec = wfex.nBlockAlign * wfex.nSamplesPerSec; - hr = IDirectSoundBuffer_SetFormat(lpDSBPrimary, &wfex); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedSetFormat); - return DSOUND_Error; - } - - initprintf(" - Creating secondary buffer\n"); - ZeroMemory(&dsbuf, sizeof(dsbuf)); - dsbuf.dwSize = sizeof(DSBUFFERDESC); - dsbuf.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_LOCSOFTWARE; - dsbuf.dwBufferBytes = buffersize; - dsbuf.lpwfxFormat = &wfex; - hr = IDirectSound_CreateSoundBuffer(lpDS, &dsbuf, &lpDSBSecondary, NULL); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedCreateSecondary); - return DSOUND_Error; - } - - hr = IDirectSoundBuffer_QueryInterface(lpDSBSecondary, &IID_IDirectSoundNotify, (LPVOID *)&lpDSNotify); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedQueryNotify); - return DSOUND_Error; - } - - hPosNotify = (HANDLE *)malloc(sizeof(HANDLE)); - if (!hPosNotify) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedSetNotify); - return DSOUND_Error; - } - - hPosNotify[0] = CreateEvent(NULL, FALSE, FALSE, NULL); - if (!hPosNotify) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedCreateNotifyEvent); - return DSOUND_Error; - } - - _DSOUND_BufferLength = 0; - _DSOUND_NumBuffers = 1; - posn.dwOffset = 0; - posn.hEventNotify = hPosNotify[0]; - - hr = IDirectSoundNotify_SetNotificationPositions(lpDSNotify, 1, &posn); - if (hr != DS_OK) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedSetNotify); - return DSOUND_Error; - } - - DSOUND_Installed = TRUE; - - DSOUND_SetErrorCode(DSOUND_Ok); - return DSOUND_Ok; -} - - -/* - * DSOUND_Shutdown - * Shuts down DirectSound and it's associates. - */ -int32_t DSOUND_Shutdown(void) -{ - int32_t i; - - if (DSOUND_Installed) initprintf("Uninitializing DirectSound...\n"); - - DSOUND_Installed = FALSE; - - DSOUND_StopPlayback(); - - if (lpDSNotify) - { - IDirectSoundNotify_Release(lpDSNotify); - lpDSNotify = NULL; - } - - if (hPosNotify) - { - for (i=0; i<_DSOUND_NumBuffers; i++) - { - if (hPosNotify[i]) CloseHandle(hPosNotify[i]); - } - free(hPosNotify); - hPosNotify = NULL; - } - - if (lpDSBSecondary) - { -// initprintf(" - Releasing secondary buffer\n"); - IDirectSoundBuffer_Stop(lpDSBSecondary); - IDirectSoundBuffer_Release(lpDSBSecondary); - lpDSBSecondary = NULL; - } - - if (lpDSBPrimary) - { -// initprintf(" - Releasing primary buffer\n"); - IDirectSoundBuffer_Release(lpDSBPrimary); - lpDSBPrimary = NULL; - } - - if (lpDS) - { -// initprintf(" - Releasing DirectSound object\n"); - IDirectSound_Release(lpDS); - lpDS = NULL; - } - - if (hDSoundDLL) - { -// initprintf(" - Unloading DSOUND.DLL\n"); - FreeLibrary(hDSoundDLL); - hDSoundDLL = NULL; - } - - DSOUND_SetErrorCode(DSOUND_Ok); - return DSOUND_Ok; -} - - -/* - * DSOUND_SetMixMode - * Bit of filler for the future. - */ -int32_t DSOUND_SetMixMode(int32_t mode) -{ - return mode; -} - - -//#define DEBUGAUDIO - -#ifdef DEBUGAUDIO -#include -#endif -static DWORD WINAPI isr(LPVOID parm) -{ - HANDLE *handles; - HRESULT hr; - int32_t rv; -#ifdef DEBUGAUDIO - int32_t h; -#endif - int32_t p; - LPVOID lockptr; DWORD lockbytes; - LPVOID lockptr2; DWORD lockbytes2; - - UNREFERENCED_PARAMETER(parm); - - handles = (HANDLE *)malloc(sizeof(HANDLE)*(1+_DSOUND_NumBuffers)); - if (!handles) return 1; - - handles[0] = isrfinish; - for (p=0; p<_DSOUND_NumBuffers; p++) - handles[p+1] = hPosNotify[p]; - -#ifdef DEBUGAUDIO - h = creat("audio.raw",S_IREAD|S_IWRITE); -#endif - - while (1) - { -#ifdef USE_OPENAL - AL_Update(); -#endif - rv = WaitForMultipleObjects(1+_DSOUND_NumBuffers, handles, FALSE, INFINITE); - - if (!(rv >= WAIT_OBJECT_0 && rv <= WAIT_OBJECT_0+1+_DSOUND_NumBuffers)) return -1; - - if (rv == WAIT_OBJECT_0) - { - // we've been asked to finish up - break; - } - - // otherwise we just service the interrupt - if (_DSOUND_CallBack) - { - DisableInterrupts(); - - p = _DSOUND_CallBack(rv-WAIT_OBJECT_0-1); -#ifdef DEBUGAUDIO - write(h, _DSOUND_MixBuffer + p*_DSOUND_BufferLength, _DSOUND_BufferLength); -#endif - - hr = IDirectSoundBuffer_Lock(lpDSBSecondary, p*_DSOUND_BufferLength, _DSOUND_BufferLength, - &lockptr, &lockbytes, &lockptr2, &lockbytes2, 0); - if (hr == DSERR_BUFFERLOST) - { - hr = IDirectSoundBuffer_Restore(lpDSBSecondary); - } - if (hr == DS_OK) - { - /* - #define copybuf(S,D,c) \ - ({ void *__S=(S), *__D=(D); int32_t __c=(c); \ - __asm__ __volatile__ ("rep; movsl" \ - : "+S" (__S), "+D" (__D), "+c" (__c) : : "memory", "cc"); \ - 0; }) - */ - //copybuf(_DSOUND_MixBuffer + p * _DSOUND_BufferLength, lockptr, _DSOUND_BufferLength >> 2); - Bmemcpy(lockptr, _DSOUND_MixBuffer + p * _DSOUND_BufferLength, _DSOUND_BufferLength); - IDirectSoundBuffer_Unlock(lpDSBSecondary, lockptr, lockbytes, lockptr2, lockbytes2); - } - - RestoreInterrupts(0); - } - } - -#ifdef DEBUGAUDIO - close(h); -#endif - - return 0; -} - - -/* - * DSOUND_BeginBufferedPlayback - * Spins off a thread that behaves somewhat like the SoundBlaster DMA ISR did. - */ -int32_t DSOUND_BeginBufferedPlayback(char *BufferStart, int32_t(*CallBackFunc)(int32_t), int32_t buffersize, int32_t numdivisions) -{ - DWORD threadid; - HRESULT hr; - DSBPOSITIONNOTIFY *posns; - int32_t i; - - _DSOUND_CallBack = CallBackFunc; - _DSOUND_MixBuffer = BufferStart; - - if (!lpDSBSecondary) return DSOUND_Error; - - if (isrthread) - { - DSOUND_StopPlayback(); - } - - isrfinish = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!isrfinish) - { - DSOUND_SetErrorCode(DSOUND_FailedCreateFinishEvent); - return DSOUND_Error; - } - - isrthread = CreateThread(NULL, 0, isr, NULL, CREATE_SUSPENDED, &threadid); - if (!isrthread) - { - DSOUND_SetErrorCode(DSOUND_FailedCreateThread); - return DSOUND_Error; - } - - hPosNotify = (HANDLE *)malloc(sizeof(HANDLE)*numdivisions); - if (!hPosNotify) - { - DSOUND_Shutdown(); - DSOUND_SetErrorCode(DSOUND_FailedSetNotify); - return DSOUND_Error; - } - - memset(hPosNotify, 0, sizeof(HANDLE)*numdivisions); - for (i=0; i -#include -//#include -#include "multivoc.h" -#include "ll_man.h" -#include "fx_man.h" - -#ifndef TRUE -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) -#endif - -static uint32_t FX_MixRate; - -static char tempbuf[2048]; -extern void initprintf(const char *, ...); - -int32_t FX_SoundDevice = -1; -int32_t FX_ErrorCode = FX_Ok; -int32_t 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 -( - int32_t ErrorNumber -) - -{ - char *ErrorString; - - switch (ErrorNumber) - { - case FX_Warning : - case FX_Error : - ErrorString = FX_ErrorString(FX_ErrorCode); - break; - - case FX_Ok : - ErrorString = "Fx ok."; - break; - - case FX_ASSVersion : - ErrorString = "Apogee Sound System Version 0 " - "Programmed by Jim Dose\n" - "(c) Copyright 1995 James R. Dose. All Rights Reserved.\n"; - break; - - case FX_BlasterError : - case FX_SoundCardError : - ErrorString = "Sound device 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); -} - - -#if 0 -/*--------------------------------------------------------------------- - Function: FX_SetupCard - - Sets the configuration of a sound device. ----------------------------------------------------------------------*/ - -int32_t FX_SetupCard -( - int32_t SoundCard, - fx_device *device -) - -{ - int32_t status; - int32_t DeviceStatus; - - FX_SoundDevice = SoundCard; - - status = FX_Ok; - FX_SetErrorCode(FX_Ok); - - switch (SoundCard) - { - case SoundBlaster : - DeviceStatus = BLASTER_Init(); - if (DeviceStatus != BLASTER_Ok) - { - FX_SetErrorCode(FX_SoundCardError); - status = FX_Error; - break; - } - - device->MaxVoices = 32; - BLASTER_GetCardInfo(&device->MaxSampleBits, &device->MaxChannels); - break; - - default : - FX_SetErrorCode(FX_InvalidCard); - status = FX_Error; - } - return(status); -} -#endif - - -#if 0 -/*--------------------------------------------------------------------- - Function: FX_GetBlasterSettings - - Returns the current BLASTER environment variable settings. ----------------------------------------------------------------------*/ - -int32_t FX_GetBlasterSettings -( - fx_blaster_config *blaster -) - -{ - int32_t status; - BLASTER_CONFIG Blaster; - - FX_SetErrorCode(FX_Ok); - - status = BLASTER_GetEnv(&Blaster); - if (status != BLASTER_Ok) - { - FX_SetErrorCode(FX_BlasterError); - return(FX_Error); - } - - blaster->Type = Blaster.Type; - blaster->Address = Blaster.Address; - blaster->Interrupt = Blaster.Interrupt; - blaster->Dma8 = Blaster.Dma8; - blaster->Dma16 = Blaster.Dma16; - blaster->Midi = Blaster.Midi; - blaster->Emu = Blaster.Emu; - - return(FX_Ok); -} -#endif - - -#if 0 -/*--------------------------------------------------------------------- - Function: FX_SetupSoundBlaster - - Handles manual setup of the Sound Blaster information. ----------------------------------------------------------------------*/ - -int32_t FX_SetupSoundBlaster -( - fx_blaster_config blaster, - int32_t *MaxVoices, - int32_t *MaxSampleBits, - int32_t *MaxChannels -) - -{ - int32_t DeviceStatus; - BLASTER_CONFIG Blaster; - - FX_SetErrorCode(FX_Ok); - - FX_SoundDevice = SoundBlaster; - - Blaster.Type = blaster.Type; - Blaster.Address = blaster.Address; - Blaster.Interrupt = blaster.Interrupt; - Blaster.Dma8 = blaster.Dma8; - Blaster.Dma16 = blaster.Dma16; - Blaster.Midi = blaster.Midi; - Blaster.Emu = blaster.Emu; - - BLASTER_SetCardSettings(Blaster); - - DeviceStatus = BLASTER_Init(); - if (DeviceStatus != BLASTER_Ok) - { - FX_SetErrorCode(FX_SoundCardError); - return(FX_Error); - } - - *MaxVoices = 8; - BLASTER_GetCardInfo(MaxSampleBits, MaxChannels); - - return(FX_Ok); -} -#endif - - -/*--------------------------------------------------------------------- - Function: FX_Init - - Selects which sound device to use. ----------------------------------------------------------------------*/ - -int32_t FX_Init -( - int32_t SoundCard, - int32_t numvoices, - int32_t numchannels, - int32_t samplebits, - uint32_t mixrate -) - -{ - int32_t status; - int32_t devicestatus; - - if (FX_Installed) - { - FX_Shutdown(); - } - - FX_MixRate = mixrate; - - status = FX_Ok; - FX_SoundDevice = SoundCard; - - devicestatus = MV_Init(SoundCard, FX_MixRate, numvoices, - numchannels, samplebits); - if (devicestatus != MV_Ok) - { - FX_SetErrorCode(FX_MultiVocError); - status = FX_Error; - } - - if (status == FX_Ok) - { - FX_Installed = TRUE; - } - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: FX_Shutdown - - Terminates use of sound device. ----------------------------------------------------------------------*/ - -int32_t FX_Shutdown -( - void -) - -{ - int32_t status; - - if (!FX_Installed) - { - return(FX_Ok); - } - - status = MV_Shutdown(); - if (status != MV_Ok) - { - FX_SetErrorCode(FX_MultiVocError); - status = FX_Error; - } - - FX_Installed = FALSE; - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetCallback - - Sets the function to call when a voice is done. ----------------------------------------------------------------------*/ - -int32_t FX_SetCallBack -( - void(*function)(uint32_t) -) - -{ - MV_SetCallBack(function); - - return(FX_Ok); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetVolume - - Sets the volume of the current sound device. ----------------------------------------------------------------------*/ - -void FX_SetVolume -( - int32_t volume -) - -{ - MV_SetVolume(volume); -} - - -/*--------------------------------------------------------------------- - Function: FX_GetVolume - - Returns the volume of the current sound device. ----------------------------------------------------------------------*/ - -int32_t FX_GetVolume -( - void -) - -{ - return MV_GetVolume(); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetReverseStereo - - Set the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -void FX_SetReverseStereo -( - int32_t setting -) - -{ - MV_SetReverseStereo(setting); -} - - -/*--------------------------------------------------------------------- - Function: FX_GetReverseStereo - - Returns the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -int32_t FX_GetReverseStereo -( - void -) - -{ - return MV_GetReverseStereo(); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetReverb - - Sets the reverb level. ----------------------------------------------------------------------*/ - -void FX_SetReverb -( - int32_t reverb -) - -{ - MV_SetReverb(reverb); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetFastReverb - - Sets the reverb level. ----------------------------------------------------------------------*/ - -void FX_SetFastReverb -( - int32_t reverb -) - -{ - MV_SetFastReverb(reverb); -} - - -/*--------------------------------------------------------------------- - Function: FX_GetMaxReverbDelay - - Returns the maximum delay time for reverb. ----------------------------------------------------------------------*/ - -int32_t FX_GetMaxReverbDelay -( - void -) - -{ - return MV_GetMaxReverbDelay(); -} - - -/*--------------------------------------------------------------------- - Function: FX_GetReverbDelay - - Returns the current delay time for reverb. ----------------------------------------------------------------------*/ - -int32_t FX_GetReverbDelay -( - void -) - -{ - return MV_GetReverbDelay(); -} - - -/*--------------------------------------------------------------------- - Function: FX_SetReverbDelay - - Sets the delay level of reverb to add to mix. ----------------------------------------------------------------------*/ - -void FX_SetReverbDelay -( - int32_t delay -) - -{ - MV_SetReverbDelay(delay); -} - - -/*--------------------------------------------------------------------- - Function: FX_VoiceAvailable - - Checks if a voice can be play at the specified priority. ----------------------------------------------------------------------*/ - -int32_t FX_VoiceAvailable -( - int32_t priority -) - -{ - return MV_VoiceAvailable(priority); -} - -/*--------------------------------------------------------------------- - Function: FX_EndLooping - - Stops the voice associated with the specified handle from looping - without stoping the sound. ----------------------------------------------------------------------*/ - -int32_t FX_EndLooping -( - int32_t handle -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_SetPan -( - int32_t handle, - int32_t vol, - int32_t left, - int32_t right -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_SetPitch -( - int32_t handle, - int32_t pitchoffset -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_SetFrequency -( - int32_t handle, - int32_t frequency -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_PlayVOC -( - char *ptr, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_PlayLoopedVOC -( - char *ptr, - int32_t loopstart, - int32_t loopend, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t handle; - - handle = MV_PlayLoopedVOC(ptr, loopstart, loopend, pitchoffset, - vol, left, right, priority, callbackval); - if (handle < MV_Ok) - { - Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); - initprintf(tempbuf); - FX_SetErrorCode(FX_MultiVocError); - handle = FX_Warning; - } - - return(handle); -} - - -/*--------------------------------------------------------------------- - Function: FX_PlayWAV - - Begin playback of sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int32_t FX_PlayWAV -( - char *ptr, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t 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_PlayOGG - - Begin playback of sound data with the given volume and priority. ----------------------------------------------------------------------*/ - -int32_t FX_PlayOGG -( - char *ptr, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t handle; - - handle = MV_PlayOGG(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. ----------------------------------------------------------------------*/ - -int32_t FX_PlayLoopedWAV -( - char *ptr, - int32_t loopstart, - int32_t loopend, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t handle; - - handle = MV_PlayLoopedWAV(ptr, loopstart, loopend, - pitchoffset, vol, left, right, priority, callbackval); - if (handle < MV_Ok) - { - Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); - initprintf(tempbuf); - FX_SetErrorCode(FX_MultiVocError); - handle = FX_Warning; - } - - return(handle); -} - -int32_t FX_PlayLoopedOGG -( - char *ptr, - int32_t loopstart, - int32_t loopend, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t handle; - - handle = MV_PlayLoopedOGG(ptr, loopstart, loopend, - pitchoffset, vol, left, right, priority, callbackval); - if (handle < MV_Ok) - { - Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); - initprintf(tempbuf); - FX_SetErrorCode(FX_MultiVocError); - handle = FX_Warning; - } - - return(handle); -} - -/*--------------------------------------------------------------------- - Function: FX_PlayVOC3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int32_t FX_PlayVOC3D -( - char *ptr, - int32_t pitchoffset, - int32_t angle, - int32_t distance, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t handle; - - handle = MV_PlayVOC3D(ptr, pitchoffset, angle, distance, - priority, callbackval); - if (handle < MV_Ok) - { - FX_SetErrorCode(FX_MultiVocError); - handle = FX_Warning; - } - - return(handle); -} - -int32_t FX_PlayOGG3D -( - char *ptr, - int32_t pitchoffset, - int32_t angle, - int32_t distance, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t handle; - - handle = MV_PlayOGG3D(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. ----------------------------------------------------------------------*/ - -int32_t FX_PlayWAV3D -( - char *ptr, - int32_t pitchoffset, - int32_t angle, - int32_t distance, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_PlayRaw -( - char *ptr, - uint32_t length, - uint32_t rate, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_PlayLoopedRaw -( - char *ptr, - uint32_t length, - char *loopstart, - char *loopend, - uint32_t rate, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_Pan3D -( - int32_t handle, - int32_t angle, - int32_t distance -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_SoundActive -( - int32_t handle -) - -{ - return(MV_VoicePlaying(handle)); -} - - -/*--------------------------------------------------------------------- - Function: FX_SoundsPlaying - - Reports the number of voices playing. ----------------------------------------------------------------------*/ - -int32_t FX_SoundsPlaying -( - void -) - -{ - return(MV_VoicesPlaying()); -} - - -/*--------------------------------------------------------------------- - Function: FX_StopSound - - Halts playback of a specific voice ----------------------------------------------------------------------*/ - -int32_t FX_StopSound -( - int32_t handle -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_StopAllSounds -( - void -) - -{ - int32_t 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. ----------------------------------------------------------------------*/ - -int32_t FX_StartDemandFeedPlayback -( - void(*function)(char **ptr, uint32_t *length), - int32_t rate, - int32_t pitchoffset, - int32_t vol, - int32_t left, - int32_t right, - int32_t priority, - uint32_t callbackval -) - -{ - int32_t 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); -} - -#if 0 -/*--------------------------------------------------------------------- - Function: FX_StartRecording - - Starts the sound recording engine. ----------------------------------------------------------------------*/ - -int32_t FX_StartRecording -( - int32_t MixRate, - void(*function)(char *ptr, int32_t length) -) - -{ - int32_t status; - - switch (FX_SoundDevice) - { - case SoundBlaster : - status = MV_StartRecording(MixRate, function); - if (status != MV_Ok) - { - FX_SetErrorCode(FX_MultiVocError); - status = FX_Warning; - } - else - { - status = FX_Ok; - } - break; - - default : - FX_SetErrorCode(FX_InvalidCard); - status = FX_Warning; - break; - } - - return(status); -} -#endif - -#if 0 -/*--------------------------------------------------------------------- - Function: FX_StopRecord - - Stops the sound record engine. ----------------------------------------------------------------------*/ - -void FX_StopRecord -( - void -) - -{ - // Stop sound playback - switch (FX_SoundDevice) - { - case SoundBlaster : - MV_StopRecord(); - break; - } -} -#endif - -extern void MUSIC_Update(void); -void AudioUpdate(void) { MUSIC_Update(); } diff --git a/polymer/eduke32/source/jaudiolib/fx_man.h b/polymer/eduke32/source/jaudiolib/fx_man.h deleted file mode 100644 index e0393a123..000000000 --- a/polymer/eduke32/source/jaudiolib/fx_man.h +++ /dev/null @@ -1,143 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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 "compat.h" - -typedef struct - { - int32_t MaxVoices; - int32_t MaxSampleBits; - int32_t MaxChannels; - } fx_device; - -#define MonoFx 1 -#define StereoFx 2 - -typedef struct - { - uint32_t Address; - uint32_t Type; - uint32_t Interrupt; - uint32_t Dma8; - uint32_t Dma16; - uint32_t Midi; - uint32_t 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( int32_t ErrorNumber ); -//int32_t FX_SetupCard( int32_t SoundCard, fx_device *device ); -//int32_t FX_GetBlasterSettings( fx_blaster_config *blaster ); -//int32_t FX_SetupSoundBlaster( fx_blaster_config blaster, int32_t *MaxVoices, int32_t *MaxSampleBits, int32_t *MaxChannels ); -int32_t FX_Init( int32_t SoundCard, int32_t numvoices, int32_t numchannels, int32_t samplebits, uint32_t mixrate ); -int32_t FX_Shutdown( void ); -int32_t FX_SetCallBack( void ( *function )( uint32_t ) ); -void FX_SetVolume( int32_t volume ); -int32_t FX_GetVolume( void ); - -void FX_SetReverseStereo( int32_t setting ); -int32_t FX_GetReverseStereo( void ); -void FX_SetReverb( int32_t reverb ); -void FX_SetFastReverb( int32_t reverb ); -int32_t FX_GetMaxReverbDelay( void ); -int32_t FX_GetReverbDelay( void ); -void FX_SetReverbDelay( int32_t delay ); - -int32_t FX_VoiceAvailable( int32_t priority ); -int32_t FX_EndLooping( int32_t handle ); -int32_t FX_SetPan( int32_t handle, int32_t vol, int32_t left, int32_t right ); -int32_t FX_SetPitch( int32_t handle, int32_t pitchoffset ); -int32_t FX_SetFrequency( int32_t handle, int32_t frequency ); - -int32_t FX_PlayVOC( char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, - int32_t priority, uint32_t callbackval ); -int32_t FX_PlayLoopedVOC( char *ptr, int32_t loopstart, int32_t loopend, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t FX_PlayWAV( char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, - int32_t priority, uint32_t callbackval ); -int32_t FX_PlayLoopedWAV( char *ptr, int32_t loopstart, int32_t loopend, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t FX_PlayLoopedOGG( char *ptr, int32_t loopstart, int32_t loopend, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t FX_PlayOGG3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, - int32_t priority, uint32_t callbackval ); -int32_t FX_PlayVOC3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, - int32_t priority, uint32_t callbackval ); -int32_t FX_PlayWAV3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, - int32_t priority, uint32_t callbackval ); -int32_t FX_PlayRaw( char *ptr, uint32_t length, uint32_t rate, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t FX_PlayLoopedRaw( char *ptr, uint32_t length, char *loopstart, - char *loopend, uint32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, - int32_t right, int32_t priority, uint32_t callbackval ); -int32_t FX_Pan3D( int32_t handle, int32_t angle, int32_t distance ); -int32_t FX_SoundActive( int32_t handle ); -int32_t FX_SoundsPlaying( void ); -int32_t FX_StopSound( int32_t handle ); -int32_t FX_StopAllSounds( void ); -int32_t FX_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *length ), - int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, - int32_t priority, uint32_t callbackval ); -int32_t FX_StartRecording( int32_t MixRate, void ( *function )( char *ptr, int32_t length ) ); -void FX_StopRecord( void ); - -void FX_Update(void); -#endif diff --git a/polymer/eduke32/source/jaudiolib/interrup.h b/polymer/eduke32/source/jaudiolib/interrup.h deleted file mode 100644 index caad3b7f0..000000000 --- a/polymer/eduke32/source/jaudiolib/interrup.h +++ /dev/null @@ -1,50 +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 - -uint32_t DisableInterrupts( void ); -void RestoreInterrupts( uint32_t flags ); - -#ifdef PLAT_DOS -#pragma aux DisableInterrupts = \ - "pushfd", \ - "pop eax", \ - "cli" \ - modify [ eax ]; - -#pragma aux RestoreInterrupts = \ - "push eax", \ - "popfd" \ - parm [ eax ]; -#endif - -#endif diff --git a/polymer/eduke32/source/jaudiolib/linklist.h b/polymer/eduke32/source/jaudiolib/linklist.h deleted file mode 100644 index 6b593bbbc..000000000 --- a/polymer/eduke32/source/jaudiolib/linklist.h +++ /dev/null @@ -1,119 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -#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/polymer/eduke32/source/jaudiolib/ll_man.c b/polymer/eduke32/source/jaudiolib/ll_man.c deleted file mode 100644 index c456d86fb..000000000 --- a/polymer/eduke32/source/jaudiolib/ll_man.c +++ /dev/null @@ -1,103 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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. -**********************************************************************/ - -#include -#include "ll_man.h" - -#define OFFSET( structure, offset ) \ - ( *( ( char ** )&( structure )[ offset ] ) ) - - -/********************************************************************** - - Memory locked functions: - -**********************************************************************/ - - -void LL_AddNode -( - char *item, - char **head, - char **tail, - int32_t next, - int32_t 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, - int32_t next, - int32_t 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; -} - - diff --git a/polymer/eduke32/source/jaudiolib/ll_man.h b/polymer/eduke32/source/jaudiolib/ll_man.h deleted file mode 100644 index 7d81f464b..000000000 --- a/polymer/eduke32/source/jaudiolib/ll_man.h +++ /dev/null @@ -1,77 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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 - -#include "compat.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, int32_t next, int32_t prev ); -void LL_RemoveNode( char *node, char **head, char **tail, int32_t next, int32_t prev ); - -#define LL_AddToHead( type, listhead, node ) \ - LL_AddNode( ( char * )( node ), \ - ( char ** )&( ( listhead )->start ), \ - ( char ** )&( ( listhead )->end ), \ - ( int32_t )&( ( type * ) 0 )->next, \ - ( int32_t )&( ( type * ) 0 )->prev ) - -#define LL_AddToTail( type, listhead, node ) \ - LL_AddNode( ( char * )( node ), \ - ( char ** )&( ( listhead )->end ), \ - ( char ** )&( ( listhead )->start ), \ - ( int32_t )&( ( type * ) 0 )->prev, \ - ( int32_t )&( ( type * ) 0 )->next ) - -#define LL_Remove( type, listhead, node ) \ - LL_RemoveNode( ( char * )( node ), \ - ( char ** )&( ( listhead )->start ), \ - ( char ** )&( ( listhead )->end ), \ - ( int32_t )&( ( type * ) 0 )->next, \ - ( int32_t )&( ( type * ) 0 )->prev ) - -#define LL_NextNode( node ) ( ( node )->next ) -#define LL_PreviousNode( node ) ( ( node )->prev ) - -#endif diff --git a/polymer/eduke32/source/jaudiolib/midi.c b/polymer/eduke32/source/jaudiolib/midi.c deleted file mode 100644 index 870665a11..000000000 --- a/polymer/eduke32/source/jaudiolib/midi.c +++ /dev/null @@ -1,2069 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - module: MIDI.C - - author: James R. Dose - date: May 25, 1994 - - Midi song file playback routines. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include -#include -#include "standard.h" -#include "music.h" -#include "_midi.h" -#include "midi.h" -#include "mpu401.h" -#include "compat.h" - -#define WIN32_LEAN_AND_MEAN -#include - -extern int32_t MUSIC_SoundDevice; - -static const int32_t _MIDI_CommandLengths[ NUM_MIDI_CHANNELS ] = -{ - 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0 -}; - -static int32_t(*_MIDI_RerouteFunctions[ NUM_MIDI_CHANNELS ]) -( - int32_t event, - int32_t c1, - int32_t c2 -) = -{ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL -}; - -static track *_MIDI_TrackPtr = NULL; -static int32_t _MIDI_TrackMemSize; -static int32_t _MIDI_NumTracks; - -static int32_t _MIDI_SongActive = FALSE; -static int32_t _MIDI_SongLoaded = FALSE; -static int32_t _MIDI_Loop = FALSE; - -static int32_t _MIDI_Division; -static int32_t _MIDI_Tick = 0; -static int32_t _MIDI_Beat = 1; -static int32_t _MIDI_Measure = 1; -static uint32_t _MIDI_Time; -static int32_t _MIDI_BeatsPerMeasure; -static int32_t _MIDI_TicksPerBeat; -static int32_t _MIDI_TimeBase; -static int32_t _MIDI_FPSecondsPerTick; -static uint32_t _MIDI_TotalTime; -static int32_t _MIDI_TotalTicks; -static int32_t _MIDI_TotalBeats; -static int32_t _MIDI_TotalMeasures; - -uint32_t _MIDI_PositionInTicks; -uint32_t _MIDI_GlobalPositionInTicks; - -static int32_t _MIDI_Context; - -static int32_t _MIDI_ActiveTracks; -static int32_t _MIDI_TotalVolume = MIDI_MaxVolume; - -static int32_t _MIDI_ChannelVolume[ NUM_MIDI_CHANNELS ]; -static int32_t _MIDI_UserChannelVolume[ NUM_MIDI_CHANNELS ] = -{ - 256, 256, 256, 256, 256, 256, 256, 256, - 256, 256, 256, 256, 256, 256, 256, 256 -}; - -static midifuncs *_MIDI_Funcs = NULL; - -static int32_t Reset = FALSE; - -int32_t MIDI_Tempo = 120; - -char MIDI_PatchMap[ 128 ]; - - -/********************************************************************** - - Memory locked functions: - -**********************************************************************/ - - -/*--------------------------------------------------------------------- - Function: _MIDI_ReadNumber - - Reads a variable length number from a MIDI track. ----------------------------------------------------------------------*/ - -static int32_t _MIDI_ReadNumber -( - void *from, - size_t size -) - -{ - char *FromPtr; - int32_t value; - - if (size > 4) - { - size = 4; - } - - FromPtr = (char *)from; - - value = 0; - while (size--) - { - value <<= 8; - value += *FromPtr++; - } - - return(value); -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_ReadDelta - - Reads a variable length encoded delta delay time from the MIDI data. ----------------------------------------------------------------------*/ - -static int32_t _MIDI_ReadDelta -( - track *ptr -) - -{ - int32_t value; - char c; - - GET_NEXT_EVENT(ptr, value); - - if (value & 0x80) - { - value &= 0x7f; - do - { - GET_NEXT_EVENT(ptr, c); - value = (value << 7) + (c & 0x7f); - } - while (c & 0x80); - } - - return(value); -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_ResetTracks - - Sets the track pointers to the beginning of the song. ----------------------------------------------------------------------*/ - -static void _MIDI_ResetTracks -( - void -) - -{ - int32_t i; - track *ptr; - - _MIDI_Tick = 0; - _MIDI_Beat = 1; - _MIDI_Measure = 1; - _MIDI_Time = 0; - _MIDI_BeatsPerMeasure = 4; - _MIDI_TicksPerBeat = _MIDI_Division; - _MIDI_TimeBase = 4; - - _MIDI_PositionInTicks = 0; - //_MIDI_GlobalPositionInTicks = 0; - _MIDI_ActiveTracks = 0; - _MIDI_Context = 0; - - ptr = _MIDI_TrackPtr; - for (i = 0; i < _MIDI_NumTracks; i++) - { - ptr->pos = ptr->start; - ptr->delay = _MIDI_ReadDelta(ptr); - ptr->active = ptr->EMIDI_IncludeTrack; - ptr->RunningStatus = 0; - ptr->currentcontext = 0; - ptr->context[ 0 ].loopstart = ptr->start; - ptr->context[ 0 ].loopcount = 0; - - if (ptr->active) - { - _MIDI_ActiveTracks++; - } - - ptr++; - } -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_AdvanceTick - - Increment tick counters. ----------------------------------------------------------------------*/ - -static void _MIDI_AdvanceTick -( - void -) - -{ - _MIDI_PositionInTicks++; - _MIDI_Time += _MIDI_FPSecondsPerTick; - - _MIDI_Tick++; - while (_MIDI_Tick > _MIDI_TicksPerBeat) - { - _MIDI_Tick -= _MIDI_TicksPerBeat; - _MIDI_Beat++; - } - while (_MIDI_Beat > _MIDI_BeatsPerMeasure) - { - _MIDI_Beat -= _MIDI_BeatsPerMeasure; - _MIDI_Measure++; - } -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_SysEx - - Interpret SysEx Event. ----------------------------------------------------------------------*/ - -static void _MIDI_SysEx -( - track *Track -) - -{ - int32_t length; - - length = _MIDI_ReadDelta(Track); - Track->pos += length; -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_MetaEvent - - Interpret Meta Event. ----------------------------------------------------------------------*/ - -static void _MIDI_MetaEvent -( - track *Track -) - -{ - int32_t command; - int32_t length; - int32_t denominator; - int32_t tempo; - - GET_NEXT_EVENT(Track, command); - GET_NEXT_EVENT(Track, length); - - switch (command) - { - case MIDI_END_OF_TRACK : - Track->active = FALSE; - - _MIDI_ActiveTracks--; - break; - - case MIDI_TEMPO_CHANGE : - tempo = 60000000L / _MIDI_ReadNumber(Track->pos, 3); - MIDI_SetTempo(tempo); - break; - - case MIDI_TIME_SIGNATURE : - if ((_MIDI_Tick > 0) || (_MIDI_Beat > 1)) - { - _MIDI_Measure++; - } - - _MIDI_Tick = 0; - _MIDI_Beat = 1; - - _MIDI_BeatsPerMeasure = (int32_t)*Track->pos; - denominator = (int32_t)*(Track->pos + 1); - _MIDI_TimeBase = 1; - while (denominator > 0) - { - _MIDI_TimeBase += _MIDI_TimeBase; - denominator--; - } - _MIDI_TicksPerBeat = (_MIDI_Division * 4) / _MIDI_TimeBase; - break; - } - - Track->pos += length; -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_InterpretControllerInfo - - Interprets the MIDI controller info. ----------------------------------------------------------------------*/ - -static int32_t _MIDI_InterpretControllerInfo -( - track *Track, - int32_t TimeSet, - int32_t channel, - int32_t c1, - int32_t c2 -) - -{ - track *trackptr; - int32_t tracknum; - int32_t loopcount; - - switch (c1) - { - case MIDI_MONO_MODE_ON : - Track->pos++; - break; - - case MIDI_VOLUME : - if (!Track->EMIDI_VolumeChange) - { - _MIDI_SetChannelVolume(channel, c2); - } - break; - - case EMIDI_INCLUDE_TRACK : - case EMIDI_EXCLUDE_TRACK : - break; - - case EMIDI_PROGRAM_CHANGE : - if (Track->EMIDI_ProgramChange) - { - _MIDI_Funcs->ProgramChange(channel, MIDI_PatchMap[ c2 & 0x7f ]); - } - break; - - case EMIDI_VOLUME_CHANGE : - if (Track->EMIDI_VolumeChange) - { - _MIDI_SetChannelVolume(channel, c2); - } - break; - - case EMIDI_CONTEXT_START : - break; - - case EMIDI_CONTEXT_END : - if ((Track->currentcontext == _MIDI_Context) || - (_MIDI_Context < 0) || - (Track->context[ _MIDI_Context ].pos == NULL)) - { - break; - } - - Track->currentcontext = _MIDI_Context; - Track->context[ 0 ].loopstart = Track->context[ _MIDI_Context ].loopstart; - Track->context[ 0 ].loopcount = Track->context[ _MIDI_Context ].loopcount; - Track->pos = Track->context[ _MIDI_Context ].pos; - Track->RunningStatus = Track->context[ _MIDI_Context ].RunningStatus; - - if (TimeSet) - { - break; - } - - _MIDI_Time = Track->context[ _MIDI_Context ].time; - _MIDI_FPSecondsPerTick = Track->context[ _MIDI_Context ].FPSecondsPerTick; - _MIDI_Tick = Track->context[ _MIDI_Context ].tick; - _MIDI_Beat = Track->context[ _MIDI_Context ].beat; - _MIDI_Measure = Track->context[ _MIDI_Context ].measure; - _MIDI_BeatsPerMeasure = Track->context[ _MIDI_Context ].BeatsPerMeasure; - _MIDI_TicksPerBeat = Track->context[ _MIDI_Context ].TicksPerBeat; - _MIDI_TimeBase = Track->context[ _MIDI_Context ].TimeBase; - TimeSet = TRUE; - break; - - case EMIDI_LOOP_START : - case EMIDI_SONG_LOOP_START : - if (c2 == 0) - { - loopcount = EMIDI_INFINITE; - } - else - { - loopcount = c2; - } - - if (c1 == EMIDI_SONG_LOOP_START) - { - trackptr = _MIDI_TrackPtr; - tracknum = _MIDI_NumTracks; - } - else - { - trackptr = Track; - tracknum = 1; - } - - while (tracknum > 0) - { - trackptr->context[ 0 ].loopcount = loopcount; - trackptr->context[ 0 ].pos = trackptr->pos; - trackptr->context[ 0 ].loopstart = trackptr->pos; - trackptr->context[ 0 ].RunningStatus = trackptr->RunningStatus; - trackptr->context[ 0 ].active = trackptr->active; - trackptr->context[ 0 ].delay = trackptr->delay; - trackptr->context[ 0 ].time = _MIDI_Time; - trackptr->context[ 0 ].FPSecondsPerTick = _MIDI_FPSecondsPerTick; - trackptr->context[ 0 ].tick = _MIDI_Tick; - trackptr->context[ 0 ].beat = _MIDI_Beat; - trackptr->context[ 0 ].measure = _MIDI_Measure; - trackptr->context[ 0 ].BeatsPerMeasure = _MIDI_BeatsPerMeasure; - trackptr->context[ 0 ].TicksPerBeat = _MIDI_TicksPerBeat; - trackptr->context[ 0 ].TimeBase = _MIDI_TimeBase; - trackptr++; - tracknum--; - } - break; - - case EMIDI_LOOP_END : - case EMIDI_SONG_LOOP_END : - if ((c2 != EMIDI_END_LOOP_VALUE) || - (Track->context[ 0 ].loopstart == NULL) || - (Track->context[ 0 ].loopcount == 0)) - { - break; - } - - if (c1 == EMIDI_SONG_LOOP_END) - { - trackptr = _MIDI_TrackPtr; - tracknum = _MIDI_NumTracks; - _MIDI_ActiveTracks = 0; - } - else - { - trackptr = Track; - tracknum = 1; - _MIDI_ActiveTracks--; - } - - while (tracknum > 0) - { - if (trackptr->context[ 0 ].loopcount != EMIDI_INFINITE) - { - trackptr->context[ 0 ].loopcount--; - } - - trackptr->pos = trackptr->context[ 0 ].loopstart; - trackptr->RunningStatus = trackptr->context[ 0 ].RunningStatus; - trackptr->delay = trackptr->context[ 0 ].delay; - trackptr->active = trackptr->context[ 0 ].active; - if (trackptr->active) - { - _MIDI_ActiveTracks++; - } - - if (!TimeSet) - { - _MIDI_Time = trackptr->context[ 0 ].time; - _MIDI_FPSecondsPerTick = trackptr->context[ 0 ].FPSecondsPerTick; - _MIDI_Tick = trackptr->context[ 0 ].tick; - _MIDI_Beat = trackptr->context[ 0 ].beat; - _MIDI_Measure = trackptr->context[ 0 ].measure; - _MIDI_BeatsPerMeasure = trackptr->context[ 0 ].BeatsPerMeasure; - _MIDI_TicksPerBeat = trackptr->context[ 0 ].TicksPerBeat; - _MIDI_TimeBase = trackptr->context[ 0 ].TimeBase; - TimeSet = TRUE; - } - - trackptr++; - tracknum--; - } - break; - - default : - if (_MIDI_Funcs->ControlChange) - { - _MIDI_Funcs->ControlChange(channel, c1, c2); - } - } - - return TimeSet; -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_ServiceRoutine - - Task that interperates the MIDI data. ----------------------------------------------------------------------*/ - -static int32_t _MIDI_ServiceRoutine(void) -{ - int32_t event; - int32_t channel; - int32_t command; - track *Track; - int32_t tracknum; - int32_t status; - int32_t c1 = 0; - int32_t c2 = 0; - int32_t TimeSet = FALSE; - - if (_MIDI_SongActive) - { - Track = _MIDI_TrackPtr; - tracknum = 0; - while (tracknum < _MIDI_NumTracks) - { - while ((Track->active) && (Track->delay == 0)) - { - GET_NEXT_EVENT(Track, event); - - if (GET_MIDI_COMMAND(event) == MIDI_SPECIAL) - { - switch (event) - { - case MIDI_SYSEX : - case MIDI_SYSEX_CONTINUE : - _MIDI_SysEx(Track); - break; - - case MIDI_META_EVENT : - _MIDI_MetaEvent(Track); - break; - } - - if (Track->active) - { - Track->delay = _MIDI_ReadDelta(Track); - } - continue; - } - - if (event & MIDI_RUNNING_STATUS) - { - Track->RunningStatus = event; - } - else - { - event = Track->RunningStatus; - Track->pos--; - } - - channel = GET_MIDI_CHANNEL(event); - command = GET_MIDI_COMMAND(event); - - if (_MIDI_CommandLengths[ command ] > 0) - { - GET_NEXT_EVENT(Track, c1); - if (_MIDI_CommandLengths[ command ] > 1) - { - GET_NEXT_EVENT(Track, c2); - } - } - - if (_MIDI_RerouteFunctions[ channel ] != NULL) - { - status = _MIDI_RerouteFunctions[ channel ](event, c1, c2); - - if (status == MIDI_DONT_PLAY) - { - Track->delay = _MIDI_ReadDelta(Track); - continue; - } - } - - switch (command) - { - case MIDI_NOTE_OFF : - if (_MIDI_Funcs->NoteOff) - { - _MIDI_Funcs->NoteOff(channel, c1, c2); - } - break; - - case MIDI_NOTE_ON : - if (_MIDI_Funcs->NoteOn) - { - _MIDI_Funcs->NoteOn(channel, c1, c2); - } - break; - - case MIDI_POLY_AFTER_TCH : - if (_MIDI_Funcs->PolyAftertouch) - { - _MIDI_Funcs->PolyAftertouch(channel, c1, c2); - } - break; - - case MIDI_CONTROL_CHANGE : - TimeSet = _MIDI_InterpretControllerInfo(Track, TimeSet, channel, c1, c2); - break; - - case MIDI_PROGRAM_CHANGE : - if ((_MIDI_Funcs->ProgramChange) && (!Track->EMIDI_ProgramChange)) - { - _MIDI_Funcs->ProgramChange(channel, MIDI_PatchMap[ c1 & 0x7f ]); - } - break; - - case MIDI_AFTER_TOUCH : - if (_MIDI_Funcs->ChannelAftertouch) - { - _MIDI_Funcs->ChannelAftertouch(channel, c1); - } - break; - - case MIDI_PITCH_BEND : - if (_MIDI_Funcs->PitchBend) - { - _MIDI_Funcs->PitchBend(channel, c1, c2); - } - break; - - default : - break; - } - - Track->delay = _MIDI_ReadDelta(Track); - } - - Track->delay--; - Track++; - tracknum++; - - if (_MIDI_ActiveTracks == 0) - { - _MIDI_ResetTracks(); - if (_MIDI_Loop) - { - tracknum = 0; - Track = _MIDI_TrackPtr; - } - else - { - _MIDI_SongActive = FALSE; - break; - } - } - } - - _MIDI_AdvanceTick(); - _MIDI_GlobalPositionInTicks++; - } - return 0; -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_SendControlChange - - Sends a control change to the proper device ----------------------------------------------------------------------*/ - -static int32_t _MIDI_SendControlChange -( - int32_t channel, - int32_t c1, - int32_t c2 -) - -{ - int32_t status; - - if (_MIDI_RerouteFunctions[ channel ] != NULL) - { - status = _MIDI_RerouteFunctions[ channel ](0xB0 + channel, - c1, c2); - if (status == MIDI_DONT_PLAY) - { - return(MIDI_Ok); - } - } - - if (_MIDI_Funcs == NULL) - { - return(MIDI_Error); - } - - if (_MIDI_Funcs->ControlChange == NULL) - { - return(MIDI_Error); - } - - _MIDI_Funcs->ControlChange(channel, c1, c2); - - return(MIDI_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_RerouteMidiChannel - - Sets callback function to reroute MIDI commands from specified - function. ----------------------------------------------------------------------*/ - -void MIDI_RerouteMidiChannel -( - int32_t channel, - int32_t(*function)(int32_t event, int32_t c1, int32_t c2) -) - -{ - if ((channel >= 1) && (channel <= 16)) - { - _MIDI_RerouteFunctions[ channel - 1 ] = function; - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_AllNotesOff - - Sends all notes off commands on all midi channels. ----------------------------------------------------------------------*/ - -int32_t MIDI_AllNotesOff -( - void -) - -{ - int32_t channel; - - for (channel = 0; channel < NUM_MIDI_CHANNELS; channel++) - { - _MIDI_SendControlChange(channel, 0x40, 0); - _MIDI_SendControlChange(channel, MIDI_ALL_NOTES_OFF, 0); - _MIDI_SendControlChange(channel, 0x78, 0); - } - - return(MIDI_Ok); -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_SetChannelVolume - - Sets the volume of the specified midi channel. ----------------------------------------------------------------------*/ - -static void _MIDI_SetChannelVolume -( - int32_t channel, - int32_t volume -) - -{ - int32_t status; - int32_t remotevolume; - - _MIDI_ChannelVolume[ channel ] = volume; - - if (_MIDI_RerouteFunctions[ channel ] != NULL) - { - remotevolume = volume * _MIDI_TotalVolume; - remotevolume *= _MIDI_UserChannelVolume[ channel ]; - remotevolume /= MIDI_MaxVolume; - remotevolume >>= 8; - - status = _MIDI_RerouteFunctions[ channel ](0xB0 + channel, - MIDI_VOLUME, remotevolume); - if (status == MIDI_DONT_PLAY) - { - return; - } - } - - if (_MIDI_Funcs == NULL) - { - return; - } - - if (_MIDI_Funcs->ControlChange == NULL) - { - return; - } - - // For user volume - volume *= _MIDI_UserChannelVolume[ channel ]; - - if (_MIDI_Funcs->SetVolume == NULL) - { - volume *= _MIDI_TotalVolume; - volume /= MIDI_MaxVolume; - } - - // For user volume - volume >>= 8; - - _MIDI_Funcs->ControlChange(channel, MIDI_VOLUME, volume); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetUserChannelVolume - - Sets the volume of the specified midi channel. ----------------------------------------------------------------------*/ - -void MIDI_SetUserChannelVolume -( - int32_t channel, - int32_t volume -) - -{ - // Convert channel from 1-16 to 0-15 - channel--; - - volume = max(0, volume); - volume = min(volume, 256); - - if ((channel >= 0) && (channel < NUM_MIDI_CHANNELS)) - { - _MIDI_UserChannelVolume[ channel ] = volume; - _MIDI_SetChannelVolume(channel, _MIDI_ChannelVolume[ channel ]); - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_ResetUserChannelVolume - - Sets the volume of the specified midi channel. ----------------------------------------------------------------------*/ - -void MIDI_ResetUserChannelVolume -( - void -) - -{ - int32_t channel; - - for (channel = 0; channel < NUM_MIDI_CHANNELS; channel++) - { - _MIDI_UserChannelVolume[ channel ] = 256; - } - - _MIDI_SendChannelVolumes(); -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_SendChannelVolumes - - Sets the volume on all the midi channels. ----------------------------------------------------------------------*/ - -static void _MIDI_SendChannelVolumes -( - void -) - -{ - int32_t channel; - - for (channel = 0; channel < NUM_MIDI_CHANNELS; channel++) - { - _MIDI_SetChannelVolume(channel, _MIDI_ChannelVolume[ channel ]); - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_Reset - - Resets the MIDI device to General Midi defaults. ----------------------------------------------------------------------*/ - -int32_t MIDI_Reset -( - void -) - -{ - int32_t channel; - - MIDI_AllNotesOff(); - - for (channel = 0; channel < NUM_MIDI_CHANNELS; channel++) - { - _MIDI_SendControlChange(channel, MIDI_RESET_ALL_CONTROLLERS, 0); - _MIDI_SendControlChange(channel, MIDI_RPN_MSB, MIDI_PITCHBEND_MSB); - _MIDI_SendControlChange(channel, MIDI_RPN_LSB, MIDI_PITCHBEND_LSB); - _MIDI_SendControlChange(channel, MIDI_DATAENTRY_MSB, 2); /* Pitch Bend Sensitivity MSB */ - _MIDI_SendControlChange(channel, MIDI_DATAENTRY_LSB, 0); /* Pitch Bend Sensitivity LSB */ - _MIDI_ChannelVolume[ channel ] = GENMIDI_DefaultVolume; - } - - _MIDI_SendChannelVolumes(); - - Reset = TRUE; - - return(MIDI_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetVolume - - Sets the total volume of the music. ----------------------------------------------------------------------*/ - -int32_t MIDI_SetVolume -( - int32_t volume -) - -{ - int32_t i; - - if (_MIDI_Funcs == NULL) - { - return(MIDI_NullMidiModule); - } - - volume = min(MIDI_MaxVolume, volume); - volume = max(0, volume); - - _MIDI_TotalVolume = volume; - - if (_MIDI_Funcs->SetVolume) - { - _MIDI_Funcs->SetVolume(volume); - - for (i = 0; i < NUM_MIDI_CHANNELS; i++) - { - if (_MIDI_RerouteFunctions[ i ] != NULL) - { - _MIDI_SetChannelVolume(i, _MIDI_ChannelVolume[ i ]); - } - } - } - else - { - _MIDI_SendChannelVolumes(); - } - - return(MIDI_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_GetVolume - - Returns the total volume of the music. ----------------------------------------------------------------------*/ - -int32_t MIDI_GetVolume -( - void -) - -{ - int32_t volume; - - if (_MIDI_Funcs == NULL) - { - return(MIDI_NullMidiModule); - } - - if (_MIDI_Funcs->GetVolume) - { - volume = _MIDI_Funcs->GetVolume(); - } - else - { - volume = _MIDI_TotalVolume; - } - - return(volume); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetContext - - Sets the song context. ----------------------------------------------------------------------*/ - -void MIDI_SetContext -( - int32_t context -) - -{ - if ((context > 0) && (context < EMIDI_NUM_CONTEXTS)) - { - _MIDI_Context = context; - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_GetContext - - Returns the current song context. ----------------------------------------------------------------------*/ - -int32_t MIDI_GetContext -( - void -) - -{ - return _MIDI_Context; -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetLoopFlag - - Sets whether the song should loop when finished or not. ----------------------------------------------------------------------*/ - -void MIDI_SetLoopFlag -( - int32_t loopflag -) - -{ - _MIDI_Loop = loopflag; -} - - -/*--------------------------------------------------------------------- - Function: MIDI_ContinueSong - - Continues playback of a paused song. ----------------------------------------------------------------------*/ - -void MIDI_ContinueSong -( - void -) - -{ - if (_MIDI_SongLoaded) - { - _MIDI_SongActive = TRUE; - MPU_Unpause(); - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_PauseSong - - Pauses playback of the current song. ----------------------------------------------------------------------*/ - -void MIDI_PauseSong -( - void -) - -{ - if (_MIDI_SongLoaded) - { - _MIDI_SongActive = FALSE; - MIDI_AllNotesOff(); - MPU_Pause(); - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SongPlaying - - Returns whether a song is playing or not. ----------------------------------------------------------------------*/ - -int32_t MIDI_SongPlaying -( - void -) - -{ - return(_MIDI_SongActive); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetMidiFuncs - - Selects the routines that send the MIDI data to the music device. ----------------------------------------------------------------------*/ - -void MIDI_SetMidiFuncs -( - midifuncs *funcs -) - -{ - _MIDI_Funcs = funcs; -} - - -/*--------------------------------------------------------------------- - Function: MIDI_StopSong - - Stops playback of the currently playing song. ----------------------------------------------------------------------*/ - -void MIDI_StopSong -( - void -) - -{ - if (_MIDI_SongLoaded) - { - _MIDI_SongActive = FALSE; - _MIDI_SongLoaded = FALSE; - - MIDI_Reset(); - _MIDI_ResetTracks(); - - if (_MIDI_Funcs->ReleasePatches) - { - _MIDI_Funcs->ReleasePatches(); - } - - Bfree(_MIDI_TrackPtr); - - _MIDI_TrackPtr = NULL; - _MIDI_NumTracks = 0; - _MIDI_TrackMemSize = 0; - - _MIDI_TotalTime = 0; - _MIDI_TotalTicks = 0; - _MIDI_TotalBeats = 0; - _MIDI_TotalMeasures = 0; - - MPU_Reset(); - } -} - - -/*--------------------------------------------------------------------- - Function: MIDI_PlaySong - - Begins playback of a MIDI song. ----------------------------------------------------------------------*/ - -int32_t MIDI_PlaySong -( - char *song, - int32_t loopflag -) - -{ - int32_t numtracks; - int32_t format; - int32_t headersize; - int32_t tracklength; - track *CurrentTrack; - char *ptr; - - if (_MIDI_SongLoaded) - { - MIDI_StopSong(); - } - - MPU_Init(MUSIC_SoundDevice); - - _MIDI_Loop = loopflag; - - if (_MIDI_Funcs == NULL) - { - return(MIDI_NullMidiModule); - } - - if (*(uint32_t *)song != MIDI_HEADER_SIGNATURE) - { - return(MIDI_InvalidMidiFile); - } - - song += 4; - - headersize = _MIDI_ReadNumber(song, 4); - song += 4; - format = _MIDI_ReadNumber(song, 2); - _MIDI_NumTracks = _MIDI_ReadNumber(song + 2, 2); - _MIDI_Division = _MIDI_ReadNumber(song + 4, 2); - if (_MIDI_Division < 0) - { - // If a SMPTE time division is given, just set to 96 so no errors occur - _MIDI_Division = 96; - } - - if (format > MAX_FORMAT) - { - return(MIDI_UnknownMidiFormat); - } - - ptr = song + headersize; - - if (_MIDI_NumTracks == 0) - { - return(MIDI_NoTracks); - } - - _MIDI_TrackMemSize = _MIDI_NumTracks * sizeof(track); - _MIDI_TrackPtr = Bmalloc(_MIDI_TrackMemSize); - if (_MIDI_TrackPtr == NULL) - { - return(MIDI_NoMemory); - } - - CurrentTrack = _MIDI_TrackPtr; - numtracks = _MIDI_NumTracks; - while (numtracks--) - { - if (*(uint32_t *)ptr != MIDI_TRACK_SIGNATURE) - { - Bfree(_MIDI_TrackPtr); - - _MIDI_TrackPtr = NULL; - _MIDI_TrackMemSize = 0; - - return(MIDI_InvalidTrack); - } - - tracklength = _MIDI_ReadNumber(ptr + 4, 4); - ptr += 8; - CurrentTrack->start = ptr; - ptr += tracklength; - CurrentTrack++; - } - - if (_MIDI_Funcs->GetVolume != NULL) - { - _MIDI_TotalVolume = _MIDI_Funcs->GetVolume(); - } - - _MIDI_InitEMIDI(); - - if (_MIDI_Funcs->LoadPatch) - { - MIDI_LoadTimbres(); - } - - _MIDI_ResetTracks(); - - if (!Reset) - { - MIDI_Reset(); - } - - Reset = FALSE; - - MIDI_SetDivision(_MIDI_Division); - //MIDI_SetTempo( 120 ); - - _MIDI_SongLoaded = TRUE; - _MIDI_SongActive = TRUE; - - while (_MPU_BuffersWaiting < 4) _MIDI_ServiceRoutine(); - MPU_BeginPlayback(); - - return(MIDI_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetTempo - - Sets the song tempo. ----------------------------------------------------------------------*/ - -void MIDI_SetTempo -( - int32_t tempo -) - -{ - int32_t tickspersecond; - - MIDI_Tempo = tempo; - tickspersecond = ((tempo) * _MIDI_Division) / 60; - _MIDI_FPSecondsPerTick = (1 << TIME_PRECISION) / tickspersecond; - MPU_SetTempo(tempo); -} - -void MIDI_SetDivision(int32_t division) -{ - MPU_SetDivision(division); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_GetTempo - - Returns the song tempo. ----------------------------------------------------------------------*/ - -int32_t MIDI_GetTempo -( - void -) - -{ - return(MIDI_Tempo); -} - - -/*--------------------------------------------------------------------- - Function: _MIDI_ProcessNextTick - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -static int32_t _MIDI_ProcessNextTick -( - void -) - -{ - int32_t event; - int32_t channel; - int32_t command; - track *Track; - int32_t tracknum; - int32_t status; - int32_t c1 = 0; - int32_t c2 = 0; - int32_t TimeSet = FALSE; - - Track = _MIDI_TrackPtr; - tracknum = 0; - while ((tracknum < _MIDI_NumTracks) && (Track != NULL)) - { - while ((Track->active) && (Track->delay == 0)) - { - GET_NEXT_EVENT(Track, event); - - if (GET_MIDI_COMMAND(event) == MIDI_SPECIAL) - { - switch (event) - { - case MIDI_SYSEX : - case MIDI_SYSEX_CONTINUE : - _MIDI_SysEx(Track); - break; - - case MIDI_META_EVENT : - _MIDI_MetaEvent(Track); - break; - } - - if (Track->active) - { - Track->delay = _MIDI_ReadDelta(Track); - } - - continue; - } - - if (event & MIDI_RUNNING_STATUS) - { - Track->RunningStatus = event; - } - else - { - event = Track->RunningStatus; - Track->pos--; - } - - channel = GET_MIDI_CHANNEL(event); - command = GET_MIDI_COMMAND(event); - - if (_MIDI_CommandLengths[ command ] > 0) - { - GET_NEXT_EVENT(Track, c1); - if (_MIDI_CommandLengths[ command ] > 1) - { - GET_NEXT_EVENT(Track, c2); - } - } - - if (_MIDI_RerouteFunctions[ channel ] != NULL) - { - status = _MIDI_RerouteFunctions[ channel ](event, c1, c2); - - if (status == MIDI_DONT_PLAY) - { - Track->delay = _MIDI_ReadDelta(Track); - continue; - } - } - - switch (command) - { - case MIDI_NOTE_OFF : - break; - - case MIDI_NOTE_ON : - break; - - case MIDI_POLY_AFTER_TCH : - if (_MIDI_Funcs->PolyAftertouch) - { - _MIDI_Funcs->PolyAftertouch(channel, c1, c2); - } - break; - - case MIDI_CONTROL_CHANGE : - TimeSet = _MIDI_InterpretControllerInfo(Track, TimeSet, - channel, c1, c2); - break; - - case MIDI_PROGRAM_CHANGE : - if ((_MIDI_Funcs->ProgramChange) && - (!Track->EMIDI_ProgramChange)) - { - _MIDI_Funcs->ProgramChange(channel, c1); - } - break; - - case MIDI_AFTER_TOUCH : - if (_MIDI_Funcs->ChannelAftertouch) - { - _MIDI_Funcs->ChannelAftertouch(channel, c1); - } - break; - - case MIDI_PITCH_BEND : - if (_MIDI_Funcs->PitchBend) - { - _MIDI_Funcs->PitchBend(channel, c1, c2); - } - break; - - default : - break; - } - - Track->delay = _MIDI_ReadDelta(Track); - } - - Track->delay--; - Track++; - tracknum++; - - if (_MIDI_ActiveTracks == 0) - { - break; - } - } - - _MIDI_AdvanceTick(); - - return(TimeSet); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetSongTick - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MIDI_SetSongTick -( - uint32_t PositionInTicks -) - -{ - if (!_MIDI_SongLoaded) - { - return; - } - - MIDI_PauseSong(); - - if (PositionInTicks < _MIDI_PositionInTicks) - { - _MIDI_ResetTracks(); - MIDI_Reset(); - } - - while (_MIDI_PositionInTicks < PositionInTicks) - { - if (_MIDI_ProcessNextTick()) - { - break; - } - if (_MIDI_ActiveTracks == 0) - { - _MIDI_ResetTracks(); - if (!_MIDI_Loop) - { - return; - } - break; - } - } - - MIDI_SetVolume(_MIDI_TotalVolume); - MIDI_ContinueSong(); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetSongTime - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MIDI_SetSongTime -( - uint32_t milliseconds -) - -{ - uint32_t mil; - uint32_t sec; - uint32_t newtime; - - if (!_MIDI_SongLoaded) - { - return; - } - - MIDI_PauseSong(); - - mil = ((milliseconds % 1000) << TIME_PRECISION) / 1000; - sec = (milliseconds / 1000) << TIME_PRECISION; - newtime = sec + mil; - - if (newtime < _MIDI_Time) - { - _MIDI_ResetTracks(); - MIDI_Reset(); - } - - while (_MIDI_Time < newtime) - { - if (_MIDI_ProcessNextTick()) - { - break; - } - if (_MIDI_ActiveTracks == 0) - { - _MIDI_ResetTracks(); - if (!_MIDI_Loop) - { - return; - } - break; - } - } - - MIDI_SetVolume(_MIDI_TotalVolume); - MIDI_ContinueSong(); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_SetSongPosition - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MIDI_SetSongPosition -( - int32_t measure, - int32_t beat, - int32_t tick -) - -{ - uint32_t pos; - - if (!_MIDI_SongLoaded) - { - return; - } - - MIDI_PauseSong(); - - pos = RELATIVE_BEAT(measure, beat, tick); - - if (pos < (uint32_t)RELATIVE_BEAT(_MIDI_Measure, _MIDI_Beat, _MIDI_Tick)) - { - _MIDI_ResetTracks(); - MIDI_Reset(); - } - - while ((uint32_t)RELATIVE_BEAT(_MIDI_Measure, _MIDI_Beat, _MIDI_Tick) < pos) - { - if (_MIDI_ProcessNextTick()) - { - break; - } - if (_MIDI_ActiveTracks == 0) - { - _MIDI_ResetTracks(); - if (!_MIDI_Loop) - { - return; - } - break; - } - } - - MIDI_SetVolume(_MIDI_TotalVolume); - MIDI_ContinueSong(); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_GetSongPosition - - Returns the position of the song pointer in Measures, beats, ticks. ----------------------------------------------------------------------*/ - -void MIDI_GetSongPosition -( - songposition *pos -) - -{ - uint32_t mil; - uint32_t sec; - - mil = (_MIDI_Time & ((1 << TIME_PRECISION) - 1)) * 1000; - sec = _MIDI_Time >> TIME_PRECISION; - pos->milliseconds = (mil >> TIME_PRECISION) + (sec * 1000); - pos->tickposition = _MIDI_PositionInTicks; - pos->measure = _MIDI_Measure; - pos->beat = _MIDI_Beat; - pos->tick = _MIDI_Tick; -} - - -/*--------------------------------------------------------------------- - Function: MIDI_GetSongLength - - Returns the length of the song. ----------------------------------------------------------------------*/ - -void MIDI_GetSongLength -( - songposition *pos -) - -{ - uint32_t mil; - uint32_t sec; - - mil = (_MIDI_TotalTime & ((1 << TIME_PRECISION) - 1)) * 1000; - sec = _MIDI_TotalTime >> TIME_PRECISION; - - pos->milliseconds = (mil >> TIME_PRECISION) + (sec * 1000); - pos->measure = _MIDI_TotalMeasures; - pos->beat = _MIDI_TotalBeats; - pos->tick = _MIDI_TotalTicks; - pos->tickposition = 0; -} - - -/*--------------------------------------------------------------------- - Function: MIDI_InitEMIDI - - Sets up the EMIDI ----------------------------------------------------------------------*/ - -static void _MIDI_InitEMIDI -( - void -) - -{ - int32_t event; - int32_t command; - int32_t channel; - int32_t length; - int32_t IncludeFound; - track *Track; - int32_t tracknum; - int32_t type; - int32_t c1; - int32_t c2; - - type = EMIDI_GeneralMIDI; - - _MIDI_ResetTracks(); - - _MIDI_TotalTime = 0; - _MIDI_TotalTicks = 0; - _MIDI_TotalBeats = 0; - _MIDI_TotalMeasures = 0; - - Track = _MIDI_TrackPtr; - tracknum = 0; - while ((tracknum < _MIDI_NumTracks) && (Track != NULL)) - { - _MIDI_Tick = 0; - _MIDI_Beat = 1; - _MIDI_Measure = 1; - _MIDI_Time = 0; - _MIDI_BeatsPerMeasure = 4; - _MIDI_TicksPerBeat = _MIDI_Division; - _MIDI_TimeBase = 4; - - _MIDI_PositionInTicks = 0; - _MIDI_ActiveTracks = 0; - _MIDI_Context = -1; - - Track->RunningStatus = 0; - Track->active = TRUE; - - Track->EMIDI_ProgramChange = FALSE; - Track->EMIDI_VolumeChange = FALSE; - Track->EMIDI_IncludeTrack = TRUE; - - memset(Track->context, 0, sizeof(Track->context)); - - while (Track->delay > 0) - { - _MIDI_AdvanceTick(); - Track->delay--; - } - - IncludeFound = FALSE; - while (Track->active) - { - GET_NEXT_EVENT(Track, event); - - if (GET_MIDI_COMMAND(event) == MIDI_SPECIAL) - { - switch (event) - { - case MIDI_SYSEX : - case MIDI_SYSEX_CONTINUE : - _MIDI_SysEx(Track); - break; - - case MIDI_META_EVENT : - _MIDI_MetaEvent(Track); - break; - } - - if (Track->active) - { - Track->delay = _MIDI_ReadDelta(Track); - while (Track->delay > 0) - { - _MIDI_AdvanceTick(); - Track->delay--; - } - } - - continue; - } - - if (event & MIDI_RUNNING_STATUS) - { - Track->RunningStatus = event; - } - else - { - event = Track->RunningStatus; - Track->pos--; - } - - channel = GET_MIDI_CHANNEL(event); - command = GET_MIDI_COMMAND(event); - length = _MIDI_CommandLengths[ command ]; - - if (command == MIDI_CONTROL_CHANGE) - { - if (*Track->pos == MIDI_MONO_MODE_ON) - { - length++; - } - GET_NEXT_EVENT(Track, c1); - GET_NEXT_EVENT(Track, c2); - length -= 2; - - switch (c1) - { - case EMIDI_LOOP_START : - case EMIDI_SONG_LOOP_START : - if (c2 == 0) - { - Track->context[ 0 ].loopcount = EMIDI_INFINITE; - } - else - { - Track->context[ 0 ].loopcount = c2; - } - - Track->context[ 0 ].pos = Track->pos; - Track->context[ 0 ].loopstart = Track->pos; - Track->context[ 0 ].RunningStatus = Track->RunningStatus; - Track->context[ 0 ].time = _MIDI_Time; - Track->context[ 0 ].FPSecondsPerTick = _MIDI_FPSecondsPerTick; - Track->context[ 0 ].tick = _MIDI_Tick; - Track->context[ 0 ].beat = _MIDI_Beat; - Track->context[ 0 ].measure = _MIDI_Measure; - Track->context[ 0 ].BeatsPerMeasure = _MIDI_BeatsPerMeasure; - Track->context[ 0 ].TicksPerBeat = _MIDI_TicksPerBeat; - Track->context[ 0 ].TimeBase = _MIDI_TimeBase; - break; - - case EMIDI_LOOP_END : - case EMIDI_SONG_LOOP_END : - if (c2 == EMIDI_END_LOOP_VALUE) - { - Track->context[ 0 ].loopstart = NULL; - Track->context[ 0 ].loopcount = 0; - } - break; - - case EMIDI_INCLUDE_TRACK : - if (EMIDI_AffectsCurrentCard(c2, type)) - { - //printf( "Include track %d on card %d\n", tracknum, c2 ); - IncludeFound = TRUE; - Track->EMIDI_IncludeTrack = TRUE; - } - else if (!IncludeFound) - { - //printf( "Track excluded %d on card %d\n", tracknum, c2 ); - IncludeFound = TRUE; - Track->EMIDI_IncludeTrack = FALSE; - } - break; - - case EMIDI_EXCLUDE_TRACK : - if (EMIDI_AffectsCurrentCard(c2, type)) - { - //printf( "Exclude track %d on card %d\n", tracknum, c2 ); - Track->EMIDI_IncludeTrack = FALSE; - } - break; - - case EMIDI_PROGRAM_CHANGE : - if (!Track->EMIDI_ProgramChange) - //printf( "Program change on track %d\n", tracknum ); - Track->EMIDI_ProgramChange = TRUE; - break; - - case EMIDI_VOLUME_CHANGE : - if (!Track->EMIDI_VolumeChange) - //printf( "Volume change on track %d\n", tracknum ); - Track->EMIDI_VolumeChange = TRUE; - break; - - case EMIDI_CONTEXT_START : - if ((c2 > 0) && (c2 < EMIDI_NUM_CONTEXTS)) - { - Track->context[ c2 ].pos = Track->pos; - Track->context[ c2 ].loopstart = Track->context[ 0 ].loopstart; - Track->context[ c2 ].loopcount = Track->context[ 0 ].loopcount; - Track->context[ c2 ].RunningStatus = Track->RunningStatus; - Track->context[ c2 ].time = _MIDI_Time; - Track->context[ c2 ].FPSecondsPerTick = _MIDI_FPSecondsPerTick; - Track->context[ c2 ].tick = _MIDI_Tick; - Track->context[ c2 ].beat = _MIDI_Beat; - Track->context[ c2 ].measure = _MIDI_Measure; - Track->context[ c2 ].BeatsPerMeasure = _MIDI_BeatsPerMeasure; - Track->context[ c2 ].TicksPerBeat = _MIDI_TicksPerBeat; - Track->context[ c2 ].TimeBase = _MIDI_TimeBase; - } - break; - - case EMIDI_CONTEXT_END : - break; - } - } - - Track->pos += length; - Track->delay = _MIDI_ReadDelta(Track); - - while (Track->delay > 0) - { - _MIDI_AdvanceTick(); - Track->delay--; - } - } - - _MIDI_TotalTime = max(_MIDI_TotalTime, _MIDI_Time); - if (RELATIVE_BEAT(_MIDI_Measure, _MIDI_Beat, _MIDI_Tick) > - RELATIVE_BEAT(_MIDI_TotalMeasures, _MIDI_TotalBeats, - _MIDI_TotalTicks)) - { - _MIDI_TotalTicks = _MIDI_Tick; - _MIDI_TotalBeats = _MIDI_Beat; - _MIDI_TotalMeasures = _MIDI_Measure; - } - - Track++; - tracknum++; - } - - _MIDI_ResetTracks(); -} - - -/*--------------------------------------------------------------------- - Function: MIDI_LoadTimbres - - Preloads the timbres on cards that use patch-caching. ----------------------------------------------------------------------*/ - -void MIDI_LoadTimbres -( - void -) - -{ - int32_t event; - int32_t command; - int32_t channel; - int32_t length; - int32_t Finished; - track *Track; - int32_t tracknum; - - Track = _MIDI_TrackPtr; - tracknum = 0; - while ((tracknum < _MIDI_NumTracks) && (Track != NULL)) - { - Finished = FALSE; - while (!Finished) - { - GET_NEXT_EVENT(Track, event); - - if (GET_MIDI_COMMAND(event) == MIDI_SPECIAL) - { - switch (event) - { - case MIDI_SYSEX : - case MIDI_SYSEX_CONTINUE : - length = _MIDI_ReadDelta(Track); - Track->pos += length; - break; - - case MIDI_META_EVENT : - GET_NEXT_EVENT(Track, command); - GET_NEXT_EVENT(Track, length); - - if (command == MIDI_END_OF_TRACK) - { - Finished = TRUE; - } - - Track->pos += length; - break; - } - - if (!Finished) - { - _MIDI_ReadDelta(Track); - } - - continue; - } - - if (event & MIDI_RUNNING_STATUS) - { - Track->RunningStatus = event; - } - else - { - event = Track->RunningStatus; - Track->pos--; - } - - channel = GET_MIDI_CHANNEL(event); - command = GET_MIDI_COMMAND(event); - length = _MIDI_CommandLengths[ command ]; - - if (command == MIDI_CONTROL_CHANGE) - { - if (*Track->pos == MIDI_MONO_MODE_ON) - { - length++; - } - - if (*Track->pos == EMIDI_PROGRAM_CHANGE) - { - _MIDI_Funcs->LoadPatch(*(Track->pos + 1)); - } - } - - if (channel == MIDI_RHYTHM_CHANNEL) - { - if (command == MIDI_NOTE_ON) - { - _MIDI_Funcs->LoadPatch(128 + *Track->pos); - } - } - else - { - if (command == MIDI_PROGRAM_CHANGE) - { - _MIDI_Funcs->LoadPatch(*Track->pos); - } - } - Track->pos += length; - _MIDI_ReadDelta(Track); - } - Track++; - tracknum++; - } - - _MIDI_ResetTracks(); -} - - -void MIDI_UpdateMusic(void) -{ - if (!_MIDI_SongLoaded || !_MIDI_SongActive) return; - while (_MPU_BuffersWaiting < 4) _MIDI_ServiceRoutine(); -} - diff --git a/polymer/eduke32/source/jaudiolib/midi.h b/polymer/eduke32/source/jaudiolib/midi.h deleted file mode 100644 index e3eab853a..000000000 --- a/polymer/eduke32/source/jaudiolib/midi.h +++ /dev/null @@ -1,100 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - module: MIDI.H - - author: James R. Dose - date: May 25, 1994 - - Public header for MIDI.C. Midi song file playback routines. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __MIDI_H -#define __MIDI_H - -enum MIDI_Errors - { - MIDI_Warning = -2, - MIDI_Error = -1, - MIDI_Ok = 0, - MIDI_NullMidiModule, - MIDI_InvalidMidiFile, - MIDI_UnknownMidiFormat, - MIDI_NoTracks, - MIDI_InvalidTrack, - MIDI_NoMemory, - MIDI_DPMI_Error - }; - - -#define MIDI_PASS_THROUGH 1 -#define MIDI_DONT_PLAY 0 - -#define MIDI_MaxVolume 255 - -extern char MIDI_PatchMap[ 128 ]; - -typedef struct - { - void ( *NoteOff )( int32_t channel, int32_t key, int32_t velocity ); - void ( *NoteOn )( int32_t channel, int32_t key, int32_t velocity ); - void ( *PolyAftertouch )( int32_t channel, int32_t key, int32_t pressure ); - void ( *ControlChange )( int32_t channel, int32_t number, int32_t value ); - void ( *ProgramChange )( int32_t channel, int32_t program ); - void ( *ChannelAftertouch )( int32_t channel, int32_t pressure ); - void ( *PitchBend )( int32_t channel, int32_t lsb, int32_t msb ); - void ( *ReleasePatches )( void ); - void ( *LoadPatch )( int32_t number ); - void ( *SetVolume )( int32_t volume ); - int32_t ( *GetVolume )( void ); - void ( *FinishBuffer )( void ); - } midifuncs; - -void MIDI_RerouteMidiChannel( int32_t channel, int32_t ( *function )( int32_t event, int32_t c1, int32_t c2 ) ); -int32_t MIDI_AllNotesOff( void ); -void MIDI_SetUserChannelVolume( int32_t channel, int32_t volume ); -void MIDI_ResetUserChannelVolume( void ); -int32_t MIDI_Reset( void ); -int32_t MIDI_SetVolume( int32_t volume ); -int32_t MIDI_GetVolume( void ); -void MIDI_SetMidiFuncs( midifuncs *funcs ); -void MIDI_SetContext( int32_t context ); -int32_t MIDI_GetContext( void ); -void MIDI_SetLoopFlag( int32_t loopflag ); -void MIDI_ContinueSong( void ); -void MIDI_PauseSong( void ); -int32_t MIDI_SongPlaying( void ); -void MIDI_StopSong( void ); -int32_t MIDI_PlaySong( char *song, int32_t loopflag ); -void MIDI_SetTempo( int32_t tempo ); -int32_t MIDI_GetTempo( void ); -void MIDI_SetSongTick( uint32_t PositionInTicks ); -void MIDI_SetSongTime( uint32_t milliseconds ); -void MIDI_SetSongPosition( int32_t measure, int32_t beat, int32_t tick ); -void MIDI_GetSongPosition( songposition *pos ); -void MIDI_GetSongLength( songposition *pos ); -void MIDI_LoadTimbres( void ); -void MIDI_UpdateMusic(void); -void MIDI_SetDivision( int32_t division ); - -#endif diff --git a/polymer/eduke32/source/jaudiolib/mpu401.c b/polymer/eduke32/source/jaudiolib/mpu401.c deleted file mode 100644 index b83685d84..000000000 --- a/polymer/eduke32/source/jaudiolib/mpu401.c +++ /dev/null @@ -1,496 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - module: MPU401.C - - author: James R. Dose - date: January 1, 1994 - - Low level routines to support sending of MIDI data to MPU401 - compatible MIDI interfaces. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include "mpu401.h" -#include "compat.h" -#include "osd.h" - -#define WIN32_LEAN_AND_MEAN -#include -#include - -static HMIDISTRM hmido = (HMIDISTRM)-1; -static MIDIOUTCAPS midicaps; -static DWORD mididevice = -1; - -typedef struct -{ - int32_t time; - int32_t stream; - int32_t event; -} -MIDIEVENTHEAD; -#define PAD(x) ((((x)+3)&(~3))) - -#define BUFFERLEN (32*4*4) -#define NUMBUFFERS 8 -static char eventbuf[NUMBUFFERS][BUFFERLEN]; -static int32_t eventcnt[NUMBUFFERS]; -static MIDIHDR bufferheaders[NUMBUFFERS]; -int32_t _MPU_CurrentBuffer = 0; -int32_t _MPU_BuffersWaiting = 0; - -extern uint32_t _MIDI_GlobalPositionInTicks; -uint32_t _MPU_LastEvent=0; - -#define MIDI_NOTE_OFF 0x80 -#define MIDI_NOTE_ON 0x90 -#define MIDI_POLY_AFTER_TCH 0xA0 -#define MIDI_CONTROL_CHANGE 0xB0 -#define MIDI_PROGRAM_CHANGE 0xC0 -#define MIDI_AFTER_TOUCH 0xD0 -#define MIDI_PITCH_BEND 0xE0 -#define MIDI_META_EVENT 0xFF -#define MIDI_END_OF_TRACK 0x2F -#define MIDI_TEMPO_CHANGE 0x51 -#define MIDI_MONO_MODE_ON 0x7E -#define MIDI_ALL_NOTES_OFF 0x7B - - -/********************************************************************** - - Memory locked functions: - -**********************************************************************/ - - -void MPU_FinishBuffer(int32_t buffer) -{ - if (!eventcnt[buffer]) return; - ZeroMemory(&bufferheaders[buffer], sizeof(MIDIHDR)); - bufferheaders[buffer].lpData = eventbuf[buffer]; - bufferheaders[buffer].dwBufferLength = - bufferheaders[buffer].dwBytesRecorded = eventcnt[buffer]; - midiOutPrepareHeader((HMIDIOUT)hmido, &bufferheaders[buffer], sizeof(MIDIHDR)); - midiStreamOut(hmido, &bufferheaders[buffer], sizeof(MIDIHDR)); - // OSD_Printf("Sending %d bytes (buffer %d)\n",eventcnt[buffer],buffer); - _MPU_BuffersWaiting++; -} - -void MPU_BeginPlayback(void) -{ - _MPU_LastEvent = _MIDI_GlobalPositionInTicks; - if (hmido != (HMIDISTRM)-1) midiStreamRestart(hmido); -} - -void MPU_Pause(void) -{ - if (hmido != (HMIDISTRM)-1) midiStreamPause(hmido); -} - -void MPU_Unpause(void) -{ - if (hmido != (HMIDISTRM)-1) midiStreamRestart(hmido); -} - - -void CALLBACK MPU_MIDICallback(HMIDIOUT handle, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) -{ - int32_t i; - - UNREFERENCED_PARAMETER(dwInstance); - UNREFERENCED_PARAMETER(dwParam2); - - switch (uMsg) - { - case MOM_DONE: - midiOutUnprepareHeader((HMIDIOUT)handle, (MIDIHDR*)dwParam1, sizeof(MIDIHDR)); - for (i=0;i BUFFERLEN) - { - // buffer over-full - nextbuffer = MPU_GetNextBuffer(); - if (nextbuffer < 0) - { - // OSD_Printf("All buffers full!\n"); - return; - } - MPU_FinishBuffer(_MPU_CurrentBuffer); - _MPU_CurrentBuffer = nextbuffer; - } - - p = eventbuf[_MPU_CurrentBuffer] + eventcnt[_MPU_CurrentBuffer]; - ((int32_t*)p)[0] = _MIDI_GlobalPositionInTicks - _MPU_LastEvent; - ((int32_t*)p)[1] = 0; - ((int32_t*)p)[2] = (MEVT_SHORTMSG << 24) | ((*((int32_t*)data)) & masks[count-1]); - eventcnt[_MPU_CurrentBuffer] += 12; - } - else - { - padded = PAD(count); - if (eventcnt[_MPU_CurrentBuffer] + 12 + padded > BUFFERLEN) - { - // buffer over-full - nextbuffer = MPU_GetNextBuffer(); - if (nextbuffer < 0) - { - // OSD_Printf("All buffers full!\n"); - return; - } - MPU_FinishBuffer(_MPU_CurrentBuffer); - _MPU_CurrentBuffer = nextbuffer; - } - - p = eventbuf[_MPU_CurrentBuffer] + eventcnt[_MPU_CurrentBuffer]; - ((int32_t*)p)[0] = _MIDI_GlobalPositionInTicks - _MPU_LastEvent; - ((int32_t*)p)[1] = 0; - ((int32_t*)p)[2] = (MEVT_LONGMSG<<24) | (count & 0xffffffl); - p+=12; eventcnt[_MPU_CurrentBuffer] += 12; - for (; count>0; count--, padded--, eventcnt[_MPU_CurrentBuffer]++) - *(p++) = *(data++); - for (; padded>0; padded--, eventcnt[_MPU_CurrentBuffer]++) - *(p++) = 0; - } - _MPU_LastEvent = _MIDI_GlobalPositionInTicks; -} - - -/*--------------------------------------------------------------------- - Function: MPU_SendMidiImmediate - - Sends a MIDI message immediately to the the music device. ----------------------------------------------------------------------*/ -void MPU_SendMidiImmediate(char *data, int32_t count) -{ - MIDIHDR mhdr; - static int32_t masks[3] = { 0x00ffffffl, 0x0000ffffl, 0x000000ffl }; - - if (!count) return; - if (count<=3) midiOutShortMsg((HMIDIOUT)hmido, (*((int32_t*)data)) & masks[count-1]); - else - { - ZeroMemory(&mhdr, sizeof(mhdr)); - mhdr.lpData = data; - mhdr.dwBufferLength = count; - midiOutPrepareHeader((HMIDIOUT)hmido, &mhdr, sizeof(MIDIHDR)); - midiOutLongMsg((HMIDIOUT)hmido, &mhdr, sizeof(MIDIHDR)); - while (!(mhdr.dwFlags & MHDR_DONE)) ; - midiOutUnprepareHeader((HMIDIOUT)hmido, &mhdr, sizeof(MIDIHDR)); - } -} - - -/*--------------------------------------------------------------------- - Function: MPU_Reset - - Resets the MPU401 card. ----------------------------------------------------------------------*/ - -int32_t MPU_Reset -( - void -) - -{ - midiStreamStop(hmido); - midiStreamClose(hmido); - - return(MPU_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MPU_Init - - Detects and initializes the MPU401 card. ----------------------------------------------------------------------*/ - -int32_t MPU_Init -( - int32_t addr -) - -{ - int32_t i; - - for (i=0;i -#include -#ifndef _MSC_VER -#include -#endif - -#include -#ifdef _WIN32 -#include "dsoundout.h" -#ifdef USE_OPENAL -#include "openal.h" -#endif -#else -#include "dsl.h" -#endif -#include "compat.h" -#include "baselayer.h" -#include "linklist.h" -#include "pitch.h" -#include "multivoc.h" -#include "_multivc.h" - -#define STEREO 1 -#define SIXTEEN_BIT 2 - -#define MONO_8BIT 0 -#define STEREO_8BIT (STEREO) -#define MONO_16BIT (SIXTEEN_BIT) -#define STEREO_16BIT (STEREO | SIXTEEN_BIT) - -#define IS_QUIET(ptr) ((void *)(ptr) == (void *)&MV_VolumeTable[ 0 ]) - -static int32_t MV_ReverbLevel; -static int32_t MV_ReverbDelay; -static VOLUME16 *MV_ReverbTable = NULL; - -//static signed short MV_VolumeTable[ MV_MaxVolume + 1 ][ 256 ]; -static int16_t MV_VolumeTable[ 255 + 1 ][ 256 ]; - -//static Pan MV_PanTable[ MV_NumPanPositions ][ MV_MaxVolume + 1 ]; -static Pan MV_PanTable[ MV_NumPanPositions ][ 255 + 1 ]; - -static int32_t MV_Installed = FALSE; -static int32_t MV_SoundCard = -1; -static int32_t MV_TotalVolume = MV_MaxTotalVolume; -static int32_t MV_MaxVoices = 1; -static int32_t MV_Recording; - -static int32_t MV_BufferSize = 0; -static int32_t MV_BufferLength; - -static int32_t MV_NumberOfBuffers = NumberOfBuffers; - -static int32_t MV_MixMode = MONO_8BIT; -static int32_t MV_Channels = 1; -static int32_t MV_Bits = 8; - -static int32_t MV_Silence = SILENCE_8BIT; -static int32_t MV_SwapLeftRight = FALSE; - -static int32_t MV_RequestedMixRate; -static int32_t MV_MixRate; - -static int32_t MV_BuffShift; - -static int32_t MV_TotalMemory; - -static int32_t MV_BufferEmpty[ NumberOfBuffers ]; -char *MV_MixBuffer[ NumberOfBuffers + 1 ]; -static char *MV_MixBufferPtr = NULL; - -static VoiceNode *MV_Voices = NULL; - -static VoiceNode VoiceList; -static VoiceNode VoicePool; - -int32_t MV_MixPage = 0; -static int32_t MV_VoiceHandle = MV_MinVoiceHandle; - -static void(*MV_CallBackFunc)(uint32_t) = NULL; -static void(*MV_RecordFunc)(char *ptr, int32_t length) = NULL; -static void(*MV_MixFunction)(VoiceNode *voice, int32_t buffer); - -static int32_t MV_MaxVolume = 255; - -char *MV_HarshClipTable; -char *MV_MixDestination; -int16_t *MV_LeftVolume; -int16_t *MV_RightVolume; -int32_t MV_SampleSize = 1; -int32_t MV_RightChannelOffset; - -uint32_t MV_MixPosition; - -int32_t MV_ErrorCode = MV_Ok; - -#define MV_SetErrorCode(status) \ - MV_ErrorCode = (status); - - -/*--------------------------------------------------------------------- - Function: ClearBuffer_DW - - Function code relocated from _multivc.h due to linking issues. ----------------------------------------------------------------------*/ - -void ClearBuffer_DW(void *ptr, int32_t data, int32_t length) -{ - int32_t *pptr = ptr; - for (; length>0; length--) *(pptr++) = data; -} - - -/*--------------------------------------------------------------------- - 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(int32_t 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_BlasterError : -#if defined(_WIN32) - ErrorString = DSOUND_ErrorString(DSOUND_ErrorCode); -#else - ErrorString = DSL_ErrorString(DSL_ErrorCode); -#endif - 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_InvalidOGGFile : - ErrorString = "Invalid OGG file passed in to Multivoc."; - break; - case MV_InvalidMixMode : - ErrorString = "Invalid mix mode request in Multivoc."; - 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: - -**********************************************************************/ - - -/*--------------------------------------------------------------------- - Function: MV_GetBufferSize - - Returns the buffer size for the given samplerate. ----------------------------------------------------------------------*/ -#if defined(_WIN32) -#define BASEBUFSZ (512+128) -static uint32_t MV_GetBufferSize(uint32_t samplerate) -{ - static uint32_t lastsr = 0, lastbufsz = 0; - - if (samplerate == lastsr) return lastbufsz; - - lastsr = samplerate; - lastbufsz = (samplerate*BASEBUFSZ/22050)&(~15); - -#ifdef RENDERTYPEWIN - { - extern int32_t is_vista; - - if (is_vista) - lastbufsz = (samplerate*BASEBUFSZ/22050*2)&(~15); - } -#endif - - return lastbufsz; -} -#endif - -/*--------------------------------------------------------------------- - Function: MV_Mix - - Mixes the sound into the buffer. ----------------------------------------------------------------------*/ - -static void MV_Mix(VoiceNode *voice, int32_t buffer) -{ - char *start; - int32_t length; - int32_t voclength; - uint32_t position; - uint32_t rate; - uint32_t FixedPointBufferSize; - - 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) -{ - uint32_t flags; - - flags = DisableInterrupts(); - LL_SortedInsertion(&VoiceList, voice, prev, next, VoiceNode, priority); - -// if(!voice->bufsnd)voice->bufsnd=(char *)Bcalloc(0x8000*4,sizeof(uint8_t)); -// if(!voice->bufsnd)initprintf("Attention. It gonna crash! Thank you."); // FIXME: change the msg - RestoreInterrupts(flags); -} - - -/*--------------------------------------------------------------------- - Function: MV_StopVoice - - Removes the voice from the play list and adds it to the free list. ----------------------------------------------------------------------*/ - -void MV_StopVoice(VoiceNode *voice) -{ - uint32_t flags; - - flags = DisableInterrupts(); -// if(!voice->bufsnd)Bfree(voice->bufsnd); - // move the voice from the play list to the free list - LL_Remove(voice, next, prev); - LL_Add(&VoicePool, voice, next, prev); - - RestoreInterrupts(flags); -} - - -/*--------------------------------------------------------------------- - Function: MV_ServiceVoc - - Starts playback of the waiting buffer and mixes the next one. ----------------------------------------------------------------------*/ - -// static int32_t backcolor = 1; - -int32_t MV_ServiceVoc(int32_t buffer) -{ - VoiceNode *voice; - VoiceNode *next; - - // Get the currently playing buffer -#if defined(_WIN32) - MV_MixPage = buffer; -#else - UNREFERENCED_PARAMETER(buffer); -#endif - - // 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); - MV_BufferEmpty[ MV_MixPage ] = TRUE; - } - } - else - { - char *end; - char *source; - char *dest; - int32_t count; - int32_t 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, MV_ReverbTable, count / 2); - } - else - { - MV_16BitReverbFast(source, dest, count / 2, MV_ReverbLevel); - } - } - else - { - if (MV_ReverbTable != NULL) - { - MV_8BitReverb((char *)source, (char *)dest, MV_ReverbTable, count); - } - else - { - MV_8BitReverbFast((char *)source, (char *)dest, 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); - } - } - } - - return MV_MixPage; -} - - -/*--------------------------------------------------------------------- - Function: MV_GetNextVOCBlock - - Interperate the information of a VOC format sound file. ----------------------------------------------------------------------*/ - -static playbackstatus MV_GetNextVOCBlock(VoiceNode *voice) -{ - char *ptr; - int32_t blocktype; - int32_t lastblocktype; - uint32_t blocklength = 0; - uint32_t samplespeed = 0; - uint32_t tc = 0; - int32_t packtype; - int32_t voicemode; - int32_t done; - uint32_t BitsPerSample; - uint32_t Channels; - uint32_t 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 = (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; - } - - blocktype = (int32_t)*ptr; - blocklength = (*(uint32_t *)(ptr + 1)) & 0x00ffffff; - ptr += 4; - - switch (blocktype) - { - case 0 : - // End of data - if ((voice->LoopStart == NULL) || ((uint32_t *)voice->LoopStart >= (uint32_t *)(ptr - 4))) - { - voice->Playing = FALSE; - done = TRUE; - } - else - { - voice->BlockLength = (char*)(ptr - 4) - 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 = (uint32_t)*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 = *(uint16_t *)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 = (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 = *(uint16_t *)ptr; - packtype = *(ptr + 2); - voicemode = *(ptr + 3); - ptr += blocklength; - break; - - case 9 : - // New sound data block - samplespeed = *(uint32_t *)ptr; - BitsPerSample = (unsigned)*(ptr + 4); - Channels = (unsigned)*(ptr + 5); - Format = (unsigned)*(uint16_t *)(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_GetNextOGGBlock - - Controls playback of demand fed data. ----------------------------------------------------------------------*/ - -void downsample(char *ptr,int32_t size,int32_t factor) -{ - int16_t *pti=(int16_t *)ptr;int32_t i,j,sum; - - for (i=0;i>factor;i++) - { - sum=0; - for (j=0;j<1<>factor; - } -} - -playbackstatus MV_GetNextOGGBlock(VoiceNode *voice) -{ - int32_t sz; - int32_t size=0; - int32_t section,result; - -// initprintf("_%d %d, %d\n",voice->callbackval,voice->position,voice->BlockLength); - if (voice->BlockLength <= 0) - { - if (voice->LoopStart == NULL) - { -// initprintf("END %d\n",voice->callbackval); - voice->Playing = FALSE; - return(NoMoreData); - } -// initprintf("repeat 2\n"); - - voice->BlockLength = voice->LoopSize; - voice->length = 0; - voice->position = 0; - ov_pcm_seek(&voice->OGGstream.oggStream,0); - } - - voice->position -= voice->length; - sz=voice->length = min(voice->BlockLength, 0x8000); - voice->BlockLength -= voice->length; - voice->length <<= 16; - - sz<<=voice->downsample+1; - while (sizeOGGstream.oggStream,voice->bufsnd+(size>>voice->downsample),sz-size,0,2,1,§ion); - if (result> 0) - { - downsample(voice->bufsnd+(size>>voice->downsample),result,voice->downsample); - size+=result; - } - else if (result==0) - { -// initprintf("!repeat %d\n",voice->callbackval); - voice->BlockLength=0; - voice->length=size<<16;break; - } - else - { - initprintf("#%d\n",result); - break; - } - } - voice->sound=voice->bufsnd; - - return(KeepPlaying); -} - -/*--------------------------------------------------------------------- - Function: MV_ServiceRecord - - Starts recording of the waiting buffer. ----------------------------------------------------------------------*/ -#if 0 -static void MV_ServiceRecord(void) -{ - if (MV_RecordFunc) - { - MV_RecordFunc(MV_MixBuffer[ 0 ] + MV_MixPage * MixBufferSize, MixBufferSize); - } - - // Toggle which buffer we'll mix next - MV_MixPage++; - if (MV_MixPage >= NumberOfBuffers) - { - MV_MixPage = 0; - } -} -#endif - -/*--------------------------------------------------------------------- - Function: MV_GetVoice - - Locates the voice with the specified handle. ----------------------------------------------------------------------*/ - -VoiceNode *MV_GetVoice(int32_t handle) -{ - VoiceNode *voice; - uint32_t 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); - voice = NULL; - } - - return(voice); -} - - -/*--------------------------------------------------------------------- - Function: MV_VoicePlaying - - Checks if the voice associated with the specified handle is - playing. ----------------------------------------------------------------------*/ - -int32_t MV_VoicePlaying(int32_t 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. ----------------------------------------------------------------------*/ - -int32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_Kill(int32_t handle) -{ - VoiceNode *voice; - uint32_t flags; - uint32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_VoicesPlaying(void) -{ - VoiceNode *voice; - int32_t NumVoices = 0; - uint32_t 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(int32_t priority) -{ - VoiceNode *voice; - VoiceNode *node; - uint32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_VoiceAvailable(int32_t priority) -{ - VoiceNode *voice; - VoiceNode *node; - uint32_t 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, uint32_t rate, int32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_SetPitch(int32_t handle, int32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_SetFrequency(int32_t handle, int32_t 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 int16_t *MV_GetVolumeTable(int32_t vol) -{ - int32_t volume; - int16_t *table; - - volume = MIX_VOLUME(vol); - - table = (int16_t*)&MV_VolumeTable[ volume ]; - - return(table); -} - - -/*--------------------------------------------------------------------- - Function: MV_SetVoiceMixMode - - Selects which method should be used to mix the voice. ----------------------------------------------------------------------*/ - -static void MV_SetVoiceMixMode(VoiceNode *voice) -{ - uint32_t flags; - int32_t 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, int32_t vol, int32_t left, int32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_EndLooping(int32_t handle) -{ - VoiceNode *voice; - uint32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_SetPan(int32_t handle, int32_t vol, int32_t left, int32_t right) -{ - VoiceNode *voice; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - voice = MV_GetVoice(handle); - if (voice == NULL) - { - MV_SetErrorCode(MV_VoiceNotFound); - return(MV_Warning); - } - - MV_SetVoiceVolume(voice, vol, left, right); - - return(MV_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MV_Pan3D - - Set the angle and distance from the listener of the voice associated - with the specified handle. ----------------------------------------------------------------------*/ - -int32_t MV_Pan3D(int32_t handle, int32_t angle, int32_t distance) -{ - int32_t left; - int32_t right; - int32_t mid; - int32_t volume; - int32_t status; - - if (distance < 0) - { - distance = -distance; - angle += MV_NumPanPositions / 2; - } - - volume = MIX_VOLUME(distance); - - // Ensure angle is within 0 - 31 - angle &= MV_MaxPanPosition; - - left = MV_PanTable[ angle ][ volume ].left; - right = MV_PanTable[ angle ][ volume ].right; - mid = max(0, 255 - distance); - - status = MV_SetPan(handle, mid, left, right); - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_SetReverb - - Sets the level of reverb to add to mix. ----------------------------------------------------------------------*/ - -void MV_SetReverb(int32_t reverb) -{ - MV_ReverbLevel = MIX_VOLUME(reverb); - MV_ReverbTable = &MV_VolumeTable[ MV_ReverbLevel ]; -} - - -/*--------------------------------------------------------------------- - Function: MV_SetFastReverb - - Sets the level of reverb to add to mix. ----------------------------------------------------------------------*/ - -void MV_SetFastReverb(int32_t reverb) -{ - MV_ReverbLevel = max(0, min(16, reverb)); - MV_ReverbTable = NULL; -} - - -/*--------------------------------------------------------------------- - Function: MV_GetMaxReverbDelay - - Returns the maximum delay time for reverb. ----------------------------------------------------------------------*/ - -int32_t MV_GetMaxReverbDelay(void) -{ - int32_t maxdelay; - - maxdelay = MixBufferSize * MV_NumberOfBuffers; - - return maxdelay; -} - - -/*--------------------------------------------------------------------- - Function: MV_GetReverbDelay - - Returns the current delay time for reverb. ----------------------------------------------------------------------*/ - -int32_t MV_GetReverbDelay(void) -{ - return MV_ReverbDelay / MV_SampleSize; -} - - -/*--------------------------------------------------------------------- - Function: MV_SetReverbDelay - - Sets the delay level of reverb to add to mix. ----------------------------------------------------------------------*/ - -void MV_SetReverbDelay(int32_t delay) -{ - int32_t maxdelay; - - maxdelay = MV_GetMaxReverbDelay(); - MV_ReverbDelay = max((signed)MixBufferSize, min(delay, maxdelay)); - MV_ReverbDelay *= MV_SampleSize; -} - - -/*--------------------------------------------------------------------- - Function: MV_SetMixMode - - Prepares Multivoc to play stereo of mono digitized sounds. ----------------------------------------------------------------------*/ - -int32_t MV_SetMixMode(int32_t numchannels, int32_t samplebits) -{ - int32_t mode; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - mode = 0; - if (numchannels == 2) - { - mode |= STEREO; - } - if (samplebits == 16) - { - mode |= SIXTEEN_BIT; - } - -//#if defined(_WIN32) -// MV_MixMode = DSOUND_SetMixMode(mode); -//#else - MV_MixMode = mode; -//#endif - - MV_Channels = 1; - if (MV_MixMode & STEREO) - { - MV_Channels = 2; - } - - MV_Bits = 8; - if (MV_MixMode & SIXTEEN_BIT) - { - MV_Bits = 16; - } - - MV_BuffShift = 7 + MV_Channels; - MV_SampleSize = sizeof(MONO8) * MV_Channels; - - if (MV_Bits == 8) - { - MV_Silence = SILENCE_8BIT; - } - else - { - MV_Silence = SILENCE_16BIT; - MV_BuffShift += 1; - MV_SampleSize *= 2; - } - - MV_BufferSize = MixBufferSize * MV_SampleSize; - MV_NumberOfBuffers = TotalBufferSize / MV_BufferSize; - MV_BufferLength = TotalBufferSize; - - MV_RightChannelOffset = MV_SampleSize / 2; - - return(MV_Ok); -} - - -// --------------------------------------------------------------------- -// OGG file -// --------------------------------------------------------------------- -ov_callbacks cb; - -size_t ReadOgg(void *ptr, size_t size1, size_t nmemb, void *datasource) -{ - sounddef *d=(sounddef *)datasource; - size1*=nmemb; - /* if (d->pos>=d->size) - return 0;*/ - if (d->pos+size1>=d->size) - size1=d->size-d->pos; - Bmemcpy(ptr,(d->ptrsnd+d->pos),size1); - d->pos+=size1; - return size1; -} - -int32_t SeekOgg(void *datasource,ogg_int64_t offset,int32_t whence) -{ - sounddef *d=(sounddef *)datasource; - switch (whence) - { - case SEEK_SET: - whence=offset; - break; - case SEEK_CUR: - whence=d->pos+offset; - break; - case SEEK_END: - whence=d->size-offset; - break; - default: return -1; - } - /* if (whence>=(int32_t)d->size||whence<0) - return -1;*/ - d->pos=whence; - return 0; -} - -intptr_t TellOgg(void *datasource) -{ - sounddef *d=(sounddef *)datasource; - return d->pos; -} - - -int32_t CloseOgg(void *datasource) -{ - UNREFERENCED_PARAMETER(datasource); - return 0; -} - - -/*--------------------------------------------------------------------- - Function: MV_StartPlayback - - Starts the sound playback engine. ----------------------------------------------------------------------*/ - -int32_t MV_StartPlayback(void) -{ - int32_t status; - int32_t buffer; - - cb.close_func=CloseOgg; - cb.read_func =ReadOgg; - cb.seek_func =SeekOgg; - cb.tell_func =(void *)TellOgg; - - // Initialize the buffers - ClearBuffer_DW(MV_MixBuffer[ 0 ], MV_Silence, TotalBufferSize >> 2); - for (buffer = 0; buffer < MV_NumberOfBuffers; buffer++) - { - MV_BufferEmpty[ buffer ] = TRUE; - } - - // Set the mix buffer variables - MV_MixPage = 1; - MV_MixFunction = MV_Mix; - MV_MixRate = MV_RequestedMixRate; - - // Start playback -#if defined(_WIN32) - status = DSOUND_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers); -#else - status = DSL_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers); -#endif - - if (status != 0) - { - MV_SetErrorCode(MV_BlasterError); - return(MV_Error); - } - - return(MV_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MV_StopPlayback - - Stops the sound playback engine. ----------------------------------------------------------------------*/ - -void MV_StopPlayback(void) -{ - VoiceNode *voice; - VoiceNode *next; - uint32_t flags; - - // Stop sound playback -#if defined(_WIN32) - DSOUND_StopPlayback(); -#else - DSL_StopPlayback(); -#endif - - // Make sure all callbacks are done. - flags = DisableInterrupts(); - - for (voice = VoiceList.next; voice != &VoiceList; voice = next) - { - next = voice->next; - - MV_StopVoice(voice); - - if (MV_CallBackFunc) - { - MV_CallBackFunc(voice->callbackval); - } - } - - RestoreInterrupts(flags); -} - - -#if 0 -/*--------------------------------------------------------------------- - Function: MV_StartRecording - - Starts the sound recording engine. ----------------------------------------------------------------------*/ - -int32_t MV_StartRecording(int32_t MixRate, void(*function)(char *ptr, int32_t length)) -{ - int32_t status; - - switch (MV_SoundCard) - { - case SoundBlaster : - break; - - default : - MV_SetErrorCode(MV_UnsupportedCard); - return(MV_Error); - break; - } - - if (function == NULL) - { - MV_SetErrorCode(MV_NullRecordFunction); - return(MV_Error); - } - - MV_StopPlayback(); - - // Initialize the buffers - ClearBuffer_DW(MV_MixBuffer[ 0 ], SILENCE_8BIT, TotalBufferSize >> 2); - - // Set the mix buffer variables - MV_MixPage = 0; - - MV_RecordFunc = function; - - // Start playback - switch (MV_SoundCard) - { - case SoundBlaster : - status = BLASTER_BeginBufferedRecord(MV_MixBuffer[ 0 ], TotalBufferSize, NumberOfBuffers, MixRate, MONO_8BIT, MV_ServiceRecord); - - if (status != BLASTER_Ok) - { - MV_SetErrorCode(MV_BlasterError); - return(MV_Error); - } - break; - } - - MV_Recording = TRUE; - return(MV_Ok); -} -#endif - -#if 0 -/*--------------------------------------------------------------------- - Function: MV_StopRecord - - Stops the sound record engine. ----------------------------------------------------------------------*/ - -void MV_StopRecord(void) -{ - // Stop sound playback - switch (MV_SoundCard) - { - case SoundBlaster : - BLASTER_StopPlayback(); - break; - } - - MV_Recording = FALSE; - MV_StartPlayback(); -} -#endif - - -/*--------------------------------------------------------------------- - Function: MV_StartDemandFeedPlayback - - Plays a digitized sound from a user controlled buffering system. ----------------------------------------------------------------------*/ - -int32_t MV_StartDemandFeedPlayback(void(*function)(char **ptr, uint32_t *length), int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - VoiceNode *voice; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - // Request a voice from the voice pool - voice = MV_AllocVoice(priority); - if (voice == NULL) - { - MV_SetErrorCode(MV_NoVoices); - return(MV_Error); - } - - voice->wavetype = DemandFeed; - voice->bits = 8; - voice->GetSound = MV_GetNextDemandFeedBlock; - voice->NextBlock = NULL; - voice->DemandFeed = function; - voice->LoopStart = NULL; - voice->LoopCount = 0; - voice->BlockLength = 0; - voice->position = 0; - voice->sound = NULL; - voice->length = 0; - voice->BlockLength = 0; - voice->Playing = TRUE; - voice->next = NULL; - voice->prev = NULL; - voice->priority = priority; - voice->callbackval = callbackval; - - MV_SetVoicePitch(voice, rate, pitchoffset); - MV_SetVoiceVolume(voice, vol, left, right); - MV_PlayVoice(voice); - - return(voice->handle); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayRaw - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int32_t MV_PlayRaw(char *ptr, uint32_t length, uint32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - int32_t status; - - status = MV_PlayLoopedRaw(ptr, length, NULL, NULL, rate, pitchoffset, vol, left, right, priority, callbackval); - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayLoopedRaw - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int32_t MV_PlayLoopedRaw(char *ptr, int32_t length, char *loopstart, char *loopend, uint32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - VoiceNode *voice; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - // Request a voice from the voice pool - voice = MV_AllocVoice(priority); - if (voice == NULL) - { - MV_SetErrorCode(MV_NoVoices); - return(MV_Error); - } - - voice->wavetype = 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. ----------------------------------------------------------------------*/ - -int32_t MV_PlayWAV(char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - int32_t status; - - status = MV_PlayLoopedWAV(ptr, -1, -1, pitchoffset, vol, left, right, priority, callbackval); - if (status < MV_Ok) - { - Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); - initprintf(tempbuf); - } - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayWAV3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int32_t MV_PlayWAV3D(char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval) -{ - int32_t left; - int32_t right; - int32_t mid; - int32_t volume; - int32_t status; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - if (distance < 0) - { - distance = -distance; - angle += MV_NumPanPositions / 2; - } - - volume = MIX_VOLUME(distance); - - // Ensure angle is within 0 - 31 - angle &= MV_MaxPanPosition; - - left = MV_PanTable[ angle ][ volume ].left; - right = MV_PanTable[ angle ][ volume ].right; - mid = max(0, 255 - distance); - - status = MV_PlayWAV(ptr, pitchoffset, mid, left, right, priority, callbackval); - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayLoopedWAV - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int32_t MV_PlayLoopedWAV(char *ptr, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - riff_header *riff; - format_header *format; - data_header *data; - VoiceNode *voice; - int32_t length; - int32_t absloopend; - int32_t absloopstart; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - riff = (riff_header *)ptr; - - if ((strncmp(riff->RIFF, "RIFF", 4) != 0) || (strncmp(riff->WAVE, "WAVE", 4) != 0) || (strncmp(riff->fmt, "fmt ", 4) != 0)) - { - MV_SetErrorCode(MV_InvalidWAVFile); - return(MV_Error); - } - - format = (format_header *)(riff + 1); - data = (data_header *)(((char *)format) + riff->format_size); - - // Check if it's PCM data. - if (format->wFormatTag != 1) - { - MV_SetErrorCode(MV_InvalidWAVFile); - return(MV_Error); - } - - if (format->nChannels != 1) - { - MV_SetErrorCode(MV_InvalidWAVFile); - return(MV_Error); - } - - if ((format->nBitsPerSample != 8) && (format->nBitsPerSample != 16)) - { - MV_SetErrorCode(MV_InvalidWAVFile); - return(MV_Error); - } - - if (strncmp((char *)data->DATA, "data", 4) != 0) - { - MV_SetErrorCode(MV_InvalidWAVFile); - return(MV_Error); - } - - // Request a voice from the voice pool - voice = MV_AllocVoice(priority); - if (voice == NULL) - { - MV_SetErrorCode(MV_NoVoices); - return(MV_Error); - } - - voice->wavetype = WAV; - voice->bits = format->nBitsPerSample; - voice->GetSound = MV_GetNextWAVBlock; - - length = data->size; - absloopstart = loopstart; - absloopend = loopend; - if (voice->bits == 16) - { - loopstart *= 2; - data->size &= ~1; - loopend *= 2; - length /= 2; - } - - loopend = min(loopend, (signed)data->size); - absloopend = min(absloopend, length); - - voice->Playing = TRUE; - voice->DemandFeed = NULL; - voice->LoopStart = NULL; - voice->LoopCount = 0; - voice->position = 0; - voice->length = 0; - voice->BlockLength = absloopend; - voice->NextBlock = (char *)(data + 1); - voice->next = NULL; - voice->prev = NULL; - voice->priority = priority; - voice->callbackval = callbackval; - voice->LoopStart = voice->NextBlock + loopstart; - voice->LoopEnd = voice->NextBlock + loopend; - voice->LoopSize = absloopend - absloopstart; - - if ((loopstart >= (signed)data->size) || (loopstart < 0)) - { - voice->LoopStart = NULL; - voice->LoopEnd = NULL; - voice->BlockLength = length; - } - - MV_SetVoicePitch(voice, format->nSamplesPerSec, pitchoffset); - MV_SetVoiceVolume(voice, vol, left, right); - MV_PlayVoice(voice); - - return(voice->handle); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayVOC3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int32_t MV_PlayVOC3D(char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval) -{ - int32_t left; - int32_t right; - int32_t mid; - int32_t volume; - int32_t status; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - if (distance < 0) - { - distance = -distance; - angle += MV_NumPanPositions / 2; - } - - volume = MIX_VOLUME(distance); - - // Ensure angle is within 0 - 31 - angle &= MV_MaxPanPosition; - - left = MV_PanTable[ angle ][ volume ].left; - right = MV_PanTable[ angle ][ volume ].right; - mid = max(0, 255 - distance); - - status = MV_PlayVOC(ptr, pitchoffset, mid, left, right, priority, callbackval); - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayVOC - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int32_t MV_PlayVOC(char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - int32_t status; - - status = MV_PlayLoopedVOC(ptr, -1, -1, pitchoffset, vol, left, right, priority, callbackval); - if (status < MV_Ok) - { - Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); - initprintf(tempbuf); - } - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayLoopedVOC - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int32_t MV_PlayLoopedVOC(char *ptr, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - VoiceNode *voice; - int32_t status; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - // Make sure it's a valid VOC file. - status = strncmp(ptr, "Creative Voice File", 19); - if (status != 0) - { - MV_SetErrorCode(MV_InvalidVOCFile); - return(MV_Error); - } - - // Request a voice from the voice pool - voice = MV_AllocVoice(priority); - if (voice == NULL) - { - MV_SetErrorCode(MV_NoVoices); - return(MV_Error); - } - - voice->wavetype = VOC; - voice->bits = 8; - voice->GetSound = MV_GetNextVOCBlock; - voice->NextBlock = ptr + *(uint16_t *)(ptr + 0x14); - voice->DemandFeed = NULL; - voice->LoopStart = NULL; - voice->LoopCount = 0; - voice->BlockLength = 0; - voice->PitchScale = PITCH_GetScale(pitchoffset); - voice->length = 0; - voice->next = NULL; - voice->prev = NULL; - voice->priority = priority; - voice->callbackval = callbackval; - voice->LoopStart = (char *)loopstart; - voice->LoopEnd = (char *)loopend; - voice->LoopSize = loopend - loopstart + 1; - - if (loopstart < 0) - { - voice->LoopStart = NULL; - voice->LoopEnd = NULL; - } - - MV_SetVoiceVolume(voice, vol, left, right); - MV_PlayVoice(voice); - - return(voice->handle); -} - -/*--------------------------------------------------------------------- - Function: MV_PlayLoopedOGG - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ -VoiceNode *voice; - -int32_t MV_PlayLoopedOGG(char *ptr, int32_t loopstart, int32_t loopend, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - vorbis_info *vorbisInfo; - int32_t length; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - // Request a voice from the voice pool - voice = MV_AllocVoice(priority); - if (voice == NULL) - { - MV_SetErrorCode(MV_NoVoices); - return(MV_Error); - } - - voice->OGGstream.pos=0; - voice->OGGstream.ptrsnd=ptr; - voice->OGGstream.size=g_sounds[callbackval].soundsiz; - voice->downsample=0; - if (ov_open_callbacks(&voice->OGGstream,&voice->OGGstream.oggStream,0,0,cb)<0) - { - MV_SetErrorCode(MV_InvalidOGGFile); - return(MV_Error); - } - - vorbisInfo=ov_info(&voice->OGGstream.oggStream,-1); - if (!vorbisInfo) - { - MV_SetErrorCode(MV_InvalidOGGFile); - return(MV_Error); - } - while ((ogg_int64_t)(vorbisInfo->rate)/(1<downsample)*PITCH_GetScale(pitchoffset)/0x1000000/0x100) - voice->downsample++; - length=ov_pcm_total(&voice->OGGstream.oggStream,-1); - if (!length) - length=0xffffff; - /* if (length == OV_EINVAL) - { - MV_SetErrorCode(MV_InvalidOGGFile); - return(MV_Error); - }*/ - - loopend=length=length>>voice->downsample; - - voice->wavetype = OGG; - voice->bits = 16; - voice->GetSound = MV_GetNextOGGBlock; - - voice->Playing = TRUE; - voice->DemandFeed = NULL; - voice->LoopStart = NULL; - voice->LoopCount = 0; - voice->position = 0; - voice->length = 0; - voice->BlockLength = loopend; - voice->NextBlock = NULL; - voice->next = NULL; - voice->prev = NULL; - voice->priority = priority; - voice->callbackval = callbackval; - voice->LoopStart = voice->NextBlock + loopstart+1; - voice->LoopEnd = voice->NextBlock + loopend+1; - voice->LoopSize = loopend - loopstart; - - if (loopstart < 0) - { - voice->LoopStart = NULL; - voice->LoopEnd = NULL; - voice->BlockLength = length; - } - - MV_SetVoicePitch(voice, vorbisInfo->rate>>voice->downsample, pitchoffset); - if (vorbisInfo->channels==2) - voice->downsample++; - MV_SetVoiceVolume(voice, vol, left, right); - MV_PlayVoice(voice); - - return(voice->handle); -} - -/*--------------------------------------------------------------------- - Function: MV_PlayOGG - - Begin playback of sound data with the given sound levels and - priority. ----------------------------------------------------------------------*/ - -int32_t MV_PlayOGG(char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, uint32_t callbackval) -{ - int32_t status; - - status = MV_PlayLoopedOGG(ptr, -1, -1, pitchoffset, vol, left, right, priority, callbackval); - if (status < MV_Ok) - { - Bsprintf(tempbuf, "Sound error %d: %s\n",callbackval, FX_ErrorString(FX_Error)); - initprintf(tempbuf); - } - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MV_PlayOGG3D - - Begin playback of sound data at specified angle and distance - from listener. ----------------------------------------------------------------------*/ - -int32_t MV_PlayOGG3D(char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, int32_t priority, uint32_t callbackval) -{ - int32_t left; - int32_t right; - int32_t mid; - int32_t volume; - int32_t status; - - if (!MV_Installed) - { - MV_SetErrorCode(MV_NotInstalled); - return(MV_Error); - } - - if (distance < 0) - { - distance = -distance; - angle += MV_NumPanPositions / 2; - } - - volume = MIX_VOLUME(distance); - - // Ensure angle is within 0 - 31 - angle &= MV_MaxPanPosition; - - left = MV_PanTable[ angle ][ volume ].left; - right = MV_PanTable[ angle ][ volume ].right; - mid = max(0, 255 - distance); - - status = MV_PlayOGG(ptr, pitchoffset, mid, left, right, priority, callbackval); - - return(status); -} - -/*--------------------------------------------------------------------- - Function: MV_CreateVolumeTable - - Create the table used to convert sound data to a specific volume - level. ----------------------------------------------------------------------*/ - -void MV_CreateVolumeTable(int32_t index, int32_t volume, int32_t MaxVolume) -{ - int32_t val; - int32_t level; - int32_t i; - - level = (volume * MaxVolume) / MV_MaxTotalVolume; - if (MV_Bits == 16) - { - for (i = 0; i < 65536; i += 256) - { - val = i - 0x8000; - val *= level; - val /= MV_MaxVolume; - MV_VolumeTable[ index ][ i / 256 ] = val; - } - } - else - { - for (i = 0; i < 256; i++) - { - val = i - 0x80; - val *= level; - val /= MV_MaxVolume; - MV_VolumeTable[ volume ][ i ] = val; - } - } -} - - -/*--------------------------------------------------------------------- - Function: MV_CalcVolume - - Create the table used to convert sound data to a specific volume - level. ----------------------------------------------------------------------*/ - -void MV_CalcVolume(int32_t MaxVolume) -{ - int32_t 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) -{ - int32_t level; - int32_t angle; - int32_t distance; - int32_t HalfAngle; - int32_t 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(int32_t 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. ----------------------------------------------------------------------*/ - -int32_t MV_GetVolume(void) -{ - return(MV_TotalVolume); -} - - -/*--------------------------------------------------------------------- - Function: MV_SetCallBack - - Set the function to call when a voice stops. ----------------------------------------------------------------------*/ - -void MV_SetCallBack(void(*function)(uint32_t)) -{ - MV_CallBackFunc = function; -} - - -/*--------------------------------------------------------------------- - Function: MV_SetReverseStereo - - Set the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -void MV_SetReverseStereo(int32_t setting) -{ - MV_SwapLeftRight = setting; -} - - -/*--------------------------------------------------------------------- - Function: MV_GetReverseStereo - - Returns the orientation of the left and right channels. ----------------------------------------------------------------------*/ - -int32_t MV_GetReverseStereo(void) -{ - return(MV_SwapLeftRight); -} - -#if 0 -/*--------------------------------------------------------------------- - Function: MV_TestPlayback - - Checks if playback has started. ----------------------------------------------------------------------*/ - -int32_t MV_TestPlayback(void) -{ - uint32_t flags; - int32_t time; - int32_t start; - int32_t status; - int32_t pos; - - flags = DisableInterrupts(); - _enable(); - - status = MV_Error; - start = MV_MixPage; - time = clock() + CLOCKS_PER_SEC * 2; - - while (clock() < time) - { - if (MV_MixPage != start) - { - status = MV_Ok; - } - } - - RestoreInterrupts(flags); - - if (status != MV_Ok) - { - // Just in case an error doesn't get reported - MV_SetErrorCode(MV_DMAFailure); - - switch (MV_SoundCard) - { - case SoundBlaster : - pos = BLASTER_GetCurrentPos(); - break; - - default : - MV_SetErrorCode(MV_UnsupportedCard); - pos = -2; - break; - } - - if (pos > 0) - { - MV_SetErrorCode(MV_IrqFailure); - } - else if (pos == 0) - { - if (MV_Bits == 16) - { - MV_SetErrorCode(MV_DMA16Failure); - } - else - { - MV_SetErrorCode(MV_DMAFailure); - } - } - } - - return(status); -} -#endif - -/*--------------------------------------------------------------------- - Function: MV_Init - - Perform the initialization of variables and memory used by - Multivoc. ----------------------------------------------------------------------*/ - -int32_t MV_Init(int32_t soundcard, int32_t MixRate, int32_t Voices, int32_t numchannels, int32_t samplebits) -{ - char *ptr; - int32_t status; - int32_t buffer; - int32_t index; - - if (MV_Installed) - { - MV_Shutdown(); - } - - initprintf("Initializing MultiVoc... \n"); - - MV_SetErrorCode(MV_Ok); - - MV_TotalMemory = Voices * sizeof(VoiceNode) + sizeof(HARSH_CLIP_TABLE_8); - ptr = Bmalloc(MV_TotalMemory); - if (ptr == NULL) - { - MV_SetErrorCode(MV_NoMem); - return(MV_Error); - } - - MV_Voices = (VoiceNode *)ptr; - MV_HarshClipTable = ptr + (MV_TotalMemory - sizeof(HARSH_CLIP_TABLE_8)); - - // Set number of voices before calculating volume table - MV_MaxVoices = Voices; - -// initprintf(" - Maximum voices: %d\n", MV_MaxVoices); - - LL_Reset(&VoiceList, next, prev); - LL_Reset(&VoicePool, next, prev); - - for (index = 0; index < Voices; index++) - { - LL_Add(&VoicePool, &MV_Voices[ index ], next, prev); - } - - // Set the sampling rate - MV_RequestedMixRate = MixRate; - - initprintf(" - %d voices, %d byte mixing buffers\n", MV_MaxVoices, MixBufferSize); - - // Allocate mix buffer within 1st megabyte - // use calloc to clear the memory for the first playback. - ptr = (char *)Bcalloc(1,TotalBufferSize + 8); // FIXME: temporarily fixes bounds error somewhere... - if (!ptr) - { - Bfree(MV_Voices); - MV_Voices = NULL; - MV_TotalMemory = 0; - - MV_SetErrorCode(MV_NoMem); - return(MV_Error); - } - - MV_MixBufferPtr = ptr; - - MV_SetReverseStereo(FALSE); - - // Initialize the sound card -#if defined(_WIN32) - status = DSOUND_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize); -#else - status = DSL_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize); -#endif - if (status != 0) - { - MV_SetErrorCode(MV_BlasterError); - } - - if (MV_ErrorCode != MV_Ok) - { - status = MV_ErrorCode; - - Bfree(MV_Voices); - MV_Voices = NULL; - MV_TotalMemory = 0; - - free(ptr); - - 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 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); - } - - return(MV_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MV_Shutdown - - Restore any resources allocated by Multivoc back to the system. ----------------------------------------------------------------------*/ - -int32_t MV_Shutdown(void) -{ - int32_t buffer; - uint32_t flags; - - if (!MV_Installed) - { - return(MV_Ok); - } - - initprintf("Uninitializing MultiVoc...\n"); - - flags = DisableInterrupts(); - - MV_KillAllVoices(); - - MV_Installed = FALSE; - - // Stop the sound recording engine - if (MV_Recording) - { - //MV_StopRecord(); - } - - // Stop the sound playback engine - MV_StopPlayback(); - - // G_Shutdown the sound card -#if defined(_WIN32) - DSOUND_Shutdown(); -#else - DSL_Shutdown(); -#endif - - RestoreInterrupts(flags); - - // Free any voices we allocated - Bfree(MV_Voices); - MV_Voices = NULL; - MV_TotalMemory = 0; - - LL_Reset(&VoiceList, next, prev); - LL_Reset(&VoicePool, next, prev); - - MV_MaxVoices = 1; - - // Release the descriptor from our mix buffer - if (MV_MixBufferPtr) free(MV_MixBufferPtr); - MV_MixBufferPtr = NULL; - - for (buffer = 0; buffer < NumberOfBuffers; buffer++) - { - MV_MixBuffer[ buffer ] = NULL; - } - - return(MV_Ok); -} - - diff --git a/polymer/eduke32/source/jaudiolib/multivoc.h b/polymer/eduke32/source/jaudiolib/multivoc.h deleted file mode 100644 index 3cf232abd..000000000 --- a/polymer/eduke32/source/jaudiolib/multivoc.h +++ /dev/null @@ -1,133 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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 - -#include "compat.h" - -#define MV_MinVoiceHandle 1 - -extern int32_t 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_DPMI_Error, - MV_InvalidVOCFile, - MV_InvalidWAVFile, - MV_InvalidOGGFile, - MV_InvalidMixMode, - MV_IrqFailure, - MV_DMAFailure, - MV_DMA16Failure, - MV_NullRecordFunction - }; - -typedef int16_t MONO16; -typedef int8_t MONO8; - -typedef MONO8 VOLUME8[ 256 ]; -typedef MONO16 VOLUME16[ 256 ]; - -char *MV_ErrorString( int32_t ErrorNumber ); -int32_t MV_VoicePlaying( int32_t handle ); -int32_t MV_KillAllVoices( void ); -int32_t MV_Kill( int32_t handle ); -int32_t MV_VoicesPlaying( void ); -int32_t MV_VoiceAvailable( int32_t priority ); -int32_t MV_SetPitch( int32_t handle, int32_t pitchoffset ); -int32_t MV_SetFrequency( int32_t handle, int32_t frequency ); -int32_t MV_EndLooping( int32_t handle ); -int32_t MV_SetPan( int32_t handle, int32_t vol, int32_t left, int32_t right ); -int32_t MV_Pan3D( int32_t handle, int32_t angle, int32_t distance ); -void MV_SetReverb( int32_t reverb ); -void MV_SetFastReverb( int32_t reverb ); -int32_t MV_GetMaxReverbDelay( void ); -int32_t MV_GetReverbDelay( void ); -void MV_SetReverbDelay( int32_t delay ); -int32_t MV_SetMixMode( int32_t numchannels, int32_t samplebits ); -int32_t MV_StartPlayback( void ); -void MV_StopPlayback( void ); -int32_t MV_StartRecording( int32_t MixRate, void ( *function )( char *ptr, int32_t length ) ); -void MV_StopRecord( void ); -int32_t MV_StartDemandFeedPlayback( void ( *function )( char **ptr, uint32_t *length ), - int32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, - int32_t priority, uint32_t callbackval ); -int32_t MV_PlayRaw( char *ptr, uint32_t length, - uint32_t rate, int32_t pitchoffset, int32_t vol, int32_t left, - int32_t right, int32_t priority, uint32_t callbackval ); -int32_t MV_PlayLoopedRaw( char *ptr, int32_t length, - char *loopstart, char *loopend, uint32_t rate, int32_t pitchoffset, - int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t MV_PlayWAV( char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, - int32_t right, int32_t priority, uint32_t callbackval ); -int32_t MV_PlayWAV3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, - int32_t priority, uint32_t callbackval ); -int32_t MV_PlayLoopedWAV( char *ptr, int32_t loopstart, int32_t loopend, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t MV_PlayOGG( char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, - int32_t right, int32_t priority, uint32_t callbackval ); -int32_t MV_PlayOGG3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, - int32_t priority, uint32_t callbackval ); -int32_t MV_PlayLoopedOGG( char *ptr, int32_t loopstart, int32_t loopend, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -int32_t MV_PlayVOC3D( char *ptr, int32_t pitchoffset, int32_t angle, int32_t distance, - int32_t priority, uint32_t callbackval ); -int32_t MV_PlayVOC( char *ptr, int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, - int32_t priority, uint32_t callbackval ); -int32_t MV_PlayLoopedVOC( char *ptr, int32_t loopstart, int32_t loopend, - int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority, - uint32_t callbackval ); -void MV_CreateVolumeTable( int32_t index, int32_t volume, int32_t MaxVolume ); -void MV_SetVolume( int32_t volume ); -int32_t MV_GetVolume( void ); -void MV_SetCallBack( void ( *function )( uint32_t ) ); -void MV_SetReverseStereo( int32_t setting ); -int32_t MV_GetReverseStereo( void ); -int32_t MV_Init( int32_t soundcard, int32_t MixRate, int32_t Voices, int32_t numchannels, - int32_t samplebits ); -int32_t MV_Shutdown( void ); - -void MV_Update(void); - -#endif diff --git a/polymer/eduke32/source/jaudiolib/music.c b/polymer/eduke32/source/jaudiolib/music.c deleted file mode 100644 index a5335f070..000000000 --- a/polymer/eduke32/source/jaudiolib/music.c +++ /dev/null @@ -1,634 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - module: MUSIC.C - - author: James R. Dose - date: March 25, 1994 - - Device independant music playback routines. - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#include -#include -#include "music.h" -#include "midi.h" -#include "mpu401.h" -#include "compat.h" -#ifdef USE_OPENAL -#include "openal.h" -#endif -#include "duke3d.h" - -#ifndef TRUE -#define TRUE ( 1 == 1 ) -#define FALSE ( !TRUE ) -#endif - -#ifndef min -#define min(a,b) (((a)<(b))?(a):(b)) -#endif - -#ifndef max -# define max(a,b) ( ((a) > (b)) ? (a) : (b) ) -#endif - -int32_t MUSIC_SoundDevice = -1; -int32_t MUSIC_ErrorCode = MUSIC_Ok; - -static midifuncs MUSIC_MidiFunctions; - -int32_t MUSIC_InitMidi(int32_t card, midifuncs *Funcs, int32_t Address); - -#define MUSIC_SetErrorCode( status ) \ - MUSIC_ErrorCode = ( status ); - -/*--------------------------------------------------------------------- - Function: MUSIC_ErrorString - - Returns a pointer to the error message associated with an error - number. A -1 returns a pointer the current error. ----------------------------------------------------------------------*/ - -char *MUSIC_ErrorString -( - int32_t ErrorNumber -) - -{ - char *ErrorString; - - switch (ErrorNumber) - { - case MUSIC_Warning : - case MUSIC_Error : - ErrorString = MUSIC_ErrorString(MUSIC_ErrorCode); - break; - - case MUSIC_Ok : - ErrorString = "Music ok."; - break; - - case MUSIC_ASSVersion : - ErrorString = "Apogee Sound System Version WinMM " - "Programmed by Jim Dose, Ported by Jonathon Fowler\n" - "(c) Copyright 1996 James R. Dose. All Rights Reserved.\n"; - break; - - case MUSIC_SoundCardError : - case MUSIC_MPU401Error : - ErrorString = "Could not detect MPU-401."; - break; - - case MUSIC_InvalidCard : - ErrorString = "Invalid Music device."; - break; - - case MUSIC_MidiError : - ErrorString = "Error playing MIDI file."; - break; - - case MUSIC_TaskManError : - ErrorString = "TaskMan error."; - break; - - case MUSIC_DPMI_Error : - ErrorString = "DPMI Error in MUSIC."; - break; - - default : - ErrorString = "Unknown Music error code."; - break; - } - - return(ErrorString); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Init - - Selects which sound device to use. ----------------------------------------------------------------------*/ - -int32_t MUSIC_Init -( - int32_t SoundCard, - int32_t Address -) - -{ - int32_t i; - int32_t status; - - for (i = 0; i < 128; i++) - { - MIDI_PatchMap[ i ] = i; - } - - MUSIC_SoundDevice = SoundCard; - - status = MUSIC_InitMidi(SoundCard, &MUSIC_MidiFunctions, Address); - -#ifdef USE_OPENAL - if (AL_Init()) - { - int32_t i; - - // no AL support so shitcan the ogg definitions - for (i=(MAXLEVELS*(MAXVOLUMES+1))-1;i>=0;i--) // +1 volume for "intro", "briefing" music - { - if (MapInfo[i].musicfn1 != NULL) - Bfree(MapInfo[i].musicfn1); - MapInfo[i].musicfn1 = NULL; - } - } -#endif - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Shutdown - - Terminates use of sound device. ----------------------------------------------------------------------*/ - -int32_t MUSIC_Shutdown -( - void -) - -{ - int32_t status; - - status = MUSIC_Ok; - - MIDI_StopSong(); - - //MPU_Reset(); - -#ifdef USE_OPENAL - AL_Shutdown(); -#endif - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetVolume - - Sets the volume of music playback. ----------------------------------------------------------------------*/ - -void MUSIC_SetVolume -( - int32_t volume -) - -{ - volume = max(0, volume); - volume = min(volume, 255); -#ifdef USE_OPENAL - AL_SetMusicVolume(volume); -#endif - if (MUSIC_SoundDevice != -1) - { - MIDI_SetVolume(volume); - } -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetMidiChannelVolume - - Sets the volume of music playback on the specified MIDI channel. ----------------------------------------------------------------------*/ - -void MUSIC_SetMidiChannelVolume -( - int32_t channel, - int32_t volume -) - -{ - MIDI_SetUserChannelVolume(channel, volume); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_ResetMidiChannelVolumes - - Sets the volume of music playback on all MIDI channels to full volume. ----------------------------------------------------------------------*/ - -void MUSIC_ResetMidiChannelVolumes -( - void -) - -{ - MIDI_ResetUserChannelVolume(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetVolume - - Returns the volume of music playback. ----------------------------------------------------------------------*/ - -int32_t MUSIC_GetVolume -( - void -) - -{ - if (MUSIC_SoundDevice == -1) - { - return(0); - } - return(MIDI_GetVolume()); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetLoopFlag - - Set whether the music will loop or end when it reaches the end of - the song. ----------------------------------------------------------------------*/ - -void MUSIC_SetLoopFlag -( - int32_t loopflag -) - -{ - MIDI_SetLoopFlag(loopflag); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SongPlaying - - Returns whether there is a song playing. ----------------------------------------------------------------------*/ - -int32_t MUSIC_SongPlaying -( - void -) - -{ - return(MIDI_SongPlaying()); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Continue - - Continues playback of a paused song. ----------------------------------------------------------------------*/ - -void MUSIC_Continue -( - void -) - -{ -#ifdef USE_OPENAL - AL_Continue(); -#endif - MIDI_ContinueSong(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Pause - - Pauses playback of a song. ----------------------------------------------------------------------*/ - -void MUSIC_Pause -( - void -) - -{ -#ifdef USE_OPENAL - AL_Pause(); -#endif - MIDI_PauseSong(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_StopSong - - Stops playback of current song. ----------------------------------------------------------------------*/ - -int32_t MUSIC_StopSong -( - void -) - -{ -#ifdef USE_OPENAL - AL_Stop(); -#endif - MUSIC_StopFade(); - MIDI_StopSong(); - MUSIC_SetErrorCode(MUSIC_Ok); - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_PlaySong - - Begins playback of MIDI song. ----------------------------------------------------------------------*/ - -int32_t MUSIC_PlaySong -( - char *song, - int32_t loopflag -) - -{ - int32_t status; - -#ifdef USE_OPENAL - AL_PlaySong((char *)song,loopflag); - - if (AL_isntALmusic()) -#endif - { - MUSIC_StopSong(); - status = MIDI_PlaySong(song, loopflag); - if (status != MIDI_Ok) - { - MUSIC_SetErrorCode(MUSIC_MidiError); - return(MUSIC_Warning); - } - } - - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetContext - - Sets the song context. ----------------------------------------------------------------------*/ - -void MUSIC_SetContext -( - int32_t context -) - -{ - MIDI_SetContext(context); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetContext - - Returns the current song context. ----------------------------------------------------------------------*/ - -int32_t MUSIC_GetContext -( - void -) - -{ - return MIDI_GetContext(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongTick - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongTick -( - uint32_t PositionInTicks -) - -{ - MIDI_SetSongTick(PositionInTicks); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongTime - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongTime -( - uint32_t milliseconds -) - -{ - MIDI_SetSongTime(milliseconds); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongPosition - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongPosition -( - int32_t measure, - int32_t beat, - int32_t tick -) - -{ - MIDI_SetSongPosition(measure, beat, tick); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetSongPosition - - Returns the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_GetSongPosition -( - songposition *pos -) - -{ - MIDI_GetSongPosition(pos); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetSongLength - - Returns the length of the song. ----------------------------------------------------------------------*/ - -void MUSIC_GetSongLength -( - songposition *pos -) - -{ - MIDI_GetSongLength(pos); -} - - -int32_t MUSIC_InitMidi -( - int32_t card, - midifuncs *Funcs, - int32_t Address -) - -{ - UNREFERENCED_PARAMETER(card); - UNREFERENCED_PARAMETER(Address); - Funcs->NoteOff = MPU_NoteOff; - Funcs->NoteOn = MPU_NoteOn; - Funcs->PolyAftertouch = MPU_PolyAftertouch; - Funcs->ControlChange = MPU_ControlChange; - Funcs->ProgramChange = MPU_ProgramChange; - Funcs->ChannelAftertouch = MPU_ChannelAftertouch; - Funcs->PitchBend = MPU_PitchBend; - Funcs->ReleasePatches = NULL; - Funcs->LoadPatch = NULL; - Funcs->SetVolume = NULL /*MPU_SetVolume*/; - Funcs->GetVolume = NULL /*MPU_GetVolume*/; - - MIDI_SetMidiFuncs(Funcs); - - return(MIDI_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_FadeVolume - - Fades music volume from current level to another over a specified - period of time. ----------------------------------------------------------------------*/ - -int32_t MUSIC_FadeVolume -( - int32_t tovolume, - int32_t milliseconds -) - -{ - UNREFERENCED_PARAMETER(milliseconds); - MIDI_SetVolume(tovolume); - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_FadeActive - - Returns whether the fade routine is active. ----------------------------------------------------------------------*/ - -int32_t MUSIC_FadeActive -( - void -) - -{ - return(0); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_StopFade - - Stops fading the music. ----------------------------------------------------------------------*/ - -void MUSIC_StopFade -( - void -) - -{} - - -/*--------------------------------------------------------------------- - Function: MUSIC_RerouteMidiChannel - - Sets callback function to reroute MIDI commands from specified - function. ----------------------------------------------------------------------*/ - -void MUSIC_RerouteMidiChannel -( - int32_t channel, - int32_t(*function)(int32_t event, int32_t c1, int32_t c2) -) - -{ - MIDI_RerouteMidiChannel(channel, function); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_RegisterTimbreBank - - Halts playback of all sounds. ----------------------------------------------------------------------*/ - -void MUSIC_RegisterTimbreBank -( - char *timbres -) - -{ - UNREFERENCED_PARAMETER(timbres); -} - - -void MUSIC_Update(void) -{ - MIDI_UpdateMusic(); -} - diff --git a/polymer/eduke32/source/jaudiolib/music.h b/polymer/eduke32/source/jaudiolib/music.h deleted file mode 100644 index e63af97f2..000000000 --- a/polymer/eduke32/source/jaudiolib/music.h +++ /dev/null @@ -1,92 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - module: MUSIC.H - - author: James R. Dose - date: March 25, 1994 - - Public header for MUSIC.C - - (c) Copyright 1994 James R. Dose. All Rights Reserved. -**********************************************************************/ - -#ifndef __MUSIC_H -#define __MUSIC_H - -#include "compat.h" - -extern int32_t MUSIC_ErrorCode; - -enum MUSIC_ERRORS - { - MUSIC_Warning = -2, - MUSIC_Error = -1, - MUSIC_Ok = 0, - MUSIC_ASSVersion, - MUSIC_SoundCardError, - MUSIC_MPU401Error, - MUSIC_InvalidCard, - MUSIC_MidiError, - MUSIC_TaskManError, - MUSIC_DPMI_Error - }; - -typedef struct - { - uint32_t tickposition; - uint32_t milliseconds; - uint32_t measure; - uint32_t beat; - uint32_t tick; - } songposition; - -#define MUSIC_LoopSong ( 1 == 1 ) -#define MUSIC_PlayOnce ( !MUSIC_LoopSong ) - -char *MUSIC_ErrorString( int32_t ErrorNumber ); -int32_t MUSIC_Init( int32_t SoundCard, int32_t Address ); -int32_t MUSIC_Shutdown( void ); -void MUSIC_SetVolume( int32_t volume ); -void MUSIC_SetMidiChannelVolume( int32_t channel, int32_t volume ); -void MUSIC_ResetMidiChannelVolumes( void ); -int32_t MUSIC_GetVolume( void ); -void MUSIC_SetLoopFlag( int32_t loopflag ); -int32_t MUSIC_SongPlaying( void ); -void MUSIC_Continue( void ); -void MUSIC_Pause( void ); -int32_t MUSIC_StopSong( void ); -int32_t MUSIC_PlaySong( char *song, int32_t loopflag ); -void MUSIC_SetContext( int32_t context ); -int32_t MUSIC_GetContext( void ); -void MUSIC_SetSongTick( uint32_t PositionInTicks ); -void MUSIC_SetSongTime( uint32_t milliseconds ); -void MUSIC_SetSongPosition( int32_t measure, int32_t beat, int32_t tick ); -void MUSIC_GetSongPosition( songposition *pos ); -void MUSIC_GetSongLength( songposition *pos ); -int32_t MUSIC_FadeVolume( int32_t tovolume, int32_t milliseconds ); -int32_t MUSIC_FadeActive( void ); -void MUSIC_StopFade( void ); -void MUSIC_RerouteMidiChannel( int32_t channel, int32_t ( *function )( int32_t event, int32_t c1, int32_t c2 ) ); -void MUSIC_RegisterTimbreBank( char *timbres ); -void MUSIC_Update(void); - -#endif diff --git a/polymer/eduke32/source/jaudiolib/mv_mix-c.c b/polymer/eduke32/source/jaudiolib/mv_mix-c.c deleted file mode 100644 index 0d78b307f..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix-c.c +++ /dev/null @@ -1,301 +0,0 @@ -#include "multivoc.h" - -extern char *MV_MixDestination; -extern uint32_t MV_MixPosition; - -extern char *MV_LeftVolume; -extern char *MV_RightVolume; - -extern char *MV_HarshClipTable; - -extern int32_t MV_RightChannelOffset; -extern int32_t MV_SampleSize; - -void MV_Mix8BitMono(uint32_t position, uint32_t rate, - const char *start, uint32_t length) -{ - const char *src; - char *dest; - uint32_t i; - - src = (const char *)start; - dest = (char *)MV_MixDestination; - - for (i = 0; i < length; i++) - { - int32_t s = src[position >> 16]; - int32_t 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(uint32_t position, - uint32_t rate, const char *start, uint32_t length) -{ - const char *src; - char *dest; - uint32_t i; - - src = (const char *)start; - dest = (char *)MV_MixDestination; - - for (i = 0; i < length; i++) - { - int32_t s = src[(position >> 16)]; - int32_t dl = dest[0]; - int32_t 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(uint32_t position, - uint32_t rate, const char *start, uint32_t length) -{ - const int16_t *MV_LeftVolumeS; - const char *src; - int16_t *dest; - uint32_t i; - - src = (const char *)start; - dest = (int16_t *)MV_MixDestination; - - MV_LeftVolumeS = (const int16_t *)MV_LeftVolume; - - for (i = 0; i < length; i++) - { - int32_t s = src[position >> 16]; - int32_t d = dest[0]; - - s = MV_LeftVolumeS[s]; - - s += d; - - if (s < -32768) s = -32768; - if (s > 32767) s = 32767; - - *dest = (int16_t) s; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix16BitStereo(uint32_t position, - uint32_t rate, const char *start, uint32_t length) -{ - const int16_t *MV_LeftVolumeS; - const int16_t *MV_RightVolumeS; - const char *src; - int16_t *dest; - uint32_t i; - - src = (char *)start; - dest = (int16_t *)MV_MixDestination; - - MV_LeftVolumeS = (const int16_t *)MV_LeftVolume; - MV_RightVolumeS = (const int16_t *)MV_RightVolume; - - for (i = 0; i < length; i++) - { - int32_t s = src[position >> 16]; - int32_t dl = dest[0]; - int32_t 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] = (int16_t) dl; - dest[MV_RightChannelOffset/2] = (int16_t) dr; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix8BitMono16(uint32_t position, uint32_t rate, - const char *start, uint32_t length) -{ - const char *src; - char *dest; - uint32_t i; - - src = (const char *)start + 1; - dest = (char *)MV_MixDestination; - - for (i = 0; i < length; i++) - { - int32_t s = (int32_t)src[(position >> 16) * 2] + 0x80; - int32_t 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(uint32_t position, - uint32_t rate, const char *start, uint32_t length) -{ - const char *src; - char *dest; - uint32_t i; - - src = (const char *)start + 1; - dest = (char *)MV_MixDestination; - - for (i = 0; i < length; i++) - { - int32_t s = src[(position >> 16) * 2] + 0x80; - int32_t dl = dest[0]; - int32_t 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(uint32_t position, - uint32_t rate, const char *start, uint32_t length) -{ - const int16_t *MV_LeftVolumeS; - const char *src; - int16_t *dest; - uint32_t i; - - src = (const char *)start; - dest = (int16_t *)MV_MixDestination; - - MV_LeftVolumeS = (const int16_t *)MV_LeftVolume; - - for (i = 0; i < length; i++) - { - int32_t sl = src[(position >> 16) * 2 + 0]; - int32_t sh = src[(position >> 16) * 2 + 1] ^ 0x80; - - int32_t 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 = (int16_t) d; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} - -void MV_Mix16BitStereo16(uint32_t position, - uint32_t rate, const char *start, uint32_t length) -{ - const int16_t *MV_LeftVolumeS; - const int16_t *MV_RightVolumeS; - const char *src; - int16_t *dest; - uint32_t i; - - src = (const char *)start; - dest = (int16_t *)MV_MixDestination; - - MV_LeftVolumeS = (const int16_t *)MV_LeftVolume; - MV_RightVolumeS = (const int16_t *)MV_RightVolume; - - for (i = 0; i < length; i++) - { - int32_t sl = src[(position >> 16) * 2 + 0]; - int32_t sh = src[(position >> 16) * 2 + 1] ^ 0x80; - - int32_t dl = dest[0]; - int32_t dr = dest[MV_RightChannelOffset/2]; - - int32_t sll = MV_LeftVolume[sl * 2 + 1]; - int32_t slh = MV_LeftVolumeS[sh]; - - int32_t srl = MV_RightVolume[sl * 2 + 1]; - int32_t 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] = (int16_t) dl; - dest[MV_RightChannelOffset/2] = (int16_t) dr; - - position += rate; - dest += MV_SampleSize/2; - } - - MV_MixPosition = position; - MV_MixDestination = (char *)dest; -} diff --git a/polymer/eduke32/source/jaudiolib/mv_mix.masm b/polymer/eduke32/source/jaudiolib/mv_mix.masm deleted file mode 100644 index d4bcf6c5a..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix.masm +++ /dev/null @@ -1,487 +0,0 @@ -.586P - -EXTRN _MV_HarshClipTable : dword -EXTRN _MV_MixDestination : dword -EXTRN _MV_MixPosition : dword -EXTRN _MV_LeftVolume : dword -EXTRN _MV_RightVolume : dword -EXTRN _MV_SampleSize : dword -EXTRN _MV_RightChannelOffset : dword - -CODE SEGMENT PUBLIC USE32 'DATA' -ASSUME cs:CODE,ds:CODE - -;================ -; -; MV_Mix8BitMono -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix8BitMono -_MV_Mix8BitMono: -; Two at once - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [apatch7+2],bl - mov byte ptr [apatch8+2],bl - mov byte ptr [apatch9+3],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume ; Since we're mono, use left volume - mov dword ptr [apatch1+4],ebx - mov dword ptr [apatch2+4],ebx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx, 128 - mov dword ptr [apatch3+2],ebx - mov dword ptr [apatch4+2],ebx - - ; Rate scale ptr - mov dword ptr [apatch5+2],edx - mov dword ptr [apatch6+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je short exit8m - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; apatch1 - volume table -; apatch2 - volume table -; apatch3 - harsh clip table -; apatch4 - harsh clip table -; apatch5 - sample rate -; apatch6 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movzx eax, byte ptr [esi+eax] ; get first sample - movzx ebx, byte ptr [esi+ebx] ; get second sample - -;ALIGN 4 -mix8Mloop: - movzx edx, byte ptr [edi] ; get current sample from destination -apatch1: - movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample -apatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -apatch9: - movzx edx, byte ptr [edi + 1] ; get current sample from destination -apatch3: - mov eax, [eax + 12345678h] ; harsh clip new sample - add ebx, edx ; mix second sample - mov [edi], al ; write new sample to destination - mov edx, ebp ; begin calculating third sample -apatch4: - mov ebx, [ebx + 12345678h] ; harsh clip new sample -apatch5: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -apatch7: - add edi, 1 ; move destination to second sample - shr eax, 16 ; finish calculation for fourth sample - mov [edi], bl ; write new sample to destination -apatch6: - add ebp,12345678h ; advance frac pointer - movzx ebx, byte ptr [esi+eax] ; get fourth sample - movzx eax, byte ptr [esi+edx] ; get third sample -apatch8: - add edi, 2 ; move destination to third sample - dec ecx ; decrement count - jnz mix8Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit8m: - popad - ret - - -;================ -; -; MV_Mix8BitStereo -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix8BitStereo -_MV_Mix8BitStereo: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [bpatch8+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [bpatch6+3],ebx - mov dword ptr [bpatch7+2],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [bpatch1+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [bpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [bpatch3+2],edx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx,128 - mov dword ptr [bpatch4+2],ebx - mov dword ptr [bpatch5+2],ebx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je short exit8S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; bpatch1 - left volume table -; bpatch2 - right volume table -; bpatch3 - sample rate -; bpatch4 - harsh clip table -; bpatch5 - harsh clip table - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movzx ebx, byte ptr [esi+eax] ; get first sample - -;ALIGN 4 -mix8Sloop: -bpatch1: - movsx eax, byte ptr [2*ebx+12345678h] ; volume translate left sample - movzx edx, byte ptr [edi] ; get current sample from destination -bpatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -bpatch3: - add ebp,12345678h ; advance frac pointer -bpatch6: - movzx edx, byte ptr [edi+12345678h] ; get current sample from destination -bpatch4: - mov eax, [eax + 12345678h] ; harsh clip left sample - add ebx, edx ; mix right sample - mov [edi], al ; write left sample to destination -bpatch5: - mov ebx, [ebx + 12345678h] ; harsh clip right sample - mov edx, ebp ; begin calculating second sample -bpatch7: - mov [edi+12345678h], bl ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -bpatch8: - add edi, 2 ; move destination to second sample - movzx ebx, byte ptr [esi+edx] ; get second sample - dec ecx ; decrement count - jnz mix8Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position - -EXIT8S: - popad - ret - - -;================ -; -; MV_Mix16BitMono -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix16BitMono -_MV_Mix16BitMono: -; Two at once - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [cpatch5+3],bl - mov byte ptr [cpatch6+3],bl - add bl,bl - mov byte ptr [cpatch7+2],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [cpatch1+4],ebx - mov dword ptr [cpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [cpatch3+2],edx - mov dword ptr [cpatch4+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je exit16M - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; cpatch1 - volume table -; cpatch2 - volume table -; cpatch3 - sample rate -; cpatch4 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movzx eax, byte ptr [esi+eax] ; get first sample - movzx ebx, byte ptr [esi+ebx] ; get second sample - -;ALIGN 4 -mix16Mloop: - movsx edx, word ptr [edi] ; get current sample from destination -cpatch1: - movsx eax, word ptr [2*eax+12345678h] ; volume translate first sample -cpatch2: - movsx ebx, word ptr [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -cpatch5: - movsx edx, word ptr [edi + 2] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short m16skip1 - mov eax, -32768 - jmp short m16skip2 -m16skip1: - cmp eax, 32767 - jle short m16skip2 - mov eax, 32767 -m16skip2: - add ebx, edx ; mix second sample - mov [edi], ax ; write new sample to destination - mov edx, ebp ; begin calculating third sample - - cmp ebx, -32768 ; Harsh clip sample - jge short m16skip3 - mov ebx, -32768 - jmp short m16skip4 -m16skip3: - cmp ebx, 32767 - jle short m16skip4 - mov ebx, 32767 -m16skip4: -cpatch3: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -cpatch6: - mov [edi + 2], bx ; write new sample to destination - shr eax, 16 ; finish calculation for fourth sample - -cpatch4: - add ebp,12345678h ; advance frac pointer - movzx ebx, byte ptr [esi+eax] ; get fourth sample -cpatch7: - add edi, 4 ; move destination to third sample - movzx eax, byte ptr [esi+edx] ; get third sample - dec ecx ; decrement count - jnz mix16Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -EXIT16M: - popad - ret - - -;================ -; -; MV_Mix16BitStereo -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix16BitStereo -_MV_Mix16BitStereo: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [dpatch6+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [dpatch4+3],ebx - mov dword ptr [dpatch5+3],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [dpatch1+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [dpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [dpatch3+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je exit16S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; dpatch1 - left volume table -; dpatch2 - right volume table -; dpatch3 - sample rate - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movzx ebx, byte ptr [esi+eax] ; get first sample - -;ALIGN 4 -mix16Sloop: -dpatch1: - movsx eax, word ptr [2*ebx+12345678h] ; volume translate left sample - movsx edx, word ptr [edi] ; get current sample from destination -dpatch2: - movsx ebx, word ptr [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -dpatch3: - add ebp,12345678h ; advance frac pointer -dpatch4: - movsx edx, word ptr [edi+12345678h] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short s16skip1 - mov eax, -32768 - jmp short s16skip2 -s16skip1: - cmp eax, 32767 - jle short s16skip2 - mov eax, 32767 -s16skip2: - add ebx, edx ; mix right sample - mov [edi], ax ; write left sample to destination - - cmp ebx, -32768 ; Harsh clip sample - jge short s16skip3 - mov ebx, -32768 - jmp short s16skip4 -s16skip3: - cmp ebx, 32767 - jle short s16skip4 - mov ebx, 32767 -s16skip4: - - mov edx, ebp ; begin calculating second sample -dpatch5: - mov [edi+12345678h], bx ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -dpatch6: - add edi, 4 ; move destination to second sample - movzx ebx, byte ptr [esi+edx] ; get second sample - dec ecx ; decrement count - jnz mix16Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit16S: - popad - ret - -CODE ENDS -END diff --git a/polymer/eduke32/source/jaudiolib/mv_mix.nasm b/polymer/eduke32/source/jaudiolib/mv_mix.nasm deleted file mode 100644 index 56039c2a0..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix.nasm +++ /dev/null @@ -1,524 +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. -; -;Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) - -CPU 386 - -SECTION .data - -%ifdef UNDERSCORES - -%define MV_Mix8BitMono _MV_Mix8BitMono -%define MV_Mix8BitStereo _MV_Mix8BitStereo -%define MV_Mix16BitMono _MV_Mix16BitMono -%define MV_Mix16BitStereo _MV_Mix16BitStereo - -%else - -%define _MV_HarshClipTable MV_HarshClipTable -%define _MV_MixDestination MV_MixDestination -%define _MV_MixPosition MV_MixPosition -%define _MV_LeftVolume MV_LeftVolume -%define _MV_RightVolume MV_RightVolume -%define _MV_SampleSize MV_SampleSize -%define _MV_RightChannelOffset MV_RightChannelOffset - -%endif - - EXTERN _MV_HarshClipTable - EXTERN _MV_MixDestination - EXTERN _MV_MixPosition - EXTERN _MV_LeftVolume - EXTERN _MV_RightVolume - EXTERN _MV_SampleSize - EXTERN _MV_RightChannelOffset - - GLOBAL MV_Mix8BitMono - GLOBAL MV_Mix8BitStereo - GLOBAL MV_Mix16BitMono - GLOBAL MV_Mix16BitStereo - - -;================ -; -; MV_Mix8BitMono -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix8BitMono: -; Two at once - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [apatch7+2],bl - mov byte [apatch8+2],bl - mov byte [apatch9+3],bl - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] ; Since we're mono, use left volume - mov dword [apatch1+4],ebx - mov dword [apatch2+4],ebx - - ; Harsh Clip table ptr - mov ebx, dword [_MV_HarshClipTable] - add ebx, 128 - mov dword [apatch3+2],ebx - mov dword [apatch4+2],ebx - - ; Rate scale ptr - mov dword [apatch5+2],edx - mov dword [apatch6+2],edx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je short exit8m - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; apatch1 - volume table -; apatch2 - volume table -; apatch3 - harsh clip table -; apatch4 - harsh clip table -; apatch5 - sample rate -; apatch6 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movzx eax, byte [esi+eax] ; get first sample - movzx ebx, byte [esi+ebx] ; get second sample - - ALIGN 4 -mix8Mloop: - movzx edx, byte [edi] ; get current sample from destination -apatch1: - movsx eax, byte [2*eax+12345678h] ; volume translate first sample -apatch2: - movsx ebx, byte [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -apatch9: - movzx edx, byte [edi + 1] ; get current sample from destination -apatch3: - mov eax, dword [eax + 12345678h] ; harsh clip new sample - add ebx, edx ; mix second sample - mov byte [edi], al ; write new sample to destination - mov edx, ebp ; begin calculating third sample -apatch4: - mov ebx, dword [ebx + 12345678h] ; harsh clip new sample -apatch5: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -apatch7: - add edi, 1 ; move destination to second sample - shr eax, 16 ; finish calculation for fourth sample - mov byte [edi], bl ; write new sample to destination -apatch6: - add ebp,12345678h ; advance frac pointer - movzx ebx, byte [esi+eax] ; get fourth sample - movzx eax, byte [esi+edx] ; get third sample -apatch8: - add edi, 2 ; move destination to third sample - dec ecx ; decrement count - jnz mix8Mloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position -exit8m: - popad - ret - - -;================ -; -; MV_Mix8BitStereo -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix8BitStereo: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [bpatch8+2],bl - - ; Right channel offset - mov ebx, dword [_MV_RightChannelOffset] - mov dword [bpatch6+3],ebx - mov dword [bpatch7+2],ebx - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] - mov dword [bpatch1+4],ebx - - mov ebx, dword [_MV_RightVolume] - mov dword [bpatch2+4],ebx - - ; Rate scale ptr - mov dword [bpatch3+2],edx - - ; Harsh Clip table ptr - mov ebx, dword [_MV_HarshClipTable] - add ebx,128 - mov dword [bpatch4+2],ebx - mov dword [bpatch5+2],ebx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je short EXIT8S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; bpatch1 - left volume table -; bpatch2 - right volume table -; bpatch3 - sample rate -; bpatch4 - harsh clip table -; bpatch5 - harsh clip table - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movzx ebx, byte [esi+eax] ; get first sample - - ALIGN 4 -mix8Sloop: -bpatch1: - movsx eax, byte [2*ebx+12345678h] ; volume translate left sample - movzx edx, byte [edi] ; get current sample from destination -bpatch2: - movsx ebx, byte [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -bpatch3: - add ebp,12345678h ; advance frac pointer -bpatch6: - movzx edx, byte [edi+12345678h] ; get current sample from destination -bpatch4: - mov eax, dword [eax + 12345678h] ; harsh clip left sample - add ebx, edx ; mix right sample - mov byte [edi], al ; write left sample to destination -bpatch5: - mov ebx, dword [ebx + 12345678h] ; harsh clip right sample - mov edx, ebp ; begin calculating second sample -bpatch7: - mov byte [edi+12345678h], bl ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -bpatch8: - add edi, 2 ; move destination to second sample - movzx ebx, byte [esi+edx] ; get second sample - dec ecx ; decrement count - jnz mix8Sloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position - -EXIT8S: - popad - ret - - -;================ -; -; MV_Mix16BitMono -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix16BitMono: -; Two at once - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [cpatch5+3],bl - mov byte [cpatch6+3],bl - add bl,bl - mov byte [cpatch7+2],bl - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] - mov dword [cpatch1+4],ebx - mov dword [cpatch2+4],ebx - - ; Rate scale ptr - mov dword [cpatch3+2],edx - mov dword [cpatch4+2],edx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je near EXIT16M - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; cpatch1 - volume table -; cpatch2 - volume table -; cpatch3 - sample rate -; cpatch4 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movzx eax, byte [esi+eax] ; get first sample - movzx ebx, byte [esi+ebx] ; get second sample - - ALIGN 4 -mix16Mloop: - movsx edx, word [edi] ; get current sample from destination -cpatch1: - movsx eax, word [2*eax+12345678h] ; volume translate first sample -cpatch2: - movsx ebx, word [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -cpatch5: - movsx edx, word [edi + 2] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short m16skip1 - mov eax, -32768 - jmp short m16skip2 -m16skip1: - cmp eax, 32767 - jle short m16skip2 - mov eax, 32767 -m16skip2: - add ebx, edx ; mix second sample - mov word [edi], ax ; write new sample to destination - mov edx, ebp ; begin calculating third sample - - cmp ebx, -32768 ; Harsh clip sample - jge short m16skip3 - mov ebx, -32768 - jmp short m16skip4 -m16skip3: - cmp ebx, 32767 - jle short m16skip4 - mov ebx, 32767 -m16skip4: -cpatch3: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -cpatch6: - mov word [edi + 2], bx ; write new sample to destination - shr eax, 16 ; finish calculation for fourth sample - -cpatch4: - add ebp,12345678h ; advance frac pointer - movzx ebx, byte [esi+eax] ; get fourth sample -cpatch7: - add edi, 4 ; move destination to third sample - movzx eax, byte [esi+edx] ; get third sample - dec ecx ; decrement count - jnz mix16Mloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position -EXIT16M: - popad - ret - - -;================ -; -; MV_Mix16BitStereo -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix16BitStereo: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [dpatch6+2],bl - - ; Right channel offset - mov ebx, dword [_MV_RightChannelOffset] - mov dword [dpatch4+3],ebx - mov dword [dpatch5+3],ebx - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] - mov dword [dpatch1+4],ebx - - mov ebx, dword [_MV_RightVolume] - mov dword [dpatch2+4],ebx - - ; Rate scale ptr - mov dword [dpatch3+2],edx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je near exit16S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; dpatch1 - left volume table -; dpatch2 - right volume table -; dpatch3 - sample rate - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movzx ebx, byte [esi+eax] ; get first sample - - ALIGN 4 -mix16Sloop: -dpatch1: - movsx eax, word [2*ebx+12345678h] ; volume translate left sample - movsx edx, word [edi] ; get current sample from destination -dpatch2: - movsx ebx, word [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -dpatch3: - add ebp,12345678h ; advance frac pointer -dpatch4: - movsx edx, word [edi+12345678h] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short s16skip1 - mov eax, -32768 - jmp short s16skip2 -s16skip1: - cmp eax, 32767 - jle short s16skip2 - mov eax, 32767 -s16skip2: - add ebx, edx ; mix right sample - mov word [edi], ax ; write left sample to destination - - cmp ebx, -32768 ; Harsh clip sample - jge short s16skip3 - mov ebx, -32768 - jmp short s16skip4 -s16skip3: - cmp ebx, 32767 - jle short s16skip4 - mov ebx, 32767 -s16skip4: - - mov edx, ebp ; begin calculating second sample -dpatch5: - mov word [edi+12345678h], bx ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -dpatch6: - add edi, 4 ; move destination to second sample - movzx ebx, byte [esi+edx] ; get second sample - dec ecx ; decrement count - jnz mix16Sloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position -exit16S: - popad - ret - diff --git a/polymer/eduke32/source/jaudiolib/mv_mix.wasm b/polymer/eduke32/source/jaudiolib/mv_mix.wasm deleted file mode 100644 index 364f9dac6..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix.wasm +++ /dev/null @@ -1,491 +0,0 @@ -.586P - -EXTRN _MV_HarshClipTable : dword -EXTRN _MV_MixDestination : dword -EXTRN _MV_MixPosition : dword -EXTRN _MV_LeftVolume : dword -EXTRN _MV_RightVolume : dword -EXTRN _MV_SampleSize : dword -EXTRN _MV_RightChannelOffset : dword - -CODE SEGMENT PUBLIC USE32 'DATA' -ASSUME cs:CODE,ds:CODE - -;================ -; -; MV_Mix8BitMono -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix8BitMono_ -MV_Mix8BitMono_: -; Two at once - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [apatch7+2],bl - mov byte ptr [apatch8+2],bl - mov byte ptr [apatch9+3],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume ; Since we're mono, use left volume - mov dword ptr [apatch1+4],ebx - mov dword ptr [apatch2+4],ebx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx, 128 - mov dword ptr [apatch3+2],ebx - mov dword ptr [apatch4+2],ebx - - ; Rate scale ptr - mov dword ptr [apatch5+2],edx - mov dword ptr [apatch6+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je short exit8m - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; apatch1 - volume table -; apatch2 - volume table -; apatch3 - harsh clip table -; apatch4 - harsh clip table -; apatch5 - sample rate -; apatch6 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movzx eax, byte ptr [esi+eax] ; get first sample - movzx ebx, byte ptr [esi+ebx] ; get second sample - -;ALIGN 4 -mix8Mloop: - movzx edx, byte ptr [edi] ; get current sample from destination -apatch1: - movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample -apatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -apatch9: - movzx edx, byte ptr [edi + 1] ; get current sample from destination -apatch3: - mov eax, [eax + 12345678h] ; harsh clip new sample - add ebx, edx ; mix second sample - mov [edi], al ; write new sample to destination - mov edx, ebp ; begin calculating third sample -apatch4: - mov ebx, [ebx + 12345678h] ; harsh clip new sample -apatch5: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -apatch7: - add edi, 1 ; move destination to second sample - shr eax, 16 ; finish calculation for fourth sample - mov [edi], bl ; write new sample to destination -apatch6: - add ebp,12345678h ; advance frac pointer - movzx ebx, byte ptr [esi+eax] ; get fourth sample - movzx eax, byte ptr [esi+edx] ; get third sample -apatch8: - add edi, 2 ; move destination to third sample - dec ecx ; decrement count - jnz mix8Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit8m: - popad - ret - - -;================ -; -; MV_Mix8BitStereo -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix8BitStereo_ -MV_Mix8BitStereo_: - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [bpatch8+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [bpatch6+3],ebx - mov dword ptr [bpatch7+2],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [bpatch1+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [bpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [bpatch3+2],edx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx,128 - mov dword ptr [bpatch4+2],ebx - mov dword ptr [bpatch5+2],ebx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je short exit8S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; bpatch1 - left volume table -; bpatch2 - right volume table -; bpatch3 - sample rate -; bpatch4 - harsh clip table -; bpatch5 - harsh clip table - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movzx ebx, byte ptr [esi+eax] ; get first sample - -;ALIGN 4 -mix8Sloop: -bpatch1: - movsx eax, byte ptr [2*ebx+12345678h] ; volume translate left sample - movzx edx, byte ptr [edi] ; get current sample from destination -bpatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -bpatch3: - add ebp,12345678h ; advance frac pointer -bpatch6: - movzx edx, byte ptr [edi+12345678h] ; get current sample from destination -bpatch4: - mov eax, [eax + 12345678h] ; harsh clip left sample - add ebx, edx ; mix right sample - mov [edi], al ; write left sample to destination -bpatch5: - mov ebx, [ebx + 12345678h] ; harsh clip right sample - mov edx, ebp ; begin calculating second sample -bpatch7: - mov [edi+12345678h], bl ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -bpatch8: - add edi, 2 ; move destination to second sample - movzx ebx, byte ptr [esi+edx] ; get second sample - dec ecx ; decrement count - jnz mix8Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position - -EXIT8S: - popad - ret - - -;================ -; -; MV_Mix16BitMono -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix16BitMono_ -MV_Mix16BitMono_: -; Two at once - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [cpatch5+3],bl - mov byte ptr [cpatch6+3],bl - add bl,bl - mov byte ptr [cpatch7+2],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [cpatch1+4],ebx - mov dword ptr [cpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [cpatch3+2],edx - mov dword ptr [cpatch4+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je exit16M - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; cpatch1 - volume table -; cpatch2 - volume table -; cpatch3 - sample rate -; cpatch4 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movzx eax, byte ptr [esi+eax] ; get first sample - movzx ebx, byte ptr [esi+ebx] ; get second sample - -;ALIGN 4 -mix16Mloop: - movsx edx, word ptr [edi] ; get current sample from destination -cpatch1: - movsx eax, word ptr [2*eax+12345678h] ; volume translate first sample -cpatch2: - movsx ebx, word ptr [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -cpatch5: - movsx edx, word ptr [edi + 2] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short m16skip1 - mov eax, -32768 - jmp short m16skip2 -m16skip1: - cmp eax, 32767 - jle short m16skip2 - mov eax, 32767 -m16skip2: - add ebx, edx ; mix second sample - mov [edi], ax ; write new sample to destination - mov edx, ebp ; begin calculating third sample - - cmp ebx, -32768 ; Harsh clip sample - jge short m16skip3 - mov ebx, -32768 - jmp short m16skip4 -m16skip3: - cmp ebx, 32767 - jle short m16skip4 - mov ebx, 32767 -m16skip4: -cpatch3: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -cpatch6: - mov [edi + 2], bx ; write new sample to destination - shr eax, 16 ; finish calculation for fourth sample - -cpatch4: - add ebp,12345678h ; advance frac pointer - movzx ebx, byte ptr [esi+eax] ; get fourth sample -cpatch7: - add edi, 4 ; move destination to third sample - movzx eax, byte ptr [esi+edx] ; get third sample - dec ecx ; decrement count - jnz mix16Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -EXIT16M: - popad - ret - - -;================ -; -; MV_Mix16BitStereo -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix16BitStereo_ -MV_Mix16BitStereo_: - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [dpatch6+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [dpatch4+3],ebx - mov dword ptr [dpatch5+3],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [dpatch1+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [dpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [dpatch3+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je exit16S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; dpatch1 - left volume table -; dpatch2 - right volume table -; dpatch3 - sample rate - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movzx ebx, byte ptr [esi+eax] ; get first sample - -;ALIGN 4 -mix16Sloop: -dpatch1: - movsx eax, word ptr [2*ebx+12345678h] ; volume translate left sample - movsx edx, word ptr [edi] ; get current sample from destination -dpatch2: - movsx ebx, word ptr [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -dpatch3: - add ebp,12345678h ; advance frac pointer -dpatch4: - movsx edx, word ptr [edi+12345678h] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short s16skip1 - mov eax, -32768 - jmp short s16skip2 -s16skip1: - cmp eax, 32767 - jle short s16skip2 - mov eax, 32767 -s16skip2: - add ebx, edx ; mix right sample - mov [edi], ax ; write left sample to destination - - cmp ebx, -32768 ; Harsh clip sample - jge short s16skip3 - mov ebx, -32768 - jmp short s16skip4 -s16skip3: - cmp ebx, 32767 - jle short s16skip4 - mov ebx, 32767 -s16skip4: - - mov edx, ebp ; begin calculating second sample -dpatch5: - mov [edi+12345678h], bx ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -dpatch6: - add edi, 4 ; move destination to second sample - movzx ebx, byte ptr [esi+edx] ; get second sample - dec ecx ; decrement count - jnz mix16Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit16S: - popad - ret - -CODE ENDS -END diff --git a/polymer/eduke32/source/jaudiolib/mv_mix16.masm b/polymer/eduke32/source/jaudiolib/mv_mix16.masm deleted file mode 100644 index 853424fde..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix16.masm +++ /dev/null @@ -1,507 +0,0 @@ -.586P - -EXTRN _MV_HarshClipTable:DWORD -EXTRN _MV_MixDestination:DWORD -EXTRN _MV_MixPosition:DWORD -EXTRN _MV_LeftVolume:DWORD -EXTRN _MV_RightVolume:DWORD -EXTRN _MV_SampleSize:DWORD -EXTRN _MV_RightChannelOffset:DWORD - -CODE SEGMENT PUBLIC USE32 'DATA' -ASSUME cs:CODE,ds:CODE - - -;================ -; -; MV_Mix8BitMono16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix8BitMono16 -_MV_Mix8BitMono16: -; Two at once - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - inc esi - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [apatch7+2],bl - mov byte ptr [apatch8+2],bl - mov byte ptr [apatch9+3],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume ; Since we're mono, use left volume - mov dword ptr [apatch1+4],ebx - mov dword ptr [apatch2+4],ebx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx, 128 - mov dword ptr [apatch3+2],ebx - mov dword ptr [apatch4+2],ebx - - ; Rate scale ptr - mov dword ptr [apatch5+2],edx - mov dword ptr [apatch6+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je exit8m - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; apatch1 - volume table -; apatch2 - volume table -; apatch3 - harsh clip table -; apatch4 - harsh clip table -; apatch5 - sample rate -; apatch6 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movsx eax, byte ptr [esi+2*eax] ; get first sample - movsx ebx, byte ptr [esi+2*ebx] ; get second sample - add eax, 80h - add ebx, 80h - -;ALIGN 4 -mix8Mloop: - movzx edx, byte ptr [edi] ; get current sample from destination -apatch1: - movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample -apatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -apatch9: - movzx edx, byte ptr [edi + 1] ; get current sample from destination -apatch3: - mov eax, [eax + 12345678h] ; harsh clip new sample - add ebx, edx ; mix second sample - mov [edi], al ; write new sample to destination - mov edx, ebp ; begin calculating third sample -apatch4: - mov ebx, [ebx + 12345678h] ; harsh clip new sample -apatch5: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -apatch7: - add edi, 2 ; move destination to second sample - shr eax, 16 ; finish calculation for fourth sample - mov [edi], bl ; write new sample to destination -apatch6: - add ebp,12345678h ; advance frac pointer - movsx ebx, byte ptr [esi+2*eax] ; get fourth sample - movsx eax, byte ptr [esi+2*edx] ; get third sample - add ebx, 80h - add eax, 80h -apatch8: - add edi, 2 ; move destination to third sample - dec ecx ; decrement count - jnz mix8Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit8m: - popad - ret - - -;================ -; -; MV_Mix8BitStereo16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix8BitStereo16 -_MV_Mix8BitStereo16: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - inc esi - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [bpatch8+2],bl - ; mov byte ptr [bpatch9+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [bpatch6+3],ebx - mov dword ptr [bpatch7+2],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [bpatch1+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [bpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [bpatch3+2],edx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx,128 - mov dword ptr [bpatch4+2],ebx - mov dword ptr [bpatch5+2],ebx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je short exit8S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; bpatch1 - left volume table -; bpatch2 - right volume table -; bpatch3 - sample rate -; bpatch4 - harsh clip table -; bpatch5 - harsh clip table - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movsx ebx, byte ptr [esi+2*eax] ; get first sample - add ebx, 80h - -;ALIGN 4 -mix8Sloop: -bpatch1: - movsx eax, byte ptr [2*ebx+12345678h] ; volume translate left sample - movzx edx, byte ptr [edi] ; get current sample from destination -bpatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -bpatch3: - add ebp,12345678h ; advance frac pointer -bpatch6: - movzx edx, byte ptr [edi+12345678h] ; get current sample from destination -bpatch4: - mov eax, [eax + 12345678h] ; harsh clip left sample - add ebx, edx ; mix right sample - mov [edi], al ; write left sample to destination -bpatch5: - mov ebx, [ebx + 12345678h] ; harsh clip right sample - mov edx, ebp ; begin calculating second sample -bpatch7: - mov [edi+12345678h], bl ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -bpatch8: - add edi, 1 ; move destination to second sample - movsx ebx, byte ptr [esi+2*edx] ; get second sample - add ebx, 80h - dec ecx ; decrement count - jnz mix8Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position - -EXIT8S: - popad - ret - - -;================ -; -; MV_Mix16BitMono16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix16BitMono16 -_MV_Mix16BitMono16: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [cpatch4+2],bl - mov byte ptr [cpatch5+3],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [cpatch2+4],ebx - inc ebx - mov dword ptr [cpatch1+4],ebx - - ; Rate scale ptr - mov dword ptr [cpatch3+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je exit16M - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; cpatch1 - volume table -; cpatch2 - volume table -; cpatch3 - sample rate -; cpatch4 - sample rate - - mov ebx,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for first sample - movzx eax, word ptr [esi+2*ebx] ; get low byte of sample - xor eax, 8000h - movzx ebx, ah - sub ah, ah - - movsx edx, word ptr [edi] ; get current sample from destination - -;ALIGN 4 -mix16Mloop: -cpatch1: - movsx eax, byte ptr [2*eax+12345678h] ; volume translate low byte of sample -cpatch2: - movsx ebx, word ptr [2*ebx+12345678h] ; volume translate high byte of sample - lea eax, [ eax + ebx + 80h ] ; mix high byte of sample - add eax, edx ; mix low byte of sample -cpatch5: - movsx edx, word ptr [edi + 2] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short m16skip1 - mov eax, -32768 - jmp short m16skip2 -m16skip1: - cmp eax, 32767 - jle short m16skip2 - mov eax, 32767 -m16skip2: - mov ebx, ebp ; begin calculating second sample - mov [edi], ax ; write new sample to destination - - shr ebx, 16 ; finish calculation for second sample -cpatch3: - add ebp, 12345678h ; advance frac pointer - - movzx eax, word ptr [esi+2*ebx] ; get second sample -cpatch4: - add edi, 2 ; move destination to second sample - xor eax, 8000h - movzx ebx, ah - sub ah, ah - - dec ecx ; decrement count - jnz mix16Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -EXIT16M: - popad - ret - - -;================ -; -; MV_Mix16BitStereo16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC _MV_Mix16BitStereo16 -_MV_Mix16BitStereo16: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [dpatch9+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [dpatch7+3],ebx - mov dword ptr [dpatch8+3],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [dpatch1+4],ebx - inc ebx - mov dword ptr [dpatch2+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [dpatch3+4],ebx - inc ebx - mov dword ptr [dpatch4+4],ebx - - ; Rate scale ptr - mov dword ptr [dpatch5+2],edx - - ; Source ptr - mov dword ptr [dpatch6+4],esi - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je exit16S - -; eax - scratch -; ebx - scratch -; edx - scratch -; esi - scratch -; ecx - count -; edi - destination -; ebp - frac pointer -; dpatch1 - left volume table -; dpatch2 - right volume table -; dpatch3 - sample rate - - mov ebx,ebp ; begin calculating first sample - shr ebx,16 ; finish calculation for first sample - - movzx edx, word ptr [esi+2*ebx] ; get first sample - xor edx, 8000h ; Change from signed to unsigned - movzx esi, dh ; put high byte in esi - sub dh, dh ; lo byte in edx - -;ALIGN 4 -mix16Sloop: - ; Left channel -dpatch1: - movsx eax, word ptr [2*esi+12345678h] ; volume translate high byte of sample -dpatch2: - movsx ebx, byte ptr [2*edx+12345678h] ; volume translate low byte of sample - lea eax, [ eax + ebx + 80h ] ; mix high byte of sample - - ; Right channel -dpatch3: - movsx esi, word ptr [2*esi+12345678h] ; volume translate high byte of sample -dpatch4: - movsx ebx, byte ptr [2*edx+12345678h] ; volume translate low byte of sample - lea ebx, [ esi + ebx + 80h ] ; mix high byte of sample - -dpatch7: - movsx edx, word ptr [edi+12345678h] ; get current sample from destination -dpatch5: - add ebp,12345678h ; advance frac pointer - - add eax, edx ; mix left sample - - cmp eax, -32768 ; Harsh clip sample - jge short s16skip1 - mov eax, -32768 - jmp short s16skip2 -s16skip1: - cmp eax, 32767 - jle short s16skip2 - mov eax, 32767 -s16skip2: - movsx edx, word ptr [edi+2] ; get current sample from destination - mov [edi], ax ; write left sample to destination - add ebx, edx ; mix right sample - - cmp ebx, -32768 ; Harsh clip sample - jge short s16skip3 - mov ebx, -32768 - jmp short s16skip4 -s16skip3: - cmp ebx, 32767 - jle short s16skip4 - mov ebx, 32767 -s16skip4: - - mov edx, ebp ; begin calculating second sample -dpatch8: - mov [edi+12345678h], bx ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -dpatch9: - add edi, 4 ; move destination to second sample - -dpatch6: - movzx edx, word ptr [2*edx+12345678h] ; get second sample - xor edx, 8000h ; Change from signed to unsigned - movzx esi, dh ; put high byte in esi - sub dh, dh ; lo byte in edx - - dec ecx ; decrement count - jnz mix16Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit16S: - popad - ret - - -CODE ENDS -END diff --git a/polymer/eduke32/source/jaudiolib/mv_mix16.nasm b/polymer/eduke32/source/jaudiolib/mv_mix16.nasm deleted file mode 100644 index 72ee42035..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix16.nasm +++ /dev/null @@ -1,544 +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. -; -;Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) - - -CPU 386 - -SECTION .data - -%ifdef UNDERSCORES - -%define MV_Mix8BitMono16 _MV_Mix8BitMono16 -%define MV_Mix8BitStereo16 _MV_Mix8BitStereo16 -%define MV_Mix16BitMono16 _MV_Mix16BitMono16 -%define MV_Mix16BitStereo16 _MV_Mix16BitStereo16 - -%else - -%define _MV_HarshClipTable MV_HarshClipTable -%define _MV_MixDestination MV_MixDestination -%define _MV_MixPosition MV_MixPosition -%define _MV_LeftVolume MV_LeftVolume -%define _MV_RightVolume MV_RightVolume -%define _MV_SampleSize MV_SampleSize -%define _MV_RightChannelOffset MV_RightChannelOffset - -%endif - - EXTERN _MV_HarshClipTable - EXTERN _MV_MixDestination - EXTERN _MV_MixPosition - EXTERN _MV_LeftVolume - EXTERN _MV_RightVolume - EXTERN _MV_SampleSize - EXTERN _MV_RightChannelOffset - - GLOBAL MV_Mix8BitMono16 - GLOBAL MV_Mix8BitStereo16 - GLOBAL MV_Mix16BitMono16 - GLOBAL MV_Mix16BitStereo16 - -%define OFFSET - -;================ -; -; MV_Mix8BitMono16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix8BitMono16: -; Two at once - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - inc esi - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [apatch7+2],bl - mov byte [apatch8+2],bl - mov byte [apatch9+3],bl - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] ; Since we're mono, use left volume - mov dword [apatch1+4],ebx - mov dword [apatch2+4],ebx - - ; Harsh Clip table ptr - mov ebx, dword [_MV_HarshClipTable] - add ebx, 128 - mov dword [apatch3+2],ebx - mov dword [apatch4+2],ebx - - ; Rate scale ptr - mov dword [apatch5+2],edx - mov dword [apatch6+2],edx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je near exit8m - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; apatch1 - volume table -; apatch2 - volume table -; apatch3 - harsh clip table -; apatch4 - harsh clip table -; apatch5 - sample rate -; apatch6 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movsx eax, byte [esi+2*eax] ; get first sample - movsx ebx, byte [esi+2*ebx] ; get second sample - add eax, 80h - add ebx, 80h - - ALIGN 4 -mix8Mloop: - movzx edx, byte [edi] ; get current sample from destination -apatch1: - movsx eax, byte [2*eax+12345678h] ; volume translate first sample -apatch2: - movsx ebx, byte [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -apatch9: - movzx edx, byte [edi + 1] ; get current sample from destination -apatch3: - mov eax, dword [eax + 12345678h] ; harsh clip new sample - add ebx, edx ; mix second sample - mov byte [edi], al ; write new sample to destination - mov edx, ebp ; begin calculating third sample -apatch4: - mov ebx, dword [ebx + 12345678h] ; harsh clip new sample -apatch5: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -apatch7: - add edi, 2 ; move destination to second sample - shr eax, 16 ; finish calculation for fourth sample - mov byte [edi], bl ; write new sample to destination -apatch6: - add ebp,12345678h ; advance frac pointer - movsx ebx, byte [esi+2*eax] ; get fourth sample - movsx eax, byte [esi+2*edx] ; get third sample - add ebx, 80h - add eax, 80h -apatch8: - add edi, 2 ; move destination to third sample - dec ecx ; decrement count - jnz mix8Mloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position -exit8m: - popad - ret - - -;================ -; -; MV_Mix8BitStereo16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix8BitStereo16: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - inc esi - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [bpatch8+2],bl - ; mov byte [bpatch9+2],bl - - ; Right channel offset - mov ebx, dword [_MV_RightChannelOffset] - mov dword [bpatch6+3],ebx - mov dword [bpatch7+2],ebx - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] - mov dword [bpatch1+4],ebx - - mov ebx, dword [_MV_RightVolume] - mov dword [bpatch2+4],ebx - - ; Rate scale ptr - mov dword [bpatch3+2],edx - - ; Harsh Clip table ptr - mov ebx, dword [_MV_HarshClipTable] - add ebx,128 - mov dword [bpatch4+2],ebx - mov dword [bpatch5+2],ebx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je short EXIT8S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; bpatch1 - left volume table -; bpatch2 - right volume table -; bpatch3 - sample rate -; bpatch4 - harsh clip table -; bpatch5 - harsh clip table - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movsx ebx, byte [esi+2*eax] ; get first sample - add ebx, 80h - - ALIGN 4 -mix8Sloop: -bpatch1: - movsx eax, byte [2*ebx+12345678h] ; volume translate left sample - movzx edx, byte [edi] ; get current sample from destination -bpatch2: - movsx ebx, byte [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -bpatch3: - add ebp,12345678h ; advance frac pointer -bpatch6: - movzx edx, byte [edi+12345678h] ; get current sample from destination -bpatch4: - mov eax, dword [eax + 12345678h] ; harsh clip left sample - add ebx, edx ; mix right sample - mov byte [edi], al ; write left sample to destination -bpatch5: - mov ebx, dword [ebx + 12345678h] ; harsh clip right sample - mov edx, ebp ; begin calculating second sample -bpatch7: - mov byte [edi+12345678h], bl ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -bpatch8: - add edi, 1 ; move destination to second sample - movsx ebx, byte [esi+2*edx] ; get second sample - add ebx, 80h - dec ecx ; decrement count - jnz mix8Sloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position - -EXIT8S: - popad - ret - - -;================ -; -; MV_Mix16BitMono16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix16BitMono16: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [cpatch4+2],bl - mov byte [cpatch5+3],bl - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] - mov dword [cpatch2+4],ebx - inc ebx - mov dword [cpatch1+4],ebx - - ; Rate scale ptr - mov dword [cpatch3+2],edx - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je near EXIT16M - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; cpatch1 - volume table -; cpatch2 - volume table -; cpatch3 - sample rate -; cpatch4 - sample rate - - mov ebx,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for first sample - movzx eax, word [esi+2*ebx] ; get low byte of sample - xor eax, 8000h - movzx ebx, ah - sub ah, ah - - movsx edx, word [edi] ; get current sample from destination - - ALIGN 4 -mix16Mloop: -cpatch1: - movsx eax, byte [2*eax+12345678h] ; volume translate low byte of sample -cpatch2: - movsx ebx, word [2*ebx+12345678h] ; volume translate high byte of sample - lea eax, [ eax + ebx + 80h ] ; mix high byte of sample - add eax, edx ; mix low byte of sample -cpatch5: - movsx edx, word [edi + 2] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short m16skip1 - mov eax, -32768 - jmp short m16skip2 -m16skip1: - cmp eax, 32767 - jle short m16skip2 - mov eax, 32767 -m16skip2: - mov ebx, ebp ; begin calculating second sample - mov word [edi], ax ; write new sample to destination - - shr ebx, 16 ; finish calculation for second sample -cpatch3: - add ebp, 12345678h ; advance frac pointer - - movzx eax, word [esi+2*ebx] ; get second sample -cpatch4: - add edi, 2 ; move destination to second sample - xor eax, 8000h - movzx ebx, ah - sub ah, ah - - dec ecx ; decrement count - jnz mix16Mloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position -EXIT16M: - popad - ret - - -;================ -; -; MV_Mix16BitStereo16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - - ALIGN 4 -MV_Mix16BitStereo16: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, dword [_MV_SampleSize] - mov byte [dpatch9+2],bl - - ; Right channel offset - mov ebx, dword [_MV_RightChannelOffset] - mov dword [dpatch7+3],ebx - mov dword [dpatch8+3],ebx - - ; Volume table ptr - mov ebx, dword [_MV_LeftVolume] - mov dword [dpatch1+4],ebx - inc ebx - mov dword [dpatch2+4],ebx - - mov ebx, dword [_MV_RightVolume] - mov dword [dpatch3+4],ebx - inc ebx - mov dword [dpatch4+4],ebx - - ; Rate scale ptr - mov dword [dpatch5+2],edx - - ; Source ptr - mov dword [dpatch6+4],esi - - mov edi, dword [_MV_MixDestination] ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je near exit16S - -; eax - scratch -; ebx - scratch -; edx - scratch -; esi - scratch -; ecx - count -; edi - destination -; ebp - frac pointer -; dpatch1 - left volume table -; dpatch2 - right volume table -; dpatch3 - sample rate - - mov ebx,ebp ; begin calculating first sample - shr ebx,16 ; finish calculation for first sample - - movzx edx, word [esi+2*ebx] ; get first sample - xor edx, 8000h ; Change from signed to unsigned - movzx esi, dh ; put high byte in esi - sub dh, dh ; lo byte in edx - - ALIGN 4 -mix16Sloop: - ; Left channel -dpatch1: - movsx eax, word [2*esi+12345678h] ; volume translate high byte of sample -dpatch2: - movsx ebx, byte [2*edx+12345678h] ; volume translate low byte of sample - lea eax, [ eax + ebx + 80h ] ; mix high byte of sample - - ; Right channel -dpatch3: - movsx esi, word [2*esi+12345678h] ; volume translate high byte of sample -dpatch4: - movsx ebx, byte [2*edx+12345678h] ; volume translate low byte of sample - lea ebx, [ esi + ebx + 80h ] ; mix high byte of sample - -dpatch7: - movsx edx, word [edi+12345678h] ; get current sample from destination -dpatch5: - add ebp,12345678h ; advance frac pointer - - add eax, edx ; mix left sample - - cmp eax, -32768 ; Harsh clip sample - jge short s16skip1 - mov eax, -32768 - jmp short s16skip2 -s16skip1: - cmp eax, 32767 - jle short s16skip2 - mov eax, 32767 -s16skip2: - movsx edx, word [edi+2] ; get current sample from destination - mov word [edi], ax ; write left sample to destination - add ebx, edx ; mix right sample - - cmp ebx, -32768 ; Harsh clip sample - jge short s16skip3 - mov ebx, -32768 - jmp short s16skip4 -s16skip3: - cmp ebx, 32767 - jle short s16skip4 - mov ebx, 32767 -s16skip4: - - mov edx, ebp ; begin calculating second sample -dpatch8: - mov word [edi+12345678h], bx ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -dpatch9: - add edi, 4 ; move destination to second sample - -dpatch6: - movzx edx, word [2*edx+12345678h] ; get second sample - xor edx, 8000h ; Change from signed to unsigned - movzx esi, dh ; put high byte in esi - sub dh, dh ; lo byte in edx - - dec ecx ; decrement count - jnz mix16Sloop ; loop - - mov dword [_MV_MixDestination], edi ; Store the current write position - mov dword [_MV_MixPosition], ebp ; return position -exit16S: - popad - ret - diff --git a/polymer/eduke32/source/jaudiolib/mv_mix16.wasm b/polymer/eduke32/source/jaudiolib/mv_mix16.wasm deleted file mode 100644 index e719aa801..000000000 --- a/polymer/eduke32/source/jaudiolib/mv_mix16.wasm +++ /dev/null @@ -1,511 +0,0 @@ -.586P - -EXTRN _MV_HarshClipTable:DWORD -EXTRN _MV_MixDestination:DWORD -EXTRN _MV_MixPosition:DWORD -EXTRN _MV_LeftVolume:DWORD -EXTRN _MV_RightVolume:DWORD -EXTRN _MV_SampleSize:DWORD -EXTRN _MV_RightChannelOffset:DWORD - -CODE SEGMENT PUBLIC USE32 'DATA' -ASSUME cs:CODE,ds:CODE - - -;================ -; -; MV_Mix8BitMono16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix8BitMono16_ -MV_Mix8BitMono16_: -; Two at once - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - inc esi - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [apatch7+2],bl - mov byte ptr [apatch8+2],bl - mov byte ptr [apatch9+3],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume ; Since we're mono, use left volume - mov dword ptr [apatch1+4],ebx - mov dword ptr [apatch2+4],ebx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx, 128 - mov dword ptr [apatch3+2],ebx - mov dword ptr [apatch4+2],ebx - - ; Rate scale ptr - mov dword ptr [apatch5+2],edx - mov dword ptr [apatch6+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - shr ecx, 1 ; double sample count - cmp ecx, 0 - je exit8m - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; apatch1 - volume table -; apatch2 - volume table -; apatch3 - harsh clip table -; apatch4 - harsh clip table -; apatch5 - sample rate -; apatch6 - sample rate - - mov eax,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr eax,16 ; finish calculation for first sample - - mov ebx,ebp ; begin calculating second sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for second sample - - movsx eax, byte ptr [esi+2*eax] ; get first sample - movsx ebx, byte ptr [esi+2*ebx] ; get second sample - add eax, 80h - add ebx, 80h - -;ALIGN 4 -mix8Mloop: - movzx edx, byte ptr [edi] ; get current sample from destination -apatch1: - movsx eax, byte ptr [2*eax+12345678h] ; volume translate first sample -apatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate second sample - add eax, edx ; mix first sample -apatch9: - movzx edx, byte ptr [edi + 1] ; get current sample from destination -apatch3: - mov eax, [eax + 12345678h] ; harsh clip new sample - add ebx, edx ; mix second sample - mov [edi], al ; write new sample to destination - mov edx, ebp ; begin calculating third sample -apatch4: - mov ebx, [ebx + 12345678h] ; harsh clip new sample -apatch5: - add ebp,12345678h ; advance frac pointer - shr edx, 16 ; finish calculation for third sample - mov eax, ebp ; begin calculating fourth sample -apatch7: - add edi, 2 ; move destination to second sample - shr eax, 16 ; finish calculation for fourth sample - mov [edi], bl ; write new sample to destination -apatch6: - add ebp,12345678h ; advance frac pointer - movsx ebx, byte ptr [esi+2*eax] ; get fourth sample - movsx eax, byte ptr [esi+2*edx] ; get third sample - add ebx, 80h - add eax, 80h -apatch8: - add edi, 2 ; move destination to third sample - dec ecx ; decrement count - jnz mix8Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit8m: - popad - ret - - -;================ -; -; MV_Mix8BitStereo16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix8BitStereo16_ -MV_Mix8BitStereo16_: - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - inc esi - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [bpatch8+2],bl - ; mov byte ptr [bpatch9+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [bpatch6+3],ebx - mov dword ptr [bpatch7+2],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [bpatch1+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [bpatch2+4],ebx - - ; Rate scale ptr - mov dword ptr [bpatch3+2],edx - - ; Harsh Clip table ptr - mov ebx, _MV_HarshClipTable - add ebx,128 - mov dword ptr [bpatch4+2],ebx - mov dword ptr [bpatch5+2],ebx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je short exit8S - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; bpatch1 - left volume table -; bpatch2 - right volume table -; bpatch3 - sample rate -; bpatch4 - harsh clip table -; bpatch5 - harsh clip table - - mov eax,ebp ; begin calculating first sample - shr eax,16 ; finish calculation for first sample - - movsx ebx, byte ptr [esi+2*eax] ; get first sample - add ebx, 80h - -;ALIGN 4 -mix8Sloop: -bpatch1: - movsx eax, byte ptr [2*ebx+12345678h] ; volume translate left sample - movzx edx, byte ptr [edi] ; get current sample from destination -bpatch2: - movsx ebx, byte ptr [2*ebx+12345678h] ; volume translate right sample - add eax, edx ; mix left sample -bpatch3: - add ebp,12345678h ; advance frac pointer -bpatch6: - movzx edx, byte ptr [edi+12345678h] ; get current sample from destination -bpatch4: - mov eax, [eax + 12345678h] ; harsh clip left sample - add ebx, edx ; mix right sample - mov [edi], al ; write left sample to destination -bpatch5: - mov ebx, [ebx + 12345678h] ; harsh clip right sample - mov edx, ebp ; begin calculating second sample -bpatch7: - mov [edi+12345678h], bl ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -bpatch8: - add edi, 1 ; move destination to second sample - movsx ebx, byte ptr [esi+2*edx] ; get second sample - add ebx, 80h - dec ecx ; decrement count - jnz mix8Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position - -EXIT8S: - popad - ret - - -;================ -; -; MV_Mix16BitMono16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix16BitMono16_ -MV_Mix16BitMono16_: - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [cpatch4+2],bl - mov byte ptr [cpatch5+3],bl - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [cpatch2+4],ebx - inc ebx - mov dword ptr [cpatch1+4],ebx - - ; Rate scale ptr - mov dword ptr [cpatch3+2],edx - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je exit16M - -; eax - scratch -; ebx - scratch -; edx - scratch -; ecx - count -; edi - destination -; esi - source -; ebp - frac pointer -; cpatch1 - volume table -; cpatch2 - volume table -; cpatch3 - sample rate -; cpatch4 - sample rate - - mov ebx,ebp ; begin calculating first sample - add ebp,edx ; advance frac pointer - shr ebx,16 ; finish calculation for first sample - movzx eax, word ptr [esi+2*ebx] ; get low byte of sample - xor eax, 8000h - movzx ebx, ah - sub ah, ah - - movsx edx, word ptr [edi] ; get current sample from destination - -;ALIGN 4 -mix16Mloop: -cpatch1: - movsx eax, byte ptr [2*eax+12345678h] ; volume translate low byte of sample -cpatch2: - movsx ebx, word ptr [2*ebx+12345678h] ; volume translate high byte of sample - lea eax, [ eax + ebx + 80h ] ; mix high byte of sample - add eax, edx ; mix low byte of sample -cpatch5: - movsx edx, word ptr [edi + 2] ; get current sample from destination - - cmp eax, -32768 ; Harsh clip sample - jge short m16skip1 - mov eax, -32768 - jmp short m16skip2 -m16skip1: - cmp eax, 32767 - jle short m16skip2 - mov eax, 32767 -m16skip2: - mov ebx, ebp ; begin calculating second sample - mov [edi], ax ; write new sample to destination - - shr ebx, 16 ; finish calculation for second sample -cpatch3: - add ebp, 12345678h ; advance frac pointer - - movzx eax, word ptr [esi+2*ebx] ; get second sample -cpatch4: - add edi, 2 ; move destination to second sample - xor eax, 8000h - movzx ebx, ah - sub ah, ah - - dec ecx ; decrement count - jnz mix16Mloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -EXIT16M: - popad - ret - - -;================ -; -; MV_Mix16BitStereo16 -; -;================ - -; eax - position -; edx - rate -; ebx - start -; ecx - number of samples to mix - -ALIGN 16 -PUBLIC MV_Mix16BitStereo16_ -MV_Mix16BitStereo16_: - pushad - ; Thanks to Lauri Liinat for spotting this lunacy - ;mov eax, dword ptr [esp + 0*4 + 9*4] - ;mov edx, dword ptr [esp + 1*4 + 9*4] - ;mov ebx, dword ptr [esp + 2*4 + 9*4] - ;mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov ebp, eax - - mov esi, ebx ; Source pointer - - ; Sample size - mov ebx, _MV_SampleSize - mov byte ptr [dpatch9+2],bl - - ; Right channel offset - mov ebx, _MV_RightChannelOffset - mov dword ptr [dpatch7+3],ebx - mov dword ptr [dpatch8+3],ebx - - ; Volume table ptr - mov ebx, _MV_LeftVolume - mov dword ptr [dpatch1+4],ebx - inc ebx - mov dword ptr [dpatch2+4],ebx - - mov ebx, _MV_RightVolume - mov dword ptr [dpatch3+4],ebx - inc ebx - mov dword ptr [dpatch4+4],ebx - - ; Rate scale ptr - mov dword ptr [dpatch5+2],edx - - ; Source ptr - mov dword ptr [dpatch6+4],esi - - mov edi, _MV_MixDestination ; Get the position to write to - - ; Number of samples to mix - cmp ecx, 0 - je exit16S - -; eax - scratch -; ebx - scratch -; edx - scratch -; esi - scratch -; ecx - count -; edi - destination -; ebp - frac pointer -; dpatch1 - left volume table -; dpatch2 - right volume table -; dpatch3 - sample rate - - mov ebx,ebp ; begin calculating first sample - shr ebx,16 ; finish calculation for first sample - - movzx edx, word ptr [esi+2*ebx] ; get first sample - xor edx, 8000h ; Change from signed to unsigned - movzx esi, dh ; put high byte in esi - sub dh, dh ; lo byte in edx - -;ALIGN 4 -mix16Sloop: - ; Left channel -dpatch1: - movsx eax, word ptr [2*esi+12345678h] ; volume translate high byte of sample -dpatch2: - movsx ebx, byte ptr [2*edx+12345678h] ; volume translate low byte of sample - lea eax, [ eax + ebx + 80h ] ; mix high byte of sample - - ; Right channel -dpatch3: - movsx esi, word ptr [2*esi+12345678h] ; volume translate high byte of sample -dpatch4: - movsx ebx, byte ptr [2*edx+12345678h] ; volume translate low byte of sample - lea ebx, [ esi + ebx + 80h ] ; mix high byte of sample - -dpatch7: - movsx edx, word ptr [edi+12345678h] ; get current sample from destination -dpatch5: - add ebp,12345678h ; advance frac pointer - - add eax, edx ; mix left sample - - cmp eax, -32768 ; Harsh clip sample - jge short s16skip1 - mov eax, -32768 - jmp short s16skip2 -s16skip1: - cmp eax, 32767 - jle short s16skip2 - mov eax, 32767 -s16skip2: - movsx edx, word ptr [edi+2] ; get current sample from destination - mov [edi], ax ; write left sample to destination - add ebx, edx ; mix right sample - - cmp ebx, -32768 ; Harsh clip sample - jge short s16skip3 - mov ebx, -32768 - jmp short s16skip4 -s16skip3: - cmp ebx, 32767 - jle short s16skip4 - mov ebx, 32767 -s16skip4: - - mov edx, ebp ; begin calculating second sample -dpatch8: - mov [edi+12345678h], bx ; write right sample to destination - shr edx, 16 ; finish calculation for second sample -dpatch9: - add edi, 4 ; move destination to second sample - -dpatch6: - movzx edx, word ptr [2*edx+12345678h] ; get second sample - xor edx, 8000h ; Change from signed to unsigned - movzx esi, dh ; put high byte in esi - sub dh, dh ; lo byte in edx - - dec ecx ; decrement count - jnz mix16Sloop ; loop - - mov _MV_MixDestination, edi ; Store the current write position - mov _MV_MixPosition, ebp ; return position -exit16S: - popad - ret - - -CODE ENDS -END diff --git a/polymer/eduke32/source/jaudiolib/mvreverb-c.c b/polymer/eduke32/source/jaudiolib/mvreverb-c.c deleted file mode 100644 index f40724135..000000000 --- a/polymer/eduke32/source/jaudiolib/mvreverb-c.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "multivoc.h" -// #include "_multivc.h" - -void MV_16BitReverb(char *src, char *dest, VOLUME16 *volume, int count) -{ - int i; - - short *pdest = (short *)dest; - - for (i = 0; i < count; i++) - { -#if PLATFORM_BIGENDIAN - int sl = src[i*2+1]; - int sh = src[i*2+0] ^ 0x80; -#else - int sl = src[i*2+0]; - int sh = src[i*2+1] ^ 0x80; -#endif - - sl = (*volume)[sl] >> 8; - sh = (*volume)[sh]; - - pdest[i] = (short)(sl + sh + 0x80); - } -} - -void MV_8BitReverb(signed char *src, signed char *dest, 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(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(signed char *src, signed 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/polymer/eduke32/source/jaudiolib/mvreverb.masm b/polymer/eduke32/source/jaudiolib/mvreverb.masm deleted file mode 100644 index 871185610..000000000 --- a/polymer/eduke32/source/jaudiolib/mvreverb.masm +++ /dev/null @@ -1,202 +0,0 @@ -.586P - -CODE SEGMENT PUBLIC USE32 'DATA' -ASSUME cs:CODE,ds:CODE - -;================ -; -; MV_16BitReverb -; -;================ - -; eax - source position -; edx - destination position -; ebx - Volume table -; ecx - number of samples - -ALIGN 16 -PUBLIC _MV_16BitReverb -_MV_16BitReverb: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov esi, eax - lea edi, [edx - 2] - -;ALIGN 4 -rev16loop: - movzx eax, word ptr [esi] ; get sample - add edi, 2 - - movzx edx, ah - sub ah, ah - - movsx eax, byte ptr [2*eax+ebx+1] ; volume translate low byte of sample - xor edx, 80h - - movsx edx, word ptr [2*edx+ebx] ; volume translate high byte of sample - add esi, 2 - - lea eax, [ eax + edx + 80h ] ; mix high byte of sample - dec ecx ; decrement count - - mov [edi], ax ; write new sample to destination - jnz rev16loop ; loop - - popad - ret - - -;================ -; -; MV_8BitReverb -; -;================ - -; eax - source position -; edx - destination position -; ebx - Volume table -; ecx - number of samples - -ALIGN 16 -PUBLIC _MV_8BitReverb -_MV_8BitReverb: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov esi, eax - lea edi, [edx - 1] - - xor eax, eax - -;ALIGN 4 -rev8loop: -; movzx eax, byte ptr [esi] ; get sample - mov al, byte ptr [esi] ; get sample - inc edi - -; movsx eax, byte ptr [2*eax+ebx] ; volume translate sample - mov al, byte ptr [2*eax+ebx] ; volume translate sample - inc esi - -; add eax, 80h - add al, 80h - dec ecx ; decrement count - - mov [edi], al ; write new sample to destination - jnz rev8loop ; loop - - popad - ret - - -;================ -; -; MV_16BitReverbFast -; -;================ - -; eax - source position -; edx - destination position -; ebx - number of samples -; ecx - shift - -ALIGN 16 -PUBLIC _MV_16BitReverbFast -_MV_16BitReverbFast: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov esi, eax - mov eax,OFFSET rpatch16+3 - - mov [eax],cl - lea edi, [edx - 2] - -;ALIGN 4 -frev16loop: - mov ax, word ptr [esi] ; get sample - add edi, 2 - -rpatch16: - sar ax, 5 ;;;;Add 1 before shift - add esi, 2 - - mov [edi], ax ; write new sample to destination - dec ebx ; decrement count - - jnz frev16loop ; loop - - popad - ret - - -;================ -; -; MV_8BitReverbFast -; -;================ - -; eax - source position -; edx - destination position -; ebx - number of samples -; ecx - shift - -ALIGN 16 -PUBLIC _MV_8BitReverbFast -_MV_8BitReverbFast: - pushad - mov eax, dword ptr [esp + 0*4 + 9*4] - mov edx, dword ptr [esp + 1*4 + 9*4] - mov ebx, dword ptr [esp + 2*4 + 9*4] - mov ecx, dword ptr [esp + 3*4 + 9*4] - - mov esi, eax - mov eax,OFFSET rpatch8+2 - - mov edi, edx - mov edx, 80h - - mov [eax],cl - mov eax, 80h - - shr eax, cl - - dec edi - sub edx, eax - -;ALIGN 4 -frev8loop: - mov al, byte ptr [esi] ; get sample - inc esi - - mov ecx, eax - inc edi - -rpatch8: - shr eax, 3 - xor ecx, 80h ; flip the sign bit - - shr ecx, 7 ; shift the sign down to 1 - add eax, edx - - add eax, ecx ; add sign bit to round to 0 - dec ebx ; decrement count - - mov [edi], al ; write new sample to destination - jnz frev8loop ; loop - - popad - ret - -CODE ENDS -END diff --git a/polymer/eduke32/source/jaudiolib/mvreverb.nasm b/polymer/eduke32/source/jaudiolib/mvreverb.nasm deleted file mode 100644 index 23d1ca85f..000000000 --- a/polymer/eduke32/source/jaudiolib/mvreverb.nasm +++ /dev/null @@ -1,230 +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. -; -;Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) - -CPU 386 - -SECTION .data - -%ifdef UNDERSCORES - -%define MV_16BitReverb _MV_16BitReverb -%define MV_8BitReverb _MV_8BitReverb -%define MV_16BitReverbFast _MV_16BitReverbFast -%define MV_8BitReverbFast _MV_8BitReverbFast - -%endif - - GLOBAL MV_16BitReverb - GLOBAL MV_8BitReverb - GLOBAL MV_16BitReverbFast - GLOBAL MV_8BitReverbFast - -%define OFFSET - -;================ -; -; MV_16BitReverb -; -;================ - -; eax - source position -; edx - destination position -; ebx - Volume table -; ecx - number of samples - - ALIGN 4 -MV_16BitReverb: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov esi, eax - lea edi, [edx - 2] - - ALIGN 4 -rev16loop: - movzx eax, word [esi] ; get sample - add edi, 2 - - movzx edx, ah - sub ah, ah - - movsx eax, byte [2*eax+ebx+1] ; volume translate low byte of sample - xor edx, 80h - - movsx edx, word [2*edx+ebx] ; volume translate high byte of sample - add esi, 2 - - lea eax, [ eax + edx + 80h ] ; mix high byte of sample - dec ecx ; decrement count - - mov word [edi], ax ; write new sample to destination - jnz rev16loop ; loop - - popad - ret - - -;================ -; -; MV_8BitReverb -; -;================ - -; eax - source position -; edx - destination position -; ebx - Volume table -; ecx - number of samples - - ALIGN 4 -MV_8BitReverb: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov esi, eax - lea edi, [edx - 1] - - xor eax, eax - - ALIGN 4 -rev8loop: -; movzx eax, byte ptr [esi] ; get sample - mov al, byte [esi] ; get sample - inc edi - -; movsx eax, byte ptr [2*eax+ebx] ; volume translate sample - mov al, byte [2*eax+ebx] ; volume translate sample - inc esi - -; add eax, 80h - add al, 80h - dec ecx ; decrement count - - mov byte [edi], al ; write new sample to destination - jnz rev8loop ; loop - - popad - ret - - -;================ -; -; MV_16BitReverbFast -; -;================ - -; eax - source position -; edx - destination position -; ebx - number of samples -; ecx - shift - - ALIGN 4 -MV_16BitReverbFast: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov esi, eax - mov eax,OFFSET rpatch16+3 - - mov byte [eax],cl - lea edi, [edx - 2] - - ALIGN 4 -frev16loop: - mov ax, word [esi] ; get sample - add edi, 2 - -rpatch16: - sar ax, 5 ;;;;Add 1 before shift - add esi, 2 - - mov word [edi], ax ; write new sample to destination - dec ebx ; decrement count - - jnz frev16loop ; loop - - popad - ret - - -;================ -; -; MV_8BitReverbFast -; -;================ - -; eax - source position -; edx - destination position -; ebx - number of samples -; ecx - shift - - ALIGN 4 -MV_8BitReverbFast: - pushad - mov eax, dword [esp + 0*4 + 9*4] - mov edx, dword [esp + 1*4 + 9*4] - mov ebx, dword [esp + 2*4 + 9*4] - mov ecx, dword [esp + 3*4 + 9*4] - - mov esi, eax - mov eax,OFFSET rpatch8+2 - - mov edi, edx - mov edx, 80h - - mov byte [eax],cl - mov eax, 80h - - shr eax, cl - - dec edi - sub edx, eax - - ALIGN 4 -frev8loop: - mov al, byte [esi] ; get sample - inc esi - - mov ecx, eax - inc edi - -rpatch8: - shr eax, 3 - xor ecx, 80h ; flip the sign bit - - shr ecx, 7 ; shift the sign down to 1 - add eax, edx - - add eax, ecx ; add sign bit to round to 0 - dec ebx ; decrement count - - mov byte [edi], al ; write new sample to destination - jnz frev8loop ; loop - - popad - ret - diff --git a/polymer/eduke32/source/jaudiolib/mvreverb.wasm b/polymer/eduke32/source/jaudiolib/mvreverb.wasm deleted file mode 100644 index c8c1187e7..000000000 --- a/polymer/eduke32/source/jaudiolib/mvreverb.wasm +++ /dev/null @@ -1,174 +0,0 @@ -.586P - -CODE SEGMENT PUBLIC USE32 'DATA' -ASSUME cs:CODE,ds:CODE - -;================ -; -; MV_16BitReverb -; -;================ - -; eax - source position -; edx - destination position -; ebx - Volume table -; ecx - number of samples - -ALIGN 16 -PUBLIC MV_16BitReverb_ -MV_16BitReverb_: - mov esi, eax - lea edi, [edx - 2] - -;ALIGN 4 -rev16loop: - movzx eax, word ptr [esi] ; get sample - add edi, 2 - - movzx edx, ah - sub ah, ah - - movsx eax, byte ptr [2*eax+ebx+1] ; volume translate low byte of sample - xor edx, 80h - - movsx edx, word ptr [2*edx+ebx] ; volume translate high byte of sample - add esi, 2 - - lea eax, [ eax + edx + 80h ] ; mix high byte of sample - dec ecx ; decrement count - - mov [edi], ax ; write new sample to destination - jnz rev16loop ; loop - - ret - - -;================ -; -; MV_8BitReverb -; -;================ - -; eax - source position -; edx - destination position -; ebx - Volume table -; ecx - number of samples - -ALIGN 16 -PUBLIC MV_8BitReverb_ -MV_8BitReverb_: - mov esi, eax - lea edi, [edx - 1] - - xor eax, eax - -;ALIGN 4 -rev8loop: -; movzx eax, byte ptr [esi] ; get sample - mov al, byte ptr [esi] ; get sample - inc edi - -; movsx eax, byte ptr [2*eax+ebx] ; volume translate sample - mov al, byte ptr [2*eax+ebx] ; volume translate sample - inc esi - -; add eax, 80h - add al, 80h - dec ecx ; decrement count - - mov [edi], al ; write new sample to destination - jnz rev8loop ; loop - - ret - - -;================ -; -; MV_16BitReverbFast -; -;================ - -; eax - source position -; edx - destination position -; ebx - number of samples -; ecx - shift - -ALIGN 16 -PUBLIC MV_16BitReverbFast_ -MV_16BitReverbFast_: - mov esi, eax - mov eax,OFFSET rpatch16+3 - - mov [eax],cl - lea edi, [edx - 2] - -;ALIGN 4 -frev16loop: - mov ax, word ptr [esi] ; get sample - add edi, 2 - -rpatch16: - sar ax, 5 ;;;;Add 1 before shift - add esi, 2 - - mov [edi], ax ; write new sample to destination - dec ebx ; decrement count - - jnz frev16loop ; loop - - ret - - -;================ -; -; MV_8BitReverbFast -; -;================ - -; eax - source position -; edx - destination position -; ebx - number of samples -; ecx - shift - -ALIGN 16 -PUBLIC MV_8BitReverbFast_ -MV_8BitReverbFast_: - mov esi, eax - mov eax,OFFSET rpatch8+2 - - mov edi, edx - mov edx, 80h - - mov [eax],cl - mov eax, 80h - - shr eax, cl - - dec edi - sub edx, eax - -;ALIGN 4 -frev8loop: - mov al, byte ptr [esi] ; get sample - inc esi - - mov ecx, eax - inc edi - -rpatch8: - shr eax, 3 - xor ecx, 80h ; flip the sign bit - - shr ecx, 7 ; shift the sign down to 1 - add eax, edx - - add eax, ecx ; add sign bit to round to 0 - dec ebx ; decrement count - - mov [edi], al ; write new sample to destination - jnz frev8loop ; loop - - ret - -CODE ENDS -END diff --git a/polymer/eduke32/source/jaudiolib/openal.c b/polymer/eduke32/source/jaudiolib/openal.c deleted file mode 100644 index 8bc78c9e9..000000000 --- a/polymer/eduke32/source/jaudiolib/openal.c +++ /dev/null @@ -1,528 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2008 - EDuke32 developers - -This file is part of EDuke32 - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -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 "baselayer.h" -#include "compat.h" -#define AL_NO_PROTOTYPES -#define ALC_NO_PROTOTYPES -#include -#include -#include "openal.h" -// #include "_multivc.h" - -ALCdevice * device=NULL; -ALCcontext * context=NULL; - -char *ALdoing = NULL; -int32_t AL_Error; -int32_t bufsize; -int32_t openal_disabled = 0; - -typedef struct SD -{ - ALuint buffers[16]; - ALuint source; - ALenum format; - - char loop; - char type; - int32_t rate; - sounddef def; - int32_t ready; -} sounddef1; - -sounddef1 music; - -#ifdef _WIN32 -// Windows -static HMODULE hALDLL = NULL; -#else -#include -static void *alhandle = NULL; -#endif - -static char *aldriver = NULL; -static LPALGETSOURCEI balGetSourcei = NULL; -static LPALSOURCEF balSourcef = NULL; -static LPALSOURCEPLAY balSourcePlay = NULL; -static LPALSOURCEPAUSE balSourcePause = NULL; -static LPALCGETERROR balcGetError = NULL; -static LPALGETERROR balGetError = NULL; -static LPALBUFFERDATA balBufferData = NULL; -static LPALGENBUFFERS balGenBuffers = NULL; -static LPALGENSOURCES balGenSources = NULL; -static LPALSOURCEI balSourcei = NULL; -static LPALSOURCEQUEUEBUFFERS balSourceQueueBuffers = NULL; -static LPALSOURCESTOP balSourceStop = NULL; -static LPALSOURCEUNQUEUEBUFFERS balSourceUnqueueBuffers = NULL; -static LPALCMAKECONTEXTCURRENT balcMakeContextCurrent = NULL; -static LPALDELETESOURCES balDeleteSources = NULL; -static LPALDELETEBUFFERS balDeleteBuffers = NULL; -static LPALCDESTROYCONTEXT balcDestroyContext = NULL; -static LPALCCLOSEDEVICE balcCloseDevice = NULL; -static LPALCOPENDEVICE balcOpenDevice = NULL; -static LPALCCREATECONTEXT balcCreateContext = NULL; -static LPALGETSTRING balGetString = NULL; - -static void * algetproc_(const char *s, int32_t *err, int32_t fatal) -{ - void *t; -#if defined _WIN32 - t = (void*)GetProcAddress(hALDLL,s); -#else - t = (void*)dlsym(alhandle,s); -#endif - if (!t && fatal) - { - initprintf("Failed to find %s in %s\n", s, aldriver); - *err = 1; - } - return t; -} -#define ALGETPROC(s) algetproc_(s,&err,1) -#define ALGETPROCSOFT(s) algetproc_(s,&err,0) - -static int32_t unloadaldriver(void) -{ -#ifdef _WIN32 - if (!hALDLL) return 0; -#endif - - if (aldriver) - free(aldriver); - aldriver = NULL; - -#ifdef _WIN32 - if (hALDLL) - FreeLibrary(hALDLL); - hALDLL = NULL; -#else - if (alhandle) - dlclose(alhandle); - alhandle = NULL; -#endif - - balGetSourcei = NULL; - balSourcef = NULL; - balSourcePlay = NULL; - balSourcePause = NULL; - balcGetError = NULL; - balGetError = NULL; - balBufferData = NULL; - balGenBuffers = NULL; - balGenSources = NULL; - balSourcei = NULL; - balSourceQueueBuffers = NULL; - balSourceStop = NULL; - balSourceUnqueueBuffers = NULL; - balDeleteSources = NULL; - balcMakeContextCurrent = NULL; - balDeleteSources = NULL; - balDeleteBuffers = NULL; - balcDestroyContext = NULL; - balcCloseDevice = NULL; - balcOpenDevice = NULL; - balcCreateContext = NULL; - balGetString = NULL; - - return 0; -} - -static int32_t loadaldriver(void) -{ - int32_t err=0; - char *driver; - -#ifdef _WIN32 - if (hALDLL) - return 0; -#endif - -// if (!driver) - { -#ifdef _WIN32 - driver = "OpenAL32.DLL"; -#elif defined __APPLE__ - driver = "/System/Library/Frameworks/OpenGL.framework/OpenGL"; // FIXME: like I know anything about Apple. Hah. -#else - driver = "libopenal.so"; -#endif - } - - initprintf("Loading %s\n",driver); - -#ifdef _WIN32 - hALDLL = LoadLibrary(driver); - if (!hALDLL) return -1; -#else - alhandle = dlopen(driver, RTLD_NOW|RTLD_GLOBAL); - if (!alhandle) return -1; -#endif - aldriver = strdup(driver); - - balGetSourcei = ALGETPROC("alGetSourcei"); - balSourcef = ALGETPROC("alSourcef"); - balSourcePlay = ALGETPROC("alSourcePlay"); - balSourcePause = ALGETPROC("alSourcePause"); - balcGetError = ALGETPROC("alcGetError"); - balGetError = ALGETPROC("alGetError"); - balBufferData = ALGETPROC("alBufferData"); - balGenBuffers = ALGETPROC("alGenBuffers"); - balGenSources = ALGETPROC("alGenSources"); - balSourcei = ALGETPROC("alSourcei"); - balSourceQueueBuffers = ALGETPROC("alSourceQueueBuffers"); - balSourceStop = ALGETPROC("alSourceStop"); - balSourceUnqueueBuffers = ALGETPROC("alSourceUnqueueBuffers"); - balDeleteSources = ALGETPROC("alDeleteSources"); - balcMakeContextCurrent = ALGETPROC("alcMakeContextCurrent"); - balDeleteSources = ALGETPROC("alDeleteSources"); - balDeleteBuffers = ALGETPROC("alDeleteBuffers"); - balcDestroyContext = ALGETPROC("alcDestroyContext"); - balcCloseDevice = ALGETPROC("alcCloseDevice"); - balcOpenDevice = ALGETPROC("alcOpenDevice"); - balcCreateContext = ALGETPROC("alcCreateContext"); - balGetString = ALGETPROC("alGetString"); - - if (err) unloadaldriver(); - return err; -} - -char *ALC_ErrorString(int32_t code) -{ - switch (code) - { - case ALC_NO_ERROR: - return "OpenAL error: There is no current error."; - case ALC_INVALID_DEVICE: - return "OpenAL error: No device."; - case ALC_INVALID_CONTEXT: - return "OpenAL error: Invalid context ID."; - case ALC_INVALID_ENUM: - return "OpenAL error: Invalid parameter."; - case ALC_INVALID_VALUE: - return "OpenAL error: Invalid enum parameter value."; - case ALC_OUT_OF_MEMORY: - return "OpenAL error: Unable to allocate memory."; - default: - return "OpenAL error: Unknown error."; - } -} -char *AL_ErrorString(int32_t code) -{ - switch (code) - { - case AL_NO_ERROR: - return "OpenAL error: There is no current error."; - case AL_INVALID_NAME: - return "OpenAL error: Invalid name parameter."; - case AL_INVALID_ENUM: - return "OpenAL error: Invalid parameter."; - case AL_INVALID_VALUE: - return "OpenAL error: Invalid enum parameter value."; - case AL_INVALID_OPERATION: - return "OpenAL error: Illegal call."; - case AL_OUT_OF_MEMORY: - return "OpenAL error: Unable to allocate memory."; - case OV_EFAULT: - return "Internal logic fault (bug or heap/stack corruption."; - case OV_EREAD: - return "Read from media."; - case OV_EIMPL: - return "The bitstream makes use of a feature not implemented in this library version."; - case OV_EINVAL: - return "Invalid argument value."; - case OV_ENOTVORBIS: - return "Not Vorbis data."; - case OV_EBADHEADER: - return "Invalid Vorbis header."; - case OV_EVERSION: - return "Vorbis version mismatch."; - case OV_ENOTAUDIO: - return "Packet data submitted to vorbis_synthesis is not audio data."; - case OV_EBADPACKET: - return "Invalid packet submitted to vorbis_synthesis."; - case OV_EBADLINK: - return "Invalid stream section supplied to libvorbis/libvorbisfile, or the requested link is corrupt."; - case OV_ENOSEEK: - return "Bitstream is not seekable."; - default: - return "Unknown OpenAL/Ogg error."; - } -} -void check(int32_t show) -{ - AL_Error=balcGetError(device); - if (AL_Error!=ALC_NO_ERROR&&show) - initprintf("%s(%s)\n",ALC_ErrorString(AL_Error),ALdoing); - AL_Error=balGetError(); - if (AL_Error!= AL_NO_ERROR&&show) - initprintf("%s(%s)\n", AL_ErrorString(AL_Error),ALdoing); -} -extern ov_callbacks cb; - - -int32_t AL_Init() -{ - Bmemset(&music,0,sizeof(music)); // "music.def.size=0" means music not playing - if (loadaldriver()) - { - initprintf("Failed loading OpenAL driver.\nDownload OpenAL 1.1 or greater from http://www.openal.org/downloads.html\n"); - openal_disabled = 1; - - return 1; - } - - ALdoing="Init"; -// device=alcOpenDevice(ud.config.HardwareAL?"Generic Hardware":"Generic Software"); - device=balcOpenDevice(NULL); - check(1); - - if (device) - { - context=balcCreateContext(device,NULL); - check(1); - } - - if (context) - { -// char *s,*t,*u,i; - - balcMakeContextCurrent(context);check(1); - initprintf("OpenAL Information:\n" - " Version: %s\n" - " Vendor: %s\n" - " Renderer: %s\n" -// " Extensions:\n" - ,balGetString(AL_VERSION),balGetString(AL_VENDOR),balGetString(AL_RENDERER)); - - /* s = Bstrdup(balGetString(AL_EXTENSIONS)); - if (!s) initprintf(balGetString(AL_EXTENSIONS)); - else - { - i = 0; t = u = s; - while (*t) - { - if (*t == ' ') - { - if (i&1) - { - *t = 0; - initprintf(" %s\n",u); - u = t+1; - } - i++; - } - t++; - } - if (i&1) initprintf(" %s\n",u); - Bfree(s); - } - */ - } - else initprintf("OpenAL initialization failed.\n"); - - return 0; -} - -void AL_Stop(); -void AL_Shutdown() -{ - if (openal_disabled || !device) return; - - initprintf("Uninitializing OpenAL...\n"); - AL_Stop(); - ALdoing="Shut"; - balcMakeContextCurrent(NULL); - check(1); - balcDestroyContext(context); - check(1); - balcCloseDevice(device); - unloadaldriver(); -} - -#define BUFFER_SIZE 65536 // (4096 * 4*8*8) -int32_t AL_MusicVolume; -extern int32_t g_musicSize; - - -int32_t update(); -int32_t stream(ALuint buffer); -void open1(char *ptr,int32_t sizef,char loop); - - - -void AL_Pause() {if (music.def.size)balSourcePause(music.source);} -void AL_Continue() {if (music.def.size)balSourcePlay(music.source);} -void AL_Update() {if (music.def.size&&music.ready&&!update(0))AL_Stop();} -int32_t AL_isntALmusic() {return !music.def.size;} - -void AL_SetMusicVolume(int32_t volume) -{ - AL_MusicVolume=volume; - if (music.def.size)balSourcef(music.source,AL_GAIN,volume/(255.)); -} - -int32_t isplaying() -{ - ALenum state; - balGetSourcei(music.source,AL_SOURCE_STATE,&state); - return state==AL_PLAYING; -} - -int32_t update() -{ - int32_t processed=0; - int32_t active=1; - ALuint buffer; - - ALdoing="update"; - balGetSourcei(music.source,AL_BUFFERS_PROCESSED,&processed); - check(1); - if (processed) - switch (music.type) - { - case 1: - while (processed--) - { - ALdoing="update1"; - balSourceUnqueueBuffers(music.source,1,&buffer); - check(1); - active=stream(buffer); - if (active) - { - ALdoing="update2"; - balSourceQueueBuffers(music.source,1,&buffer); - check(1); - } - } - break; - } - return active; -} - -void AL_Stop() -{ - int32_t queued=0;ALuint buffer; - - if (!music.def.size) - return; - - music.ready=0; - balSourceStop(music.source); - balGetSourcei(music.source,AL_BUFFERS_QUEUED,&queued); - - ALdoing="release"; - while (queued--) - { - balSourceUnqueueBuffers(music.source,1,&buffer); - check(1); - } - balDeleteSources(1,&music.source);check(1); - balDeleteBuffers(2, music.buffers);check(1); - - if (music.type == 1) - ov_clear(&music.def.oggStream); - Bmemset(&music,0,sizeof(music)); -} - -static char pcm[BUFFER_SIZE]; - -int32_t stream(ALuint buffer) -{ - ALsizei size=0; - int32_t section,result; - - while (size 0)size+=result;else break; - } - if (!size) - return 0; - ALdoing="stream"; - balBufferData(buffer,music.format,pcm,size,music.rate); - check(1); - return 1; -} - -void AL_PlaySong(char *ptr,int32_t loop) -{ - vorbis_info* vorbisInfo; - int32_t bf=2,i; - - if (!context) - return; - Bmemset(&music,0,sizeof(sounddef1)); - switch (*ptr) - { - case 'O': - music.type=1; - break; - default: - return; - } - music.def.size=g_musicSize; - music.loop=loop; - music.def.ptrsnd=ptr; - - switch (music.type) - { - case 1: - if ((i=ov_open_callbacks(&music.def,&music.def.oggStream,0,0,cb))<0) - { - Bmemset(&music,0,sizeof(sounddef1)); - initprintf("Music error: %s\n",AL_ErrorString(i)); - return; - } - vorbisInfo=ov_info(&music.def.oggStream,-1); - if (!vorbisInfo) - { - initprintf("Music error: vorbisInfo\n"); - Bmemset(&music,0,sizeof(sounddef1)); - return; - } - music.rate=vorbisInfo->rate; - music.format=(vorbisInfo->channels==1)?AL_FORMAT_MONO16:AL_FORMAT_STEREO16; - break; - } - - ALdoing="Open"; - balGenBuffers(2, music.buffers);check(1); - balGenSources(1,&music.source);check(1); - balSourcei(music.source,AL_SOURCE_RELATIVE,AL_TRUE); - - switch (music.type) - { - case 1: - stream(music.buffers[0]); - if (!stream(music.buffers[1])) - bf=1; - balSourceQueueBuffers(music.source,bf,music.buffers); - break; - } - - AL_SetMusicVolume(AL_MusicVolume); - AL_Continue(); - music.ready=1; -} diff --git a/polymer/eduke32/source/jaudiolib/openal.h b/polymer/eduke32/source/jaudiolib/openal.h deleted file mode 100644 index ff96ec21e..000000000 --- a/polymer/eduke32/source/jaudiolib/openal.h +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2008 - EDuke32 developers - -This file is part of EDuke32 - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -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 __OPENAL_H -#define __OPENAL_H - -#include - -int32_t AL_Init(); -void AL_Shutdown(); -void AL_Update(); -char *AL_ErrorString(int32_t code); -char *ALC_ErrorString(int32_t code); - -void AL_Stop(); -int32_t AL_isntALmusic(); -void AL_PlaySong(char *song,int32_t loopflag); -void AL_Pause(); -void AL_Continue(); -void AL_SetMusicVolume(int32_t volume); - -int32_t openal_disabled; - -typedef struct sounddef -{ - uint32_t pos; - char *ptrsnd; - uint32_t size; - OggVorbis_File oggStream; -} sounddef; -#endif diff --git a/polymer/eduke32/source/jaudiolib/pitch.c b/polymer/eduke32/source/jaudiolib/pitch.c deleted file mode 100644 index 8bdc447fd..000000000 --- a/polymer/eduke32/source/jaudiolib/pitch.c +++ /dev/null @@ -1,199 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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 "standard.h" -#include "pitch.h" - -#define MAXDETUNE 25 - -static uint32_t 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 int32_t PITCH_Installed = FALSE; - - -/*--------------------------------------------------------------------- - Function: PITCH_Init - - Initializes pitch table. ----------------------------------------------------------------------*/ -/* -void PITCH_Init - ( - void - ) - - { - int32_t note; - int32_t 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: - -**********************************************************************/ - - -/*--------------------------------------------------------------------- - Function: PITCH_GetScale - - Returns a fixed-point value to scale number the specified amount. ----------------------------------------------------------------------*/ - -uint32_t PITCH_GetScale -( - int32_t pitchoffset -) - -{ - uint32_t scale; - int32_t octaveshift; - int32_t noteshift; - int32_t note; - int32_t 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); -} - - - diff --git a/polymer/eduke32/source/jaudiolib/pitch.h b/polymer/eduke32/source/jaudiolib/pitch.h deleted file mode 100644 index 442fa1e12..000000000 --- a/polymer/eduke32/source/jaudiolib/pitch.h +++ /dev/null @@ -1,46 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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 - -#include "compat.h" - -enum PITCH_ERRORS - { - PITCH_Warning = -2, - PITCH_Error = -1, - PITCH_Ok = 0, - }; - -//void PITCH_Init( void ); -uint32_t PITCH_GetScale( int32_t pitchoffset ); -#endif diff --git a/polymer/eduke32/source/jaudiolib/platform.h b/polymer/eduke32/source/jaudiolib/platform.h deleted file mode 100644 index b4e475dca..000000000 --- a/polymer/eduke32/source/jaudiolib/platform.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _INCLUDE_PLATFORM_H_ -#define _INCLUDE_PLATFORM_H_ - -#if (!defined __EXPORT__) -#define __EXPORT__ -#endif - -static __inline uint16_t _swap16(uint16_t D) -{ -#if PLATFORM_MACOSX - register uint16_t returnValue; - __asm__ volatile("lhbrx %0,0,%1" - : "=r" (returnValue) - : "r" (&D) - ); - return returnValue; -#else - return((D<<8)|(D>>8)); -#endif -} - -static __inline uint32_t _swap32(uint32_t D) -{ -#if PLATFORM_MACOSX - register uint32_t returnValue; - __asm__ volatile("lwbrx %0,0,%1" - : "=r" (returnValue) - : "r" (&D) - ); - return returnValue; -#else - return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); -#endif -} - -#if PLATFORM_MACOSX -#define PLATFORM_BIGENDIAN 1 -#define BUILDSWAP_INTEL16(x) _swap16(x) -#define BUILDSWAP_INTEL32(x) _swap32(x) -#else -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define PLATFORM_LITTLEENDIAN 1 -#define BUILDSWAP_INTEL16(x) (x) -#define BUILDSWAP_INTEL32(x) (x) -#else -#define PLATFORM_BIGENDIAN 1 -#define BUILDSWAP_INTEL16(x) _swap16(x) -#define BUILDSWAP_INTEL32(x) _swap32(x) -#endif -#endif - -extern int32_t has_altivec; /* PowerPC-specific. */ - -#endif /* !defined _INCLUDE_PLATFORM_H_ */ - -/* end of platform.h ... */ - diff --git a/polymer/eduke32/source/jaudiolib/sdlmusic.c b/polymer/eduke32/source/jaudiolib/sdlmusic.c deleted file mode 100644 index 367e820dc..000000000 --- a/polymer/eduke32/source/jaudiolib/sdlmusic.c +++ /dev/null @@ -1,418 +0,0 @@ -/* -Copyright (C) 2003-2004 Ryan C. Gordon. and James Bentler - -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. - -Originally written by Ryan C. Gordon. (icculus@clutteredmind.org) -Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu) - -*/ -/* - * A reimplementation of Jim Dose's FX_MAN routines, using SDL_mixer 1.2. - * Whee. FX_MAN is also known as the "Apogee Sound System", or "ASS" for - * short. How strangely appropriate that seems. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "duke3d.h" -#include "cache1d.h" - -#ifndef _MSC_VER -#define cdecl -#endif - -#define _NEED_SDLMIXER 1 -#include "sdl_inc.h" -#include "music.h" - -#define __FX_TRUE (1 == 1) -#define __FX_FALSE (!__FX_TRUE) - -#define DUKESND_DEBUG "DUKESND_DEBUG" - -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#endif - -int32_t MUSIC_ErrorCode = MUSIC_Ok; - -static char warningMessage[80]; -static char errorMessage[80]; -static FILE *debug_file = NULL; -static int32_t initialized_debugging = 0; -static int32_t external_midi = 0; - -static int32_t music_initialized = 0; -static int32_t music_context = 0; -static int32_t music_loopflag = MUSIC_PlayOnce; -static Mix_Music *music_musicchunk = NULL; -// static char *music_songdata = NULL; - -// This gets called all over the place for information and debugging messages. -// If the user set the DUKESND_DEBUG environment variable, the messages -// go to the file that is specified in that variable. Otherwise, they -// are ignored for the expense of the function call. If DUKESND_DEBUG is -// set to "-" (without the quotes), then the output goes to stdout. -static void musdebug(const char *fmt, ...) -{ - va_list ap; - - if (debug_file) - { - fprintf(debug_file, "DUKEMUS: "); - va_start(ap, fmt); - vfprintf(debug_file, fmt, ap); - va_end(ap); - fprintf(debug_file, "\n"); - fflush(debug_file); - } // if -} // musdebug - -static void init_debugging(void) -{ - const char *envr; - - if (initialized_debugging) - return; - - envr = getenv(DUKESND_DEBUG); - if (envr != NULL) - { - if (Bstrcmp(envr, "-") == 0) - debug_file = stdout; - else - debug_file = fopen(envr, "w"); - - if (debug_file == NULL) - fprintf(stderr, "DUKESND: -WARNING- Could not open debug file!\n"); - else - setbuf(debug_file, NULL); - } // if - - initialized_debugging = 1; -} // init_debugging - -static void setErrorMessage(const char *msg) -{ - Bstrncpy(errorMessage, msg, sizeof(errorMessage)); - // strncpy() doesn't add the null char if there isn't room... - errorMessage[sizeof(errorMessage) - 1] = '\0'; - musdebug("Error message set to [%s].", errorMessage); -} // setErrorMessage - -// The music functions... - -char *MUSIC_ErrorString(int32_t ErrorNumber) -{ - switch (ErrorNumber) - { - case MUSIC_Warning: - return(warningMessage); - - case MUSIC_Error: - return(errorMessage); - - case MUSIC_Ok: - return("OK; no error."); - - case MUSIC_ASSVersion: - return("Incorrect sound library version."); - - case MUSIC_SoundCardError: - return("General sound card error."); - - case MUSIC_InvalidCard: - return("Invalid sound card."); - - case MUSIC_MidiError: - return("MIDI error."); - - case MUSIC_MPU401Error: - return("MPU401 error."); - - case MUSIC_TaskManError: - return("Task Manager error."); - - //case MUSIC_FMNotDetected: - // return("FM not detected error."); - - case MUSIC_DPMI_Error: - return("DPMI error."); - - default: - return("Unknown error."); - } // switch - - assert(0); // shouldn't hit this point. - return(NULL); -} // MUSIC_ErrorString - -int32_t MUSIC_Init(int32_t SoundCard, int32_t Address) -{ - // Use an external MIDI player if the user has specified to do so - char *command = getenv("EDUKE32_MUSIC_CMD"); - const SDL_version *linked = Mix_Linked_Version(); - - if (SDL_VERSIONNUM(linked->major,linked->minor,linked->patch) < MIX_REQUIREDVERSION) - { - // reject running with SDL_Mixer versions older than what is stated in sdl_inc.h - initprintf("You need at least v%d.%d.%d of SDL_mixer for music\n",SDL_MIXER_MIN_X,SDL_MIXER_MIN_Y,SDL_MIXER_MIN_Z); - return(MUSIC_Error); - } - - external_midi = (command != NULL && command[0] != 0); - - if (external_midi) - Mix_SetMusicCMD(command); - else - { - FILE *fp = fopen("/etc/timidity.cfg", "r"); - if (fp == NULL) - { - initprintf("Error opening /etc/timidity.cfg: %s\n",strerror(errno)); - return MUSIC_Error; - } - Bfclose(fp); - } - - init_debugging(); - - musdebug("INIT! card=>%d, address=>%d...", SoundCard, Address); - - if (music_initialized) - { - setErrorMessage("Music system is already initialized."); - return(MUSIC_Error); - } // if - - SoundCard = 1; - - music_initialized = 1; - return(MUSIC_Ok); -} // MUSIC_Init - - -int32_t MUSIC_Shutdown(void) -{ - musdebug("shutting down sound subsystem."); - - // TODO - make sure this is being called from the menu -- SA - if (external_midi) - Mix_SetMusicCMD(NULL); - - MUSIC_StopSong(); - music_context = 0; - music_initialized = 0; - music_loopflag = MUSIC_PlayOnce; - - return(MUSIC_Ok); -} // MUSIC_Shutdown - - -void MUSIC_SetMaxFMMidiChannel(int32_t channel) -{ - musdebug("STUB ... MUSIC_SetMaxFMMidiChannel(%d).\n", channel); -} // MUSIC_SetMaxFMMidiChannel - - -void MUSIC_SetVolume(int32_t volume) -{ - volume = max(0, volume); - volume = min(volume, 255); - - Mix_VolumeMusic(volume >> 1); // convert 0-255 to 0-128. -} // MUSIC_SetVolume - - -void MUSIC_SetMidiChannelVolume(int32_t channel, int32_t volume) -{ - musdebug("STUB ... MUSIC_SetMidiChannelVolume(%d, %d).\n", channel, volume); -} // MUSIC_SetMidiChannelVolume - - -void MUSIC_ResetMidiChannelVolumes(void) -{ - musdebug("STUB ... MUSIC_ResetMidiChannelVolumes().\n"); -} // MUSIC_ResetMidiChannelVolumes - - -int32_t MUSIC_GetVolume(void) -{ - return(Mix_VolumeMusic(-1) << 1); // convert 0-128 to 0-255. -} // MUSIC_GetVolume - - -void MUSIC_SetLoopFlag(int32_t loopflag) -{ - music_loopflag = loopflag; -} // MUSIC_SetLoopFlag - - -int32_t MUSIC_SongPlaying(void) -{ - return((Mix_PlayingMusic()) ? __FX_TRUE : __FX_FALSE); -} // MUSIC_SongPlaying - - -void MUSIC_Continue(void) -{ - if (Mix_PausedMusic()) - Mix_ResumeMusic(); -} // MUSIC_Continue - - -void MUSIC_Pause(void) -{ - Mix_PauseMusic(); -} // MUSIC_Pause - - -int32_t MUSIC_StopSong(void) -{ - //if (!fx_initialized) - if (!Mix_QuerySpec(NULL, NULL, NULL)) - { - setErrorMessage("Need FX system initialized, too. Sorry."); - return(MUSIC_Error); - } // if - - if ((Mix_PlayingMusic()) || (Mix_PausedMusic())) - Mix_HaltMusic(); - - if (music_musicchunk) - Mix_FreeMusic(music_musicchunk); -// if (music_songdata) -// Bfree(music_songdata); - - music_musicchunk = NULL; -// music_songdata = NULL; - - return(MUSIC_Ok); -} // MUSIC_StopSong - -// Duke3D-specific. --ryan. -// void MUSIC_PlayMusic(char *_filename) -int32_t MUSIC_PlaySong(char *song, int32_t loopflag) -{ - MUSIC_StopSong(); - music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem((char *) song, g_musicSize)); - - if (music_musicchunk != NULL) - { - Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0); - } // if - return MUSIC_Ok; -} - - -void MUSIC_SetContext(int32_t context) -{ - musdebug("STUB ... MUSIC_SetContext().\n"); - music_context = context; -} // MUSIC_SetContext - - -int32_t MUSIC_GetContext(void) -{ - return(music_context); -} // MUSIC_GetContext - - -void MUSIC_SetSongTick(uint32_t PositionInTicks) -{ - UNREFERENCED_PARAMETER(PositionInTicks); - musdebug("STUB ... MUSIC_SetSongTick().\n"); -} // MUSIC_SetSongTick - - -void MUSIC_SetSongTime(uint32_t milliseconds) -{ - UNREFERENCED_PARAMETER(milliseconds); - musdebug("STUB ... MUSIC_SetSongTime().\n"); -}// MUSIC_SetSongTime - - -void MUSIC_SetSongPosition(int32_t measure, int32_t beat, int32_t tick) -{ - UNREFERENCED_PARAMETER(measure); - UNREFERENCED_PARAMETER(beat); - UNREFERENCED_PARAMETER(tick); - musdebug("STUB ... MUSIC_SetSongPosition().\n"); -} // MUSIC_SetSongPosition - - -void MUSIC_GetSongPosition(songposition *pos) -{ - UNREFERENCED_PARAMETER(pos); - musdebug("STUB ... MUSIC_GetSongPosition().\n"); -} // MUSIC_GetSongPosition - - -void MUSIC_GetSongLength(songposition *pos) -{ - UNREFERENCED_PARAMETER(pos); - musdebug("STUB ... MUSIC_GetSongLength().\n"); -} // MUSIC_GetSongLength - - -int32_t MUSIC_FadeVolume(int32_t tovolume, int32_t milliseconds) -{ - UNREFERENCED_PARAMETER(tovolume); - Mix_FadeOutMusic(milliseconds); - return(MUSIC_Ok); -} // MUSIC_FadeVolume - - -int32_t MUSIC_FadeActive(void) -{ - return((Mix_FadingMusic() == MIX_FADING_OUT) ? __FX_TRUE : __FX_FALSE); -} // MUSIC_FadeActive - - -void MUSIC_StopFade(void) -{ - musdebug("STUB ... MUSIC_StopFade().\n"); -} // MUSIC_StopFade - - -void MUSIC_RerouteMidiChannel(int32_t channel, int32_t cdecl(*function)(int32_t event, int32_t c1, int32_t c2)) -{ - UNREFERENCED_PARAMETER(channel); - UNREFERENCED_PARAMETER(function); - musdebug("STUB ... MUSIC_RerouteMidiChannel().\n"); -} // MUSIC_RerouteMidiChannel - - -void MUSIC_RegisterTimbreBank(char *timbres) -{ - UNREFERENCED_PARAMETER(timbres); - musdebug("STUB ... MUSIC_RegisterTimbreBank().\n"); -} // MUSIC_RegisterTimbreBank - - -void MUSIC_Update(void) -{} diff --git a/polymer/eduke32/source/jaudiolib/sdlout.c b/polymer/eduke32/source/jaudiolib/sdlout.c deleted file mode 100644 index 66b2284ef..000000000 --- a/polymer/eduke32/source/jaudiolib/sdlout.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - * DirectSound output code for MultiVoc - * by Jonathon Fowler (jonof@edgenetwk.com) - */ -//------------------------------------------------------------------------- -/* -Duke Nukem Copyright (C) 1996, 2003 3D Realms Entertainment - -This file is part of Duke Nukem 3D version 1.5 - Atomic Edition - -Duke Nukem 3D 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 "sdlout.h" -#include "sdl_inc.h" -#include -#include - -#include "sdlayer.h" - -#if defined(_MSC_VER) -#include -#endif - - -#ifndef RENDERTYPESDL -#error The SDL output module for AudioLib only works with the SDL interface. -#endif - -static int32_t(*_SDLSOUND_CallBack)(int32_t) = NULL; -static int32_t _SDLSOUND_BufferLength = 0; -static int32_t _SDLSOUND_NumBuffers = 0; -static char *_SDLSOUND_MixBuffer = NULL; - -static int32_t SDLSOUND_Installed = FALSE; - -int32_t SDLSOUND_ErrorCode = SDLSOUND_Ok; - -#define SDLSOUND_SetErrorCode( status ) \ - SDLSOUND_ErrorCode = ( status ); - -static void isr(void *userdata, char *stream, int32_t len); - -/* - * DisableInterrupts - * Enter the critical section. - */ -int32_t DisableInterrupts(void) -{ - SDL_LockAudio(); - - return 0; -} - - -/* - * RestoreInterrupts - * Leave the critical section. - */ -int32_t RestoreInterrupts(int32_t a) -{ - SDL_UnlockAudio(); - - return 0; - a=a; -} - - -/* - * SDLSOUND_ErrorString - * Returns a description of an error code. - */ -char *SDLSOUND_ErrorString(int32_t errorcode) -{ - switch (errorcode) - { - case SDLSOUND_Warning: - case SDLSOUND_Error: - return SDLSOUND_ErrorString(SDLSOUND_ErrorCode); - - case SDLSOUND_Ok: - return "SDL Sound ok."; - - default: - return "Unknown SDL sound error code."; - } -} - - -/* - * SDLSOUND_Init - * Initializes the SDL sound objects. - */ -int32_t SDLSOUND_Init(int32_t soundcard, int32_t mixrate, int32_t numchannels, int32_t samplebits, int32_t buffersize) -{ - SDL_AudioSpec spec,got; - - if (SDLSOUND_Installed) - { - SDLSOUND_Shutdown(); - } - - initprintf("Initializing SDL sound...\n"); - - initprintf(" - Requested sound format\n" - " Channels: %d\n" - " Sample rate: %dHz\n" - " Sample size: %d bits\n", - numchannels, mixrate, samplebits); - - spec.freq = mixrate; - spec.format = (samplebits == 8 ? AUDIO_U8 : AUDIO_S16LSB); - spec.channels = (numchannels == 1 ? 1:2); - spec.samples = (buffersize >> (spec.channels-1)) >> (samplebits==16); - spec.callback = isr; - spec.userdata = NULL; - - - SDLSOUND_Installed = TRUE; - - SDLSOUND_SetErrorCode(SDLSOUND_Ok); - return SDLSOUND_Ok; -} - - -/* - * SDLSOUND_Shutdown - * Shuts down SDL sound and it's associates. - */ -int32_t SDLSOUND_Shutdown(void) -{ - int32_t i; - - if (SDLSOUND_Installed) initprintf("Uninitializing SDL sound...\n"); - - SDLSOUND_Installed = FALSE; - - SDLSOUND_StopPlayback(); - - - SDLSOUND_SetErrorCode(SDLSOUND_Ok); - return SDLSOUND_Ok; -} - - -/* - * SDLSOUND_SetMixMode - * Bit of filler for the future. - */ -int32_t SDLSOUND_SetMixMode(int32_t mode) -{ - return mode; -} - - -static void isr(void *userdata, char *stream, int32_t len) -{ - // otherwise we just service the interrupt - if (_DSOUND_CallBack) - { - - p = _DSOUND_CallBack(rv-WAIT_OBJECT_0-1); - - hr = IDirectSoundBuffer_Lock(lpDSBSecondary, p*_DSOUND_BufferLength, _DSOUND_BufferLength, - &lockptr, &lockbytes, &lockptr2, &lockbytes2, 0); - if (hr == DSERR_BUFFERLOST) - { - hr = IDirectSoundBuffer_Restore(lpDSBSecondary); - } - if (hr == DS_OK) - { - /* - #define copybuf(S,D,c) \ - ({ void *__S=(S), *__D=(D); int32_t __c=(c); \ - __asm__ __volatile__ ("rep; movsl" \ - : "+S" (__S), "+D" (__D), "+c" (__c) : : "memory", "cc"); \ - 0; }) - */ - //copybuf(_DSOUND_MixBuffer + p * _DSOUND_BufferLength, lockptr, _DSOUND_BufferLength >> 2); - Bmemcpy(lockptr, _DSOUND_MixBuffer + p * _DSOUND_BufferLength, _DSOUND_BufferLength); - IDirectSoundBuffer_Unlock(lpDSBSecondary, lockptr, lockbytes, lockptr2, lockbytes2); - } - - } -} -} - - -/* - * SDLSOUND_BeginBufferedPlayback - * Unpause SDL sound playback. - */ -int32_t DSOUND_BeginBufferedPlayback(char *BufferStart, int32_t(*CallBackFunc)(int32_t), int32_t buffersize, int32_t numdivisions) -{ - _SDLSOUND_CallBack = CallBackFunc; - _SDLSOUND_MixBuffer = BufferStart; - - _SDLSOUND_BufferLength = buffersize/numdivisions; - _SDLSOUND_NumBuffers = numdivisions; - - return SDLSOUND_Ok; -} - - -/* - * DSOUND_StopPlayback - * Halts the playback thread. - */ -int32_t DSOUND_StopPlayback(void) -{ -// DWORD exitcode; - BOOL t; - int32_t i; - - if (isrthread) - { - SetEvent(isrfinish); - - initprintf("DirectSound: Waiting for sound thread to exit\n"); - if (WaitForSingleObject(isrthread, 300) == WAIT_OBJECT_0) - initprintf("DirectSound: Sound thread has exited\n"); - else - initprintf("DirectSound: Sound thread failed to exit!\n"); - /* - while (1) { - if (!GetExitCodeThread(isrthread, &exitcode)) { - DSOUND_SetErrorCode(DSOUND_FailedGetExitCode); - return DSOUND_Warning; - } - if (exitcode != STILL_ACTIVE) break; - }*/ - - CloseHandle(isrthread); - isrthread = NULL; - } - - if (isrfinish) - { - CloseHandle(isrfinish); - isrfinish = NULL; - } - - if (lpDSBSecondary) - { - IDirectSoundBuffer_Stop(lpDSBSecondary); - } - - if (hPosNotify) - { - for (i=0; i<_DSOUND_NumBuffers; i++) - { - if (hPosNotify[i]) CloseHandle(hPosNotify[i]); - } - free(hPosNotify); - hPosNotify = NULL; - } - - return DSOUND_Ok; -} - - diff --git a/polymer/eduke32/source/jaudiolib/sdlout.h b/polymer/eduke32/source/jaudiolib/sdlout.h deleted file mode 100644 index 701e3cfaa..000000000 --- a/polymer/eduke32/source/jaudiolib/sdlout.h +++ /dev/null @@ -1,48 +0,0 @@ -//------------------------------------------------------------------------- -/* -Duke Nukem Copyright (C) 1996, 2003 3D Realms Entertainment - -This file is part of Duke Nukem 3D version 1.5 - Atomic Edition - -Duke Nukem 3D 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 __sdlout_h__ -#define __sdlout_h__ - -enum SDLSOUND_ERRORS { - SDLSOUND_Warning = -2, - SDLSOUND_Error = -1, - SDLSOUND_Ok = 0 -}; - -extern int32_t SDLSOUND_ErrorCode; - -char *SDLSOUND_ErrorString(int32_t); - -int32_t DisableInterrupts(void); // simulated using critical sections -int32_t RestoreInterrupts(int32_t); - -int32_t SDLSOUND_Init(int32_t soundcard, int32_t mixrate, int32_t numchannels, int32_t samplebits, int32_t buffersize); -int32_t SDLSOUND_Shutdown(void); - -int32_t SDLSOUND_SetMixMode(int32_t mode); -int32_t SDLSOUND_BeginBufferedPlayback(char *BufferStart, int32_t (*CallBackFunc)(int32_t), int32_t buffersize, int32_t numdivisions); -int32_t SDLSOUND_StopPlayback(void); - -#endif // __sdlout_h__ - diff --git a/polymer/eduke32/source/jaudiolib/standard.h b/polymer/eduke32/source/jaudiolib/standard.h deleted file mode 100644 index 952648cb6..000000000 --- a/polymer/eduke32/source/jaudiolib/standard.h +++ /dev/null @@ -1,73 +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. - -Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com) -*/ -/********************************************************************** - 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