Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************
- *
- * PROJECT: Multi Theft Auto v1.0
- * (Shared logic for modifications)
- * LICENSE: See LICENSE in the top level directory
- * FILE: mods/shared_logic/CClientSound.h
- * PURPOSE: Sound entity class header
- * DEVELOPERS: Stanislav Bobrov <lil_Toady@hotmail.com>
- * Florian Busse <flobu@gmx.net>
- *
- *****************************************************************************/
- class CClientSound;
- #ifndef __CCLIENTSOUND_H
- #define __CCLIENTSOUND_H
- #include "CClientSoundManager.h"
- #include "CClientEntity.h"
- //#define MAX_SOUND_DISTANCE 100
- #define SOUND_PAN_THRESHOLD 0.85f
- typedef struct ST
- {
- CClientSound* pClientSound;
- SString strURL;
- bool bIs3D;
- long lFlags;
- CVector vecPosition;
- } thestruct;
- class CClientSound : public CClientEntity
- {
- friend CClientSoundManager;
- public:
- CClientSound ( CClientManager* pManager, ElementID ID );
- ~CClientSound ( void );
- eClientEntityType GetType ( void ) const { return CCLIENTSOUND; }
- void PlayStream ( const SString& strURL, bool bIs3D, bool bLoop, const CVector& vecPosition = CVector () );
- bool Play ( const SString& strPath, bool bLoop );
- bool Play3D ( const SString& strPath, const CVector& vecPosition, bool bLoop, int iangle, int oangle, float outvol );
- static void PlayStreamIntern ( void* arguments );
- void Stop ( void );
- void Set3DAttributes ( float fMinDistance, float fMaxDistance, int iIAngle, int iOAngle, float fOutVol );
- void SetPaused ( bool bPaused );
- bool IsPaused ( void );
- bool IsFinished ( void );
- void SetPlayPosition ( unsigned int uiPosition );
- unsigned int GetPlayPosition ( void );
- unsigned int GetLength ( void );
- void SetVolume ( float fVolume );
- float GetVolume ( void );
- void SetPlaybackSpeed ( float fSpeed );
- float GetPlaybackSpeed ( void );
- void SetMinDistance ( float fDistance );
- float GetMinDistance ( void );
- void SetMaxDistance ( float fDistance );
- float GetMaxDistance ( void );
- void Unlink ( void ) {};
- void GetPosition ( CVector& vecPosition ) const;
- void SetPosition ( const CVector& vecPosition );
- void SetDimension ( unsigned short usDimension );
- void RelateDimension ( unsigned short usDimension );
- DWORD m_pSound;
- bool m_b3D;
- float m_fVolume;
- CVector m_vecPosition;
- protected:
- DWORD GetSound ( void ) { return m_pSound; };
- void UpdatePosition ( void );
- private:
- CClientSoundManager* m_pSoundManager;
- HANDLE m_pThread;
- thestruct* m_pArguments;
- };
- #endif
- /*****************************************************************************
- *
- * PROJECT: Multi Theft Auto v1.0
- * (Shared logic for modifications)
- * LICENSE: See LICENSE in the top level directory
- * FILE: mods/shared_logic/CClientSound.h
- * PURPOSE: Sound entity class
- * DEVELOPERS: Stanislav Bobrov <lil_Toady@hotmail.com>
- * arc_
- * Florian Busse <flobu@gmx.net>
- *
- *****************************************************************************/
- #include <StdInc.h>
- #include <process.h>
- extern CClientGame* g_pClientGame;
- CClientSound::CClientSound ( CClientManager* pManager, ElementID ID ) : CClientEntity ( ID )
- {
- m_pManager = pManager;
- m_pSoundManager = pManager->GetSoundManager();
- m_pSound = NULL;
- SetTypeName ( "sound" );
- m_pSoundManager->AddToList ( this );
- RelateDimension ( pManager->GetSoundManager ()->GetDimension () );
- m_fVolume = 1.0f;
- m_usDimension = 0;
- m_b3D = false;
- m_pThread = 0;
- }
- CClientSound::~CClientSound ( void )
- {
- if ( m_pSound )
- BASS_ChannelStop ( m_pSound );
- m_pSoundManager->RemoveFromList ( this );
- _endthread();
- }
- bool CClientSound::Play ( const SString& strPath, bool bLoop )
- {
- long lFlags = BASS_STREAM_AUTOFREE;
- if ( bLoop )
- lFlags = BASS_SAMPLE_LOOP;
- if (
- ( m_pSound = BASS_StreamCreateFile ( false, strPath, 0, 0, lFlags ) ) ||
- ( m_pSound = BASS_MusicLoad ( false, strPath, 0, 0, lFlags, 0) ) ||
- ( m_pSound = BASS_StreamCreateURL ( strPath, 0, lFlags, NULL, NULL ) )
- )
- {
- BASS_ChannelPlay ( m_pSound, false );
- return true;
- }
- g_pCore->GetConsole()->Printf( "BASS ERROR %d in Play path = %s", BASS_ErrorGetCode(), strPath );
- return false;
- }
- bool CClientSound::Play3D ( const SString& strPath, const CVector& vecPosition, bool bLoop, int iangle, int oangle, float outvol )
- {
- long lFlags = BASS_STREAM_AUTOFREE | BASS_SAMPLE_3D | BASS_SAMPLE_MONO;
- if ( bLoop )
- lFlags |= BASS_SAMPLE_LOOP;
- if (
- ( m_pSound = BASS_StreamCreateFile ( false, strPath, 0, 0, lFlags ) ) ||
- ( m_pSound = BASS_MusicLoad ( false, strPath, 0, 0, lFlags, 0) ) ||
- ( m_pSound = BASS_StreamCreateURL ( strPath, 0, lFlags, NULL, NULL ) )
- )
- {
- m_b3D = true;
- m_vecPosition = vecPosition;
- BASS_3DVECTOR pos ( vecPosition.fX, vecPosition.fY, vecPosition.fZ );
- BASS_ChannelSet3DPosition ( m_pSound, &pos, NULL, NULL );
- g_pCore->GetConsole()->Printf( "BASS iangle = %d oangle = %d outvol = %f", iangle, oangle, outvol );
- BASS_ChannelSet3DAttributes ( m_pSound, BASS_3DMODE_NORMAL, 2, 10, iangle, oangle, outvol );
- BASS_ChannelPlay ( m_pSound, false );
- return true;
- }
- g_pCore->GetConsole()->Printf( "BASS ERROR %d in Play3D path = %s", BASS_ErrorGetCode(), strPath );
- return false;
- }
- void CClientSound::PlayStream ( const SString& strURL, bool bIs3D, bool bLoop, const CVector& vecPosition )
- {
- long lFlags = BASS_STREAM_AUTOFREE;
- if ( bLoop )
- lFlags |= BASS_SAMPLE_LOOP;
- if ( bIs3D )
- lFlags |= BASS_SAMPLE_3D | BASS_SAMPLE_MONO;
- thestruct* m_pArguments = new thestruct;
- m_pArguments->pClientSound = this;
- m_pArguments->strURL = strURL;
- m_pArguments->bIs3D = bIs3D;
- m_pArguments->lFlags = lFlags;
- m_pArguments->vecPosition = vecPosition;
- m_pThread = (HANDLE)_beginthread ( &CClientSound::PlayStreamIntern, 0, &m_pArguments );
- //WaitForSingleObject( m_pThread, INFINITE );
- //if ( m_pSound )
- // return true;
- //g_pCore->GetConsole()->Printf( "BASS ERROR %d in PlayStream bIs3D = %s path = %s", BASS_ErrorGetCode(), bIs3D ? "true" : "false", strURL );
- //return false;
- }
- void CClientSound::PlayStreamIntern ( void* arguments )
- {
- thestruct* args = (thestruct*)arguments;
- CClientSound* pClientSound = (CClientSound*)args->pClientSound;
- DWORD pSound = pClientSound->m_pSound;
- SString strURL = args->strURL;
- pClientSound->m_pSound = BASS_StreamCreateURL ( strURL, 0, args->lFlags, NULL, NULL );
- DWORD errorid = BASS_ErrorGetCode();
- if ( pClientSound->m_pSound )
- {
- if ( args->bIs3D )
- {
- pClientSound->m_b3D = true;
- pClientSound->m_vecPosition = args->vecPosition;
- BASS_3DVECTOR pos (args->vecPosition.fX, args->vecPosition.fY, args->vecPosition.fZ );
- BASS_ChannelSet3DPosition ( pClientSound->m_pSound, &pos, NULL, NULL );
- BASS_ChannelSet3DAttributes ( pClientSound->m_pSound, BASS_3DMODE_NORMAL, 2, 10, 360, 0, 0 );
- }
- BASS_ChannelPlay ( pClientSound->m_pSound, false );
- }
- delete arguments;
- _endthread ();
- }
- void CClientSound::Stop ( void )
- {
- if ( m_pSound )
- BASS_ChannelStop ( m_pSound );
- g_pClientGame->GetElementDeleter()->Delete ( this );
- }
- void CClientSound::Set3DAttributes ( float fMinDistance, float fMaxDistance, int iIAngle, int iOAngle, float fOutVol )
- {
- if ( m_pSound )
- {
- if ( !BASS_ChannelSet3DAttributes( m_pSound, -1, fMinDistance, fMaxDistance, iIAngle, iOAngle, fOutVol ) )
- g_pCore->GetConsole()->Printf( "BASS ERROR %d in Set3DAttributes fMinDistance = %f fMinDistance = %f iIAngle = %d iOAngle = %d fOutVol = %f", BASS_ErrorGetCode(), fMinDistance, fMaxDistance, iIAngle, iOAngle, fOutVol );
- }
- }
- void CClientSound::SetPaused ( bool bPaused )
- {
- if ( m_pSound )
- {
- if ( bPaused )
- BASS_ChannelPause ( m_pSound );
- else
- BASS_ChannelPlay ( m_pSound, false );
- }
- }
- bool CClientSound::IsPaused ( void )
- {
- if ( m_pSound )
- {
- return BASS_ChannelIsActive( m_pSound ) == BASS_ACTIVE_PAUSED;
- }
- return false;
- }
- bool CClientSound::IsFinished ( void )
- {
- if ( m_pSound )
- {
- return BASS_ChannelIsActive( m_pSound ) == BASS_ACTIVE_STOPPED;
- }
- return false;
- }
- void CClientSound::SetPlayPosition ( unsigned int uiPosition )
- {
- if ( m_pSound )
- {
- BASS_ChannelSetPosition( m_pSound, BASS_ChannelSeconds2Bytes( m_pSound, uiPosition/1000 ), BASS_POS_BYTE );
- }
- }
- unsigned int CClientSound::GetPlayPosition ( void )
- {
- if ( m_pSound )
- {
- QWORD pos = BASS_ChannelGetPosition( m_pSound, BASS_POS_BYTE );
- if ( pos != -1 )
- return BASS_ChannelBytes2Seconds( m_pSound, pos )*1000;
- }
- return 0;
- }
- unsigned int CClientSound::GetLength ( void )
- {
- if ( m_pSound )
- {
- QWORD length = BASS_ChannelGetLength( m_pSound, BASS_POS_BYTE );
- if ( length != -1 )
- return BASS_ChannelBytes2Seconds( m_pSound, length )*1000;
- }
- return 0;
- }
- float CClientSound::GetVolume ( void )
- {
- float fVolume = -1;
- BASS_ChannelGetAttribute( m_pSound, BASS_ATTRIB_VOL, &fVolume );
- return fVolume;
- }
- void CClientSound::SetVolume ( float fVolume )
- {
- if ( m_pSound && m_usDimension == m_pManager->GetSoundManager ()->GetDimension () )
- {
- if ( BASS_ChannelSetAttribute( m_pSound, BASS_ATTRIB_VOL, fVolume ) )
- m_fVolume = fVolume;
- }
- }
- float CClientSound::GetPlaybackSpeed ( void )
- {
- float fSpeed = -1;
- BASS_ChannelGetAttribute(m_pSound, BASS_ATTRIB_FREQ, &fSpeed);
- return fSpeed;
- }
- void CClientSound::SetPlaybackSpeed ( float fSpeed )
- {
- if ( m_pSound )
- {
- BASS_ChannelSetAttribute(m_pSound, BASS_ATTRIB_FREQ, fSpeed);
- }
- }
- void CClientSound::SetPosition ( const CVector& vecPosition )
- {
- if ( m_pSound )
- {
- m_vecPosition = vecPosition;
- BASS_3DVECTOR pos ( vecPosition.fX, vecPosition.fY, vecPosition.fZ );
- BASS_ChannelSet3DPosition ( m_pSound, &pos, NULL, NULL);
- }
- }
- void CClientSound::GetPosition ( CVector& vecPosition ) const
- {
- vecPosition = m_vecPosition;
- }
- void CClientSound::SetDimension ( unsigned short usDimension )
- {
- m_usDimension = usDimension;
- RelateDimension ( m_pManager->GetSoundManager ()->GetDimension () );
- }
- void CClientSound::RelateDimension ( unsigned short usDimension )
- {
- if ( usDimension == m_usDimension )
- {
- SetVolume ( m_fVolume );
- }
- else
- {
- m_fVolume = GetVolume ();
- SetVolume ( 0.0f );
- }
- }
- void CClientSound::SetMinDistance ( float fDistance )
- {
- if ( m_pSound )
- {
- BASS_ChannelSet3DAttributes( m_pSound, -1, fDistance, -1, -1, -1, -1 );
- }
- }
- float CClientSound::GetMinDistance ( void )
- {
- float fMinDistance;
- BASS_ChannelGet3DAttributes( m_pSound, NULL, &fMinDistance, NULL, NULL, NULL, NULL );
- return fMinDistance;
- }
- void CClientSound::SetMaxDistance ( float fDistance )
- {
- if ( m_pSound )
- {
- BASS_ChannelSet3DAttributes( m_pSound, -1, -1, fDistance, -1, -1, -1 );
- }
- }
- float CClientSound::GetMaxDistance ( void )
- {
- float fMaxDistance;
- BASS_ChannelGet3DAttributes( m_pSound, NULL, NULL, &fMaxDistance, NULL, NULL, NULL );
- return fMaxDistance;
- }
- void CClientSound::UpdatePosition ( void )
- {
- if ( !m_b3D ) return;
- // Update our position/rotation if we're attached
- DoAttaching ();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement