From f080ec41b12e5b54f7f1c5a51adb74fa601ac5f2 Mon Sep 17 00:00:00 2001 From: Roy Shapiro <70241434+RoyShapiro@users.noreply.github.com> Date: Mon, 11 Jul 2022 06:09:53 +0300 Subject: [PATCH 1/4] HL:Invasion Add MiniAudio Music implementation --- .gitmodules | 4 + CMakeLists.txt | 1 + README.md | 32 ++- dlls/CMakeLists.txt | 4 + dlls/music.cpp | 2 + dlls/musicminiaudio.cpp | 495 ++++++++++++++++++++++++++++++++++++++++ dlls/musicminiaudio.h | 83 +++++++ miniaudio | 1 + 8 files changed, 610 insertions(+), 12 deletions(-) create mode 100644 dlls/musicminiaudio.cpp create mode 100644 dlls/musicminiaudio.h create mode 160000 miniaudio diff --git a/.gitmodules b/.gitmodules index 9510c702..3ace6396 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "vgui_support"] path = vgui_support url = https://github.com/FWGS/vgui_support + +[submodule "miniaudio"] + path = miniaudio + url = https://github.com/mackron/miniaudio diff --git a/CMakeLists.txt b/CMakeLists.txt index 36fc55a8..589bd644 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ option(BUILD_CLIENT "Build client dll" ON) option(BUILD_SERVER "Build server dll" ON) option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" OFF) option(USE_GSTREAMER "Enable GStreamer." OFF) +option(USE_MINIAUDIO "Enable Miniaudio." OFF) option(USE_FMOD "Enable FMOD." OFF) if (CMAKE_SIZEOF_VOID_P EQUAL 4 OR diff --git a/README.md b/README.md index 58bac40f..01d478be 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Things fixed while transferring code: - Sniper rifle zoom states didn't work, m_pPlayer->pev->fov needed to be equalized to m_pPlayer->m_iFOV. - VGUI used to hard-crash, partially fixed: CImageLables in vgui_OrdiControl that caused the crash were replaced with CommandButtons, skipTime added to keypad, OrdiMenu and OrdiControl in order to fix double mouse key presses, +1 added to radiomsg.cpp to fix the butts of the text messages, HUD health display didn't work due to Health Msg system receieving Battery-related data, fixed by manually re-coping a part of old code and paritioning it properly. - Also fixed .txt files and fonts not loading due to backslashes, VGUI folder name being written in capitals and such. -- Music not playing fixed by creating a GStreamer implementation. +- Music not playing fixed by creating Miniaudio (thanks @nekonomicon) and GStreamer implementations. - l2m3 has a green exploding tank, which has func_door's named tremble_1 and tremble_2, when activated they cause SegFault on any non GoldSource-compatible build. Don't know why yet. Fixed by replacing a multi-manager target with garbage names if the map name and targetname match, see triggers.cpp. - Tank used to have a weird sound (glock event playback) when primary attack is activated, fixed with m_iPlayerInTankExternal see hud_tank.cpp and hl_weapons.cpp. - IR gun didn't actually Infra-Red anything, fixed by transferring changes to StudioModelRenderer.cpp. @@ -78,25 +78,33 @@ systems - you're more than welcome to do so! mkdir build cd build - cmake ../ -DUSE_VGUI=1 -DUSE_GSTREAMER=1 + cmake ../ -DUSE_VGUI=1 -DUSE_MINIAUDIO=1 make -On Debian, the following is necessary to: +Must be built with -DUSE_VGUI=1 to work properly, as this mod makes heavy use of true-VGUI, thus update the modules when clonning. + +To be able to hear music during gameplay, on the following three is necessary: +-DUSE_MINIAUDIO=1 (this is the smallest and most compatible implementation as of now), +-DUSE_GSTREAMER=1 (and have appropriate architechture (i386) gstreamer-1.0 and dev packages installed), or, +-DUSE_FMOD=1 (untested, on Windows and will require fmod headers v 3.6.1 if you can still get them somewhere). + +If using MiniAudio, make sure the submodules are updated. +As mentioned above, you have to do it anyway to get the VGUI headers. + +If GStreamer is preferred, on Debian, the following is necessary to: sudo apt install libgstreamer1.0:i386 #to play with music (also install plugins) - sudo apt install libgstreamer1.0-dev:i386 #to compile with music (-DUSE_GSTREAMER=1) + sudo apt install libgstreamer1.0-dev:i386 #to compile with music -Also added -DUSE_FMOD option for cmake and tried my best to prevent it being used in Linux (uses windows.h include). +So far GStreamer should only compile on Linux, as I haven't tested it (or linking it) on any other system. +Also, dlls/CMakeLists.txt must have a system-appropriate path to i386 version of GStreamer headers. +See set for ```ENV{PKG_CONFIG_PATH}```. + +The FMod option can be used on Windows instead (uses windows.h include), +but requires and old and outdated FMod implementation v 3.6.1. Not recommended. The following will likely be necessary to compile a gold-source compatible (old xash, e.t.c) binaries: sudo apt install libsdl2-dev:i386 (but this wants to install a ton of i386 dev packages) - -Must be built with -DUSE_VGUI=1 at least to work properly (thus, update the modules when clonning). -Must be built with either -DUSE_FMOD=1 (untested, on Windows and will require fmod headers v 3.6.1 if you can still get them somewhere), -or -DUSE_GSTREAMER=1 (and have appropriate architechture (i386) gstreamer-1.0 and dev packages installed) to be able to play with music. -So far GStreamer should only compile on Linux, as I haven't tested it (or linking it) on any other system. -Also, dlls/CMakeLists.txt must have a system-appropriate path to i386 version of GStreamer headers. -See set for ```ENV{PKG_CONFIG_PATH}```. \ No newline at end of file diff --git a/dlls/CMakeLists.txt b/dlls/CMakeLists.txt index 2e4f8e2e..84f15a72 100644 --- a/dlls/CMakeLists.txt +++ b/dlls/CMakeLists.txt @@ -41,6 +41,10 @@ if (USE_GSTREAMER AND (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")) add_definitions(-DUSE_GSTREAMER) endif() +if (USE_MINIAUDIO) + add_definitions(-DUSE_MINIAUDIO) +endif() + if (USE_FMOD AND (WIN32 OR NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Linux"))) add_definitions(-DUSE_FMOD) endif() diff --git a/dlls/music.cpp b/dlls/music.cpp index 7ca84ff9..12868736 100644 --- a/dlls/music.cpp +++ b/dlls/music.cpp @@ -18,6 +18,8 @@ This code is a placeholder for systems that support neither gstreamer nor fmod. #ifdef USE_GSTREAMER #include "musicgstreamer.cpp" +#elif defined(USE_MINIAUDIO) +#include "musicminiaudio.cpp" #elif defined(USE_FMOD) #include "musicfmod.cpp" #else diff --git a/dlls/musicminiaudio.cpp b/dlls/musicminiaudio.cpp new file mode 100644 index 00000000..5194d5c6 --- /dev/null +++ b/dlls/musicminiaudio.cpp @@ -0,0 +1,495 @@ +//------------------------------------------------------------- +//------------------------------------------------------------- +//- +//- musicminiaudio.cpp +//- +//------------------------------------------------------------- +//------------------------------------------------------------- +//- by Roy at suggestion by nekonomicon, based on code by JujU +//------------------------------------------------------------- +//- mp3 player code for HL mod +//------------------------------------------------------------- +//- +//- compatible with version 0.11.9 of Miniaudio +//- https://github.com/mackron/miniaudio +//- +//------------------------------------------------------------- + +/* +Don't forget to update the miniaudio submodule. + +Miniaudio 0.11.9 or better required. + +Tested on Debian. + +For playlist format see the bottom of the file. +*/ + + + +//--------------------------------------------------------- +// inclusions + +#include "extdll.h" +#include "util.h" +#include "cbase.h" + +#include "musicminiaudio.h" + +//These are just initial ones. If the actual track has different ones, they will be re-applied during Play(). +#define SAMPLE_FORMAT ma_format_f32 +#define CHANNEL_COUNT 2 +#define SAMPLE_RATE 48000 + +CMusic g_MusicPlayer; +void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); + +//--------------------------------------------------------- +// initialisation + +void CMusic :: Init ( void ) +{ + + if( m_bInit == TRUE ){ + return; //Do not re-init. + } + + deviceConfig = ma_device_config_init(ma_device_type_playback); + deviceConfig.playback.format = SAMPLE_FORMAT; + deviceConfig.playback.channels = CHANNEL_COUNT; + deviceConfig.sampleRate = SAMPLE_RATE; + deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song + deviceConfig.pUserData = NULL; + + if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { + ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); + return; + } + + m_bInit = TRUE; +} + + + + +//--------------------------------------------------------- +// Callback being called during playback + +void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) +{ + if(g_MusicPlayer.m_IsPlaying == FALSE){ + return; //We are paused or stopped, let's exit now. + } + + ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder; + if (pDecoder == NULL) { + return; + } + + if(frameCount<=0) return; + + ma_uint64 framesRead; + + ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead); + if(framesRead < frameCount) //This happens when the song ends. + g_MusicPlayer.songEnd(); + + (void)pInput; +} + +//--------------------------------------------------------- +// playing an audio file + + +void CMusic :: OpenFile ( const char *filename, int repeat ) +{ + audiofile_t *p = NULL; + p = new audiofile_t; + + sprintf ( p->name, filename ); + p->repeat = repeat; + p->next = m_pTrack; + + m_pTrack = p; +} + + + +//--------------------------------------------------------- +// play a list of audio files + + +void CMusic :: OpenList ( const char *filename ) +{ + + // open text file + + FILE *myfile = fopen ( filename, "r" ); + + if ( myfile == NULL ) + { + ALERT ( at_console, "MUSICPLAYER : impossible to load %s\n", filename ); + return; + } + + // saving songs to the list + + int total = 0; + + if ( fscanf ( myfile, "%i", &total ) != EOF ) + { + for ( int i=0; inext == NULL ) + break; + else + p = p->next; + } + + if ( p == NULL ) + { + ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); + return; + } + + // decrease repeat count + + p->repeat --; + + // removal of songs whose repeats ran off + + if ( p->repeat < 1 ) + { + if ( g_MusicPlayer.m_pTrack == p ) + { + delete g_MusicPlayer.m_pTrack; + g_MusicPlayer.m_pTrack = NULL; + } + else + { + audiofile_t *q = NULL; + q = g_MusicPlayer.m_pTrack; + + while ( q->next != p ) + q = q->next; + + delete q->next; + q->next = NULL; + } + } + + // close player if list is empty + + if ( g_MusicPlayer.m_pTrack == NULL ) + { + g_MusicPlayer.Reset(); + } + + // next track start + + else + { + g_MusicPlayer.Play(); + } + + return; +} + + +//--------------------------------------------------------- +// initiate playback + + +void CMusic :: Play ( void ) +{ + if ( m_IsPlaying == TRUE ) + return; + + if ( m_bInit == FALSE ) + { + Init (); + + if ( m_bInit == FALSE ) + { + ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); + return; + } + } + + // search for the first song in the list + + audiofile_t *p = NULL; + p = m_pTrack; + + while ( p != NULL ) + { + if ( p->next == NULL ) + break; + else + p = p->next; + } + + if ( p == NULL ) + { + ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); + return; + } + + //Stop playback + m_IsPlaying = FALSE; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + + // loading file + char payload [512]; + sprintf(payload, "%s", p->name); + + ALERT ( at_console, "MUSICPLAYER : Opening file %s.\n", payload ); + + result = ma_decoder_init_file(payload, NULL, &decoder); + if (result != MA_SUCCESS) { + ALERT ( at_console, "MUSICPLAYER : %s : can not load file\n", p->name ); + return; + } + + //If the new track has different properties to the previous one. + if( + deviceConfig.playback.format != decoder.outputFormat || + deviceConfig.playback.channels != decoder.outputChannels || + deviceConfig.sampleRate != decoder.outputSampleRate + ){ + deviceConfig.playback.format = decoder.outputFormat; //Change device settings + deviceConfig.playback.channels = decoder.outputChannels; + deviceConfig.sampleRate = decoder.outputSampleRate; + + ALERT ( at_console, "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate); + + //Now we need to recreate the device to apply. + ma_device_uninit(&device); //This is crucial, failing to do this results in segFault. + if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config. + ALERT ( at_console, "MUSICPLAYER : Failed to change playback device configuration.\n" ); + g_MusicPlayer.m_bInit = FALSE; //We have been deinitialized. This is NOT ideal. + return; + }else + ALERT ( at_console, "MUSICPLAYER : New configuration applied successfully.\n"); + } + + // playback + if (ma_device_start(&device) != MA_SUCCESS) { + ALERT ( at_console, "MUSICPLAYER : Failed to start playback device.\n" ); + m_IsPlaying = FALSE; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + return; + }else{ + m_IsPlaying = TRUE; + } + + return; +} + + +void CMusic :: Stop ( void ) +{ + if ( m_IsPlaying == TRUE ) + { + m_IsPlaying = FALSE; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + } +} + + +void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming. +{ + //Reset the player. + if ( m_bInit == TRUE ) + ALERT ( at_console, "MUSICPLAYER : Player reset.\n" ); + + Stop(); + + audiofile_t *p = NULL; + + while ( m_pTrack != NULL ) + { + p = m_pTrack; + m_pTrack = p->next; + delete p; + } +} + +void CMusic :: Terminate ( void ) //Cleanup and dereference +{ + ALERT ( at_console, "MUSICPLAYER : Terminating and unloading.\n" ); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); + g_MusicPlayer.m_bInit = FALSE; +} + + +//--------------------------------------------------------- +// entity class + + + +class CTriggerMusic : public CPointEntity +{ +public: + + void Spawn ( void ); + + void KeyValue ( KeyValueData *pkvd ); + void Use ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); + + + virtual int Save ( CSave &save ); + virtual int Restore ( CRestore &restore ); + + + static TYPEDESCRIPTION m_SaveData[]; + + + string_t m_iFileName; // file path + int m_iFileType; // text file (list) or audio file + +}; + +LINK_ENTITY_TO_CLASS( trigger_music, CTriggerMusic ); + + + +TYPEDESCRIPTION CTriggerMusic::m_SaveData[] = +{ + DEFINE_FIELD( CTriggerMusic, m_iFileType, FIELD_INTEGER ), + DEFINE_FIELD( CTriggerMusic, m_iFileName, FIELD_STRING ), +}; + +IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); + + + +void CTriggerMusic :: Spawn( void ) +{ + pev->solid = SOLID_NOT; + pev->effects = EF_NODRAW; + +} + +void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) +{ + if (FStrEq(pkvd->szKeyName, "filetype")) + { + m_iFileType = atoi(pkvd->szValue); + pkvd->fHandled = TRUE; + } + else if (FStrEq(pkvd->szKeyName, "filename")) + { + m_iFileName = ALLOC_STRING(pkvd->szValue); + pkvd->fHandled = TRUE; + } + else + CPointEntity::KeyValue( pkvd ); +} + +void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) +{ + if ( g_MusicPlayer.m_IsPlaying == TRUE ) + return; + + if ( m_iFileType == MUSIC_AUDIO_FILE ) + { + g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 ); + } + else + { + g_MusicPlayer.OpenList ( STRING(m_iFileName) ); + } + + g_MusicPlayer.Play(); +} + + + + + + + +/* +code + + +@PointClass base( Targetname ) = trigger_music : "Trigger Music" +[ + filetype(choices) : "File type" : 0 = + [ + 0: "File list (*.txt)" + 1: "File wav mp2 mp3 ogg raw" + ] + filename(string) : "Name (mod/folder/file.extension)" +] + +*/ + + +/*//--------------- +Playlist contents + +example: music01.txt file: + +// + +3 + +monmod/sound/mp3/music01_debut.mp3 1 +monmod/sound/mp3/music01_boucle.mp3 3 +monmod/sound/mp3/music01_fin.mp3 1 + + +// + +composition : + - total number of tracks + - path of the first music file + - times to repeat that file + - path of the second + - etc ... + +*///--------------- diff --git a/dlls/musicminiaudio.h b/dlls/musicminiaudio.h new file mode 100644 index 00000000..7bf49431 --- /dev/null +++ b/dlls/musicminiaudio.h @@ -0,0 +1,83 @@ +//------------------------------------------------------------- +//------------------------------------------------------------- +//- +//- musicminiaudio.h +//- +//------------------------------------------------------------- +//------------------------------------------------------------- +//- by Roy at suggestion by nekonomicon, based on code by JujU +//------------------------------------------------------------- +//- mp3 player code for HL mod +//------------------------------------------------------------- +//- +//- compatible with version 0.11.9 of Miniaudio +//- https://github.com/mackron/miniaudio +//- +//------------------------------------------------------------- + +#ifndef MUSIC_H +#define MUSIC_H + +#define MINIAUDIO_IMPLEMENTATION +#include "../miniaudio/miniaudio.h" + +//--------------------------------------------------------- +// defines + +#define MUSIC_AUDIO_FILE 1 +#define MUSIC_LIST_FILE 0 + +//--------------------------------------------------------- +// audio file structure + +struct audiofile_t +{ + char name [128]; + int repeat; + audiofile_t *next; +}; + +//--------------------------------------------------------- +// reader class + + +class CMusic +{ +public: + + // reading functions + + void OpenFile ( const char *filename, int repeat ); // open a single file + void OpenList ( const char *filename ); // opening a text file containing the files + + void Init ( void ); // initialization + + void Play ( void ); // playback + void Stop ( void ); // stop + void Reset ( void ); // pause and switch to next track + void Terminate ( void ); // clean-up during termination + + // variables + + BOOL m_IsPlaying; // monitors whether the music is played, used to pause the music + BOOL m_bInit; // checks if the player is initialized + + audiofile_t *m_pTrack; // playlist items + + // constructor / destructor + + CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); }; + ~CMusic () { Terminate(); }; + + // object instances + + ma_result result; + ma_decoder decoder; + ma_device_config deviceConfig; + ma_device device; + + void songEnd(); +}; + +extern CMusic g_MusicPlayer; +#endif // MUSIC_H diff --git a/miniaudio b/miniaudio new file mode 160000 index 00000000..4d813cfe --- /dev/null +++ b/miniaudio @@ -0,0 +1 @@ +Subproject commit 4d813cfe23c28db165cce6785419fee9d2399766 From 418ae2d41d8ee4a402f597c0db038bc6bab246a2 Mon Sep 17 00:00:00 2001 From: Roy Shapiro <70241434+RoyShapiro@users.noreply.github.com> Date: Tue, 12 Jul 2022 02:01:02 +0300 Subject: [PATCH 2/4] HL:Invasion Update Miniaudio implementation and remove GStreamer / FMod --- CMakeLists.txt | 4 +- README.md | 27 +- dlls/CMakeLists.txt | 50 +- dlls/fmod.h | 1091 --------------------------------------- dlls/fmod_errors.h | 32 -- dlls/music.cpp | 464 +++++++++++++++-- dlls/music.h | 74 +-- dlls/musicfmod.cpp | 446 ---------------- dlls/musicfmod.h | 94 ---- dlls/musicgstreamer.cpp | 511 ------------------ dlls/musicgstreamer.h | 85 --- dlls/musicminiaudio.cpp | 495 ------------------ dlls/musicminiaudio.h | 83 --- 13 files changed, 479 insertions(+), 2977 deletions(-) delete mode 100644 dlls/fmod.h delete mode 100644 dlls/fmod_errors.h delete mode 100644 dlls/musicfmod.cpp delete mode 100644 dlls/musicfmod.h delete mode 100644 dlls/musicgstreamer.cpp delete mode 100644 dlls/musicgstreamer.h delete mode 100644 dlls/musicminiaudio.cpp delete mode 100644 dlls/musicminiaudio.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 589bd644..cef7c1ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,9 +48,7 @@ option(USE_VOICEMGR "Enable VOICE MANAGER." OFF) option(BUILD_CLIENT "Build client dll" ON) option(BUILD_SERVER "Build server dll" ON) option(GOLDSOURCE_SUPPORT "Build goldsource compatible client library" OFF) -option(USE_GSTREAMER "Enable GStreamer." OFF) -option(USE_MINIAUDIO "Enable Miniaudio." OFF) -option(USE_FMOD "Enable FMOD." OFF) +option(DISABLE_MINIAUDIO "Disable Miniaudio." OFF) if (CMAKE_SIZEOF_VOID_P EQUAL 4 OR ((WIN32 OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") diff --git a/README.md b/README.md index 01d478be..e400249e 100644 --- a/README.md +++ b/README.md @@ -78,30 +78,15 @@ systems - you're more than welcome to do so! mkdir build cd build - cmake ../ -DUSE_VGUI=1 -DUSE_MINIAUDIO=1 + cmake ../ -DUSE_VGUI=1 make -Must be built with -DUSE_VGUI=1 to work properly, as this mod makes heavy use of true-VGUI, thus update the modules when clonning. +Must be built with -DUSE_VGUI=1 to work properly, as this mod makes heavy use of true-VGUI, +also it builds with miniaudio by default, thus update the modules when clonning. -To be able to hear music during gameplay, on the following three is necessary: --DUSE_MINIAUDIO=1 (this is the smallest and most compatible implementation as of now), --DUSE_GSTREAMER=1 (and have appropriate architechture (i386) gstreamer-1.0 and dev packages installed), or, --DUSE_FMOD=1 (untested, on Windows and will require fmod headers v 3.6.1 if you can still get them somewhere). - -If using MiniAudio, make sure the submodules are updated. -As mentioned above, you have to do it anyway to get the VGUI headers. - -If GStreamer is preferred, on Debian, the following is necessary to: - - sudo apt install libgstreamer1.0:i386 #to play with music (also install plugins) - sudo apt install libgstreamer1.0-dev:i386 #to compile with music - -So far GStreamer should only compile on Linux, as I haven't tested it (or linking it) on any other system. -Also, dlls/CMakeLists.txt must have a system-appropriate path to i386 version of GStreamer headers. -See set for ```ENV{PKG_CONFIG_PATH}```. - -The FMod option can be used on Windows instead (uses windows.h include), -but requires and old and outdated FMod implementation v 3.6.1. Not recommended. +A miniaudio music player implementation is used to allow music during gameplay, +if it can not be used in your environment, it can be disabled with the use of: +-DDISABLE_MINIAUDIO=1 cmake option. The following will likely be necessary to compile a gold-source compatible (old xash, e.t.c) binaries: diff --git a/dlls/CMakeLists.txt b/dlls/CMakeLists.txt index 84f15a72..7fc609e6 100644 --- a/dlls/CMakeLists.txt +++ b/dlls/CMakeLists.txt @@ -37,16 +37,8 @@ else() add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) endif() -if (USE_GSTREAMER AND (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")) - add_definitions(-DUSE_GSTREAMER) -endif() - -if (USE_MINIAUDIO) - add_definitions(-DUSE_MINIAUDIO) -endif() - -if (USE_FMOD AND (WIN32 OR NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Linux"))) - add_definitions(-DUSE_FMOD) +if (DISABLE_MINIAUDIO) + add_definitions(-DDISABLE_MINIAUDIO) endif() set (SVDLL_SOURCES @@ -170,40 +162,7 @@ set (SVDLL_SOURCES zombie.cpp ) -if (USE_GSTREAMER AND (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")) - #if we're using gstreamer music - if (NOT 64BIT) - set(ENV{PKG_CONFIG_PATH} "/usr/lib/i386-linux-gnu/pkgconfig") - endif() - find_package(PkgConfig REQUIRED) - pkg_check_modules(GLIB REQUIRED glib-2.0) - - set(GSTREAMER_MINIMUM_VERSION 1.0.5) - pkg_check_modules(GST1_TEST gstreamer-1.0) - if ( GST1_TEST_FOUND AND NOT ${GST1_TEST_VERSION} VERSION_LESS ${GSTREAMER_MINIMUM_VERSION} ) - pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) - add_definitions(-DGST_API_VERSION_1=1) - endif() - - link_directories( - ${GSTREAMER_LIBRARY_DIRS} - ${GLIB_LIBRARY_DIRS} - ) - set(GST_LIBRARIES - ${GSTREAMER_LIBRARIES} - ${GSTREAMER-APP_LIBRARIES} - ${GSTREAMER-AUDIO_LIBRARIES} - ${GSTREAMER-PBUTILS_LIBRARIES} - ${GSTREAMER-FFT_LIBRARIES} - - pthread - ${GLIB_LIBRARIES} - ${GLIB_GIO_LIBRARIES} - ${GLIB_GOBJECT_LIBRARIES} - ) -endif() - -include_directories (. wpn_shared ../common ../engine ../pm_shared ../game_shared ../public ${GLIB_INCLUDE_DIRS} ${GSTREAMER_INCLUDE_DIRS}) +include_directories (. wpn_shared ../common ../engine ../pm_shared ../game_shared ../public) if(MSVC) set(SVDLL_SOURCES @@ -220,9 +179,6 @@ else() endif() add_library (${SVDLL_LIBRARY} SHARED ${SVDLL_SOURCES}) -if (USE_GSTREAMER AND (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")) #More gstreamer linkage stuff - target_link_libraries(${SVDLL_LIBRARY} ${GST_LIBRARIES}) -endif() set_target_properties (${SVDLL_LIBRARY} PROPERTIES POSITION_INDEPENDENT_CODE 1) diff --git a/dlls/fmod.h b/dlls/fmod.h deleted file mode 100644 index ca3a77b2..00000000 --- a/dlls/fmod.h +++ /dev/null @@ -1,1091 +0,0 @@ -/* ========================================================================================== */ -/* FMOD Main header file. Copyright (c), Firelight Technologies Pty, Ltd 1999-2002. */ -/* ========================================================================================== */ - -#ifndef _FMOD_H_ -#define _FMOD_H_ - -/* ========================================================================================== */ -/* DEFINITIONS */ -/* ========================================================================================== */ - -#if (!defined(WIN32) && !defined(__WIN32__) && !defined(_WIN32_WCE)) || (defined(__GNUC__) && defined(WIN32)) - #ifndef _cdecl - #define _cdecl - #endif - #ifndef _stdcall - #define _stdcall - #endif -#endif - -#define F_API _stdcall -#define F_CALLBACKAPI _cdecl - -#ifdef DLL_EXPORTS - #define DLL_API __declspec(dllexport) -#else - #if defined(__LCC__) || defined(__MINGW32__) || defined(__CYGWIN32__) - #define DLL_API F_API - #else - #define DLL_API - #endif /* __LCC__ || __MINGW32__ || __CYGWIN32__ */ -#endif /* DLL_EXPORTS */ - -#define FMOD_VERSION 3.61f - -/* - FMOD defined types -*/ -typedef struct FSOUND_SAMPLE FSOUND_SAMPLE; -typedef struct FSOUND_STREAM FSOUND_STREAM; -typedef struct FSOUND_DSPUNIT FSOUND_DSPUNIT; -typedef struct FMUSIC_MODULE FMUSIC_MODULE; - -/* - Callback types -*/ -typedef void * (F_CALLBACKAPI *FSOUND_DSPCALLBACK) (void *originalbuffer, void *newbuffer, int length, int param); -typedef signed char (F_CALLBACKAPI *FSOUND_STREAMCALLBACK) (FSOUND_STREAM *stream, void *buff, int len, int param); -typedef void (F_CALLBACKAPI *FMUSIC_CALLBACK) (FMUSIC_MODULE *mod, unsigned char param); - -typedef unsigned int(F_CALLBACKAPI *FSOUND_OPENCALLBACK) (const char *name); -typedef void (F_CALLBACKAPI *FSOUND_CLOSECALLBACK) (unsigned int handle); -typedef int (F_CALLBACKAPI *FSOUND_READCALLBACK) (void *buffer, int size, unsigned int handle); -typedef int (F_CALLBACKAPI *FSOUND_SEEKCALLBACK) (unsigned int handle, int pos, signed char mode); -typedef int (F_CALLBACKAPI *FSOUND_TELLCALLBACK) (unsigned int handle); - -typedef void * (F_CALLBACKAPI *FSOUND_ALLOCCALLBACK) (unsigned int size); -typedef void * (F_CALLBACKAPI *FSOUND_REALLOCCALLBACK)(void *ptr, unsigned int size); -typedef void (F_CALLBACKAPI *FSOUND_FREECALLBACK) (void *ptr); - - -/* -[ENUM] -[ - [DESCRIPTION] - On failure of commands in FMOD, use FSOUND_GetError to attain what happened. - - [SEE_ALSO] - FSOUND_GetError -] -*/ -enum FMOD_ERRORS -{ - FMOD_ERR_NONE, /* No errors */ - FMOD_ERR_BUSY, /* Cannot call this command after FSOUND_Init. Call FSOUND_Close first. */ - FMOD_ERR_UNINITIALIZED, /* This command failed because FSOUND_Init or FSOUND_SetOutput was not called */ - FMOD_ERR_INIT, /* Error initializing output device. */ - FMOD_ERR_ALLOCATED, /* Error initializing output device, but more specifically, the output device is already in use and cannot be reused. */ - FMOD_ERR_PLAY, /* Playing the sound failed. */ - FMOD_ERR_OUTPUT_FORMAT, /* Soundcard does not support the features needed for this soundsystem (16bit stereo output) */ - FMOD_ERR_COOPERATIVELEVEL, /* Error setting cooperative level for hardware. */ - FMOD_ERR_CREATEBUFFER, /* Error creating hardware sound buffer. */ - FMOD_ERR_FILE_NOTFOUND, /* File not found */ - FMOD_ERR_FILE_FORMAT, /* Unknown file format */ - FMOD_ERR_FILE_BAD, /* Error loading file */ - FMOD_ERR_MEMORY, /* Not enough memory or resources */ - FMOD_ERR_VERSION, /* The version number of this file format is not supported */ - FMOD_ERR_INVALID_PARAM, /* An invalid parameter was passed to this function */ - FMOD_ERR_NO_EAX, /* Tried to use an EAX command on a non EAX enabled channel or output. */ - FMOD_ERR_CHANNEL_ALLOC, /* Failed to allocate a new channel */ - FMOD_ERR_RECORD, /* Recording is not supported on this machine */ - FMOD_ERR_MEDIAPLAYER, /* Windows Media Player not installed so cannot play wma or use internet streaming. */ - FMOD_ERR_CDDEVICE /* An error occured trying to open the specified CD device */ -}; - - -/* -[ENUM] -[ - [DESCRIPTION] - These output types are used with FSOUND_SetOutput, to choose which output driver to use. - - FSOUND_OUTPUT_DSOUND will not support hardware 3d acceleration if the sound card driver - does not support DirectX 6 Voice Manager Extensions. - - FSOUND_OUTPUT_WINMM is recommended for NT and CE. - - [SEE_ALSO] - FSOUND_SetOutput - FSOUND_GetOutput -] -*/ -enum FSOUND_OUTPUTTYPES -{ - FSOUND_OUTPUT_NOSOUND, /* NoSound driver, all calls to this succeed but do nothing. */ - FSOUND_OUTPUT_WINMM, /* Windows Multimedia driver. */ - FSOUND_OUTPUT_DSOUND, /* DirectSound driver. You need this to get EAX2 or EAX3 support, or FX api support. */ - FSOUND_OUTPUT_A3D, /* A3D driver. */ - - FSOUND_OUTPUT_OSS, /* Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers. */ - FSOUND_OUTPUT_ESD, /* Linux/Unix ESD (Enlightment Sound Daemon) driver. */ - FSOUND_OUTPUT_ALSA, /* Linux Alsa driver. */ - - FSOUND_OUTPUT_ASIO, /* Low latency ASIO driver */ - FSOUND_OUTPUT_XBOX, /* Xbox driver */ - FSOUND_OUTPUT_PS2, /* PlayStation 2 driver */ - FSOUND_OUTPUT_MAC, /* Mac SoundManager driver */ - FSOUND_OUTPUT_GC, /* Gamecube driver */ - - FSOUND_OUTPUT_NOSOUND_NONREALTIME /* This is the same as nosound, but the sound generation is driven by FSOUND_Update */ -}; - - -/* -[ENUM] -[ - [DESCRIPTION] - These mixer types are used with FSOUND_SetMixer, to choose which mixer to use, or to act - upon for other reasons using FSOUND_GetMixer. - It is not nescessary to set the mixer. FMOD will autodetect the best mixer for you. - - [SEE_ALSO] - FSOUND_SetMixer - FSOUND_GetMixer -] -*/ -enum FSOUND_MIXERTYPES -{ - FSOUND_MIXER_AUTODETECT, /* CE/PS2/GC Only - Non interpolating/low quality mixer. */ - FSOUND_MIXER_BLENDMODE, /* Removed / obsolete. */ - FSOUND_MIXER_MMXP5, /* Removed / obsolete. */ - FSOUND_MIXER_MMXP6, /* Removed / obsolete. */ - - FSOUND_MIXER_QUALITY_AUTODETECT,/* All platforms - Autodetect the fastest quality mixer based on your cpu. */ - FSOUND_MIXER_QUALITY_FPU, /* Win32/Linux only - Interpolating/volume ramping FPU mixer. */ - FSOUND_MIXER_QUALITY_MMXP5, /* Win32/Linux only - Interpolating/volume ramping P5 MMX mixer. */ - FSOUND_MIXER_QUALITY_MMXP6, /* Win32/Linux only - Interpolating/volume ramping ppro+ MMX mixer. */ - - FSOUND_MIXER_MONO, /* CE/PS2/GC only - MONO non interpolating/low quality mixer. For speed*/ - FSOUND_MIXER_QUALITY_MONO, /* CE/PS2/GC only - MONO Interpolating mixer. For speed */ - - FSOUND_MIXER_MAX -}; - - -/* -[ENUM] -[ - [DESCRIPTION] - These definitions describe the type of song being played. - - [SEE_ALSO] - FMUSIC_GetType -] -*/ -enum FMUSIC_TYPES -{ - FMUSIC_TYPE_NONE, - FMUSIC_TYPE_MOD, /* Protracker / Fasttracker */ - FMUSIC_TYPE_S3M, /* ScreamTracker 3 */ - FMUSIC_TYPE_XM, /* FastTracker 2 */ - FMUSIC_TYPE_IT, /* Impulse Tracker. */ - FMUSIC_TYPE_MIDI /* MIDI file */ -}; - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_DSP_PRIORITIES - - [DESCRIPTION] - These default priorities are used by FMOD internal system DSP units. They describe the - position of the DSP chain, and the order of how audio processing is executed. - You can actually through the use of FSOUND_DSP_GetxxxUnit (where xxx is the name of the DSP - unit), disable or even change the priority of a DSP unit. - - [SEE_ALSO] - FSOUND_DSP_Create - FSOUND_DSP_SetPriority - FSOUND_DSP_GetSpectrum -] -*/ -#define FSOUND_DSP_DEFAULTPRIORITY_CLEARUNIT 0 /* DSP CLEAR unit - done first */ -#define FSOUND_DSP_DEFAULTPRIORITY_SFXUNIT 100 /* DSP SFX unit - done second */ -#define FSOUND_DSP_DEFAULTPRIORITY_MUSICUNIT 200 /* DSP MUSIC unit - done third */ -#define FSOUND_DSP_DEFAULTPRIORITY_USER 300 /* User priority, use this as reference */ -#define FSOUND_DSP_DEFAULTPRIORITY_FFTUNIT 900 /* This reads data for FSOUND_DSP_GetSpectrum, so it comes after user units */ -#define FSOUND_DSP_DEFAULTPRIORITY_CLIPANDCOPYUNIT 1000 /* DSP CLIP AND COPY unit - last */ -/* [DEFINE_END] */ - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_CAPS - - [DESCRIPTION] - Driver description bitfields. Use FSOUND_Driver_GetCaps to determine if a driver enumerated - has the settings you are after. The enumerated driver depends on the output mode, see - FSOUND_OUTPUTTYPES - - [SEE_ALSO] - FSOUND_GetDriverCaps - FSOUND_OUTPUTTYPES -] -*/ -#define FSOUND_CAPS_HARDWARE 0x1 /* This driver supports hardware accelerated 3d sound. */ -#define FSOUND_CAPS_EAX2 0x2 /* This driver supports EAX 2 reverb */ -#define FSOUND_CAPS_EAX3 0x10 /* This driver supports EAX 3 reverb */ -/* [DEFINE_END] */ - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_MODES - - [DESCRIPTION] - Sample description bitfields, OR them together for loading and describing samples. - NOTE. If the file format being loaded already has a defined format, such as WAV or MP3, then - trying to override the pre-defined format with a new set of format flags will not work. For - example, an 8 bit WAV file will not load as 16bit if you specify FSOUND_16BITS. It will just - ignore the flag and go ahead loading it as 8bits. For these type of formats the only flags - you can specify that will really alter the behaviour of how it is loaded, are the following. - - FSOUND_LOOP_OFF - FSOUND_LOOP_NORMAL - FSOUND_LOOP_BIDI - FSOUND_HW3D - FSOUND_2D - FSOUND_STREAMABLE - FSOUND_LOADMEMORY - FSOUND_LOADRAW - FSOUND_MPEGACCURATE - - See flag descriptions for what these do. -] -*/ -#define FSOUND_LOOP_OFF 0x00000001 /* For non looping samples. */ -#define FSOUND_LOOP_NORMAL 0x00000002 /* For forward looping samples. */ -#define FSOUND_LOOP_BIDI 0x00000004 /* For bidirectional looping samples. (no effect if in hardware). */ -#define FSOUND_8BITS 0x00000008 /* For 8 bit samples. */ -#define FSOUND_16BITS 0x00000010 /* For 16 bit samples. */ -#define FSOUND_MONO 0x00000020 /* For mono samples. */ -#define FSOUND_STEREO 0x00000040 /* For stereo samples. */ -#define FSOUND_UNSIGNED 0x00000080 /* For user created source data containing unsigned samples. */ -#define FSOUND_SIGNED 0x00000100 /* For user created source data containing signed data. */ -#define FSOUND_DELTA 0x00000200 /* For user created source data stored as delta values. */ -#define FSOUND_IT214 0x00000400 /* For user created source data stored using IT214 compression. */ -#define FSOUND_IT215 0x00000800 /* For user created source data stored using IT215 compression. */ -#define FSOUND_HW3D 0x00001000 /* Attempts to make samples use 3d hardware acceleration. (if the card supports it) */ -#define FSOUND_2D 0x00002000 /* Tells software (not hardware) based sample not to be included in 3d processing. */ -#define FSOUND_STREAMABLE 0x00004000 /* For a streamimg sound where you feed the data to it. */ -#define FSOUND_LOADMEMORY 0x00008000 /* "name" will be interpreted as a pointer to data for streaming and samples. */ -#define FSOUND_LOADRAW 0x00010000 /* Will ignore file format and treat as raw pcm. */ -#define FSOUND_MPEGACCURATE 0x00020000 /* For FSOUND_Stream_OpenFile - for accurate FSOUND_Stream_GetLengthMs/FSOUND_Stream_SetTime. WARNING, see FSOUND_Stream_OpenFile for inital opening time performance issues. */ -#define FSOUND_FORCEMONO 0x00040000 /* For forcing stereo streams and samples to be mono - needed if using FSOUND_HW3D and stereo data - incurs a small speed hit for streams */ -#define FSOUND_HW2D 0x00080000 /* 2D hardware sounds. allows hardware specific effects */ -#define FSOUND_ENABLEFX 0x00100000 /* Allows DX8 FX to be played back on a sound. Requires DirectX 8 - Note these sounds cannot be played more than once, be 8 bit, be less than a certain size, or have a changing frequency */ -#define FSOUND_MPEGHALFRATE 0x00200000 /* For FMODCE only - decodes mpeg streams using a lower quality decode, but faster execution */ -#define FSOUND_XADPCM 0x00400000 /* For XBOX only - Contents are compressed as XADPCM */ -#define FSOUND_VAG 0x00800000 /* For PS2 only - Contents are compressed as Sony VAG format */ -#define FSOUND_NONBLOCKING 0x01000000 /* For FSOUND_Stream_OpenFile - Causes stream to open in the background and not block the foreground app - stream functions only work when ready. Poll any stream function determine when it IS ready. */ -#define FSOUND_GCADPCM 0x02000000 /* For Gamecube only - Contents are compressed as Gamecube DSP-ADPCM format */ - -#define FSOUND_NORMAL (FSOUND_16BITS | FSOUND_SIGNED | FSOUND_MONO) -/* [DEFINE_END] */ - - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_CDPLAYMODES - - [DESCRIPTION] - Playback method for a CD Audio track, with FSOUND_CD_SetPlayMode - - [SEE_ALSO] - FSOUND_CD_SetPlayMode - FSOUND_CD_Play -] -*/ -#define FSOUND_CD_PLAYCONTINUOUS 0 /* Starts from the current track and plays to end of CD. */ -#define FSOUND_CD_PLAYONCE 1 /* Plays the specified track then stops. */ -#define FSOUND_CD_PLAYLOOPED 2 /* Plays the specified track looped, forever until stopped manually. */ -#define FSOUND_CD_PLAYRANDOM 3 /* Plays tracks in random order */ -/* [DEFINE_END] */ - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_MISC_VALUES - - [DESCRIPTION] - Miscellaneous values for FMOD functions. - - [SEE_ALSO] - FSOUND_PlaySound - FSOUND_PlaySoundEx - FSOUND_Sample_Alloc - FSOUND_Sample_Load - FSOUND_SetPan -] -*/ -#define FSOUND_FREE -1 /* value to play on any free channel, or to allocate a sample in a free sample slot. */ -#define FSOUND_UNMANAGED -2 /* value to allocate a sample that is NOT managed by FSOUND or placed in a sample slot. */ -#define FSOUND_ALL -3 /* for a channel index , this flag will affect ALL channels available! Not supported by every function. */ -#define FSOUND_STEREOPAN -1 /* value for FSOUND_SetPan so that stereo sounds are not played at half volume. See FSOUND_SetPan for more on this. */ -#define FSOUND_SYSTEMCHANNEL -1000 /* special 'channel' ID for all channel based functions that want to alter the global FSOUND software mixing output channel */ -#define FSOUND_SYSTEMSAMPLE -1000 /* special 'sample' ID for all sample based functions that want to alter the global FSOUND software mixing output sample */ - -/* [DEFINE_END] */ - - -/* -[STRUCTURE] -[ - [DESCRIPTION] - Structure defining a reverb environment. - For more indepth descriptions of the reverb properties under win32, please see the EAX2 and EAX3 - documentation at http://developer.creative.com/ under the 'downloads' section. - If they do not have the EAX3 documentation, then most information can be attained from - the EAX2 documentation, as EAX3 only adds some more parameters and functionality on top of - EAX2. - Note the default reverb properties are the same as the FSOUND_PRESET_GENERIC preset. - Note that integer values that typically range from -10,000 to 1000 are represented in - decibels, and are of a logarithmic scale, not linear, wheras float values are typically linear. - PORTABILITY: Each member has the platform it supports in braces ie (win32/xbox). - Some reverb parameters are only supported in win32 and some only on xbox. If all parameters are set then - the reverb should product a similar effect on either platform. - Only Win32 supports the reverb api. - - The numerical values listed below are the maximum, minimum and default values for each variable respectively. - - [SEE_ALSO] - FSOUND_Reverb_SetProperties - FSOUND_Reverb_GetProperties - FSOUND_REVERB_PRESETS - FSOUND_REVERB_FLAGS -] -*/ -typedef struct _FSOUND_REVERB_PROPERTIES /* MIN MAX DEFAULT DESCRIPTION */ -{ - unsigned int Environment; /* 0 , 25 , 0 , sets all listener properties (win32/ps2 only) */ - float EnvSize; /* 1.0 , 100.0 , 7.5 , environment size in meters (win32 only) */ - float EnvDiffusion; /* 0.0 , 1.0 , 1.0 , environment diffusion (win32/xbox) */ - int Room; /* -10000, 0 , -1000 , room effect level (at mid frequencies) (win32/xbox/ps2) */ - int RoomHF; /* -10000, 0 , -100 , relative room effect level at high frequencies (win32/xbox) */ - int RoomLF; /* -10000, 0 , 0 , relative room effect level at low frequencies (win32 only) */ - float DecayTime; /* 0.1 , 20.0 , 1.49 , reverberation decay time at mid frequencies (win32/xbox) */ - float DecayHFRatio; /* 0.1 , 2.0 , 0.83 , high-frequency to mid-frequency decay time ratio (win32/xbox) */ - float DecayLFRatio; /* 0.1 , 2.0 , 1.0 , low-frequency to mid-frequency decay time ratio (win32 only) */ - int Reflections; /* -10000, 1000 , -2602 , early reflections level relative to room effect (win32/xbox) */ - float ReflectionsDelay; /* 0.0 , 0.3 , 0.007 , initial reflection delay time (win32/xbox) */ - float ReflectionsPan[3]; /* , , [0,0,0], early reflections panning vector (win32 only) */ - int Reverb; /* -10000, 2000 , 200 , late reverberation level relative to room effect (win32/xbox) */ - float ReverbDelay; /* 0.0 , 0.1 , 0.011 , late reverberation delay time relative to initial reflection (win32/xbox) */ - float ReverbPan[3]; /* , , [0,0,0], late reverberation panning vector (win32 only) */ - float EchoTime; /* .075 , 0.25 , 0.25 , echo time (win32 only) */ - float EchoDepth; /* 0.0 , 1.0 , 0.0 , echo depth (win32 only) */ - float ModulationTime; /* 0.04 , 4.0 , 0.25 , modulation time (win32 only) */ - float ModulationDepth; /* 0.0 , 1.0 , 0.0 , modulation depth (win32 only) */ - float AirAbsorptionHF; /* -100 , 0.0 , -5.0 , change in level per meter at high frequencies (win32 only) */ - float HFReference; /* 1000.0, 20000 , 5000.0 , reference high frequency (hz) (win32/xbox) */ - float LFReference; /* 20.0 , 1000.0, 250.0 , reference low frequency (hz) (win32 only) */ - float RoomRolloffFactor; /* 0.0 , 10.0 , 0.0 , like FSOUND_3D_SetRolloffFactor but for room effect (win32/xbox) */ - float Diffusion; /* 0.0 , 100.0 , 100.0 , Value that controls the echo density in the late reverberation decay. (xbox only) */ - float Density; /* 0.0 , 100.0 , 100.0 , Value that controls the modal density in the late reverberation decay (xbox only) */ - unsigned int Flags; /* FSOUND_REVERB_FLAGS - modifies the behavior of above properties (win32 only) */ -} FSOUND_REVERB_PROPERTIES; - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_REVERB_FLAGS - - [DESCRIPTION] - Values for the Flags member of the FSOUND_REVERB_PROPERTIES structure. - - [SEE_ALSO] - FSOUND_REVERB_PROPERTIES -] -*/ -#define FSOUND_REVERB_FLAGS_DECAYTIMESCALE 0x00000001 /* 'EnvSize' affects reverberation decay time */ -#define FSOUND_REVERB_FLAGS_REFLECTIONSSCALE 0x00000002 /* 'EnvSize' affects reflection level */ -#define FSOUND_REVERB_FLAGS_REFLECTIONSDELAYSCALE 0x00000004 /* 'EnvSize' affects initial reflection delay time */ -#define FSOUND_REVERB_FLAGS_REVERBSCALE 0x00000008 /* 'EnvSize' affects reflections level */ -#define FSOUND_REVERB_FLAGS_REVERBDELAYSCALE 0x00000010 /* 'EnvSize' affects late reverberation delay time */ -#define FSOUND_REVERB_FLAGS_DECAYHFLIMIT 0x00000020 /* AirAbsorptionHF affects DecayHFRatio */ -#define FSOUND_REVERB_FLAGS_ECHOTIMESCALE 0x00000040 /* 'EnvSize' affects echo time */ -#define FSOUND_REVERB_FLAGS_MODULATIONTIMESCALE 0x00000080 /* 'EnvSize' affects modulation time */ -#define FSOUND_REVERB_FLAGS_CORE0 0x00000100 /* PS2 Only - Reverb is applied to CORE0 (hw voices 0-23) */ -#define FSOUND_REVERB_FLAGS_CORE1 0x00000200 /* PS2 Only - Reverb is applied to CORE1 (hw voices 24-47) */ -#define FSOUND_REVERB_FLAGS_DEFAULT (FSOUND_REVERB_FLAGS_DECAYTIMESCALE | \ - FSOUND_REVERB_FLAGS_REFLECTIONSSCALE | \ - FSOUND_REVERB_FLAGS_REFLECTIONSDELAYSCALE | \ - FSOUND_REVERB_FLAGS_REVERBSCALE | \ - FSOUND_REVERB_FLAGS_REVERBDELAYSCALE | \ - FSOUND_REVERB_FLAGS_DECAYHFLIMIT | \ - FSOUND_REVERB_FLAGS_CORE0 | \ - FSOUND_REVERB_FLAGS_CORE1 ) -/* [DEFINE_END] */ - - - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_REVERB_PRESETS - - [DESCRIPTION] - A set of predefined environment PARAMETERS, created by Creative Labs - These are used to initialize an FSOUND_REVERB_PROPERTIES structure statically. - ie - FSOUND_REVERB_PROPERTIES prop = FSOUND_PRESET_GENERIC; - - [SEE_ALSO] - FSOUND_Reverb_SetProperties -] -*/ -/* Env Size Diffus Room RoomHF RmLF DecTm DecHF DecLF Refl RefDel RefPan Revb RevDel ReverbPan EchoTm EchDp ModTm ModDp AirAbs HFRef LFRef RRlOff Diffus Densty FLAGS */ -#define FSOUND_PRESET_OFF {0, 7.5f, 1.00f, -10000, -10000, 0, 1.00f, 1.00f, 1.0f, -2602, 0.007f, { 0.0f,0.0f,0.0f }, 200, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 0.0f, 0.0f, 0x33f } -#define FSOUND_PRESET_GENERIC {0, 7.5f, 1.00f, -1000, -100, 0, 1.49f, 0.83f, 1.0f, -2602, 0.007f, { 0.0f,0.0f,0.0f }, 200, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_PADDEDCELL {1, 1.4f, 1.00f, -1000, -6000, 0, 0.17f, 0.10f, 1.0f, -1204, 0.001f, { 0.0f,0.0f,0.0f }, 207, 0.002f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_ROOM {2, 1.9f, 1.00f, -1000, -454, 0, 0.40f, 0.83f, 1.0f, -1646, 0.002f, { 0.0f,0.0f,0.0f }, 53, 0.003f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_BATHROOM {3, 1.4f, 1.00f, -1000, -1200, 0, 1.49f, 0.54f, 1.0f, -370, 0.007f, { 0.0f,0.0f,0.0f }, 1030, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 60.0f, 0x3f } -#define FSOUND_PRESET_LIVINGROOM {4, 2.5f, 1.00f, -1000, -6000, 0, 0.50f, 0.10f, 1.0f, -1376, 0.003f, { 0.0f,0.0f,0.0f }, -1104, 0.004f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_STONEROOM {5, 11.6f, 1.00f, -1000, -300, 0, 2.31f, 0.64f, 1.0f, -711, 0.012f, { 0.0f,0.0f,0.0f }, 83, 0.017f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_AUDITORIUM {6, 21.6f, 1.00f, -1000, -476, 0, 4.32f, 0.59f, 1.0f, -789, 0.020f, { 0.0f,0.0f,0.0f }, -289, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_CONCERTHALL {7, 19.6f, 1.00f, -1000, -500, 0, 3.92f, 0.70f, 1.0f, -1230, 0.020f, { 0.0f,0.0f,0.0f }, -2, 0.029f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_CAVE {8, 14.6f, 1.00f, -1000, 0, 0, 2.91f, 1.30f, 1.0f, -602, 0.015f, { 0.0f,0.0f,0.0f }, -302, 0.022f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f } -#define FSOUND_PRESET_ARENA {9, 36.2f, 1.00f, -1000, -698, 0, 7.24f, 0.33f, 1.0f, -1166, 0.020f, { 0.0f,0.0f,0.0f }, 16, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_HANGAR {10, 50.3f, 1.00f, -1000, -1000, 0, 10.05f, 0.23f, 1.0f, -602, 0.020f, { 0.0f,0.0f,0.0f }, 198, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_CARPETTEDHALLWAY {11, 1.9f, 1.00f, -1000, -4000, 0, 0.30f, 0.10f, 1.0f, -1831, 0.002f, { 0.0f,0.0f,0.0f }, -1630, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_HALLWAY {12, 1.8f, 1.00f, -1000, -300, 0, 1.49f, 0.59f, 1.0f, -1219, 0.007f, { 0.0f,0.0f,0.0f }, 441, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_STONECORRIDOR {13, 13.5f, 1.00f, -1000, -237, 0, 2.70f, 0.79f, 1.0f, -1214, 0.013f, { 0.0f,0.0f,0.0f }, 395, 0.020f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_ALLEY {14, 7.5f, 0.30f, -1000, -270, 0, 1.49f, 0.86f, 1.0f, -1204, 0.007f, { 0.0f,0.0f,0.0f }, -4, 0.011f, { 0.0f,0.0f,0.0f }, 0.125f, 0.95f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_FOREST {15, 38.0f, 0.30f, -1000, -3300, 0, 1.49f, 0.54f, 1.0f, -2560, 0.162f, { 0.0f,0.0f,0.0f }, -229, 0.088f, { 0.0f,0.0f,0.0f }, 0.125f, 1.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 79.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_CITY {16, 7.5f, 0.50f, -1000, -800, 0, 1.49f, 0.67f, 1.0f, -2273, 0.007f, { 0.0f,0.0f,0.0f }, -1691, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 50.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_MOUNTAINS {17, 100.0f, 0.27f, -1000, -2500, 0, 1.49f, 0.21f, 1.0f, -2780, 0.300f, { 0.0f,0.0f,0.0f }, -1434, 0.100f, { 0.0f,0.0f,0.0f }, 0.250f, 1.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 27.0f, 100.0f, 0x1f } -#define FSOUND_PRESET_QUARRY {18, 17.5f, 1.00f, -1000, -1000, 0, 1.49f, 0.83f, 1.0f, -10000, 0.061f, { 0.0f,0.0f,0.0f }, 500, 0.025f, { 0.0f,0.0f,0.0f }, 0.125f, 0.70f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_PLAIN {19, 42.5f, 0.21f, -1000, -2000, 0, 1.49f, 0.50f, 1.0f, -2466, 0.179f, { 0.0f,0.0f,0.0f }, -1926, 0.100f, { 0.0f,0.0f,0.0f }, 0.250f, 1.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 21.0f, 100.0f, 0x3f } -#define FSOUND_PRESET_PARKINGLOT {20, 8.3f, 1.00f, -1000, 0, 0, 1.65f, 1.50f, 1.0f, -1363, 0.008f, { 0.0f,0.0f,0.0f }, -1153, 0.012f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f } -#define FSOUND_PRESET_SEWERPIPE {21, 1.7f, 0.80f, -1000, -1000, 0, 2.81f, 0.14f, 1.0f, 429, 0.014f, { 0.0f,0.0f,0.0f }, 1023, 0.021f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 0.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 80.0f, 60.0f, 0x3f } -#define FSOUND_PRESET_UNDERWATER {22, 1.8f, 1.00f, -1000, -4000, 0, 1.49f, 0.10f, 1.0f, -449, 0.007f, { 0.0f,0.0f,0.0f }, 1700, 0.011f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 1.18f, 0.348f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x3f } - -/* Non I3DL2 presets */ - -#define FSOUND_PRESET_DRUGGED {23, 1.9f, 0.50f, -1000, 0, 0, 8.39f, 1.39f, 1.0f, -115, 0.002f, { 0.0f,0.0f,0.0f }, 985, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 0.25f, 1.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f } -#define FSOUND_PRESET_DIZZY {24, 1.8f, 0.60f, -1000, -400, 0, 17.23f, 0.56f, 1.0f, -1713, 0.020f, { 0.0f,0.0f,0.0f }, -613, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 1.00f, 0.81f, 0.310f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f } -#define FSOUND_PRESET_PSYCHOTIC {25, 1.0f, 0.50f, -1000, -151, 0, 7.56f, 0.91f, 1.0f, -626, 0.020f, { 0.0f,0.0f,0.0f }, 774, 0.030f, { 0.0f,0.0f,0.0f }, 0.250f, 0.00f, 4.00f, 1.000f, -5.0f, 5000.0f, 250.0f, 0.0f, 100.0f, 100.0f, 0x1f } - -/* PlayStation 2 Only presets */ - -#define FSOUND_PRESET_PS2_ROOM {1, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_STUDIO_A {2, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_STUDIO_B {3, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_STUDIO_C {4, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_HALL {5, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_SPACE {6, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_ECHO {7, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_DELAY {8, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } -#define FSOUND_PRESET_PS2_PIPE {9, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0, 0.000f, { 0.0f,0.0f,0.0f }, 0.000f, 0.00f, 0.00f, 0.000f, 0.0f, 0000.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0x31f } - -/* [DEFINE_END] */ - - -/* -[STRUCTURE] -[ - [DESCRIPTION] - Structure defining the properties for a reverb source, related to a FSOUND channel. - For more indepth descriptions of the reverb properties under win32, please see the EAX3 - documentation at http://developer.creative.com/ under the 'downloads' section. - If they do not have the EAX3 documentation, then most information can be attained from - the EAX2 documentation, as EAX3 only adds some more parameters and functionality on top of - EAX2. - - Note the default reverb properties are the same as the FSOUND_PRESET_GENERIC preset. - Note that integer values that typically range from -10,000 to 1000 are represented in - decibels, and are of a logarithmic scale, not linear, wheras float values are typically linear. - PORTABILITY: Each member has the platform it supports in braces ie (win32/xbox). - Some reverb parameters are only supported in win32 and some only on xbox. If all parameters are set then - the reverb should product a similar effect on either platform. - Linux and FMODCE do not support the reverb api. - - The numerical values listed below are the maximum, minimum and default values for each variable respectively. - - [SEE_ALSO] - FSOUND_Reverb_SetChannelProperties - FSOUND_Reverb_GetChannelProperties - FSOUND_REVERB_CHANNELFLAGS -] -*/ -typedef struct _FSOUND_REVERB_CHANNELPROPERTIES /* MIN MAX DEFAULT */ -{ - int Direct; /* -10000, 1000, 0, direct path level (at low and mid frequencies) (win32/xbox) */ - int DirectHF; /* -10000, 0, 0, relative direct path level at high frequencies (win32/xbox) */ - int Room; /* -10000, 1000, 0, room effect level (at low and mid frequencies) (win32/xbox) */ - int RoomHF; /* -10000, 0, 0, relative room effect level at high frequencies (win32/xbox) */ - int Obstruction; /* -10000, 0, 0, main obstruction control (attenuation at high frequencies) (win32/xbox) */ - float ObstructionLFRatio; /* 0.0, 1.0, 0.0, obstruction low-frequency level re. main control (win32/xbox) */ - int Occlusion; /* -10000, 0, 0, main occlusion control (attenuation at high frequencies) (win32/xbox) */ - float OcclusionLFRatio; /* 0.0, 1.0, 0.25, occlusion low-frequency level re. main control (win32/xbox) */ - float OcclusionRoomRatio; /* 0.0, 10.0, 1.5, relative occlusion control for room effect (win32) */ - float OcclusionDirectRatio; /* 0.0, 10.0, 1.0, relative occlusion control for direct path (win32) */ - int Exclusion; /* -10000, 0, 0, main exlusion control (attenuation at high frequencies) (win32) */ - float ExclusionLFRatio; /* 0.0, 1.0, 1.0, exclusion low-frequency level re. main control (win32) */ - int OutsideVolumeHF; /* -10000, 0, 0, outside sound cone level at high frequencies (win32) */ - float DopplerFactor; /* 0.0, 10.0, 0.0, like DS3D flDopplerFactor but per source (win32) */ - float RolloffFactor; /* 0.0, 10.0, 0.0, like DS3D flRolloffFactor but per source (win32) */ - float RoomRolloffFactor; /* 0.0, 10.0, 0.0, like DS3D flRolloffFactor but for room effect (win32/xbox) */ - float AirAbsorptionFactor; /* 0.0, 10.0, 1.0, multiplies AirAbsorptionHF member of FSOUND_REVERB_PROPERTIES (win32) */ - int Flags; /* FSOUND_REVERB_CHANNELFLAGS - modifies the behavior of properties (win32) */ -} FSOUND_REVERB_CHANNELPROPERTIES; - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_REVERB_CHANNELFLAGS - - [DESCRIPTION] - Values for the Flags member of the FSOUND_REVERB_CHANNELPROPERTIES structure. - - [SEE_ALSO] - FSOUND_REVERB_CHANNELPROPERTIES -] -*/ -#define FSOUND_REVERB_CHANNELFLAGS_DIRECTHFAUTO 0x00000001 /* Automatic setting of 'Direct' due to distance from listener */ -#define FSOUND_REVERB_CHANNELFLAGS_ROOMAUTO 0x00000002 /* Automatic setting of 'Room' due to distance from listener */ -#define FSOUND_REVERB_CHANNELFLAGS_ROOMHFAUTO 0x00000004 /* Automatic setting of 'RoomHF' due to distance from listener */ -#define FSOUND_REVERB_CHANNELFLAGS_DEFAULT (FSOUND_REVERB_CHANNELFLAGS_DIRECTHFAUTO | \ - FSOUND_REVERB_CHANNELFLAGS_ROOMAUTO| \ - FSOUND_REVERB_CHANNELFLAGS_ROOMHFAUTO) -/* [DEFINE_END] */ - - -/* -[ENUM] -[ - [DESCRIPTION] - These values are used with FSOUND_FX_Enable to enable DirectX 8 FX for a channel. - - [SEE_ALSO] - FSOUND_FX_Enable - FSOUND_FX_Disable - FSOUND_FX_SetChorus - FSOUND_FX_SetCompressor - FSOUND_FX_SetDistortion - FSOUND_FX_SetEcho - FSOUND_FX_SetFlanger - FSOUND_FX_SetGargle - FSOUND_FX_SetI3DL2Reverb - FSOUND_FX_SetParamEQ - FSOUND_FX_SetWavesReverb -] -*/ -enum FSOUND_FX_MODES -{ - FSOUND_FX_CHORUS, - FSOUND_FX_COMPRESSOR, - FSOUND_FX_DISTORTION, - FSOUND_FX_ECHO, - FSOUND_FX_FLANGER, - FSOUND_FX_GARGLE, - FSOUND_FX_I3DL2REVERB, - FSOUND_FX_PARAMEQ, - FSOUND_FX_WAVES_REVERB, - - FSOUND_FX_MAX -}; - -/* -[ENUM] -[ - [DESCRIPTION] - These are speaker types defined for use with the FSOUND_SetSpeakerMode command. - Note - Only reliably works with FSOUND_OUTPUT_DSOUND or FSOUND_OUTPUT_XBOX output modes. Other output modes will only - interpret FSOUND_SPEAKERMODE_MONO and set everything else to be stereo. - Note - Only reliably works with FSOUND_OUTPUT_DSOUND or FSOUND_OUTPUT_XBOX output modes. Other output modes will only - interpret FSOUND_SPEAKERMODE_MONO and set everything else to be stereo. - - Using either DolbyDigital or DTS will use whatever 5.1 digital mode is available if destination hardware is unsure. - - [SEE_ALSO] - FSOUND_SetSpeakerMode - -] -*/ -enum FSOUND_SPEAKERMODES -{ - FSOUND_SPEAKERMODE_DOLBYDIGITAL, /* The audio is played through a speaker arrangement of surround speakers with a subwoofer. */ - FSOUND_SPEAKERMODE_HEADPHONES, /* The speakers are headphones. */ - FSOUND_SPEAKERMODE_MONO, /* The speakers are monaural. */ - FSOUND_SPEAKERMODE_QUAD, /* The speakers are quadraphonic. */ - FSOUND_SPEAKERMODE_STEREO, /* The speakers are stereo (default value). */ - FSOUND_SPEAKERMODE_SURROUND, /* The speakers are surround sound. */ - FSOUND_SPEAKERMODE_DTS /* (XBOX Only) The audio is played through a speaker arrangement of surround speakers with a subwoofer. */ -}; - - -/* -[DEFINE_START] -[ - [NAME] - FSOUND_INIT_FLAGS - - [DESCRIPTION] - Initialization flags. Use them with FSOUND_Init in the flags parameter to change various behaviour. - - FSOUND_INIT_ENABLEOUTPUTFX Is an init mode which enables the FSOUND mixer buffer to be affected by DirectX 8 effects. - Note that due to limitations of DirectSound, FSOUND_Init may fail if this is enabled because the buffersize is too small. - This can be fixed with FSOUND_SetBufferSize. Increase the BufferSize until it works. - When it is enabled you can use the FSOUND_FX api, and use FSOUND_SYSTEMCHANNEL as the channel id when setting parameters. - - [SEE_ALSO] - FSOUND_Init -] -*/ -#define FSOUND_INIT_USEDEFAULTMIDISYNTH 0x01 /* Causes MIDI playback to force software decoding. */ -#define FSOUND_INIT_GLOBALFOCUS 0x02 /* For DirectSound output - sound is not muted when window is out of focus. */ -#define FSOUND_INIT_ENABLEOUTPUTFX 0x04 /* For DirectSound output - Allows FSOUND_FX api to be used on global software mixer output! */ -#define FSOUND_INIT_ACCURATEVULEVELS 0x08 /* This latency adjusts FSOUND_GetCurrentLevels, but incurs a small cpu and memory hit */ -#define FSOUND_INIT_PS2_DISABLECORE0REVERB 0x10 /* PS2 only - Disable reverb on CORE 0 to regain SRAM */ -#define FSOUND_INIT_PS2_DISABLECORE1REVERB 0x20 /* PS2 only - Disable reverb on CORE 1 to regain SRAM */ -#define FSOUND_INIT_PS2_SWAPDMACORES 0x40 /* PS2 only - By default FMOD uses DMA CH0 for mixing, CH1 for uploads, this flag swaps them around */ -/* [DEFINE_END] */ - - - - -/* ========================================================================================== */ -/* FUNCTION PROTOTYPES */ -/* ========================================================================================== */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* ================================== */ -/* Initialization / Global functions. */ -/* ================================== */ - -/* - PRE - FSOUND_Init functions. These can't be called after FSOUND_Init is - called (they will fail). They set up FMOD system functionality. -*/ - -DLL_API signed char F_API FSOUND_SetOutput(int outputtype); -DLL_API signed char F_API FSOUND_SetDriver(int driver); -DLL_API signed char F_API FSOUND_SetMixer(int mixer); -DLL_API signed char F_API FSOUND_SetBufferSize(int len_ms); -DLL_API signed char F_API FSOUND_SetHWND(void *hwnd); -DLL_API signed char F_API FSOUND_SetMinHardwareChannels(int min); -DLL_API signed char F_API FSOUND_SetMaxHardwareChannels(int max); -DLL_API signed char F_API FSOUND_SetMemorySystem(void *pool, - int poollen, - FSOUND_ALLOCCALLBACK useralloc, - FSOUND_REALLOCCALLBACK userrealloc, - FSOUND_FREECALLBACK userfree); -/* - Main initialization / closedown functions. - Note : Use FSOUND_INIT_USEDEFAULTMIDISYNTH with FSOUND_Init for software override - with MIDI playback. - : Use FSOUND_INIT_GLOBALFOCUS with FSOUND_Init to make sound audible no matter - which window is in focus. (FSOUND_OUTPUT_DSOUND only) -*/ - -DLL_API signed char F_API FSOUND_Init(int mixrate, int maxsoftwarechannels, unsigned int flags); -DLL_API void F_API FSOUND_Close(); - -/* - Runtime system level functions -*/ - -DLL_API void F_API FSOUND_Update(); /* This is called to update 3d sound / non-realtime output */ - -DLL_API void F_API FSOUND_SetSpeakerMode(unsigned int speakermode); -DLL_API void F_API FSOUND_SetSFXMasterVolume(int volume); -DLL_API void F_API FSOUND_SetPanSeperation(float pansep); -DLL_API void F_API FSOUND_File_SetCallbacks(FSOUND_OPENCALLBACK useropen, - FSOUND_CLOSECALLBACK userclose, - FSOUND_READCALLBACK userread, - FSOUND_SEEKCALLBACK userseek, - FSOUND_TELLCALLBACK usertell); - -/* - System information functions. -*/ - -DLL_API int F_API FSOUND_GetError(); -DLL_API float F_API FSOUND_GetVersion(); -DLL_API int F_API FSOUND_GetOutput(); -DLL_API void * F_API FSOUND_GetOutputHandle(); -DLL_API int F_API FSOUND_GetDriver(); -DLL_API int F_API FSOUND_GetMixer(); -DLL_API int F_API FSOUND_GetNumDrivers(); -DLL_API signed char * F_API FSOUND_GetDriverName(int id); -DLL_API signed char F_API FSOUND_GetDriverCaps(int id, unsigned int *caps); -DLL_API int F_API FSOUND_GetOutputRate(); -DLL_API int F_API FSOUND_GetMaxChannels(); -DLL_API int F_API FSOUND_GetMaxSamples(); -DLL_API int F_API FSOUND_GetSFXMasterVolume(); -DLL_API int F_API FSOUND_GetNumHardwareChannels(); -DLL_API int F_API FSOUND_GetChannelsPlaying(); -DLL_API float F_API FSOUND_GetCPUUsage(); -DLL_API void F_API FSOUND_GetMemoryStats(unsigned int *currentalloced, unsigned int *maxalloced); - -/* =================================== */ -/* Sample management / load functions. */ -/* =================================== */ - -/* - Sample creation and management functions - Note : Use FSOUND_LOADMEMORY flag with FSOUND_Sample_Load to load from memory. - Use FSOUND_LOADRAW flag with FSOUND_Sample_Load to treat as as raw pcm data. -*/ - -DLL_API FSOUND_SAMPLE * F_API FSOUND_Sample_Load(int index, const char *name_or_data, unsigned int mode, int memlength); -DLL_API FSOUND_SAMPLE * F_API FSOUND_Sample_Alloc(int index, int length, unsigned int mode, int deffreq, int defvol, int defpan, int defpri); -DLL_API void F_API FSOUND_Sample_Free(FSOUND_SAMPLE *sptr); -DLL_API signed char F_API FSOUND_Sample_Upload(FSOUND_SAMPLE *sptr, void *srcdata, unsigned int mode); -DLL_API signed char F_API FSOUND_Sample_Lock(FSOUND_SAMPLE *sptr, int offset, int length, void **ptr1, void **ptr2, unsigned int *len1, unsigned int *len2); -DLL_API signed char F_API FSOUND_Sample_Unlock(FSOUND_SAMPLE *sptr, void *ptr1, void *ptr2, unsigned int len1, unsigned int len2); - -/* - Sample control functions -*/ - -DLL_API signed char F_API FSOUND_Sample_SetMode(FSOUND_SAMPLE *sptr, unsigned int mode); -DLL_API signed char F_API FSOUND_Sample_SetLoopPoints(FSOUND_SAMPLE *sptr, int loopstart, int loopend); -DLL_API signed char F_API FSOUND_Sample_SetDefaults(FSOUND_SAMPLE *sptr, int deffreq, int defvol, int defpan, int defpri); -DLL_API signed char F_API FSOUND_Sample_SetMinMaxDistance(FSOUND_SAMPLE *sptr, float min, float max); -DLL_API signed char F_API FSOUND_Sample_SetMaxPlaybacks(FSOUND_SAMPLE *sptr, int max); - -/* - Sample information functions -*/ - -DLL_API FSOUND_SAMPLE * F_API FSOUND_Sample_Get(int sampno); -DLL_API char * F_API FSOUND_Sample_GetName(FSOUND_SAMPLE *sptr); -DLL_API unsigned int F_API FSOUND_Sample_GetLength(FSOUND_SAMPLE *sptr); -DLL_API signed char F_API FSOUND_Sample_GetLoopPoints(FSOUND_SAMPLE *sptr, int *loopstart, int *loopend); -DLL_API signed char F_API FSOUND_Sample_GetDefaults(FSOUND_SAMPLE *sptr, int *deffreq, int *defvol, int *defpan, int *defpri); -DLL_API unsigned int F_API FSOUND_Sample_GetMode(FSOUND_SAMPLE *sptr); - -/* ============================ */ -/* Channel control functions. */ -/* ============================ */ - -/* - Playing and stopping sounds. - Note : Use FSOUND_FREE as the 'channel' variable, to let FMOD pick a free channel for you. - Use FSOUND_ALL as the 'channel' variable to control ALL channels with one function call! -*/ - -DLL_API int F_API FSOUND_PlaySound(int channel, FSOUND_SAMPLE *sptr); -DLL_API int F_API FSOUND_PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused); -DLL_API signed char F_API FSOUND_StopSound(int channel); - -/* - Functions to control playback of a channel. - Note : FSOUND_ALL can be used on most of these functions as a channel value. -*/ - -DLL_API signed char F_API FSOUND_SetFrequency(int channel, int freq); -DLL_API signed char F_API FSOUND_SetVolume(int channel, int vol); -DLL_API signed char F_API FSOUND_SetVolumeAbsolute(int channel, int vol); -DLL_API signed char F_API FSOUND_SetPan(int channel, int pan); -DLL_API signed char F_API FSOUND_SetSurround(int channel, signed char surround); -DLL_API signed char F_API FSOUND_SetMute(int channel, signed char mute); -DLL_API signed char F_API FSOUND_SetPriority(int channel, int priority); -DLL_API signed char F_API FSOUND_SetReserved(int channel, signed char reserved); -DLL_API signed char F_API FSOUND_SetPaused(int channel, signed char paused); -DLL_API signed char F_API FSOUND_SetLoopMode(int channel, unsigned int loopmode); -DLL_API signed char F_API FSOUND_SetCurrentPosition(int channel, unsigned int offset); - -/* - Channel information functions. -*/ - -DLL_API signed char F_API FSOUND_IsPlaying(int channel); -DLL_API int F_API FSOUND_GetFrequency(int channel); -DLL_API int F_API FSOUND_GetVolume(int channel); -DLL_API int F_API FSOUND_GetPan(int channel); -DLL_API signed char F_API FSOUND_GetSurround(int channel); -DLL_API signed char F_API FSOUND_GetMute(int channel); -DLL_API int F_API FSOUND_GetPriority(int channel); -DLL_API signed char F_API FSOUND_GetReserved(int channel); -DLL_API signed char F_API FSOUND_GetPaused(int channel); -DLL_API unsigned int F_API FSOUND_GetLoopMode(int channel); -DLL_API unsigned int F_API FSOUND_GetCurrentPosition(int channel); -DLL_API FSOUND_SAMPLE * F_API FSOUND_GetCurrentSample(int channel); -DLL_API signed char F_API FSOUND_GetCurrentLevels(int channel, float *l, float *r); - - -/* =================== */ -/* FX functions. */ -/* =================== */ - -/* - Functions to control DX8 only effects processing. - - - FX enabled samples can only be played once at a time, not multiple times at once. - - Sounds have to be created with FSOUND_HW2D or FSOUND_HW3D for this to work. - - FSOUND_INIT_ENABLEOUTPUTFX can be used to apply hardware effect processing to the - global mixed output of FMOD's software channels. - - FSOUND_FX_Enable returns an FX handle that you can use to alter fx parameters. - - FSOUND_FX_Enable can be called multiple times in a row, even on the same FX type, - it will return a unique handle for each FX. - - FSOUND_FX_Enable cannot be called if the sound is playing or locked. - - FSOUND_FX_Disable must be called to reset/clear the FX from a channel. -*/ - -DLL_API int F_API FSOUND_FX_Enable(int channel, unsigned int fx); /* See FSOUND_FX_MODES */ -DLL_API signed char F_API FSOUND_FX_Disable(int channel); - -DLL_API signed char F_API FSOUND_FX_SetChorus(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase); -DLL_API signed char F_API FSOUND_FX_SetCompressor(int fxid, float Gain, float Attack, float Release, float Threshold, float Ratio, float Predelay); -DLL_API signed char F_API FSOUND_FX_SetDistortion(int fxid, float Gain, float Edge, float PostEQCenterFrequency, float PostEQBandwidth, float PreLowpassCutoff); -DLL_API signed char F_API FSOUND_FX_SetEcho(int fxid, float WetDryMix, float Feedback, float LeftDelay, float RightDelay, int PanDelay); -DLL_API signed char F_API FSOUND_FX_SetFlanger(int fxid, float WetDryMix, float Depth, float Feedback, float Frequency, int Waveform, float Delay, int Phase); -DLL_API signed char F_API FSOUND_FX_SetGargle(int fxid, int RateHz, int WaveShape); -DLL_API signed char F_API FSOUND_FX_SetI3DL2Reverb(int fxid, int Room, int RoomHF, float RoomRolloffFactor, float DecayTime, float DecayHFRatio, int Reflections, float ReflectionsDelay, int Reverb, float ReverbDelay, float Diffusion, float Density, float HFReference); -DLL_API signed char F_API FSOUND_FX_SetParamEQ(int fxid, float Center, float Bandwidth, float Gain); -DLL_API signed char F_API FSOUND_FX_SetWavesReverb(int fxid, float InGain, float ReverbMix, float ReverbTime, float HighFreqRTRatio); - -/* =================== */ -/* 3D sound functions. */ -/* =================== */ - -/* - See also FSOUND_Sample_SetMinMaxDistance (above) - Note! FSOUND_3D_Update is now called FSOUND_Update. -*/ - -DLL_API void F_API FSOUND_3D_SetDopplerFactor(float scale); -DLL_API void F_API FSOUND_3D_SetDistanceFactor(float scale); -DLL_API void F_API FSOUND_3D_SetRolloffFactor(float scale); -DLL_API signed char F_API FSOUND_3D_SetAttributes(int channel, float *pos, float *vel); -DLL_API signed char F_API FSOUND_3D_GetAttributes(int channel, float *pos, float *vel); - -DLL_API void F_API FSOUND_3D_Listener_SetCurrent(int current, int numlisteners); /* use this if you use multiple listeners / splitscreen */ -DLL_API void F_API FSOUND_3D_Listener_SetAttributes(float *pos, float *vel, float fx, float fy, float fz, float tx, float ty, float tz); -DLL_API void F_API FSOUND_3D_Listener_GetAttributes(float *pos, float *vel, float *fx, float *fy, float *fz, float *tx, float *ty, float *tz); - -/* ========================= */ -/* File Streaming functions. */ -/* ========================= */ - -/* - Note : Use FSOUND_LOADMEMORY flag with FSOUND_Stream_OpenFile to stream from memory. - Use FSOUND_LOADRAW flag with FSOUND_Stream_OpenFile to treat stream as raw pcm data. - Use FSOUND_MPEGACCURATE flag with FSOUND_Stream_OpenFile to open mpegs in 'accurate mode' for settime/gettime/getlengthms. - Use FSOUND_FREE as the 'channel' variable, to let FMOD pick a free channel for you. -*/ - -DLL_API signed char F_API FSOUND_Stream_SetBufferSize(int ms); /* call this before opening streams, not after */ - -DLL_API FSOUND_STREAM * F_API FSOUND_Stream_OpenFile(const char *filename, unsigned int mode, int memlength); -DLL_API FSOUND_STREAM * F_API FSOUND_Stream_Create(FSOUND_STREAMCALLBACK callback, int length, unsigned int mode, int samplerate, int userdata); -DLL_API signed char F_API FSOUND_Stream_Close(FSOUND_STREAM *stream); - -DLL_API int F_API FSOUND_Stream_Play(int channel, FSOUND_STREAM *stream); -DLL_API int F_API FSOUND_Stream_PlayEx(int channel, FSOUND_STREAM *stream, FSOUND_DSPUNIT *dsp, signed char startpaused); -DLL_API signed char F_API FSOUND_Stream_Stop(FSOUND_STREAM *stream); - -DLL_API int F_API FSOUND_Stream_GetOpenState(FSOUND_STREAM *stream); /* use with FSOUND_NONBLOCKING opened streams */ -DLL_API signed char F_API FSOUND_Stream_SetPosition(FSOUND_STREAM *stream, unsigned int position); -DLL_API unsigned int F_API FSOUND_Stream_GetPosition(FSOUND_STREAM *stream); -DLL_API signed char F_API FSOUND_Stream_SetTime(FSOUND_STREAM *stream, int ms); -DLL_API int F_API FSOUND_Stream_GetTime(FSOUND_STREAM *stream); -DLL_API int F_API FSOUND_Stream_GetLength(FSOUND_STREAM *stream); -DLL_API int F_API FSOUND_Stream_GetLengthMs(FSOUND_STREAM *stream); - -DLL_API signed char F_API FSOUND_Stream_SetLoopPoints(FSOUND_STREAM *stream, unsigned int loopstartpcm, unsigned int loopendpcm); -DLL_API FSOUND_SAMPLE * F_API FSOUND_Stream_GetSample(FSOUND_STREAM *stream); -DLL_API FSOUND_DSPUNIT *F_API FSOUND_Stream_CreateDSP(FSOUND_STREAM *stream, FSOUND_DSPCALLBACK callback, int priority, int param); -DLL_API signed char F_API FSOUND_Stream_SetEndCallback(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata); - -DLL_API signed char F_API FSOUND_Stream_SetSynchCallback(FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata); -DLL_API int F_API FSOUND_Stream_AddSynchPoint(FSOUND_STREAM *stream, unsigned int pcmoffset, int userdata); -DLL_API signed char F_API FSOUND_Stream_DeleteSynchPoint(FSOUND_STREAM *stream, int index); -DLL_API int F_API FSOUND_Stream_GetNumSynchPoints(FSOUND_STREAM *stream); - -DLL_API signed char F_API FSOUND_Stream_SetSubStream(FSOUND_STREAM *stream, int index); /* For FMOD .FSB bank files. Console only currently. */ -DLL_API int F_API FSOUND_Stream_GetNumSubStreams(FSOUND_STREAM *stream); /* For FMOD .FSB bank files. Console only currently. */ - -/* =================== */ -/* CD audio functions. */ -/* =================== */ - -/* - Note : 0 = default cdrom. Otherwise specify the drive letter, for example. 'D'. -*/ - -DLL_API signed char F_API FSOUND_CD_Play(char drive, int track); -DLL_API void F_API FSOUND_CD_SetPlayMode(char drive, signed char mode); -DLL_API signed char F_API FSOUND_CD_Stop(char drive); -DLL_API signed char F_API FSOUND_CD_SetPaused(char drive, signed char paused); -DLL_API signed char F_API FSOUND_CD_SetVolume(char drive, int volume); -DLL_API signed char F_API FSOUND_CD_Eject(char drive); - -DLL_API signed char F_API FSOUND_CD_GetPaused(char drive); -DLL_API int F_API FSOUND_CD_GetTrack(char drive); -DLL_API int F_API FSOUND_CD_GetNumTracks(char drive); -DLL_API int F_API FSOUND_CD_GetVolume(char drive); -DLL_API int F_API FSOUND_CD_GetTrackLength(char drive, int track); -DLL_API int F_API FSOUND_CD_GetTrackTime(char drive); - -/* ============== */ -/* DSP functions. */ -/* ============== */ - -/* - DSP Unit control and information functions. - These functions allow you access to the mixed stream that FMOD uses to play back sound on. -*/ - -DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_Create(FSOUND_DSPCALLBACK callback, int priority, int param); -DLL_API void F_API FSOUND_DSP_Free(FSOUND_DSPUNIT *unit); -DLL_API void F_API FSOUND_DSP_SetPriority(FSOUND_DSPUNIT *unit, int priority); -DLL_API int F_API FSOUND_DSP_GetPriority(FSOUND_DSPUNIT *unit); -DLL_API void F_API FSOUND_DSP_SetActive(FSOUND_DSPUNIT *unit, signed char active); -DLL_API signed char F_API FSOUND_DSP_GetActive(FSOUND_DSPUNIT *unit); - -/* - Functions to get hold of FSOUND 'system DSP unit' handles. -*/ - -DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetClearUnit(); -DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetSFXUnit(); -DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetMusicUnit(); -DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetFFTUnit(); -DLL_API FSOUND_DSPUNIT *F_API FSOUND_DSP_GetClipAndCopyUnit(); - -/* - Miscellaneous DSP functions - Note for the spectrum analysis function to work, you have to enable the FFT DSP unit with - the following code FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE); - It is off by default to save cpu usage. -*/ - -DLL_API signed char F_API FSOUND_DSP_MixBuffers(void *destbuffer, void *srcbuffer, int len, int freq, int vol, int pan, unsigned int mode); -DLL_API void F_API FSOUND_DSP_ClearMixBuffer(); -DLL_API int F_API FSOUND_DSP_GetBufferLength(); /* Length of each DSP update */ -DLL_API int F_API FSOUND_DSP_GetBufferLengthTotal(); /* Total buffer length due to FSOUND_SetBufferSize */ -DLL_API float * F_API FSOUND_DSP_GetSpectrum(); /* Array of 512 floats - call FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit(), TRUE)) for this to work. */ - -/* =================================================================================== */ -/* Reverb functions. (eax2/eax3 reverb) (ONLY SUPPORTED ON WIN32 W/ FSOUND_HW3D FLAG) */ -/* =================================================================================== */ - -/* - See top of file for definitions and information on the reverb parameters. -*/ - -DLL_API signed char F_API FSOUND_Reverb_SetProperties(FSOUND_REVERB_PROPERTIES *prop); -DLL_API signed char F_API FSOUND_Reverb_GetProperties(FSOUND_REVERB_PROPERTIES *prop); -DLL_API signed char F_API FSOUND_Reverb_SetChannelProperties(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop); -DLL_API signed char F_API FSOUND_Reverb_GetChannelProperties(int channel, FSOUND_REVERB_CHANNELPROPERTIES *prop); - -/* ===================================================== */ -/* Recording functions (ONLY SUPPORTED IN WIN32, WINCE) */ -/* ===================================================== */ - -/* - Recording initialization functions -*/ - -DLL_API signed char F_API FSOUND_Record_SetDriver(int outputtype); -DLL_API int F_API FSOUND_Record_GetNumDrivers(); -DLL_API signed char * F_API FSOUND_Record_GetDriverName(int id); -DLL_API int F_API FSOUND_Record_GetDriver(); - -/* - Recording functionality. Only one recording session will work at a time. -*/ - -DLL_API signed char F_API FSOUND_Record_StartSample(FSOUND_SAMPLE *sptr, signed char loop); -DLL_API signed char F_API FSOUND_Record_Stop(); -DLL_API int F_API FSOUND_Record_GetPosition(); - -/* ========================================================================================== */ -/* FMUSIC API (MOD,S3M,XM,IT,MIDI PLAYBACK) */ -/* ========================================================================================== */ - -/* - Song management / playback functions. -*/ - -DLL_API FMUSIC_MODULE * F_API FMUSIC_LoadSong(const char *name); -DLL_API FMUSIC_MODULE * F_API FMUSIC_LoadSongMemory(void *data, int length); -DLL_API signed char F_API FMUSIC_FreeSong(FMUSIC_MODULE *mod); -DLL_API signed char F_API FMUSIC_PlaySong(FMUSIC_MODULE *mod); -DLL_API signed char F_API FMUSIC_StopSong(FMUSIC_MODULE *mod); -DLL_API void F_API FMUSIC_StopAllSongs(); - -DLL_API signed char F_API FMUSIC_SetZxxCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback); -DLL_API signed char F_API FMUSIC_SetRowCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int rowstep); -DLL_API signed char F_API FMUSIC_SetOrderCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int orderstep); -DLL_API signed char F_API FMUSIC_SetInstCallback(FMUSIC_MODULE *mod, FMUSIC_CALLBACK callback, int instrument); - -DLL_API signed char F_API FMUSIC_SetSample(FMUSIC_MODULE *mod, int sampno, FSOUND_SAMPLE *sptr); -DLL_API signed char F_API FMUSIC_SetUserData(FMUSIC_MODULE *mod, unsigned int userdata); -DLL_API signed char F_API FMUSIC_OptimizeChannels(FMUSIC_MODULE *mod, int maxchannels, int minvolume); - -/* - Runtime song functions. -*/ - -DLL_API signed char F_API FMUSIC_SetReverb(signed char reverb); /* MIDI only */ -DLL_API signed char F_API FMUSIC_SetLooping(FMUSIC_MODULE *mod, signed char looping); -DLL_API signed char F_API FMUSIC_SetOrder(FMUSIC_MODULE *mod, int order); -DLL_API signed char F_API FMUSIC_SetPaused(FMUSIC_MODULE *mod, signed char pause); -DLL_API signed char F_API FMUSIC_SetMasterVolume(FMUSIC_MODULE *mod, int volume); -DLL_API signed char F_API FMUSIC_SetMasterSpeed(FMUSIC_MODULE *mode, float speed); -DLL_API signed char F_API FMUSIC_SetPanSeperation(FMUSIC_MODULE *mod, float pansep); - -/* - Static song information functions. -*/ - -DLL_API char * F_API FMUSIC_GetName(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetType(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetNumOrders(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetNumPatterns(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetNumInstruments(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetNumSamples(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetNumChannels(FMUSIC_MODULE *mod); -DLL_API FSOUND_SAMPLE * F_API FMUSIC_GetSample(FMUSIC_MODULE *mod, int sampno); -DLL_API int F_API FMUSIC_GetPatternLength(FMUSIC_MODULE *mod, int orderno); - -/* - Runtime song information. -*/ - -DLL_API signed char F_API FMUSIC_IsFinished(FMUSIC_MODULE *mod); -DLL_API signed char F_API FMUSIC_IsPlaying(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetMasterVolume(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetGlobalVolume(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetOrder(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetPattern(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetSpeed(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetBPM(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetRow(FMUSIC_MODULE *mod); -DLL_API signed char F_API FMUSIC_GetPaused(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetTime(FMUSIC_MODULE *mod); -DLL_API int F_API FMUSIC_GetRealChannel(FMUSIC_MODULE *mod, int modchannel); -DLL_API unsigned int F_API FMUSIC_GetUserData(FMUSIC_MODULE *mod); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/dlls/fmod_errors.h b/dlls/fmod_errors.h deleted file mode 100644 index 31b13daf..00000000 --- a/dlls/fmod_errors.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _FMOD_ERRORS_H -#define _FMOD_ERRORS_H - -static char *FMOD_ErrorString(int errcode) -{ - switch (errcode) - { - case FMOD_ERR_NONE: return "No errors"; - case FMOD_ERR_BUSY: return "Cannot call this command after FSOUND_Init. Call FSOUND_Close first."; - case FMOD_ERR_UNINITIALIZED: return "This command failed because FSOUND_Init was not called or called properly"; - case FMOD_ERR_PLAY: return "Playing the sound failed."; - case FMOD_ERR_INIT: return "Error initializing output device."; - case FMOD_ERR_ALLOCATED: return "The output device is already in use and cannot be reused."; - case FMOD_ERR_OUTPUT_FORMAT: return "Soundcard does not support the features needed for this soundsystem (16bit stereo output)"; - case FMOD_ERR_COOPERATIVELEVEL: return "Error setting cooperative level for hardware."; - case FMOD_ERR_CREATEBUFFER: return "Error creating hardware sound buffer."; - case FMOD_ERR_FILE_NOTFOUND: return "File not found"; - case FMOD_ERR_FILE_FORMAT: return "Unknown file format"; - case FMOD_ERR_FILE_BAD: return "Error loading file"; - case FMOD_ERR_MEMORY: return "Not enough memory "; - case FMOD_ERR_VERSION: return "The version number of this file format is not supported"; - case FMOD_ERR_INVALID_PARAM: return "An invalid parameter was passed to this function"; - case FMOD_ERR_NO_EAX: return "Tried to use an EAX command on a non EAX enabled channel or output."; - case FMOD_ERR_CHANNEL_ALLOC: return "Failed to allocate a new channel"; - case FMOD_ERR_RECORD: return "Recording not supported on this device"; - case FMOD_ERR_MEDIAPLAYER: return "Required Mediaplayer codec is not installed"; - - default : return "Unknown error"; - }; -}; - -#endif diff --git a/dlls/music.cpp b/dlls/music.cpp index 12868736..daf53817 100644 --- a/dlls/music.cpp +++ b/dlls/music.cpp @@ -1,28 +1,31 @@ -//--------------------------------------------------------- -//--------------------------------------------------------- -//- --- -//- music.cpp --- -//- --- -//--------------------------------------------------------- -//--------------------------------------------------------- -//- by Roy, based on the code by JujU ----------- -//--------------------------------------------------------- -//- fake and null mp3 player code for HL mod ----------- -//--------------------------------------------------------- +//------------------------------------------------------------- +//------------------------------------------------------------- +//- +//- music.cpp +//- +//------------------------------------------------------------- +//------------------------------------------------------------- +//- by Roy at suggestion by nekonomicon, based on code by JujU +//------------------------------------------------------------- +//- mp3 player code for HL mod +//------------------------------------------------------------- +//- +//- compatible with version 0.11.9 of Miniaudio +//- https://github.com/mackron/miniaudio +//- +//------------------------------------------------------------- -/*//--------------- +/* +Don't forget to update the miniaudio submodule. -This code is a placeholder for systems that support neither gstreamer nor fmod. +Miniaudio 0.11.9 or better required. + +Tested on Debian. + +For playlist format see the bottom of the file. +*/ -*///--------------- -#ifdef USE_GSTREAMER -#include "musicgstreamer.cpp" -#elif defined(USE_MINIAUDIO) -#include "musicminiaudio.cpp" -#elif defined(USE_FMOD) -#include "musicfmod.cpp" -#else //--------------------------------------------------------- // inclusions @@ -30,28 +33,342 @@ This code is a placeholder for systems that support neither gstreamer nor fmod. #include "extdll.h" #include "util.h" #include "cbase.h" +#include "gamerules.h" //We need g_pGameRules to determine if we're in multiplayer. -#include "music.h" +#ifndef DISABLE_MINIAUDIO //Use this to exclude the player in it's entirety. Will use empty "trigger_music" with no playback. +#include "music.h" + +//These are just initial ones. If the actual track has different ones, they will be re-applied during Play(). +#define SAMPLE_FORMAT ma_format_f32 +#define CHANNEL_COUNT 2 +#define SAMPLE_RATE 48000 CMusic g_MusicPlayer; +void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); - -//Fake functions to have something to work with on Linux //--------------------------------------------------------- +// initialisation -void CMusic :: Init ( void ){} -void CMusic :: OpenFile ( const char *filename, int repeat ){} -void CMusic :: OpenList ( const char *filename ){} -signed char EndCallback ( void *stream, void *buff, int len, int param ) +void CMusic :: Init ( void ) { - return TRUE; + + if( m_bInit == TRUE ){ + return; //Do not re-init. + } + + deviceConfig = ma_device_config_init(ma_device_type_playback); + deviceConfig.playback.format = SAMPLE_FORMAT; + deviceConfig.playback.channels = CHANNEL_COUNT; + deviceConfig.sampleRate = SAMPLE_RATE; + deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song + deviceConfig.pUserData = NULL; + + if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { + ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); + return; + } + + m_bInit = TRUE; } -void CMusic :: Play ( void ){} -void CMusic :: Stop ( void ){} -void CMusic :: Reset ( void ){} + + + //--------------------------------------------------------- -// The actual game entity +// Callback being called during playback + +void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) +{ + if(g_MusicPlayer.m_IsPlaying == FALSE){ + return; //We are paused or stopped, let's exit now. + } + + ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder; + if (pDecoder == NULL) { + return; + } + + if(frameCount<=0) return; + + ma_uint64 framesRead; + + ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead); + if(framesRead < frameCount) //This happens when the song ends. + g_MusicPlayer.songEnd(); + + (void)pInput; +} + +//--------------------------------------------------------- +// playing an audio file + + +void CMusic :: OpenFile ( const char *filename, int repeat ) +{ + audiofile_t *p = NULL; + p = new audiofile_t; + + sprintf ( p->name, filename ); + p->repeat = repeat; + p->next = m_pTrack; + + m_pTrack = p; +} + + + +//--------------------------------------------------------- +// play a list of audio files + + +void CMusic :: OpenList ( const char *filename ) +{ + + // open text file + + FILE *myfile = fopen ( filename, "r" ); + + if ( myfile == NULL ) + { + ALERT ( at_console, "MUSICPLAYER : impossible to load %s\n", filename ); + return; + } + + // saving songs to the list + + int total = 0; + + if ( fscanf ( myfile, "%i", &total ) != EOF ) + { + for ( int i=0; inext == NULL ) + break; + else + p = p->next; + } + + if ( p == NULL ) + { + ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); + return; + } + + // decrease repeat count + + p->repeat --; + + // removal of songs whose repeats ran off + + if ( p->repeat < 1 ) + { + if ( g_MusicPlayer.m_pTrack == p ) + { + delete g_MusicPlayer.m_pTrack; + g_MusicPlayer.m_pTrack = NULL; + } + else + { + audiofile_t *q = NULL; + q = g_MusicPlayer.m_pTrack; + + while ( q->next != p ) + q = q->next; + + delete q->next; + q->next = NULL; + } + } + + // close player if list is empty + + if ( g_MusicPlayer.m_pTrack == NULL ) + { + g_MusicPlayer.Reset(); + } + + // next track start + + else + { + g_MusicPlayer.Play(); + } + + return; +} + + +//--------------------------------------------------------- +// initiate playback + + +void CMusic :: Play ( void ) +{ + if ( m_IsPlaying == TRUE ) + return; + + if ( m_bInit == FALSE ) + { + Init (); + + if ( m_bInit == FALSE ) + { + ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); + return; + } + } + + // search for the first song in the list + + audiofile_t *p = NULL; + p = m_pTrack; + + while ( p != NULL ) + { + if ( p->next == NULL ) + break; + else + p = p->next; + } + + if ( p == NULL ) + { + ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); + return; + } + + //Stop playback + m_IsPlaying = FALSE; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + + // loading file + char payload [512]; + sprintf(payload, "%s", p->name); + + ALERT ( at_console, "MUSICPLAYER : Opening file %s.\n", payload ); + + result = ma_decoder_init_file(payload, NULL, &decoder); + if (result != MA_SUCCESS) { + ALERT ( at_console, "MUSICPLAYER : %s : can not load file\n", p->name ); + return; + } + + //If the new track has different properties to the previous one. + if( + deviceConfig.playback.format != decoder.outputFormat || + deviceConfig.playback.channels != decoder.outputChannels || + deviceConfig.sampleRate != decoder.outputSampleRate + ){ + deviceConfig.playback.format = decoder.outputFormat; //Change device settings + deviceConfig.playback.channels = decoder.outputChannels; + deviceConfig.sampleRate = decoder.outputSampleRate; + + ALERT ( at_console, "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate); + + //Now we need to recreate the device to apply. + ma_device_uninit(&device); //This is crucial, failing to do this results in segFault. + if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config. + ALERT ( at_console, "MUSICPLAYER : Failed to change playback device configuration.\n" ); + g_MusicPlayer.m_bInit = FALSE; //We have been deinitialized. This is NOT ideal. + return; + }else + ALERT ( at_console, "MUSICPLAYER : New configuration applied successfully.\n"); + } + + // playback + if (ma_device_start(&device) != MA_SUCCESS) { + ALERT ( at_console, "MUSICPLAYER : Failed to start playback device.\n" ); + m_IsPlaying = FALSE; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + return; + }else{ + m_IsPlaying = TRUE; + } + + return; +} + + +void CMusic :: Stop ( void ) +{ + if ( m_IsPlaying == TRUE ) + { + m_IsPlaying = FALSE; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + } +} + + +void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming. +{ + //Reset the player. + if ( m_bInit == TRUE ) + ALERT ( at_console, "MUSICPLAYER : Player reset.\n" ); + + Stop(); + + audiofile_t *p = NULL; + + while ( m_pTrack != NULL ) + { + p = m_pTrack; + m_pTrack = p->next; + delete p; + } +} + +void CMusic :: Terminate ( void ) //Cleanup and dereference +{ + ALERT ( at_console, "MUSICPLAYER : Terminating and unloading.\n" ); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); + g_MusicPlayer.m_bInit = FALSE; +} +#endif //End if #ifndef DISABLE_MINIAUDIO + +//--------------------------------------------------------- +// entity class @@ -68,11 +385,12 @@ public: virtual int Save ( CSave &save ); virtual int Restore ( CRestore &restore ); + static TYPEDESCRIPTION m_SaveData[]; - string_t m_iFileName; // chemin du fichier - int m_iFileType; // fichier texte ( liste ) ou fichier audio + string_t m_iFileName; // file path + int m_iFileType; // text file (list) or audio file }; @@ -92,8 +410,14 @@ IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); void CTriggerMusic :: Spawn( void ) { + if( g_pGameRules->IsDeathmatch() ) //Do not spawn in multiplayer. + { + REMOVE_ENTITY( ENT( pev ) ); + return; + } pev->solid = SOLID_NOT; pev->effects = EF_NODRAW; + } void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) @@ -114,6 +438,72 @@ void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { - return; + if( g_pGameRules->IsMultiplayer() ) //Do not activate / do anything in multiplayer. + return; + +#ifndef DISABLE_MINIAUDIO + if ( g_MusicPlayer.m_IsPlaying == TRUE ) + return; + + if ( m_iFileType == MUSIC_AUDIO_FILE ) + { + g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 ); + } + else + { + g_MusicPlayer.OpenList ( STRING(m_iFileName) ); + } + + g_MusicPlayer.Play(); +#else + return; //Do nothing, we have neither g_MusicPlayer, nor miniaudio. +#endif } -#endif \ No newline at end of file + + + + + + + +/* +code + + +@PointClass base( Targetname ) = trigger_music : "Trigger Music" +[ + filetype(choices) : "File type" : 0 = + [ + 0: "File list (*.txt)" + 1: "File wav mp2 mp3 ogg raw" + ] + filename(string) : "Name (mod/folder/file.extension)" +] + +*/ + + +/*//--------------- +Playlist contents + +example: music01.txt file: + +// + +3 + +monmod/sound/mp3/music01_debut.mp3 1 +monmod/sound/mp3/music01_boucle.mp3 3 +monmod/sound/mp3/music01_fin.mp3 1 + + +// + +composition : + - total number of tracks + - path of the first music file + - times to repeat that file + - path of the second + - etc ... + +*///--------------- diff --git a/dlls/music.h b/dlls/music.h index 39a4088e..e6e8bf44 100644 --- a/dlls/music.h +++ b/dlls/music.h @@ -1,20 +1,26 @@ -//--------------------------------------------------------- -//--------------------------------------------------------- -//- --- -//- music.h --- -//- --- -//--------------------------------------------------------- -//--------------------------------------------------------- -//- by Roy, based on the code by JujU ----------- -//--------------------------------------------------------- -//- tee file for null player -//--------------------------------------------------------- - +//------------------------------------------------------------- +//------------------------------------------------------------- +//- +//- music.h +//- +//------------------------------------------------------------- +//------------------------------------------------------------- +//- by Roy at suggestion by nekonomicon, based on code by JujU +//------------------------------------------------------------- +//- mp3 player code for HL mod +//------------------------------------------------------------- +//- +//- compatible with version 0.11.9 of Miniaudio +//- https://github.com/mackron/miniaudio +//- +//------------------------------------------------------------- #ifndef MUSIC_H #define MUSIC_H -//Temporary plug to have something to work with on Linux modif de Roy +#define MINIAUDIO_IMPLEMENTATION +#include "../miniaudio/miniaudio.h" + //--------------------------------------------------------- // defines @@ -22,7 +28,7 @@ #define MUSIC_LIST_FILE 0 //--------------------------------------------------------- -// structure of the audio file entity +// audio file structure struct audiofile_t { @@ -32,41 +38,45 @@ struct audiofile_t }; //--------------------------------------------------------- -// music class +// reader class class CMusic { public: - // fonctions de lecture + // reading functions - void OpenFile ( const char *filename, int repeat ); // ouverture d'un simple fichier - void OpenList ( const char *filename ); // ouverture d'un fichier texte contenant les fichiers + void OpenFile ( const char *filename, int repeat ); // open a single file + void OpenList ( const char *filename ); // opening a text file containing the files - void Init ( void ); // initialisation + void Init ( void ); // initialization - void Play ( void ); // lecture - void Stop ( void ); // arr - void Reset ( void ); // fermeture + void Play ( void ); // playback + void Stop ( void ); // stop + void Reset ( void ); // pause and switch to next track + void Terminate ( void ); // clean-up during termination // variables - - int m_fsound; //We don't actually have FMOD, so just an int handle. + BOOL m_IsPlaying; // monitors whether the music is played, used to pause the music + BOOL m_bInit; // checks if the player is initialized - BOOL m_IsPlaying; // t - BOOL m_bInit; // t + audiofile_t *m_pTrack; // playlist items - audiofile_t *m_pTrack; //current track - - // constructor & destructor + // constructor / destructor CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); }; - ~CMusic () {}; + ~CMusic () { Terminate(); }; - // functions import - // none, see window / Julien's code. + // object instances + + ma_result result; + ma_decoder decoder; + ma_device_config deviceConfig; + ma_device device; + + void songEnd(); }; extern CMusic g_MusicPlayer; diff --git a/dlls/musicfmod.cpp b/dlls/musicfmod.cpp deleted file mode 100644 index 90b9c3b5..00000000 --- a/dlls/musicfmod.cpp +++ /dev/null @@ -1,446 +0,0 @@ -//--------------------------------------------------------- -//--------------------------------------------------------- -//- --- -//- musicfmod.cpp --- -//- --- -//--------------------------------------------------------- -//--------------------------------------------------------- -//- par JujU ----------- -//- julien.lecorre@free.fr ----------- -//--------------------------------------------------------- -//- code du lecteur mp3 pour mod HL ----------- -//--------------------------------------------------------- -//- --- -//- compatible avec la version 3.6.1 de fmod.dll --- -//- http://www.fmod.org/ --- -//- --- -//--------------------------------------------------------- - - -/*//--------------- - -mettre la dll fmod.dll dans le dossier half life. - -changer l'adresse de la dll dans le #define FMOD_DLL_PATH -du fichier .h -attention, mettre des \\ et pas des \ dans l'adresse. - -code -fin de ce fichier. - -composition des fichiers texte listes de fichiers audio : -voir - -*///--------------- - - - -//--------------------------------------------------------- -// inclusions - -#include "extdll.h" -#include "util.h" -#include "cbase.h" - -#include "musicfmod.h" - -CMusic g_MusicPlayer; - -//--------------------------------------------------------- -// initialisation - -void CMusic :: Init ( void ) -{ - m_hFmodDll = LoadLibrary ( FMOD_DLL_PATH ); - - if ( m_hFmodDll == NULL ) - return; - - (FARPROC&)FSOUND_INIT = GetProcAddress(m_hFmodDll, "_FSOUND_Init@12"); - (FARPROC&)FSOUND_CLOSE = GetProcAddress(m_hFmodDll, "_FSOUND_Close@0"); - (FARPROC&)FSOUND_STREAM_OPENFILE = GetProcAddress(m_hFmodDll, "_FSOUND_Stream_OpenFile@12"); - (FARPROC&)FSOUND_STREAM_CLOSE = GetProcAddress(m_hFmodDll, "_FSOUND_Stream_Close@4"); - (FARPROC&)FSOUND_STREAM_PLAY = GetProcAddress(m_hFmodDll, "_FSOUND_Stream_Play@8"); - (FARPROC&)FSOUND_STREAM_ENDCALLBACK = GetProcAddress(m_hFmodDll, "_FSOUND_Stream_SetEndCallback@12"); - - - if ( !( FSOUND_INIT && FSOUND_CLOSE && FSOUND_STREAM_OPENFILE && FSOUND_STREAM_CLOSE && FSOUND_STREAM_PLAY && FSOUND_STREAM_ENDCALLBACK )) - { - FreeLibrary( m_hFmodDll ); - return; - } - - - if (!FSOUND_INIT(44100, 1, 0)) - return; - - - m_bInit = TRUE; -} - - - - -//--------------------------------------------------------- -// lecture d'un fichier audio - - -void CMusic :: OpenFile ( const char *filename, int repeat ) -{ - audiofile_t *p = NULL; - p = new audiofile_t; - - sprintf ( p->name, filename ); - p->repeat = repeat; - p->next = m_pTrack; - - m_pTrack = p; -} - - - -//--------------------------------------------------------- -// lecture d'une liste de fichiers audio - - -void CMusic :: OpenList ( const char *filename ) -{ - - // ouverture du fichier texte - - FILE *myfile = fopen ( filename, "r" ); - - if ( myfile == NULL ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : impossible d'ouvrir %s\n\\\n", filename ); - return; - } - - // enregistrement des morceaux dans la liste - - int total = 0; - - if ( fscanf ( myfile, "%i", &total ) != EOF ) - { - for ( int i=0; inext == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : aucun morceau dans la liste\n\\\n" ); - return TRUE; - } - - // d - - p->repeat --; - - // suppression des morceaux dont la r - - if ( p->repeat < 1 ) - { - if ( g_MusicPlayer.m_pTrack == p ) - { - delete g_MusicPlayer.m_pTrack; - g_MusicPlayer.m_pTrack = NULL; - } - else - { - audiofile_t *q = NULL; - q = g_MusicPlayer.m_pTrack; - - while ( q->next != p ) - q = q->next; - - delete q->next; - q->next = NULL; - } - } - - // fermeture du lecteur si la liste est vide - - if ( g_MusicPlayer.m_pTrack == NULL ) - { - g_MusicPlayer.Reset (); - } - - // lancement du morceau suivant - - else - { - g_MusicPlayer.Play(); - } - - return TRUE; -} - - -//--------------------------------------------------------- -// lecture - - -void CMusic :: Play ( void ) -{ - if ( m_IsPlaying == TRUE ) - return; - - if ( m_bInit == FALSE ) - { - Init (); - - if ( m_bInit == FALSE ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : initialisation impossible\n\\\n" ); - return; - } - } - - // recherche du premier morceau de la liste - - audiofile_t *p = NULL; - p = m_pTrack; - - while ( p != NULL ) - { - if ( p->next == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : aucun morceau dans la liste\n\\\n" ); - return; - } - - // chargement du fichier - - m_fsound = FSOUND_STREAM_OPENFILE( p->name, FSOUND_NORMAL | FSOUND_LOOP_OFF, 0 ); - - if (!m_fsound) - { - ALERT ( at_console, "\\\nMUSICPLAYER : %s : fichier introuvable\n\\\n", p->name ); - return; - } - - // lecture - - FSOUND_STREAM_PLAY ( FSOUND_FREE, m_fsound ); - m_IsPlaying = TRUE; - - // callback en fin de morceau - - FSOUND_STREAM_ENDCALLBACK ( m_fsound, EndCallback, 0 ); -} - - -void CMusic :: Stop ( void ) -{ - if ( m_IsPlaying == TRUE ) - { - m_IsPlaying = FALSE; - FSOUND_STREAM_CLOSE ( m_fsound ); - } -} - - -void CMusic :: Reset ( void ) -{ - //r - - Stop (); - - audiofile_t *p = NULL; - - while ( m_pTrack != NULL ) - { - p = m_pTrack; - m_pTrack = p->next; - delete p; - } - - if ( m_bInit == TRUE ) - { - FSOUND_CLOSE(); - g_MusicPlayer.m_bInit = FALSE; - - // FreeLibrary( g_MusicPlayer.m_hFmodDll ); - g_MusicPlayer.m_hFmodDll = NULL; - } -} - - - - -//--------------------------------------------------------- -// classe de l'entit - - - -class CTriggerMusic : public CPointEntity -{ -public: - - void Spawn ( void ); - - void KeyValue ( KeyValueData *pkvd ); - void Use ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - - - virtual int Save ( CSave &save ); - virtual int Restore ( CRestore &restore ); - - static TYPEDESCRIPTION m_SaveData[]; - - - string_t m_iFileName; // chemin du fichier - int m_iFileType; // fichier texte ( liste ) ou fichier audio - -}; - -LINK_ENTITY_TO_CLASS( trigger_music, CTriggerMusic ); - - - -TYPEDESCRIPTION CTriggerMusic::m_SaveData[] = -{ - DEFINE_FIELD( CTriggerMusic, m_iFileType, FIELD_INTEGER ), - DEFINE_FIELD( CTriggerMusic, m_iFileName, FIELD_STRING ), -}; - -IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); - - - -void CTriggerMusic :: Spawn( void ) -{ - pev->solid = SOLID_NOT; - pev->effects = EF_NODRAW; -} - -void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) -{ - if (FStrEq(pkvd->szKeyName, "filetype")) - { - m_iFileType = atoi(pkvd->szValue); - pkvd->fHandled = TRUE; - } - else if (FStrEq(pkvd->szKeyName, "filename")) - { - m_iFileName = ALLOC_STRING(pkvd->szValue); - pkvd->fHandled = TRUE; - } - else - CPointEntity::KeyValue( pkvd ); -} - -void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) -{ - if ( g_MusicPlayer.m_IsPlaying == TRUE ) - return; - - if ( m_iFileType == MUSIC_AUDIO_FILE ) - { - g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 ); - } - else - { - g_MusicPlayer.OpenList ( STRING(m_iFileName) ); - } - - g_MusicPlayer.Play(); -} - - - - - - -/*//--------------- -code - - -@PointClass base( Targetname ) = trigger_music : "Trigger Music" -[ - filetype(choices) : "Type de fichier" : 0 = - [ - 0: "Liste de fichiers (*.txt)" - 1: "Fichier wav mp2 mp3 ogg raw" - ] - filename(string) : "Nom (mod/dossier/fichier.extension)" -] - -*///--------------- - - -/*//--------------- -composition des listes de fichiers audio - -exemple : fichier music01.txt : - -// - -3 - -monmod/sound/mp3/music01_debut.mp3 1 -monmod/sound/mp3/music01_boucle.mp3 3 -monmod/sound/mp3/music01_fin.mp3 1 - - -// - -composition : - - nombre total de morceaux diff - - adresse du premier fichier musique - - nombre de lectures de ce fichier - - adresse du deuxi - - etc ... - -*///--------------- diff --git a/dlls/musicfmod.h b/dlls/musicfmod.h deleted file mode 100644 index 23d7acb2..00000000 --- a/dlls/musicfmod.h +++ /dev/null @@ -1,94 +0,0 @@ -//--------------------------------------------------------- -//--------------------------------------------------------- -//- --- -//- musicfmod.h --- -//- --- -//--------------------------------------------------------- -//--------------------------------------------------------- -//- par JujU ----------- -//- julien.lecorre@free.fr ----------- -//--------------------------------------------------------- -//- fichier d'en t -//--------------------------------------------------------- -//- --- -//- compatible avec la version 3.6.1 de fmod.dll --- -//- http://www.fmod.org/ --- -//- --- -//--------------------------------------------------------- - - - -#ifndef MUSIC_H -#define MUSIC_H - -#include -#include - -//--------------------------------------------------------- -// defines - -#define MUSIC_AUDIO_FILE 1 -#define MUSIC_LIST_FILE 0 - -#define FMOD_DLL_PATH "invasion\\fmod.dll" - - - -//--------------------------------------------------------- -// structure fichier audio - -struct audiofile_t -{ - char name [128]; - int repeat; - audiofile_t *next; -}; - -//--------------------------------------------------------- -// classe du lecteur - - -class CMusic -{ -public: - - // fonctions de lecture - - void OpenFile ( const char *filename, int repeat ); // ouverture d'un simple fichier - void OpenList ( const char *filename ); // ouverture d'un fichier texte contenant les fichiers - - void Init ( void ); // initialisation - - void Play ( void ); // lecture - void Stop ( void ); // arr - void Reset ( void ); // fermeture - - // variables - - FSOUND_STREAM *m_fsound; // handle du fichier en cours de lecture - - BOOL m_IsPlaying; // t - BOOL m_bInit; // t - - audiofile_t *m_pTrack; // morceaux - - // constructeur / destructeur - - CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); }; - ~CMusic () {}; - - // fonctions import - - signed char (_stdcall * FSOUND_INIT ) (int mixrate, int maxsoftwarechannels, unsigned int flags); - void (_stdcall * FSOUND_CLOSE ) (void); - FSOUND_STREAM * (_stdcall * FSOUND_STREAM_OPENFILE ) (const char *filename, unsigned int mode, int memlength); - signed char (_stdcall * FSOUND_STREAM_CLOSE ) (FSOUND_STREAM *stream); - int (_stdcall * FSOUND_STREAM_PLAY ) (int channel, FSOUND_STREAM *stream); - signed char (_stdcall * FSOUND_STREAM_ENDCALLBACK) (FSOUND_STREAM *stream, FSOUND_STREAMCALLBACK callback, int userdata); - - HINSTANCE m_hFmodDll; -}; - -extern CMusic g_MusicPlayer; - -#endif // MUSIC_H diff --git a/dlls/musicgstreamer.cpp b/dlls/musicgstreamer.cpp deleted file mode 100644 index 39354181..00000000 --- a/dlls/musicgstreamer.cpp +++ /dev/null @@ -1,511 +0,0 @@ -//--------------------------------------------------------- -//--------------------------------------------------------- -//- --- -//- musicgstreamer.cpp --- -//- --- -//--------------------------------------------------------- -//--------------------------------------------------------- -//- by Roy, based on the code by JujU ----------- -//--------------------------------------------------------- -//- mp3 player code for HL mod ----------- -//--------------------------------------------------------- -//- --- -//- compatible with version 1.0 of Gstreamer --- -//- http://www.gstreamer.freedesktop.org/ --- -//- --- -//--------------------------------------------------------- - - -/*//--------------- - -Don't forget to link the actual library to GStreamer. - -GStreamer 1.0 or better required. - -Tested -with 32-bit GStreamer on Debian - -For playlist format: -see the bottom of the file - -*///--------------- - - - -//--------------------------------------------------------- -// inclusions - -#include "extdll.h" -#include "util.h" -#include "cbase.h" - -#include "musicgstreamer.h" - -CMusic g_MusicPlayer; - -//--------------------------------------------------------- -// initialisation - -void CMusic :: Init ( void ) -{ - int argc = 0; - char** argv = nullptr; - GError *error = nullptr; - - if( m_bInit == TRUE ){ - return; //Do not re-init. - } - - if (gst_init_check(&argc,&argv,&error)!=TRUE) - { - ALERT ( at_console, "\\\nMUSICPLAYER : unable to initialize\n\\\n" ); - return; - } - - m_bInit = TRUE; -} - - - - -//--------------------------------------------------------- -// monitoring the bus - - -void CMusic :: updateBus ( ) -{ - if(gstBus == NULL) return; //Do not react if bus doesn't exist. - gstMsg = gst_bus_pop (gstBus); - if(gstMsg != NULL){ - if (GST_MESSAGE_TYPE (gstMsg) == GST_MESSAGE_ERROR) { - ALERT( at_console, "\\\nMUSICPLAYER : A GStreamer error has occured.\n\\\n" ); - }else if (GST_MESSAGE_TYPE (gstMsg) == GST_MESSAGE_EOS) { - ALERT( at_console, "\\\nMUSICPLAYER : A song has ended.\n\\\n" ); - songEnd(); - } - } - if(gstMsg != NULL) gst_message_unref (gstMsg); -} - - - - -//--------------------------------------------------------- -// playing an audio file - - -void CMusic :: OpenFile ( const char *filename, int repeat ) -{ - audiofile_t *p = NULL; - p = new audiofile_t; - - sprintf ( p->name, filename ); - p->repeat = repeat; - p->next = m_pTrack; - - m_pTrack = p; -} - - - -//--------------------------------------------------------- -// play a list of audio files - - -void CMusic :: OpenList ( const char *filename ) -{ - - // open text file - - FILE *myfile = fopen ( filename, "r" ); - - if ( myfile == NULL ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : impossible to load %s\n\\\n", filename ); - return; - } - - // saving songs to the list - - int total = 0; - - if ( fscanf ( myfile, "%i", &total ) != EOF ) - { - for ( int i=0; inext == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : no song in the list\n\\\n" ); - return; - } - - // d - - p->repeat --; - - // removal of songs whose r - - if ( p->repeat < 1 ) - { - if ( g_MusicPlayer.m_pTrack == p ) - { - delete g_MusicPlayer.m_pTrack; - g_MusicPlayer.m_pTrack = NULL; - } - else - { - audiofile_t *q = NULL; - q = g_MusicPlayer.m_pTrack; - - while ( q->next != p ) - q = q->next; - - delete q->next; - q->next = NULL; - } - } - - // close player if list is empty - - if ( g_MusicPlayer.m_pTrack == NULL ) - { - g_MusicPlayer.Reset (); - } - - // next track start - - else - { - g_MusicPlayer.Play(); - } - - return; -} - - -//--------------------------------------------------------- -// instruction - - -void CMusic :: Play ( void ) -{ - if ( m_IsPlaying == TRUE ) - return; - - if ( m_bInit == FALSE ) - { - Init (); - - if ( m_bInit == FALSE ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : unable to initialize\n\\\n" ); - return; - } - } - - // search for the first song in the list - - audiofile_t *p = NULL; - p = m_pTrack; - - while ( p != NULL ) - { - if ( p->next == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : no song in the list\n\\\n" ); - return; - } - - //Stop previous pipeline activity - if (gstPipeline != NULL){ - gst_element_set_state (gstPipeline, GST_STATE_NULL); - gst_object_unref (gstPipeline); - gstPipeline = NULL; - } - if (gstBus != NULL){ - gst_object_unref (gstBus); - gstBus = NULL; - } - - // loading file - char pipelinePayload [512]; - sprintf(pipelinePayload, "filesrc location=%s ! decodebin ! audioconvert ! audioresample ! autoaudiosink", p->name); - gstPipeline = gst_parse_launch(pipelinePayload, NULL); - - - if (gstPipeline == NULL) - { - ALERT ( at_console, "\\\nMUSICPLAYER : %s : can not start playing the file\n\\\n", p->name ); - return; - } - - // playback - - gst_element_set_state (gstPipeline, GST_STATE_PLAYING); - m_IsPlaying = TRUE; - - // callback at the end of the song - - gstBus = gst_element_get_bus (gstPipeline); //Get bus to monitor -} - - -void CMusic :: Stop ( void ) -{ - if ( m_IsPlaying == TRUE ) - { - m_IsPlaying = FALSE; - if (gstPipeline != NULL){ - gst_element_set_state (gstPipeline, GST_STATE_READY); - } - } -} - - -void CMusic :: Reset ( void ) -{ - //r - - Stop (); - - audiofile_t *p = NULL; - - while ( m_pTrack != NULL ) - { - p = m_pTrack; - m_pTrack = p->next; - delete p; - } - - if ( m_bInit == TRUE ) - { - if (gstPipeline != NULL){ - gst_element_set_state (gstPipeline, GST_STATE_NULL); - gst_object_unref (gstPipeline); - gstPipeline = NULL; - } - if (gstBus != NULL){ - gst_object_unref (gstBus); - gstBus = NULL; - } - - //complete - //we don't actually de-initialize gst here - } -} - -void CMusic :: Terminate ( void ) //Cleanup and dereference -{ - Stop (); - if ( m_bInit == TRUE ) - { - ALERT ( at_console, "\\\nMUSICPLAYER : de-initializing and dereferencing\n\\\n" ); - if (gstPipeline != NULL){ - gst_element_set_state (gstPipeline, GST_STATE_NULL); - gst_object_unref (gstPipeline); - gstPipeline = NULL; - } - if (gstBus != NULL){ - gst_object_unref (gstBus); - gstBus = NULL; - } - - gst_deinit (); - g_MusicPlayer.m_bInit = FALSE; //Neither. - - //complete - } -} - - -//--------------------------------------------------------- -// entity class - - - -class CTriggerMusic : public CPointEntity -{ -public: - - void Spawn ( void ); - - void KeyValue ( KeyValueData *pkvd ); - void Use ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - - void EXPORT Think( void ); - - virtual int Save ( CSave &save ); - virtual int Restore ( CRestore &restore ); - - - static TYPEDESCRIPTION m_SaveData[]; - - - string_t m_iFileName; // file path - int m_iFileType; // text file (list) or audio file - -}; - -LINK_ENTITY_TO_CLASS( trigger_music, CTriggerMusic ); - - - -TYPEDESCRIPTION CTriggerMusic::m_SaveData[] = -{ - DEFINE_FIELD( CTriggerMusic, m_iFileType, FIELD_INTEGER ), - DEFINE_FIELD( CTriggerMusic, m_iFileName, FIELD_STRING ), -}; - -IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); - - - -void CTriggerMusic :: Spawn( void ) -{ - pev->solid = SOLID_NOT; - pev->effects = EF_NODRAW; - - SetThink( &CTriggerMusic::Think ); - pev->nextthink = gpGlobals->time; -} - -void CTriggerMusic::Think( void ) //We need to monitor gst message bus for updates -{ - //if(g_MusicPlayer == NULL) return; - g_MusicPlayer.updateBus(); - pev->nextthink = gpGlobals->time + 0.25f; // Think again in 1/4 second -} - -void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) -{ - if (FStrEq(pkvd->szKeyName, "filetype")) - { - m_iFileType = atoi(pkvd->szValue); - pkvd->fHandled = TRUE; - } - else if (FStrEq(pkvd->szKeyName, "filename")) - { - m_iFileName = ALLOC_STRING(pkvd->szValue); - pkvd->fHandled = TRUE; - } - else - CPointEntity::KeyValue( pkvd ); -} - -void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) -{ - if ( g_MusicPlayer.m_IsPlaying == TRUE ) - return; - - if ( m_iFileType == MUSIC_AUDIO_FILE ) - { - g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 ); - } - else - { - g_MusicPlayer.OpenList ( STRING(m_iFileName) ); - } - - g_MusicPlayer.Play(); -} - - - - - - - -/*//--------------- -code - - -@PointClass base( Targetname ) = trigger_music : "Trigger Music" -[ - filetype(choices) : "File type" : 0 = - [ - 0: "File list (*.txt)" - 1: "File wav mp2 mp3 ogg raw" - ] - filename(string) : "Name (mod/folder/file.extension)" -] - -*///--------------- - - -/*//--------------- -composing lists of audio files - -example: music01.txt file: - -// - -3 - -monmod/sound/mp3/music01_debut.mp3 1 -monmod/sound/mp3/music01_boucle.mp3 3 -monmod/sound/mp3/music01_fin.mp3 1 - - -// - -composition : - - total number of diff chunks - - address of the first music file - - number of readings of this file - - address of the second - - etc ... - -*///--------------- diff --git a/dlls/musicgstreamer.h b/dlls/musicgstreamer.h deleted file mode 100644 index 4dd34679..00000000 --- a/dlls/musicgstreamer.h +++ /dev/null @@ -1,85 +0,0 @@ -//--------------------------------------------------------- -//--------------------------------------------------------- -//- --- -//- musicgstreamer.h --- -//- --- -//--------------------------------------------------------- -//--------------------------------------------------------- -//- by Roy, based on the code by JujU ----------- -//--------------------------------------------------------- -//- tee file -//--------------------------------------------------------- -//- --- -//- compatible with version 1.0 of Gstreamer --- -//- http://www.gstreamer.freedesktop.org/ --- -//- --- -//--------------------------------------------------------- - - - -#ifndef MUSIC_H -#define MUSIC_H - -#include - - -//--------------------------------------------------------- -// defines - -#define MUSIC_AUDIO_FILE 1 -#define MUSIC_LIST_FILE 0 - -//--------------------------------------------------------- -// audio file structure - -struct audiofile_t -{ - char name [128]; - int repeat; - audiofile_t *next; -}; - -//--------------------------------------------------------- -// reader class - - -class CMusic -{ -public: - - // reading functions - - void OpenFile ( const char *filename, int repeat ); // open a single file - void OpenList ( const char *filename ); // opening a text file containing the files - - void Init ( void ); // initialization - - void Play ( void ); // playback - void Stop ( void ); // stop - void Reset ( void ); // closing, but not really - void Terminate ( void ); // actually closing - - // variables - - BOOL m_IsPlaying; // t - BOOL m_bInit; // t - - audiofile_t *m_pTrack; // parts - - // constructor / destructor - - CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); }; - ~CMusic () { Terminate(); }; - - // import functions - - GstElement *gstPipeline; - GstBus *gstBus; - GstMessage *gstMsg; - - void updateBus(); - void songEnd(); -}; - -extern CMusic g_MusicPlayer; -#endif // MUSIC_H diff --git a/dlls/musicminiaudio.cpp b/dlls/musicminiaudio.cpp deleted file mode 100644 index 5194d5c6..00000000 --- a/dlls/musicminiaudio.cpp +++ /dev/null @@ -1,495 +0,0 @@ -//------------------------------------------------------------- -//------------------------------------------------------------- -//- -//- musicminiaudio.cpp -//- -//------------------------------------------------------------- -//------------------------------------------------------------- -//- by Roy at suggestion by nekonomicon, based on code by JujU -//------------------------------------------------------------- -//- mp3 player code for HL mod -//------------------------------------------------------------- -//- -//- compatible with version 0.11.9 of Miniaudio -//- https://github.com/mackron/miniaudio -//- -//------------------------------------------------------------- - -/* -Don't forget to update the miniaudio submodule. - -Miniaudio 0.11.9 or better required. - -Tested on Debian. - -For playlist format see the bottom of the file. -*/ - - - -//--------------------------------------------------------- -// inclusions - -#include "extdll.h" -#include "util.h" -#include "cbase.h" - -#include "musicminiaudio.h" - -//These are just initial ones. If the actual track has different ones, they will be re-applied during Play(). -#define SAMPLE_FORMAT ma_format_f32 -#define CHANNEL_COUNT 2 -#define SAMPLE_RATE 48000 - -CMusic g_MusicPlayer; -void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); - -//--------------------------------------------------------- -// initialisation - -void CMusic :: Init ( void ) -{ - - if( m_bInit == TRUE ){ - return; //Do not re-init. - } - - deviceConfig = ma_device_config_init(ma_device_type_playback); - deviceConfig.playback.format = SAMPLE_FORMAT; - deviceConfig.playback.channels = CHANNEL_COUNT; - deviceConfig.sampleRate = SAMPLE_RATE; - deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song - deviceConfig.pUserData = NULL; - - if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { - ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); - return; - } - - m_bInit = TRUE; -} - - - - -//--------------------------------------------------------- -// Callback being called during playback - -void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) -{ - if(g_MusicPlayer.m_IsPlaying == FALSE){ - return; //We are paused or stopped, let's exit now. - } - - ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder; - if (pDecoder == NULL) { - return; - } - - if(frameCount<=0) return; - - ma_uint64 framesRead; - - ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead); - if(framesRead < frameCount) //This happens when the song ends. - g_MusicPlayer.songEnd(); - - (void)pInput; -} - -//--------------------------------------------------------- -// playing an audio file - - -void CMusic :: OpenFile ( const char *filename, int repeat ) -{ - audiofile_t *p = NULL; - p = new audiofile_t; - - sprintf ( p->name, filename ); - p->repeat = repeat; - p->next = m_pTrack; - - m_pTrack = p; -} - - - -//--------------------------------------------------------- -// play a list of audio files - - -void CMusic :: OpenList ( const char *filename ) -{ - - // open text file - - FILE *myfile = fopen ( filename, "r" ); - - if ( myfile == NULL ) - { - ALERT ( at_console, "MUSICPLAYER : impossible to load %s\n", filename ); - return; - } - - // saving songs to the list - - int total = 0; - - if ( fscanf ( myfile, "%i", &total ) != EOF ) - { - for ( int i=0; inext == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); - return; - } - - // decrease repeat count - - p->repeat --; - - // removal of songs whose repeats ran off - - if ( p->repeat < 1 ) - { - if ( g_MusicPlayer.m_pTrack == p ) - { - delete g_MusicPlayer.m_pTrack; - g_MusicPlayer.m_pTrack = NULL; - } - else - { - audiofile_t *q = NULL; - q = g_MusicPlayer.m_pTrack; - - while ( q->next != p ) - q = q->next; - - delete q->next; - q->next = NULL; - } - } - - // close player if list is empty - - if ( g_MusicPlayer.m_pTrack == NULL ) - { - g_MusicPlayer.Reset(); - } - - // next track start - - else - { - g_MusicPlayer.Play(); - } - - return; -} - - -//--------------------------------------------------------- -// initiate playback - - -void CMusic :: Play ( void ) -{ - if ( m_IsPlaying == TRUE ) - return; - - if ( m_bInit == FALSE ) - { - Init (); - - if ( m_bInit == FALSE ) - { - ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); - return; - } - } - - // search for the first song in the list - - audiofile_t *p = NULL; - p = m_pTrack; - - while ( p != NULL ) - { - if ( p->next == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); - return; - } - - //Stop playback - m_IsPlaying = FALSE; //Pause playback. - ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. - - // loading file - char payload [512]; - sprintf(payload, "%s", p->name); - - ALERT ( at_console, "MUSICPLAYER : Opening file %s.\n", payload ); - - result = ma_decoder_init_file(payload, NULL, &decoder); - if (result != MA_SUCCESS) { - ALERT ( at_console, "MUSICPLAYER : %s : can not load file\n", p->name ); - return; - } - - //If the new track has different properties to the previous one. - if( - deviceConfig.playback.format != decoder.outputFormat || - deviceConfig.playback.channels != decoder.outputChannels || - deviceConfig.sampleRate != decoder.outputSampleRate - ){ - deviceConfig.playback.format = decoder.outputFormat; //Change device settings - deviceConfig.playback.channels = decoder.outputChannels; - deviceConfig.sampleRate = decoder.outputSampleRate; - - ALERT ( at_console, "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate); - - //Now we need to recreate the device to apply. - ma_device_uninit(&device); //This is crucial, failing to do this results in segFault. - if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config. - ALERT ( at_console, "MUSICPLAYER : Failed to change playback device configuration.\n" ); - g_MusicPlayer.m_bInit = FALSE; //We have been deinitialized. This is NOT ideal. - return; - }else - ALERT ( at_console, "MUSICPLAYER : New configuration applied successfully.\n"); - } - - // playback - if (ma_device_start(&device) != MA_SUCCESS) { - ALERT ( at_console, "MUSICPLAYER : Failed to start playback device.\n" ); - m_IsPlaying = FALSE; //Pause playback. - ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. - return; - }else{ - m_IsPlaying = TRUE; - } - - return; -} - - -void CMusic :: Stop ( void ) -{ - if ( m_IsPlaying == TRUE ) - { - m_IsPlaying = FALSE; //Pause playback. - ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. - } -} - - -void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming. -{ - //Reset the player. - if ( m_bInit == TRUE ) - ALERT ( at_console, "MUSICPLAYER : Player reset.\n" ); - - Stop(); - - audiofile_t *p = NULL; - - while ( m_pTrack != NULL ) - { - p = m_pTrack; - m_pTrack = p->next; - delete p; - } -} - -void CMusic :: Terminate ( void ) //Cleanup and dereference -{ - ALERT ( at_console, "MUSICPLAYER : Terminating and unloading.\n" ); - ma_device_uninit(&device); - ma_decoder_uninit(&decoder); - g_MusicPlayer.m_bInit = FALSE; -} - - -//--------------------------------------------------------- -// entity class - - - -class CTriggerMusic : public CPointEntity -{ -public: - - void Spawn ( void ); - - void KeyValue ( KeyValueData *pkvd ); - void Use ( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); - - - virtual int Save ( CSave &save ); - virtual int Restore ( CRestore &restore ); - - - static TYPEDESCRIPTION m_SaveData[]; - - - string_t m_iFileName; // file path - int m_iFileType; // text file (list) or audio file - -}; - -LINK_ENTITY_TO_CLASS( trigger_music, CTriggerMusic ); - - - -TYPEDESCRIPTION CTriggerMusic::m_SaveData[] = -{ - DEFINE_FIELD( CTriggerMusic, m_iFileType, FIELD_INTEGER ), - DEFINE_FIELD( CTriggerMusic, m_iFileName, FIELD_STRING ), -}; - -IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); - - - -void CTriggerMusic :: Spawn( void ) -{ - pev->solid = SOLID_NOT; - pev->effects = EF_NODRAW; - -} - -void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) -{ - if (FStrEq(pkvd->szKeyName, "filetype")) - { - m_iFileType = atoi(pkvd->szValue); - pkvd->fHandled = TRUE; - } - else if (FStrEq(pkvd->szKeyName, "filename")) - { - m_iFileName = ALLOC_STRING(pkvd->szValue); - pkvd->fHandled = TRUE; - } - else - CPointEntity::KeyValue( pkvd ); -} - -void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) -{ - if ( g_MusicPlayer.m_IsPlaying == TRUE ) - return; - - if ( m_iFileType == MUSIC_AUDIO_FILE ) - { - g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 ); - } - else - { - g_MusicPlayer.OpenList ( STRING(m_iFileName) ); - } - - g_MusicPlayer.Play(); -} - - - - - - - -/* -code - - -@PointClass base( Targetname ) = trigger_music : "Trigger Music" -[ - filetype(choices) : "File type" : 0 = - [ - 0: "File list (*.txt)" - 1: "File wav mp2 mp3 ogg raw" - ] - filename(string) : "Name (mod/folder/file.extension)" -] - -*/ - - -/*//--------------- -Playlist contents - -example: music01.txt file: - -// - -3 - -monmod/sound/mp3/music01_debut.mp3 1 -monmod/sound/mp3/music01_boucle.mp3 3 -monmod/sound/mp3/music01_fin.mp3 1 - - -// - -composition : - - total number of tracks - - path of the first music file - - times to repeat that file - - path of the second - - etc ... - -*///--------------- diff --git a/dlls/musicminiaudio.h b/dlls/musicminiaudio.h deleted file mode 100644 index 7bf49431..00000000 --- a/dlls/musicminiaudio.h +++ /dev/null @@ -1,83 +0,0 @@ -//------------------------------------------------------------- -//------------------------------------------------------------- -//- -//- musicminiaudio.h -//- -//------------------------------------------------------------- -//------------------------------------------------------------- -//- by Roy at suggestion by nekonomicon, based on code by JujU -//------------------------------------------------------------- -//- mp3 player code for HL mod -//------------------------------------------------------------- -//- -//- compatible with version 0.11.9 of Miniaudio -//- https://github.com/mackron/miniaudio -//- -//------------------------------------------------------------- - -#ifndef MUSIC_H -#define MUSIC_H - -#define MINIAUDIO_IMPLEMENTATION -#include "../miniaudio/miniaudio.h" - -//--------------------------------------------------------- -// defines - -#define MUSIC_AUDIO_FILE 1 -#define MUSIC_LIST_FILE 0 - -//--------------------------------------------------------- -// audio file structure - -struct audiofile_t -{ - char name [128]; - int repeat; - audiofile_t *next; -}; - -//--------------------------------------------------------- -// reader class - - -class CMusic -{ -public: - - // reading functions - - void OpenFile ( const char *filename, int repeat ); // open a single file - void OpenList ( const char *filename ); // opening a text file containing the files - - void Init ( void ); // initialization - - void Play ( void ); // playback - void Stop ( void ); // stop - void Reset ( void ); // pause and switch to next track - void Terminate ( void ); // clean-up during termination - - // variables - - BOOL m_IsPlaying; // monitors whether the music is played, used to pause the music - BOOL m_bInit; // checks if the player is initialized - - audiofile_t *m_pTrack; // playlist items - - // constructor / destructor - - CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); }; - ~CMusic () { Terminate(); }; - - // object instances - - ma_result result; - ma_decoder decoder; - ma_device_config deviceConfig; - ma_device device; - - void songEnd(); -}; - -extern CMusic g_MusicPlayer; -#endif // MUSIC_H From 3e62e6b719f8bcae8732d1de1c8476b28c054249 Mon Sep 17 00:00:00 2001 From: Roy Shapiro <70241434+RoyShapiro@users.noreply.github.com> Date: Tue, 12 Jul 2022 14:34:50 +0300 Subject: [PATCH 3/4] HL:Invasion Move music player to the client side --- cl_dll/CMakeLists.txt | 5 + cl_dll/clientmusic.cpp | 443 +++++++++++++++++++++++++++ dlls/music.h => cl_dll/clientmusic.h | 26 +- cl_dll/hud.cpp | 1 + cl_dll/hud.h | 9 +- dlls/CMakeLists.txt | 4 - dlls/music.cpp | 419 +------------------------ dlls/player.cpp | 2 + 8 files changed, 488 insertions(+), 421 deletions(-) create mode 100644 cl_dll/clientmusic.cpp rename dlls/music.h => cl_dll/clientmusic.h (74%) diff --git a/cl_dll/CMakeLists.txt b/cl_dll/CMakeLists.txt index c14466aa..1aa317fd 100644 --- a/cl_dll/CMakeLists.txt +++ b/cl_dll/CMakeLists.txt @@ -46,6 +46,10 @@ if (GOLDSOURCE_SUPPORT) add_definitions(-DGOLDSOURCE_SUPPORT) endif() +if (DISABLE_MINIAUDIO) + add_definitions(-DDISABLE_MINIAUDIO) +endif() + if (USE_VGUI) add_definitions(-DUSE_VGUI) if (USE_NOVGUI_MOTD) @@ -73,6 +77,7 @@ set (CLDLL_SOURCES hudzoom.cpp lensflare.cpp nvg.cpp + clientmusic.cpp particules.cpp studio_util.cpp StudioModelRenderer.cpp diff --git a/cl_dll/clientmusic.cpp b/cl_dll/clientmusic.cpp new file mode 100644 index 00000000..000d1277 --- /dev/null +++ b/cl_dll/clientmusic.cpp @@ -0,0 +1,443 @@ +//------------------------------------------------------------- +//------------------------------------------------------------- +//- +//- clientmusic.cpp +//- +//------------------------------------------------------------- +//------------------------------------------------------------- +//- by Roy at suggestion by nekonomicon, based on code by JujU +//------------------------------------------------------------- +//- mp3 player code for HL mod +//------------------------------------------------------------- +//- +//- compatible with version 0.11.9 of Miniaudio +//- https://github.com/mackron/miniaudio +//- +//------------------------------------------------------------- + +/* +Don't forget to update the miniaudio submodule. + +Miniaudio 0.11.9 or better required. + +Tested on Debian. + +For playlist format see the bottom of the file. +*/ + + + +//--------------------------------------------------------- +// inclusions + + +#include "hud.h" +#include "cl_util.h" +#include "const.h" +#include "parsemsg.h" + +#ifndef DISABLE_MINIAUDIO //Use this to exclude the player in it's entirety. Will use empty "trigger_music" with no playback. +#include "clientmusic.h" + +CMusic g_MusicPlayer; //Instantiate. + +//These are just initial ones. If the actual track has different ones, they will be re-applied during Play(). +#define SAMPLE_FORMAT ma_format_f32 +#define CHANNEL_COUNT 2 +#define SAMPLE_RATE 48000 + +//--------------------------------------------------------- +// implementation CHudMusic class methods (defined in hud.h) + +//CHudMusic is declared in hud.h and is needed to receive messages. +//hud.cpp also contains and Init function call. +//The implementation goes here: + +#endif //The code above can be disabled if we don't actually use a music player, but this +//section here must be present anyway, since we need to implement things hud.h and hud.cpp +//expect us to implement. + +DECLARE_MESSAGE(m_MusicPlayer, CMusicOpen ); + +int CHudMusic :: Init( void ){ + HOOK_MESSAGE( CMusicOpen ); + return 1; +} + +int CHudMusic :: MsgFunc_CMusicOpen ( const char *pszName, int iSize, void *pbuf ){ + + char* fnString; + char filename[512]; + int filetype = 0; + + BEGIN_READ( pbuf, iSize ); + filetype = READ_BYTE(); + fnString = READ_STRING(); + + sprintf(filename,"%s",fnString); + +#ifndef DISABLE_MINIAUDIO //This part must only be present if we actually have a music player. + //gEngfuncs.Con_Printf ( "MUSICPLAYER : Received message from server: File type is %d, file name is: %s\n", filetype, filename ); + + if(filetype != MUSIC_AUDIO_FILE) + g_MusicPlayer.OpenList ( filename ); + else + g_MusicPlayer.OpenFile ( filename, 1 ); + g_MusicPlayer.Play(); + +#else //Otherwise we do nothing here. + //gEngfuncs.Con_Printf ( "MUSICPLAYER : Received message, but player is disabled. Discarding.\n" ); +#endif + + return 1; +} + +#ifndef DISABLE_MINIAUDIO //The code below can, once again, be disabled if we don't +//actually use a music player. + +//Define callback, so we can use it during init. The implementation can be found below. +void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); + +//--------------------------------------------------------- +// initialisation + +void CMusic :: Init ( void ) +{ + if( m_bInit == true ){ + return; //Do not re-init. + } + + deviceConfig = ma_device_config_init(ma_device_type_playback); + deviceConfig.playback.format = SAMPLE_FORMAT; + deviceConfig.playback.channels = CHANNEL_COUNT; + deviceConfig.sampleRate = SAMPLE_RATE; + deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song + deviceConfig.pUserData = NULL; + + if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { + gEngfuncs.Con_Printf ( "MUSICPLAYER : unable to initialize\n" ); + return; + } + + m_bInit = true; + return; +} + +//--------------------------------------------------------- +// Callback being called during playback + +void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) +{ + if(g_MusicPlayer.m_IsPlaying == false){ + return; //We are paused or stopped, let's exit now. + } + + ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder; + if (pDecoder == NULL) { + return; + } + + if(frameCount<=0) return; + + ma_uint64 framesRead; + + ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead); + if(framesRead < frameCount) //This happens when the song ends. + g_MusicPlayer.songEnd(); + + (void)pInput; +} + +//--------------------------------------------------------- +// playing an audio file + + +void CMusic :: OpenFile ( char *filename, int repeat ) +{ + audiofile_t *p = NULL; + p = new audiofile_t; + + sprintf ( p->name, filename ); + p->repeat = repeat; + p->next = m_pTrack; + + m_pTrack = p; +} + + + +//--------------------------------------------------------- +// play a list of audio files + + +void CMusic :: OpenList ( char *filename ) +{ + + // open text file + + FILE *myfile = fopen ( filename, "r" ); + + if ( myfile == NULL ) + { + gEngfuncs.Con_Printf ( "MUSICPLAYER : impossible to load %s\n", filename ); + return; + } + + // saving songs to the list + + int total = 0; + + if ( fscanf ( myfile, "%i", &total ) != EOF ) + { + for ( int i=0; inext == NULL ) + break; + else + p = p->next; + } + + if ( p == NULL ) + { + gEngfuncs.Con_Printf ( "MUSICPLAYER : no song in the list\n" ); + return; + } + + // decrease repeat count + + p->repeat --; + + // removal of songs whose repeats ran off + + if ( p->repeat < 1 ) + { + if ( g_MusicPlayer.m_pTrack == p ) + { + delete g_MusicPlayer.m_pTrack; + g_MusicPlayer.m_pTrack = NULL; + } + else + { + audiofile_t *q = NULL; + q = g_MusicPlayer.m_pTrack; + + while ( q->next != p ) + q = q->next; + + delete q->next; + q->next = NULL; + } + } + + // close player if list is empty + + if ( g_MusicPlayer.m_pTrack == NULL ) + { + g_MusicPlayer.Reset(); + } + + // next track start + + else + { + g_MusicPlayer.Play(); + } + + return; +} + + +//--------------------------------------------------------- +// initiate playback + + +void CMusic :: Play ( void ) +{ + if ( m_IsPlaying == true ) + return; + + if ( m_bInit == false ) + { + Init (); + + if ( m_bInit == false ) + { + gEngfuncs.Con_Printf ( "MUSICPLAYER : unable to initialize\n" ); + return; + } + } + + // search for the first song in the list + + audiofile_t *p = NULL; + p = m_pTrack; + + while ( p != NULL ) + { + if ( p->next == NULL ) + break; + else + p = p->next; + } + + if ( p == NULL ) + { + gEngfuncs.Con_Printf ( "MUSICPLAYER : no song in the list\n" ); + return; + } + + //Stop playback + m_IsPlaying = false; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + + // loading file + char payload [512]; + sprintf(payload, "%s", p->name); + + gEngfuncs.Con_Printf ( "MUSICPLAYER : Opening file %s.\n", payload ); + + result = ma_decoder_init_file(payload, NULL, &decoder); + if (result != MA_SUCCESS) { + gEngfuncs.Con_Printf ( "MUSICPLAYER : %s : can not load file\n", p->name ); + return; + } + + //If the new track has different properties to the previous one. + if( + deviceConfig.playback.format != decoder.outputFormat || + deviceConfig.playback.channels != decoder.outputChannels || + deviceConfig.sampleRate != decoder.outputSampleRate + ){ + deviceConfig.playback.format = decoder.outputFormat; //Change device settings + deviceConfig.playback.channels = decoder.outputChannels; + deviceConfig.sampleRate = decoder.outputSampleRate; + + gEngfuncs.Con_Printf ( "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate); + + //Now we need to recreate the device to apply. + ma_device_uninit(&device); //This is crucial, failing to do this results in segFault. + if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config. + gEngfuncs.Con_Printf ( "MUSICPLAYER : Failed to change playback device configuration.\n" ); + g_MusicPlayer.m_bInit = false; //We have been deinitialized. This is NOT ideal. + return; + }else + gEngfuncs.Con_Printf ( "MUSICPLAYER : New configuration applied successfully.\n"); + } + + // playback + if (ma_device_start(&device) != MA_SUCCESS) { + gEngfuncs.Con_Printf ( "MUSICPLAYER : Failed to start playback device.\n" ); + m_IsPlaying = false; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + return; + }else{ + m_IsPlaying = true; + } + + return; +} + + +void CMusic :: Stop ( void ) +{ + if ( m_IsPlaying == true ) + { + m_IsPlaying = false; //Pause playback. + ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. + } +} + + +void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming. +{ + //Reset the player. + if ( m_bInit == true ) + gEngfuncs.Con_Printf ( "MUSICPLAYER : Player reset.\n" ); + + Stop(); + + audiofile_t *p = NULL; + + while ( m_pTrack != NULL ) + { + p = m_pTrack; + m_pTrack = p->next; + delete p; + } +} + +void CMusic :: Terminate ( void ) //Cleanup and dereference +{ + gEngfuncs.Con_Printf ( "MUSICPLAYER : Terminating and unloading.\n" ); + ma_device_uninit(&device); + ma_decoder_uninit(&decoder); + g_MusicPlayer.m_bInit = false; +} + +#endif //End if #ifndef DISABLE_MINIAUDIO + +/*//--------------- +Playlist contents + +example: music01.txt file: + +// + +3 + +monmod/sound/mp3/music01_debut.mp3 1 +monmod/sound/mp3/music01_boucle.mp3 3 +monmod/sound/mp3/music01_fin.mp3 1 + + +// + +composition : + - total number of tracks + - path of the first music file + - times to repeat that file + - path of the second + - etc ... + +*///--------------- diff --git a/dlls/music.h b/cl_dll/clientmusic.h similarity index 74% rename from dlls/music.h rename to cl_dll/clientmusic.h index e6e8bf44..0174837f 100644 --- a/dlls/music.h +++ b/cl_dll/clientmusic.h @@ -1,7 +1,7 @@ //------------------------------------------------------------- //------------------------------------------------------------- //- -//- music.h +//- clientmusic.h //- //------------------------------------------------------------- //------------------------------------------------------------- @@ -15,8 +15,8 @@ //- //------------------------------------------------------------- -#ifndef MUSIC_H -#define MUSIC_H +#ifndef CLIENTMUSIC_H +#define CLIENTMUSIC_H #define MINIAUDIO_IMPLEMENTATION #include "../miniaudio/miniaudio.h" @@ -41,14 +41,14 @@ struct audiofile_t // reader class -class CMusic +class CMusic //: public CHudBase { public: // reading functions - void OpenFile ( const char *filename, int repeat ); // open a single file - void OpenList ( const char *filename ); // opening a text file containing the files + void OpenFile ( char *filename, int repeat ); // open a single file + void OpenList ( char *filename ); // opening a text file containing the files void Init ( void ); // initialization @@ -59,14 +59,14 @@ public: // variables - BOOL m_IsPlaying; // monitors whether the music is played, used to pause the music - BOOL m_bInit; // checks if the player is initialized + bool m_IsPlaying; // monitors whether the music is played, used to pause the music + bool m_bInit; // checks if the player is initialized audiofile_t *m_pTrack; // playlist items // constructor / destructor - CMusic () { m_bInit = FALSE; m_IsPlaying = FALSE; m_pTrack = NULL; Reset(); }; + CMusic () { m_bInit = false; m_IsPlaying = false; m_pTrack = NULL; Reset(); }; ~CMusic () { Terminate(); }; // object instances @@ -76,8 +76,14 @@ public: ma_device_config deviceConfig; ma_device device; + // messages + + int MsgFunc_CMusicOpen ( const char *pszName, int iSize, void *pbuf ); + + // monitoring functions + void songEnd(); }; extern CMusic g_MusicPlayer; -#endif // MUSIC_H +#endif // CLIENTMUSIC_H diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index 8a15a89c..e3e6254c 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -469,6 +469,7 @@ void CHud::Init( void ) m_Particules.Init(); m_Sniper.Init(); m_NVG.Init(); + m_MusicPlayer.Init(); //modif de Roy, we need to initialize the music player's message receiver (see hud.h) m_RPG.Init(); m_Fog.Init(); m_LFlammes.Init(); diff --git a/cl_dll/hud.h b/cl_dll/hud.h index 08517811..ceb06295 100644 --- a/cl_dll/hud.h +++ b/cl_dll/hud.h @@ -801,7 +801,13 @@ public: }; - +// modif de Roy +class CHudMusic : public CHudBase // This class is simply a message receiver for the music player +{ +public: //The methods are implemented in clientmusic.cpp + int Init( void ); //This gets called from hud.cpp + int MsgFunc_CMusicOpen ( const char *pszName, int iSize, void *pbuf ); +}; // modif de Julien // @@ -1078,6 +1084,7 @@ public: CHudParticules m_Particules; CHudSniper m_Sniper; CHudNVG m_NVG; + CHudMusic m_MusicPlayer; //modif de Roy, we need an instance of the music player's message receiver CHudRPG m_RPG; CHudFog m_Fog; CHudLFlammes m_LFlammes; diff --git a/dlls/CMakeLists.txt b/dlls/CMakeLists.txt index 7fc609e6..2e6c959d 100644 --- a/dlls/CMakeLists.txt +++ b/dlls/CMakeLists.txt @@ -37,10 +37,6 @@ else() add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) endif() -if (DISABLE_MINIAUDIO) - add_definitions(-DDISABLE_MINIAUDIO) -endif() - set (SVDLL_SOURCES aflock.cpp agrunt.cpp diff --git a/dlls/music.cpp b/dlls/music.cpp index daf53817..b605fc55 100644 --- a/dlls/music.cpp +++ b/dlls/music.cpp @@ -7,365 +7,26 @@ //------------------------------------------------------------- //- by Roy at suggestion by nekonomicon, based on code by JujU //------------------------------------------------------------- -//- mp3 player code for HL mod +//- mp3 player code for HL mod; trigger_music implementation //------------------------------------------------------------- //- -//- compatible with version 0.11.9 of Miniaudio -//- https://github.com/mackron/miniaudio +//- This is the server-side code. +//- It implements trigger_music, which simply informs the +//- client when and what music needs to be played. +//- No actual playback happens here. +//- We just send a message containing file type and filename. //- //------------------------------------------------------------- -/* -Don't forget to update the miniaudio submodule. - -Miniaudio 0.11.9 or better required. - -Tested on Debian. - -For playlist format see the bottom of the file. -*/ - - - //--------------------------------------------------------- // inclusions #include "extdll.h" #include "util.h" #include "cbase.h" -#include "gamerules.h" //We need g_pGameRules to determine if we're in multiplayer. -#ifndef DISABLE_MINIAUDIO //Use this to exclude the player in it's entirety. Will use empty "trigger_music" with no playback. -#include "music.h" +extern int gmsgCMusicMessage; //This is simply a "handle" for the message. It's defined in player.cpp, can be defined here, but we'll follow the conventions. -//These are just initial ones. If the actual track has different ones, they will be re-applied during Play(). -#define SAMPLE_FORMAT ma_format_f32 -#define CHANNEL_COUNT 2 -#define SAMPLE_RATE 48000 - -CMusic g_MusicPlayer; -void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); - -//--------------------------------------------------------- -// initialisation - -void CMusic :: Init ( void ) -{ - - if( m_bInit == TRUE ){ - return; //Do not re-init. - } - - deviceConfig = ma_device_config_init(ma_device_type_playback); - deviceConfig.playback.format = SAMPLE_FORMAT; - deviceConfig.playback.channels = CHANNEL_COUNT; - deviceConfig.sampleRate = SAMPLE_RATE; - deviceConfig.dataCallback = CMusic_DecoderCallback; // this contains the callback that monitors the end of the song - deviceConfig.pUserData = NULL; - - if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { - ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); - return; - } - - m_bInit = TRUE; -} - - - - -//--------------------------------------------------------- -// Callback being called during playback - -void CMusic_DecoderCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) -{ - if(g_MusicPlayer.m_IsPlaying == FALSE){ - return; //We are paused or stopped, let's exit now. - } - - ma_decoder* pDecoder = (ma_decoder*)&g_MusicPlayer.decoder; - if (pDecoder == NULL) { - return; - } - - if(frameCount<=0) return; - - ma_uint64 framesRead; - - ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount, &framesRead); - if(framesRead < frameCount) //This happens when the song ends. - g_MusicPlayer.songEnd(); - - (void)pInput; -} - -//--------------------------------------------------------- -// playing an audio file - - -void CMusic :: OpenFile ( const char *filename, int repeat ) -{ - audiofile_t *p = NULL; - p = new audiofile_t; - - sprintf ( p->name, filename ); - p->repeat = repeat; - p->next = m_pTrack; - - m_pTrack = p; -} - - - -//--------------------------------------------------------- -// play a list of audio files - - -void CMusic :: OpenList ( const char *filename ) -{ - - // open text file - - FILE *myfile = fopen ( filename, "r" ); - - if ( myfile == NULL ) - { - ALERT ( at_console, "MUSICPLAYER : impossible to load %s\n", filename ); - return; - } - - // saving songs to the list - - int total = 0; - - if ( fscanf ( myfile, "%i", &total ) != EOF ) - { - for ( int i=0; inext == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); - return; - } - - // decrease repeat count - - p->repeat --; - - // removal of songs whose repeats ran off - - if ( p->repeat < 1 ) - { - if ( g_MusicPlayer.m_pTrack == p ) - { - delete g_MusicPlayer.m_pTrack; - g_MusicPlayer.m_pTrack = NULL; - } - else - { - audiofile_t *q = NULL; - q = g_MusicPlayer.m_pTrack; - - while ( q->next != p ) - q = q->next; - - delete q->next; - q->next = NULL; - } - } - - // close player if list is empty - - if ( g_MusicPlayer.m_pTrack == NULL ) - { - g_MusicPlayer.Reset(); - } - - // next track start - - else - { - g_MusicPlayer.Play(); - } - - return; -} - - -//--------------------------------------------------------- -// initiate playback - - -void CMusic :: Play ( void ) -{ - if ( m_IsPlaying == TRUE ) - return; - - if ( m_bInit == FALSE ) - { - Init (); - - if ( m_bInit == FALSE ) - { - ALERT ( at_console, "MUSICPLAYER : unable to initialize\n" ); - return; - } - } - - // search for the first song in the list - - audiofile_t *p = NULL; - p = m_pTrack; - - while ( p != NULL ) - { - if ( p->next == NULL ) - break; - else - p = p->next; - } - - if ( p == NULL ) - { - ALERT ( at_console, "MUSICPLAYER : no song in the list\n" ); - return; - } - - //Stop playback - m_IsPlaying = FALSE; //Pause playback. - ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. - - // loading file - char payload [512]; - sprintf(payload, "%s", p->name); - - ALERT ( at_console, "MUSICPLAYER : Opening file %s.\n", payload ); - - result = ma_decoder_init_file(payload, NULL, &decoder); - if (result != MA_SUCCESS) { - ALERT ( at_console, "MUSICPLAYER : %s : can not load file\n", p->name ); - return; - } - - //If the new track has different properties to the previous one. - if( - deviceConfig.playback.format != decoder.outputFormat || - deviceConfig.playback.channels != decoder.outputChannels || - deviceConfig.sampleRate != decoder.outputSampleRate - ){ - deviceConfig.playback.format = decoder.outputFormat; //Change device settings - deviceConfig.playback.channels = decoder.outputChannels; - deviceConfig.sampleRate = decoder.outputSampleRate; - - ALERT ( at_console, "MUSICPLAYER : Changing format to %d, channels to %d and sample rate to %d.\n", deviceConfig.playback.format, deviceConfig.playback.channels, deviceConfig.sampleRate); - - //Now we need to recreate the device to apply. - ma_device_uninit(&device); //This is crucial, failing to do this results in segFault. - if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { //Apply new config. - ALERT ( at_console, "MUSICPLAYER : Failed to change playback device configuration.\n" ); - g_MusicPlayer.m_bInit = FALSE; //We have been deinitialized. This is NOT ideal. - return; - }else - ALERT ( at_console, "MUSICPLAYER : New configuration applied successfully.\n"); - } - - // playback - if (ma_device_start(&device) != MA_SUCCESS) { - ALERT ( at_console, "MUSICPLAYER : Failed to start playback device.\n" ); - m_IsPlaying = FALSE; //Pause playback. - ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. - return; - }else{ - m_IsPlaying = TRUE; - } - - return; -} - - -void CMusic :: Stop ( void ) -{ - if ( m_IsPlaying == TRUE ) - { - m_IsPlaying = FALSE; //Pause playback. - ma_decoder_seek_to_pcm_frame(&decoder, 0); //Reset the file to start. - } -} - - -void CMusic :: Reset ( void ) //Should instead be called "Next Track", but we keep Julien's naming. -{ - //Reset the player. - if ( m_bInit == TRUE ) - ALERT ( at_console, "MUSICPLAYER : Player reset.\n" ); - - Stop(); - - audiofile_t *p = NULL; - - while ( m_pTrack != NULL ) - { - p = m_pTrack; - m_pTrack = p->next; - delete p; - } -} - -void CMusic :: Terminate ( void ) //Cleanup and dereference -{ - ALERT ( at_console, "MUSICPLAYER : Terminating and unloading.\n" ); - ma_device_uninit(&device); - ma_decoder_uninit(&decoder); - g_MusicPlayer.m_bInit = FALSE; -} -#endif //End if #ifndef DISABLE_MINIAUDIO //--------------------------------------------------------- // entity class @@ -410,14 +71,8 @@ IMPLEMENT_SAVERESTORE( CTriggerMusic, CPointEntity ); void CTriggerMusic :: Spawn( void ) { - if( g_pGameRules->IsDeathmatch() ) //Do not spawn in multiplayer. - { - REMOVE_ENTITY( ENT( pev ) ); - return; - } pev->solid = SOLID_NOT; pev->effects = EF_NODRAW; - } void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) @@ -438,36 +93,14 @@ void CTriggerMusic :: KeyValue( KeyValueData *pkvd ) void CTriggerMusic :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { - if( g_pGameRules->IsMultiplayer() ) //Do not activate / do anything in multiplayer. - return; - -#ifndef DISABLE_MINIAUDIO - if ( g_MusicPlayer.m_IsPlaying == TRUE ) - return; - - if ( m_iFileType == MUSIC_AUDIO_FILE ) - { - g_MusicPlayer.OpenFile ( STRING(m_iFileName), 1 ); - } - else - { - g_MusicPlayer.OpenList ( STRING(m_iFileName) ); - } - - g_MusicPlayer.Play(); -#else - return; //Do nothing, we have neither g_MusicPlayer, nor miniaudio. -#endif + MESSAGE_BEGIN( MSG_ALL, gmsgCMusicMessage, NULL ); //Inform the client side, we have some music to play. + WRITE_BYTE( m_iFileType ); //Send file type. + WRITE_STRING( STRING(m_iFileName) ); //Send file name. + MESSAGE_END(); } - - - - - - /* -code +FGD file entity code @PointClass base( Targetname ) = trigger_music : "Trigger Music" @@ -480,30 +113,4 @@ code filename(string) : "Name (mod/folder/file.extension)" ] -*/ - - -/*//--------------- -Playlist contents - -example: music01.txt file: - -// - -3 - -monmod/sound/mp3/music01_debut.mp3 1 -monmod/sound/mp3/music01_boucle.mp3 3 -monmod/sound/mp3/music01_fin.mp3 1 - - -// - -composition : - - total number of tracks - - path of the first music file - - times to repeat that file - - path of the second - - etc ... - -*///--------------- +*/ \ No newline at end of file diff --git a/dlls/player.cpp b/dlls/player.cpp index 918e2d4c..392f3425 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -234,6 +234,7 @@ int gmsgTankView = 0; int gmsgRadioMsg = 0; int gmsgKeypad = 0; int gmsgConveyor = 0; +int gmsgCMusicMessage = 0; //modif de Roy, Used by the music player to send filenames to the client side. void LinkUserMessages( void ) @@ -321,6 +322,7 @@ void LinkUserMessages( void ) gmsgKeypad = REG_USER_MSG( "Keypad", -1); gmsgConveyor = REG_USER_MSG( "Conveyor", -1); //fin de modifs de Julien + gmsgCMusicMessage = REG_USER_MSG( "CMusicOpen", -1 ); //modif de Roy, Used by the music player to send filenames to the client side. gmsgTeamNames = REG_USER_MSG( "TeamNames", -1 ); gmsgBhopcap = REG_USER_MSG( "Bhopcap", 1 ); From 98b0726bf848213cf8ba51685ebe2b69cd342c3f Mon Sep 17 00:00:00 2001 From: Roy Shapiro <70241434+RoyShapiro@users.noreply.github.com> Date: Tue, 12 Jul 2022 23:57:32 +0300 Subject: [PATCH 4/4] HL:Invasion Attempt to fix Win32 artifact auto-build --- cl_dll/clientmusic.h | 8 ++ cl_dll/hud_spectator.h | 11 -- cl_dll/view.cpp | 308 +---------------------------------------- 3 files changed, 15 insertions(+), 312 deletions(-) diff --git a/cl_dll/clientmusic.h b/cl_dll/clientmusic.h index 0174837f..dab59db5 100644 --- a/cl_dll/clientmusic.h +++ b/cl_dll/clientmusic.h @@ -19,7 +19,15 @@ #define CLIENTMUSIC_H #define MINIAUDIO_IMPLEMENTATION + +#if _WIN32 +#define HSPRITE WINDOWS_HSPRITE //Apparently miniaudio introduces a win32 conflict here. +#endif #include "../miniaudio/miniaudio.h" +#if _WIN32 +#undef HSPRITE +#endif + //--------------------------------------------------------- // defines diff --git a/cl_dll/hud_spectator.h b/cl_dll/hud_spectator.h index 79cd3738..800928e0 100644 --- a/cl_dll/hud_spectator.h +++ b/cl_dll/hud_spectator.h @@ -17,12 +17,6 @@ #define INSET_MAP_FREE 3 #define INSET_MAP_CHASE 4 -#define MAIN_CHASE_LOCKED 1 //modif de Julien o para Julien, old map definitions. -#define MAIN_CHASE_FREE 2 -#define MAIN_ROAMING 3 -#define MAIN_IN_EYE 4 -#define MAIN_MAP_FREE 5 - #define MAX_SPEC_HUD_MESSAGES 8 #define OVERVIEW_TILE_SIZE 128 // don't change this @@ -87,11 +81,6 @@ public: int Draw( float flTime ); - int m_iMainMode; //modif de Julien o para Julien - int m_iInsetMode; //old stuff HLINVASION TODO Check what this stuff actually does - int m_iObserverTarget; //and more old stuff. (Not observerFlags!) - vec3_t m_mapAngles; // cuurent map view angles (cameraAngles?) - int m_iDrawCycle; client_textmessage_t m_HUDMessages[MAX_SPEC_HUD_MESSAGES]; char m_HUDMessageText[MAX_SPEC_HUD_MESSAGES][128]; diff --git a/cl_dll/view.cpp b/cl_dll/view.cpp index d83f0e3d..789a1fe3 100644 --- a/cl_dll/view.cpp +++ b/cl_dll/view.cpp @@ -35,7 +35,6 @@ // modif de Julien extern float in_fov; - // Spectator Mode extern "C" { @@ -123,7 +122,6 @@ cvar_t v_ipitch_level = {"v_ipitch_level", "0.3", 0, 0.3}; float v_idlescale; // used by TFC for concussion grenade effect -/* //============================================================================= /* void V_NormalizeAngles( float *angles ) @@ -569,21 +567,9 @@ void V_CalcNormalRefdef( struct ref_params_s *pparams ) AngleVectors( camAngles, camForward, camRight, camUp ); - -/* // modif de Julien - if ( gHUD.m_HudTank.m_iPlayerInTank == true ) + for( i = 0; i < 3; i++ ) { - VectorCopy( gEngfuncs.GetEntityByIndex( gHUD.m_HudTank.m_iCamEnt - 1 )->origin, pparams->vieworg ); - - for ( i = 0; i < 3; i++ ) - pparams->vieworg[ i ] += -ofs[2] * camForward[ i ]; - } - else*/ - { - for ( i = 0; i < 3; i++ ) - { - pparams->vieworg[ i ] += -ofs[2] * camForward[ i ]; - } + pparams->vieworg[i] += -ofs[2] * camForward[i]; } } @@ -753,7 +739,7 @@ void V_CalcNormalRefdef( struct ref_params_s *pparams ) VectorCopy( camAngles, pparams->viewangles ); } - // Apply this at all times //HLINVASION Julien --> This whole section was only in the ThirdPerson if block above in Julien's code. + // Apply this at all times { float pitch = camAngles[0]; @@ -803,286 +789,6 @@ void V_CalcNormalRefdef( struct ref_params_s *pparams ) if ( in_fov != 0 && in_fov != 90 ) view->model = NULL; - -} - - -void V_GetInEyePos(int entity, float *origin, float * angles ) -{ - cl_entity_t * ent = gEngfuncs.GetEntityByIndex( entity ); - - if ( !ent ) - return; - - if ( !ent->player || g_PlayerInfoList[entity].name == NULL ) - return; - - VectorCopy ( ent->origin, origin ); - VectorCopy ( ent->angles, angles ); - - angles[0]*=-M_PI; - - if ( ent->curstate.solid == SOLID_NOT ) - { - angles[ROLL] = 80; // dead view angle - origin[2]+= -8 ; // PM_DEAD_VIEWHEIGHT - } - else if (ent->curstate.usehull == 1 ) - origin[2]+= 12; // VEC_DUCK_VIEW; - else - // exacty eye position can't be caluculated since it depends on - // client values like cl_bobcycle, this offset matches the default values - origin[2]+= 28; // DEFAULT_VIEWHEIGHT -} - -/* -================== -V_CalcSpectatorRefdef - -================== -*/ -void V_CalcSpectatorRefdef ( struct ref_params_s *pparams ) -{ - cl_entity_t *ent, *view; - vec3_t angles; - static viewinterp_t ViewInterp; - - static float lasttime; - - static float lastang[3]; - static float lastorg[3]; - - vec3_t delta; - - - // ent is the player model ( visible when out of body ) - ent = gEngfuncs.GetLocalPlayer(); - - // view is the weapon model (only visible from inside body ) - view = gEngfuncs.GetViewModel(); - - - // refresh position - VectorCopy ( pparams->simorg, pparams->vieworg ); - - // done all the spectator smoothing only once in the first frame - - // Observer angle capturing and smoothing - if ( iHasNewViewOrigin ) - { - // Get the angles from the physics code - VectorCopy( vecNewViewOrigin, pparams->vieworg ); - } - else - { - // otherwise copy normal vieworigin into vecNewViewOrigin - VectorCopy( pparams->vieworg, vecNewViewOrigin ); - } - - VectorCopy ( pparams->cl_viewangles, pparams->viewangles ); - - // Observer angle capturing and smoothing - if ( iHasNewViewAngles ) - { - // Get the angles from the physics code - VectorCopy( vecNewViewAngles, pparams->viewangles ); - } - else - { - // otherwise copy normal viewangle into vewNewViewAngles - VectorCopy( pparams->viewangles, vecNewViewAngles); - } - - // do the smoothing only once per frame - if (pparams->nextView == 0) - { - // smooth angles - - VectorSubtract( pparams->viewangles, lastang, delta ); - if ( Length( delta ) != 0.0f ) - { - VectorCopy( pparams->viewangles, ViewInterp.Angles[ ViewInterp.CurrentAngle & ORIGIN_MASK ] ); - ViewInterp.AngleTime[ ViewInterp.CurrentAngle & ORIGIN_MASK ] = pparams->time; - ViewInterp.CurrentAngle++; - VectorCopy( pparams->viewangles, lastang ); - } - - if ( cl_vsmoothing && cl_vsmoothing->value && ( iIsSpectator & SPEC_SMOOTH_ANGLES ) ) - { - int foundidx; - int i; - float t; - - t = pparams->time - cl_vsmoothing->value; - - for ( i = 1; i < ORIGIN_MASK; i++ ) - { - foundidx = ViewInterp.CurrentAngle - 1 - i; - if ( ViewInterp.AngleTime[ foundidx & ORIGIN_MASK ] <= t ) - break; - } - - if ( i < ORIGIN_MASK && ViewInterp.AngleTime[ foundidx & ORIGIN_MASK ] != 0.0 ) - { - // Interpolate - double dt; - float da; - vec3_t v1,v2; - - AngleVectors( ViewInterp.Angles[ foundidx & ORIGIN_MASK ], v1, NULL, NULL ); - AngleVectors( ViewInterp.Angles[ (foundidx + 1) & ORIGIN_MASK ], v2, NULL, NULL ); - da = AngleBetweenVectors( v1, v2 ); - - dt = ViewInterp.AngleTime[ (foundidx + 1) & ORIGIN_MASK ] - ViewInterp.AngleTime[ foundidx & ORIGIN_MASK ]; - - if ( dt > 0.0 && ( da < 22.5f) ) - { - double frac; - - frac = ( t - ViewInterp.AngleTime[ foundidx & ORIGIN_MASK] ) / dt; - frac = Q_min( 1.0, frac ); - - // interpolate angles - InterpolateAngles( ViewInterp.Angles[ foundidx & ORIGIN_MASK ], ViewInterp.Angles[ (foundidx + 1) & ORIGIN_MASK ], vecNewViewAngles, frac ); - VectorCopy( vecNewViewAngles, pparams->viewangles ); - } - } - } - - // smooth origin - - VectorSubtract( pparams->vieworg, lastorg, delta ); - - if ( Length( delta ) != 0.0 ) - { - VectorCopy( pparams->vieworg, ViewInterp.Origins[ ViewInterp.CurrentOrigin & ORIGIN_MASK ] ); - ViewInterp.OriginTime[ ViewInterp.CurrentOrigin & ORIGIN_MASK ] = pparams->time; - ViewInterp.CurrentOrigin++; - - VectorCopy( pparams->vieworg, lastorg ); - } - - if ( cl_vsmoothing && cl_vsmoothing->value && ( iIsSpectator & SPEC_SMOOTH_ORIGIN ) ) - { - int foundidx; - int i; - float t; - - t = pparams->time - cl_vsmoothing->value; - - for ( i = 1; i < ORIGIN_MASK; i++ ) - { - foundidx = ViewInterp.CurrentOrigin - 1 - i; - if ( ViewInterp.OriginTime[ foundidx & ORIGIN_MASK ] <= t ) - break; - } - - if ( i < ORIGIN_MASK && ViewInterp.OriginTime[ foundidx & ORIGIN_MASK ] != 0.0 ) - { - // Interpolate - vec3_t delta; - double frac; - double dt; - vec3_t neworg; - - dt = ViewInterp.OriginTime[ (foundidx + 1) & ORIGIN_MASK ] - ViewInterp.OriginTime[ foundidx & ORIGIN_MASK ]; - if ( dt > 0.0 ) - { - frac = ( t - ViewInterp.OriginTime[ foundidx & ORIGIN_MASK] ) / dt; - frac = Q_min( 1.0, frac ); - VectorSubtract( ViewInterp.Origins[ ( foundidx + 1 ) & ORIGIN_MASK ], ViewInterp.Origins[ foundidx & ORIGIN_MASK ], delta ); - VectorMA( ViewInterp.Origins[ foundidx & ORIGIN_MASK ], frac, delta, neworg ); - - // Dont interpolate large changes - if ( Length( delta ) < 64 ) - { - VectorSubtract( neworg, pparams->simorg, delta ); - - VectorAdd( pparams->vieworg, delta, pparams->vieworg ); - VectorCopy( pparams->vieworg, vecNewViewOrigin ); - } - } - } - } - } - - - - - lasttime = pparams->time; - - view->model = NULL; - - if ( pparams->nextView == 0 ) - { - // first renderer cycle - - switch (gHUD.m_Spectator.m_iMainMode) - { - case MAIN_MAP_FREE : pparams->onlyClientDraw = true; - - angles = pparams->cl_viewangles; - angles[0] = 51.25f + 38.75f*(angles[0]/90.0f); - - VectorCopy ( angles, gHUD.m_Spectator.m_mapAngles ); - - gHUD.m_Spectator.GetMapPosition( pparams->vieworg ); - VectorCopy ( angles, pparams->viewangles ); - break; - - case MAIN_IN_EYE : V_GetInEyePos( gHUD.m_Spectator.m_iObserverTarget, - pparams->vieworg, pparams->viewangles ); - - break; - - default : pparams->onlyClientDraw = false; - break; - } - - if ( gHUD.m_Spectator.m_iInsetMode != INSET_OFF ) - pparams->nextView = 1; // force a second renderer view - - gHUD.m_Spectator.m_iDrawCycle = 0; - - } - else - { - // second renderer cycle - - // set inset parameters - pparams->viewport[0] = XRES(gHUD.m_Spectator.m_OverviewData.insetWindowX); // change viewport to inset window - pparams->viewport[1] = YRES(gHUD.m_Spectator.m_OverviewData.insetWindowY); - pparams->viewport[2] = XRES(gHUD.m_Spectator.m_OverviewData.insetWindowWidth); - pparams->viewport[3] = YRES(gHUD.m_Spectator.m_OverviewData.insetWindowHeight); - pparams->nextView = 0; // on further view - pparams->onlyClientDraw = false; - - // override some settings in certain modes - switch (gHUD.m_Spectator.m_iInsetMode) - { - case INSET_MAP_FREE : pparams->onlyClientDraw = true; - - angles = pparams->cl_viewangles; - angles[0] = 51.25f + 38.75f*(angles[0]/90.0f); - - VectorCopy ( angles, gHUD.m_Spectator.m_mapAngles ); - - gHUD.m_Spectator.GetMapPosition( pparams->vieworg ); - - VectorCopy ( angles, pparams->viewangles ); - break; - - case INSET_IN_EYE : V_GetInEyePos( gHUD.m_Spectator.m_iObserverTarget, - pparams->vieworg, pparams->viewangles ); - - break; - } - - gHUD.m_Spectator.m_iDrawCycle = 1; - } - - v_angles = pparams->viewangles; - v_origin = pparams->vieworg; } void V_SmoothInterpolateAngles( float * startAngle, float * endAngle, float * finalAngle, float degreesPerSec ) @@ -1527,7 +1233,7 @@ void V_ResetChaseCam() v_resetCamera = true; } -/*void V_GetInEyePos( int target, float *origin, float *angles ) //Redefinition of the above //modif de Julien o para Julien +void V_GetInEyePos( int target, float *origin, float *angles ) { if( !target ) { @@ -1558,7 +1264,7 @@ void V_ResetChaseCam() // exacty eye position can't be caluculated since it depends on // client values like cl_bobcycle, this offset matches the default values origin[2] += 28.0f; // DEFAULT_VIEWHEIGHT -}*/ +} void V_GetMapFreePosition( float *cl_angles, float *origin, float *angles ) { @@ -1674,7 +1380,7 @@ V_CalcSpectatorRefdef ================== */ -/*void V_CalcSpectatorRefdef( struct ref_params_s * pparams ) //Redefinition of the above //modif de Julien o para Julien +void V_CalcSpectatorRefdef( struct ref_params_s * pparams ) { static vec3_t velocity( 0.0f, 0.0f, 0.0f ); @@ -1832,7 +1538,7 @@ V_CalcSpectatorRefdef VectorCopy( v_cl_angles, pparams->cl_viewangles ); VectorCopy( v_angles, pparams->viewangles ) VectorCopy( v_origin, pparams->vieworg ); -}*/ +} void DLLEXPORT V_CalcRefdef( struct ref_params_s *pparams ) {