From 6b956dfe2a2009c60dd3f375c016b9ced678d9ea Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 8 Mar 2008 07:46:30 +0000 Subject: [PATCH] git-svn-id: https://svn.eduke32.com/eduke32@637 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 8 +- polymer/eduke32/source/game.c | 2 + polymer/eduke32/source/jaudiolib/_multivc.h | 6 +- polymer/eduke32/source/jaudiolib/fx_man.c | 9 +- polymer/eduke32/source/jaudiolib/multivoc.c | 14 +- polymer/eduke32/source/jaudiolib/multivoc.h | 2 - polymer/eduke32/source/jaudiolib/music.c | 1214 +++++++++---------- polymer/eduke32/source/jaudiolib/openal.c | 760 ++++++------ polymer/eduke32/source/jaudiolib/openal.h | 2 +- polymer/eduke32/source/jaudiolib/sdlmusic.c | 30 +- polymer/eduke32/source/premap.c | 3 +- polymer/eduke32/source/sounds.c | 24 +- 12 files changed, 1037 insertions(+), 1037 deletions(-) diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 43da3d27b..28819fd25 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -53,16 +53,12 @@ ifeq ($(PLATFORM),LINUX) OBJ=obj EOBJ=eobj NASMFLAGS+= -f elf - ifeq ($(USE_OPENAL),1) - LIBS+= -lvorbisfile -lvorbis -logg - endif + LIBS+= -lvorbisfile -lvorbis -logg else ifeq ($(PLATFORM),WINDOWS) OBJ=obj_win EOBJ=eobj_win - ifeq ($(USE_OPENAL),1) - LIBS+= -L$(ALROOT)/lib -lvorbisfile -lvorbis -logg - endif + LIBS+= -L$(ALROOT)/lib -lvorbisfile -lvorbis -logg else OBJ=obj EOBJ=eobj diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index b115aa1ec..af2e8ef0b 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8720,8 +8720,10 @@ static int parsegroupfiles(scriptfile *script) initprintf("Error: missing ID for music definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr)); break; } +#ifdef USE_OPENAL if (AL_DefineMusic(ID,ext)) initprintf("Error: invalid music ID on line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr)); +#endif } break; diff --git a/polymer/eduke32/source/jaudiolib/_multivc.h b/polymer/eduke32/source/jaudiolib/_multivc.h index 4889d66d6..ceaa1cfeb 100644 --- a/polymer/eduke32/source/jaudiolib/_multivc.h +++ b/polymer/eduke32/source/jaudiolib/_multivc.h @@ -88,9 +88,7 @@ typedef enum VOC, DemandFeed, WAV, -#ifdef USE_OPENAL OGG -#endif } wavedata; typedef enum @@ -134,11 +132,11 @@ typedef struct VoiceNode int priority; void ( *DemandFeed )( char **ptr, unsigned int *length ); -#ifdef USE_OPENAL + struct sounddef OGGstream; char *bufsnd; int downsample; -#endif + short *LeftVolume; short *RightVolume; diff --git a/polymer/eduke32/source/jaudiolib/fx_man.c b/polymer/eduke32/source/jaudiolib/fx_man.c index 816f582bd..b1f9abf44 100644 --- a/polymer/eduke32/source/jaudiolib/fx_man.c +++ b/polymer/eduke32/source/jaudiolib/fx_man.c @@ -705,7 +705,6 @@ int FX_PlayWAV Begin playback of sound data with the given volume and priority. ---------------------------------------------------------------------*/ -#ifdef USE_OPENAL int FX_PlayOGG ( char *ptr, @@ -730,7 +729,6 @@ int FX_PlayOGG return(handle); } -#endif /*--------------------------------------------------------------------- Function: FX_PlayWAV @@ -766,7 +764,7 @@ int FX_PlayLoopedWAV return(handle); } -#ifdef USE_OPENAL + int FX_PlayLoopedOGG ( char *ptr, @@ -795,7 +793,7 @@ int FX_PlayLoopedOGG return(handle); } -#endif + /*--------------------------------------------------------------------- Function: FX_PlayVOC3D @@ -826,7 +824,7 @@ int FX_PlayVOC3D return(handle); } -#ifdef USE_OPENAL + int FX_PlayOGG3D ( char *ptr, @@ -850,7 +848,6 @@ int FX_PlayOGG3D return(handle); } -#endif /*--------------------------------------------------------------------- Function: FX_PlayWAV3D diff --git a/polymer/eduke32/source/jaudiolib/multivoc.c b/polymer/eduke32/source/jaudiolib/multivoc.c index 0d9197747..eaf00d4d9 100644 --- a/polymer/eduke32/source/jaudiolib/multivoc.c +++ b/polymer/eduke32/source/jaudiolib/multivoc.c @@ -206,11 +206,9 @@ char *MV_ErrorString(int ErrorNumber) case MV_InvalidWAVFile : ErrorString = "Invalid WAV file passed in to Multivoc."; break; -#ifdef USE_OPENAL case MV_InvalidOGGFile : ErrorString = "Invalid OGG file passed in to Multivoc."; break; -#endif case MV_InvalidMixMode : ErrorString = "Invalid mix mode request in Multivoc."; break; @@ -918,7 +916,7 @@ playbackstatus MV_GetNextWAVBlock(VoiceNode *voice) Controls playback of demand fed data. ---------------------------------------------------------------------*/ -#ifdef USE_OPENAL + void downsample(char *ptr,int size,int factor) { short *pti=(short *)ptr;int i,j,sum; @@ -982,7 +980,7 @@ playbackstatus MV_GetNextOGGBlock(VoiceNode *voice) return(KeepPlaying); } -#endif + /*--------------------------------------------------------------------- Function: MV_ServiceRecord @@ -2406,7 +2404,7 @@ int MV_PlayLoopedVOC(char *ptr, int loopstart, int loopend, int pitchoffset, int priority. ---------------------------------------------------------------------*/ VoiceNode *voice; -#ifdef USE_OPENAL + int MV_PlayLoopedOGG(char *ptr, int loopstart, int loopend, int pitchoffset, int vol, int left, int right, int priority, unsigned int callbackval) { vorbis_info *vorbisInfo; @@ -2546,7 +2544,7 @@ int MV_PlayOGG3D(char *ptr, int pitchoffset, int angle, int distance, int priori return(status); } -#endif + /*--------------------------------------------------------------------- Function: MV_CreateVolumeTable @@ -2886,11 +2884,11 @@ int MV_Init(int soundcard, int MixRate, int Voices, int numchannels, int sampleb Bfree(map[i].musicfn1); } - for (i=MAXSOUNDS-1;i>=0;i--) +/* for (i=MAXSOUNDS-1;i>=0;i--) { if (g_sounds[i].filename1 != NULL) Bfree(g_sounds[i].filename1); - } + } */ } #endif #if defined(_WIN32) diff --git a/polymer/eduke32/source/jaudiolib/multivoc.h b/polymer/eduke32/source/jaudiolib/multivoc.h index 866a93082..2a9dd94eb 100644 --- a/polymer/eduke32/source/jaudiolib/multivoc.h +++ b/polymer/eduke32/source/jaudiolib/multivoc.h @@ -50,9 +50,7 @@ enum MV_Errors MV_DPMI_Error, MV_InvalidVOCFile, MV_InvalidWAVFile, -#ifdef USE_OPENAL MV_InvalidOGGFile, -#endif MV_InvalidMixMode, MV_IrqFailure, MV_DMAFailure, diff --git a/polymer/eduke32/source/jaudiolib/music.c b/polymer/eduke32/source/jaudiolib/music.c index badaf1565..7731e0ec8 100644 --- a/polymer/eduke32/source/jaudiolib/music.c +++ b/polymer/eduke32/source/jaudiolib/music.c @@ -1,612 +1,612 @@ -/* -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" -#ifdef USE_OPENAL -#include "openal.h" -#endif - -#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 - -int MUSIC_SoundDevice = -1; -int MUSIC_ErrorCode = MUSIC_Ok; - -static midifuncs MUSIC_MidiFunctions; - -int MUSIC_InitMidi(int card, midifuncs *Funcs, int 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 -( - int 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. ----------------------------------------------------------------------*/ - -int MUSIC_Init -( - int SoundCard, - int Address -) - -{ - int i; - int status; - - for (i = 0; i < 128; i++) - { - MIDI_PatchMap[ i ] = i; - } - - MUSIC_SoundDevice = SoundCard; - - status = MUSIC_InitMidi(SoundCard, &MUSIC_MidiFunctions, Address); - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Shutdown - - Terminates use of sound device. ----------------------------------------------------------------------*/ - -int MUSIC_Shutdown -( - void -) - -{ - int status; - - status = MUSIC_Ok; - - MIDI_StopSong(); - - //MPU_Reset(); - - return(status); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetVolume - - Sets the volume of music playback. ----------------------------------------------------------------------*/ - -void MUSIC_SetVolume -( - int volume -) - -{ - volume = max(0, volume); - volume = min(volume, 255); -#ifdef USE_OPENAL +/* +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" +#ifdef USE_OPENAL +#include "openal.h" +#endif + +#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 + +int MUSIC_SoundDevice = -1; +int MUSIC_ErrorCode = MUSIC_Ok; + +static midifuncs MUSIC_MidiFunctions; + +int MUSIC_InitMidi(int card, midifuncs *Funcs, int 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 +( + int 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. +---------------------------------------------------------------------*/ + +int MUSIC_Init +( + int SoundCard, + int Address +) + +{ + int i; + int status; + + for (i = 0; i < 128; i++) + { + MIDI_PatchMap[ i ] = i; + } + + MUSIC_SoundDevice = SoundCard; + + status = MUSIC_InitMidi(SoundCard, &MUSIC_MidiFunctions, Address); + + return(status); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_Shutdown + + Terminates use of sound device. +---------------------------------------------------------------------*/ + +int MUSIC_Shutdown +( + void +) + +{ + int status; + + status = MUSIC_Ok; + + MIDI_StopSong(); + + //MPU_Reset(); + + return(status); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_SetVolume + + Sets the volume of music playback. +---------------------------------------------------------------------*/ + +void MUSIC_SetVolume +( + int volume +) + +{ + volume = max(0, volume); + volume = min(volume, 255); +#ifdef USE_OPENAL if (!openal_disabled) - 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 -( - int channel, - int 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. ----------------------------------------------------------------------*/ - -int 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 -( - int loopflag -) - -{ - MIDI_SetLoopFlag(loopflag); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SongPlaying - - Returns whether there is a song playing. ----------------------------------------------------------------------*/ - -int MUSIC_SongPlaying -( - void -) - -{ - return(MIDI_SongPlaying()); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Continue - - Continues playback of a paused song. ----------------------------------------------------------------------*/ - -void MUSIC_Continue -( - void -) - -{ -#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 +( + int channel, + int 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. +---------------------------------------------------------------------*/ + +int 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 +( + int loopflag +) + +{ + MIDI_SetLoopFlag(loopflag); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_SongPlaying + + Returns whether there is a song playing. +---------------------------------------------------------------------*/ + +int MUSIC_SongPlaying +( + void +) + +{ + return(MIDI_SongPlaying()); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_Continue + + Continues playback of a paused song. +---------------------------------------------------------------------*/ + +void MUSIC_Continue +( + void +) + +{ +#ifdef USE_OPENAL if (!openal_disabled) - AL_Continue(); -#endif - MIDI_ContinueSong(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_Pause - - Pauses playback of a song. ----------------------------------------------------------------------*/ - -void MUSIC_Pause -( - void -) - -{ -#ifdef USE_OPENAL + AL_Continue(); +#endif + MIDI_ContinueSong(); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_Pause + + Pauses playback of a song. +---------------------------------------------------------------------*/ + +void MUSIC_Pause +( + void +) + +{ +#ifdef USE_OPENAL if (!openal_disabled) - AL_Pause(); -#endif - MIDI_PauseSong(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_StopSong - - Stops playback of current song. ----------------------------------------------------------------------*/ - -int MUSIC_StopSong -( - void -) - -{ -#ifdef USE_OPENAL + AL_Pause(); +#endif + MIDI_PauseSong(); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_StopSong + + Stops playback of current song. +---------------------------------------------------------------------*/ + +int MUSIC_StopSong +( + void +) + +{ +#ifdef USE_OPENAL if (!openal_disabled) - AL_stop(); -#endif - MUSIC_StopFade(); - MIDI_StopSong(); - MUSIC_SetErrorCode(MUSIC_Ok); - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_PlaySong - - Begins playback of MIDI song. ----------------------------------------------------------------------*/ - -int MUSIC_PlaySong -( - unsigned char *song, - int loopflag -) - -{ - int status; - -#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. +---------------------------------------------------------------------*/ + +int MUSIC_PlaySong +( + unsigned char *song, + int loopflag +) + +{ + int status; + +#ifdef USE_OPENAL if (!openal_disabled) - AL_PlaySong((char *)song,loopflag); - if(openal_disabled || 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 -( - int context -) - -{ - MIDI_SetContext(context); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_GetContext - - Returns the current song context. ----------------------------------------------------------------------*/ - -int MUSIC_GetContext -( - void -) - -{ - return MIDI_GetContext(); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongTick - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongTick -( - unsigned int PositionInTicks -) - -{ - MIDI_SetSongTick(PositionInTicks); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongTime - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongTime -( - unsigned int milliseconds -) - -{ - MIDI_SetSongTime(milliseconds); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_SetSongPosition - - Sets the position of the song pointer. ----------------------------------------------------------------------*/ - -void MUSIC_SetSongPosition -( - int measure, - int beat, - int 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); -} - - -int MUSIC_InitMidi -( - int card, - midifuncs *Funcs, - int 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. ----------------------------------------------------------------------*/ - -int MUSIC_FadeVolume -( - int tovolume, - int milliseconds -) - -{ - MIDI_SetVolume(tovolume); - return(MUSIC_Ok); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_FadeActive - - Returns whether the fade routine is active. ----------------------------------------------------------------------*/ - -int 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 -( - int channel, - int(*function)(int event, int c1, int c2) -) - -{ - MIDI_RerouteMidiChannel(channel, function); -} - - -/*--------------------------------------------------------------------- - Function: MUSIC_RegisterTimbreBank - - Halts playback of all sounds. ----------------------------------------------------------------------*/ - -void MUSIC_RegisterTimbreBank -( - unsigned char *timbres -) - -{} - - -void MUSIC_Update(void) -{ - MIDI_UpdateMusic(); -} - + AL_PlaySong((char *)song,loopflag); + if(openal_disabled || 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 +( + int context +) + +{ + MIDI_SetContext(context); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_GetContext + + Returns the current song context. +---------------------------------------------------------------------*/ + +int MUSIC_GetContext +( + void +) + +{ + return MIDI_GetContext(); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_SetSongTick + + Sets the position of the song pointer. +---------------------------------------------------------------------*/ + +void MUSIC_SetSongTick +( + unsigned int PositionInTicks +) + +{ + MIDI_SetSongTick(PositionInTicks); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_SetSongTime + + Sets the position of the song pointer. +---------------------------------------------------------------------*/ + +void MUSIC_SetSongTime +( + unsigned int milliseconds +) + +{ + MIDI_SetSongTime(milliseconds); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_SetSongPosition + + Sets the position of the song pointer. +---------------------------------------------------------------------*/ + +void MUSIC_SetSongPosition +( + int measure, + int beat, + int 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); +} + + +int MUSIC_InitMidi +( + int card, + midifuncs *Funcs, + int 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. +---------------------------------------------------------------------*/ + +int MUSIC_FadeVolume +( + int tovolume, + int milliseconds +) + +{ + MIDI_SetVolume(tovolume); + return(MUSIC_Ok); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_FadeActive + + Returns whether the fade routine is active. +---------------------------------------------------------------------*/ + +int 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 +( + int channel, + int(*function)(int event, int c1, int c2) +) + +{ + MIDI_RerouteMidiChannel(channel, function); +} + + +/*--------------------------------------------------------------------- + Function: MUSIC_RegisterTimbreBank + + Halts playback of all sounds. +---------------------------------------------------------------------*/ + +void MUSIC_RegisterTimbreBank +( + unsigned char *timbres +) + +{} + + +void MUSIC_Update(void) +{ + MIDI_UpdateMusic(); +} + diff --git a/polymer/eduke32/source/jaudiolib/openal.c b/polymer/eduke32/source/jaudiolib/openal.c index 3b0225fae..854bbec9d 100644 --- a/polymer/eduke32/source/jaudiolib/openal.c +++ b/polymer/eduke32/source/jaudiolib/openal.c @@ -1,36 +1,36 @@ -#ifdef _WIN32 -#include "dsound.h" -#endif - -#include "baselayer.h" -#include "compat.h" -#include -#include -#include -#include "_multivc.h" - -ALCdevice * device=NULL; -ALCcontext * context=NULL; - -char *ALdoing=""; -int AL_Error; -int bufsize; -int openal_disabled = 0; - -typedef struct SD -{ - ALuint buffers[16]; - ALuint source; - ALenum format; - - char loop; - char type; - int rate; - sounddef def; -}sounddef1; - -sounddef1 sounds1[2]; - +#ifdef _WIN32 +#include "dsound.h" +#endif + +#include "baselayer.h" +#include "compat.h" +#include +#include +#include +#include "_multivc.h" + +ALCdevice * device=NULL; +ALCcontext * context=NULL; + +char *ALdoing=""; +int AL_Error; +int bufsize; +int openal_disabled = 0; + +typedef struct SD +{ + ALuint buffers[16]; + ALuint source; + ALenum format; + + char loop; + char type; + int rate; + sounddef def; +}sounddef1; + +sounddef1 sounds1[2]; + #ifdef _WIN32 // Windows static HANDLE hALDLL; @@ -38,33 +38,33 @@ static HANDLE hALDLL; #include static void *alhandle = NULL; -#endif - -char *aldriver = NULL; - -void (AL_APIENTRY * balGetSourcei)( ALuint sid, ALenum param, ALint* value ); -void (AL_APIENTRY * balSourcef)( ALuint sid, ALenum param, ALfloat value ); -void (AL_APIENTRY * balSourcePlay)( ALuint sid ); -void (AL_APIENTRY * balSourcePause)( ALuint sid ); -ALCenum (ALC_APIENTRY * balcGetError)( ALCdevice *device ); -ALenum (AL_APIENTRY * balGetError)( void ); -void (AL_APIENTRY * balBufferData)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq ); -void (AL_APIENTRY * balGenBuffers)( ALsizei n, ALuint* buffers ); -void (AL_APIENTRY * balGenSources)( ALsizei n, ALuint* sources ); -void (AL_APIENTRY * balSourcei)( ALuint sid, ALenum param, ALint value ); -void (AL_APIENTRY * balSourceQueueBuffers)( ALuint sid, ALsizei numEntries, const ALuint *bids ); -void (AL_APIENTRY * balSourceStop)( ALuint sid ); -void (AL_APIENTRY * balSourceUnqueueBuffers)( ALuint sid, ALsizei numEntries, ALuint *bids ); -void (AL_APIENTRY * bbalDeleteSources)( ALsizei n, const ALuint* sources ); -ALCboolean (ALC_APIENTRY * balcMakeContextCurrent)( ALCcontext *context ); -void (AL_APIENTRY * balDeleteSources)( ALsizei n, const ALuint* sources ); -void (AL_APIENTRY * balDeleteBuffers)( ALsizei n, const ALuint* buffers ); -void (ALC_APIENTRY * balcDestroyContext)( ALCcontext *context ); -ALCboolean (ALC_APIENTRY * balcCloseDevice)( ALCdevice *device ); -ALCdevice *(ALC_APIENTRY * balcOpenDevice)( const ALCchar *devicename ); -ALCcontext *(ALC_APIENTRY * balcCreateContext)( ALCdevice *device, const ALCint* attrlist ); -const ALchar* (AL_APIENTRY * balGetString)( ALenum param ); - +#endif + +char *aldriver = NULL; + +void (AL_APIENTRY * balGetSourcei)( ALuint sid, ALenum param, ALint* value ); +void (AL_APIENTRY * balSourcef)( ALuint sid, ALenum param, ALfloat value ); +void (AL_APIENTRY * balSourcePlay)( ALuint sid ); +void (AL_APIENTRY * balSourcePause)( ALuint sid ); +ALCenum (ALC_APIENTRY * balcGetError)( ALCdevice *device ); +ALenum (AL_APIENTRY * balGetError)( void ); +void (AL_APIENTRY * balBufferData)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq ); +void (AL_APIENTRY * balGenBuffers)( ALsizei n, ALuint* buffers ); +void (AL_APIENTRY * balGenSources)( ALsizei n, ALuint* sources ); +void (AL_APIENTRY * balSourcei)( ALuint sid, ALenum param, ALint value ); +void (AL_APIENTRY * balSourceQueueBuffers)( ALuint sid, ALsizei numEntries, const ALuint *bids ); +void (AL_APIENTRY * balSourceStop)( ALuint sid ); +void (AL_APIENTRY * balSourceUnqueueBuffers)( ALuint sid, ALsizei numEntries, ALuint *bids ); +void (AL_APIENTRY * bbalDeleteSources)( ALsizei n, const ALuint* sources ); +ALCboolean (ALC_APIENTRY * balcMakeContextCurrent)( ALCcontext *context ); +void (AL_APIENTRY * balDeleteSources)( ALsizei n, const ALuint* sources ); +void (AL_APIENTRY * balDeleteBuffers)( ALsizei n, const ALuint* buffers ); +void (ALC_APIENTRY * balcDestroyContext)( ALCcontext *context ); +ALCboolean (ALC_APIENTRY * balcCloseDevice)( ALCdevice *device ); +ALCdevice *(ALC_APIENTRY * balcOpenDevice)( const ALCchar *devicename ); +ALCcontext *(ALC_APIENTRY * balcCreateContext)( ALCdevice *device, const ALCint* attrlist ); +const ALchar* (AL_APIENTRY * balGetString)( ALenum param ); + static void * algetproc_(const char *s, int *err, int fatal) { void *t; @@ -101,26 +101,26 @@ int unloadaldriver(void) #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; - bbalDeleteSources = NULL; - balcMakeContextCurrent = NULL; - balDeleteSources = NULL; - balDeleteBuffers = NULL; - balcDestroyContext = NULL; - balcCloseDevice = NULL; - balcOpenDevice = NULL; - balcCreateContext = 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; + bbalDeleteSources = NULL; + balcMakeContextCurrent = NULL; + balDeleteSources = NULL; + balDeleteBuffers = NULL; + balcDestroyContext = NULL; + balcCloseDevice = NULL; + balcOpenDevice = NULL; + balcCreateContext = NULL; balGetString = NULL; return 0; @@ -159,309 +159,309 @@ int loadaldriver(void) 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"); + 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(int 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(int 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(int 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; - - -int AL_Init() -{ - if (loadaldriver()) - { - initprintf("Failed loading OpenAL driver.\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) - { - balcMakeContextCurrent(context);check(1); - initprintf("OpenAL Information:\n" - " Version: %s\n" - " Vendor: %s\n\n",balGetString(AL_VERSION),balGetString(AL_VENDOR)); - } else initprintf("OpenAL initialisation failed. Try http://www.openal.org/\n"); - - ALdoing="Open"; - balGenBuffers(16, sounds1[1].buffers); - check(1); - balGenSources(1,&sounds1[1].source); - check(1); - - return 0; -} - -void AL_Shutdown() -{ - ALdoing="Delete source"; - balDeleteSources(1,&sounds1[1].source); - check(1); - ALdoing="Delete buffers"; - balDeleteBuffers(16, sounds1[1].buffers); - check(1); - - ALdoing="Shut"; - balcMakeContextCurrent(NULL); - check(1); - balcDestroyContext(context); - check(1); - balcCloseDevice(device); - unloadaldriver(); -} - -#define BUFFER_SIZE (4096 * 4*8*8) -int AL_MusicVolume; -sounddef1 music; -extern int Musicsize; - - -void AL_stop(); -int update(); -int stream(ALuint buffer); -void open1(char *ptr,int 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&&!update(0))AL_stop();} -int AL_isntALmusic() {return !music.def.size;} - -void AL_SetMusicVolume(int volume) -{ - AL_MusicVolume=volume; - if(music.def.size)balSourcef(music.source,AL_GAIN,volume/(255.)); -} - -int isplaying() -{ - ALenum state; - balGetSourcei(music.source,AL_SOURCE_STATE,&state); - return state==AL_PLAYING; -} - -int update() -{ - int processed=0; - int active=1; - ALuint buffer; - - ALdoing="update"; - balGetSourcei(music.source,AL_BUFFERS_PROCESSED,&processed); - check(1); - if(processed) - switch(music.type) - { - case 1: - while(processed--) - { - balSourceUnqueueBuffers(music.source,1,&buffer); - check(1); - active=stream(buffer); - if(active) - { - balSourceQueueBuffers(music.source,1,&buffer); - check(1); - } - } - break; - } - return active; -} - -void AL_stop() -{ - int queued=0;ALuint buffer; - - if(!music.def.size)return; - - 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(sounddef1)); -} - -int stream(ALuint buffer) -{ - char pcm[BUFFER_SIZE]; - ALsizei size=0; - int 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,int loop) -{ - vorbis_info* vorbisInfo; - int bf=2,i; - ALenum format;ALsizei size;ALsizei freq;ALvoid* data; - - if(!context)return; - Bmemset(&music,0,sizeof(sounddef1)); - switch(*ptr) - { - case 'O':music.type=1;break; - default: return; - } - music.def.size=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(); -} +char *ALC_ErrorString(int 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(int 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(int 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; + + +int AL_Init() +{ + if (loadaldriver()) + { + initprintf("Failed loading OpenAL driver.\nDownload OpenAL 1.1 or greater from http://www.openal.org/downloads.html."); + 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) + { + balcMakeContextCurrent(context);check(1); + initprintf("OpenAL Information:\n" + " Version: %s\n" + " Vendor: %s\n\n",balGetString(AL_VERSION),balGetString(AL_VENDOR)); + } else initprintf("OpenAL initialization failed.\n"); + + ALdoing="Open"; + balGenBuffers(16, sounds1[1].buffers); + check(1); + balGenSources(1,&sounds1[1].source); + check(1); + + return 0; +} + +void AL_Shutdown() +{ + ALdoing="Delete source"; + balDeleteSources(1,&sounds1[1].source); + check(1); + ALdoing="Delete buffers"; + balDeleteBuffers(16, sounds1[1].buffers); + check(1); + + ALdoing="Shut"; + balcMakeContextCurrent(NULL); + check(1); + balcDestroyContext(context); + check(1); + balcCloseDevice(device); + unloadaldriver(); +} + +#define BUFFER_SIZE (4096 * 4*8*8) +int AL_MusicVolume; +sounddef1 music; +extern int Musicsize; + + +void AL_Stop(); +int update(); +int stream(ALuint buffer); +void open1(char *ptr,int 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&&!update(0))AL_Stop();} +int AL_isntALmusic() {return !music.def.size;} + +void AL_SetMusicVolume(int volume) +{ + AL_MusicVolume=volume; + if(music.def.size)balSourcef(music.source,AL_GAIN,volume/(255.)); +} + +int isplaying() +{ + ALenum state; + balGetSourcei(music.source,AL_SOURCE_STATE,&state); + return state==AL_PLAYING; +} + +int update() +{ + int processed=0; + int active=1; + ALuint buffer; + + ALdoing="update"; + balGetSourcei(music.source,AL_BUFFERS_PROCESSED,&processed); + check(1); + if(processed) + switch(music.type) + { + case 1: + while(processed--) + { + balSourceUnqueueBuffers(music.source,1,&buffer); + check(1); + active=stream(buffer); + if(active) + { + balSourceQueueBuffers(music.source,1,&buffer); + check(1); + } + } + break; + } + return active; +} + +void AL_Stop() +{ + int queued=0;ALuint buffer; + + if(!music.def.size)return; + + 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(sounddef1)); +} + +int stream(ALuint buffer) +{ + char pcm[BUFFER_SIZE]; + ALsizei size=0; + int 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,int loop) +{ + vorbis_info* vorbisInfo; + int bf=2,i; + ALenum format;ALsizei size;ALsizei freq;ALvoid* data; + + if(!context)return; + Bmemset(&music,0,sizeof(sounddef1)); + switch(*ptr) + { + case 'O':music.type=1;break; + default: return; + } + music.def.size=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(); +} diff --git a/polymer/eduke32/source/jaudiolib/openal.h b/polymer/eduke32/source/jaudiolib/openal.h index c36d64f86..07dda75c5 100644 --- a/polymer/eduke32/source/jaudiolib/openal.h +++ b/polymer/eduke32/source/jaudiolib/openal.h @@ -9,7 +9,7 @@ void AL_Update(); char *AL_ErrorString(int code); char *ALC_ErrorString(int code); -void AL_stop(); +void AL_Stop(); int AL_isntALmusic(); void AL_PlaySong(char *song,int loopflag); void AL_Pause(); diff --git a/polymer/eduke32/source/jaudiolib/sdlmusic.c b/polymer/eduke32/source/jaudiolib/sdlmusic.c index d68ed8902..8121b06b0 100755 --- a/polymer/eduke32/source/jaudiolib/sdlmusic.c +++ b/polymer/eduke32/source/jaudiolib/sdlmusic.c @@ -54,6 +54,10 @@ Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu) #include #include "music.h" +#ifdef USE_OPENAL +#include "openal.h" +#endif + #define __FX_TRUE (1 == 1) #define __FX_FALSE (!__FX_TRUE) @@ -376,6 +380,11 @@ void MUSIC_SetVolume(int volume) volume = max(0, volume); volume = min(volume, 255); +#ifdef USE_OPENAL + if (!openal_disabled) + AL_SetMusicVolume(volume); +#endif + Mix_VolumeMusic(volume >> 1); // convert 0-255 to 0-128. } // MUSIC_SetVolume @@ -412,6 +421,10 @@ int MUSIC_SongPlaying(void) void MUSIC_Continue(void) { +#ifdef USE_OPENAL + if (!openal_disabled) + AL_Continue(); +#endif if (Mix_PausedMusic()) Mix_ResumeMusic(); else if (music_songdata) @@ -421,12 +434,20 @@ void MUSIC_Continue(void) void MUSIC_Pause(void) { +#ifdef USE_OPENAL + if (!openal_disabled) + AL_Pause(); +#endif Mix_PauseMusic(); } // MUSIC_Pause int MUSIC_StopSong(void) { +#ifdef USE_OPENAL + if (!openal_disabled) + AL_Stop(); +#endif //if (!fx_initialized) if (!Mix_QuerySpec(NULL, NULL, NULL)) { @@ -450,7 +471,12 @@ int MUSIC_StopSong(void) int MUSIC_PlaySong(unsigned char *song, int loopflag) { //SDL_RWops *rw; - +#ifdef USE_OPENAL + if (!openal_disabled) + AL_PlaySong((char *)song,loopflag); + if(openal_disabled || AL_isntALmusic()) +#endif + { MUSIC_StopSong(); music_songdata = (char *)song; @@ -468,7 +494,7 @@ int MUSIC_PlaySong(unsigned char *song, int loopflag) music_musicchunk = Mix_LoadMUS_RW(rw); Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_PlayOnce) ? 0 : -1); */ - + } return(MUSIC_Ok); } // MUSIC_PlaySong diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index e8860be14..ea7cf2d61 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1605,7 +1605,8 @@ int enterlevel(int g) FX_StopAllSounds(); clearsoundlocks(); FX_SetReverb(0); - playmusicMAP(&env_music_fn[1][0],MAXVOLUMES*MAXLEVELS+2); // loadmus + MUSIC_StopSong(); + playmusicMAP(&env_music_fn[2][0],MAXVOLUMES*MAXLEVELS+2); // loadmus if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0) { diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index 3a1573c4b..defdc5f1d 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -392,14 +392,10 @@ int xyzsound(int num,int i,int x,int y,int z) if (*g_sounds[num].ptr == 'C') voice = FX_PlayLoopedVOC(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz, pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num); -#ifdef USE_OPENAL - else if (!openal_disabled) - { + else if (*g_sounds[num].ptr == 'O') voice = FX_PlayLoopedOGG(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz, pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num); - } -#endif else voice = FX_PlayLoopedWAV(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz, pitch,sndist>>6,sndist>>6,0,g_sounds[num].pr,num); @@ -408,13 +404,9 @@ int xyzsound(int num,int i,int x,int y,int z) { if (*g_sounds[num].ptr == 'C') voice = FX_PlayVOC3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num); -#ifdef USE_OPENAL - else if (!openal_disabled) - { + else if (*g_sounds[num].ptr == 'O') voice = FX_PlayOGG3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num); - } -#endif else voice = FX_PlayWAV3D(g_sounds[ num ].ptr,pitch,sndang>>6,sndist>>6, g_sounds[num].pr, num); } @@ -477,17 +469,13 @@ void sound(int num) voice = FX_PlayLoopedVOC(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz, pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num); } -#ifdef USE_OPENAL - else if (!openal_disabled) - { + else if (*g_sounds[num].ptr == 'O') { start = (int)*(unsigned short *)(g_sounds[num].ptr + 0x14); voice = FX_PlayLoopedOGG(g_sounds[num].ptr, start, start + g_sounds[num].soundsiz, pitch,LOUDESTVOLUME,LOUDESTVOLUME,LOUDESTVOLUME,g_sounds[num].pr,num); } - } -#endif else { start = (int)*(unsigned short *)(g_sounds[num].ptr + 0x14); @@ -499,13 +487,9 @@ void sound(int num) { if (*g_sounds[num].ptr == 'C') voice = FX_PlayVOC3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num); -#ifdef USE_OPENAL - else if (!openal_disabled) - { + else if (*g_sounds[num].ptr == 'O') voice = FX_PlayOGG3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num); - } -#endif else voice = FX_PlayWAV3D(g_sounds[ num ].ptr, pitch,0,255-LOUDESTVOLUME,g_sounds[num].pr, num); }