2001-11-03 10:52:42 +00:00
|
|
|
#include "stdafx.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
2002-07-28 20:28:37 +00:00
|
|
|
Class: RageSound
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-07-28 20:28:37 +00:00
|
|
|
Desc: See header.
|
2001-11-04 19:34:28 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-07-28 20:28:37 +00:00
|
|
|
Chris Danford
|
2001-11-04 19:34:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "RageSound.h"
|
|
|
|
|
#include "RageUtil.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-10-13 17:30:48 +00:00
|
|
|
RageSound* SOUND = NULL;
|
|
|
|
|
|
|
|
|
|
/* I use this to turn off sound, since Bass doesn't want to work under
|
|
|
|
|
* VTune. -glenn */
|
|
|
|
|
#if 0
|
|
|
|
|
RageSound::RageSound( HWND hWnd ) { }
|
|
|
|
|
RageSound::~RageSound() { }
|
|
|
|
|
void RageSound::PlayOnceStreamed( CString sPath ) { }
|
|
|
|
|
void RageSound::PlayOnceStreamedFromDir( CString sDir ) { }
|
|
|
|
|
#else
|
|
|
|
|
|
2002-09-15 03:13:21 +00:00
|
|
|
#pragma comment(lib, "bass/bass.lib")
|
2002-09-15 02:58:33 +00:00
|
|
|
|
2002-10-13 17:30:48 +00:00
|
|
|
#include "bass/bass.h"
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
RageSound::RageSound()
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "RageSound::RageSound()" );
|
2002-06-24 22:04:31 +00:00
|
|
|
|
|
|
|
|
if( BASS_GetVersion() != MAKELONG(1,6) )
|
|
|
|
|
throw RageException( "BASS version 1.6 DLL could not be loaded. Verify that Bass.dll exists in the program directory.");
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-11 04:53:31 +00:00
|
|
|
if( !BASS_Init( -1, 44100, BASS_DEVICE_LEAVEVOL|BASS_DEVICE_LATENCY, NULL ) )
|
2001-12-11 11:25:37 +00:00
|
|
|
{
|
2002-06-14 22:25:22 +00:00
|
|
|
throw RageException(
|
2002-02-11 04:46:31 +00:00
|
|
|
"There was an error while initializing your sound card.\n\n"
|
|
|
|
|
"The most likely cause of this problem is that you do not have a sound card\n"
|
|
|
|
|
"installed, or that you have not yet installed a driver for your sound card.\n"
|
|
|
|
|
"Before running this program again, please verify that your sound card is\n"
|
2002-07-11 19:02:26 +00:00
|
|
|
"is working in other applications."
|
2002-02-11 04:46:31 +00:00
|
|
|
);
|
2001-12-11 11:25:37 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
BASS_Start();
|
2002-03-09 06:19:40 +00:00
|
|
|
|
|
|
|
|
ZeroMemory( &m_info, sizeof(m_info) );
|
|
|
|
|
m_info.size = sizeof(m_info);
|
|
|
|
|
BASS_GetInfo( &m_info );
|
|
|
|
|
|
|
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace(
|
2002-03-09 06:19:40 +00:00
|
|
|
"Sound card info:\n"
|
|
|
|
|
" - play latency is %u ms\n"
|
|
|
|
|
" - total device hardware memory is %u bytes\n"
|
|
|
|
|
" - free device hardware memory is %u bytes\n"
|
|
|
|
|
" - number of free sample slots in the hardware is %u\n"
|
|
|
|
|
" - number of free 3D sample slots in the hardware is %u\n"
|
|
|
|
|
" - min sample rate supported by the hardware is %u\n"
|
|
|
|
|
" - max sample rate supported by the hardware is %u",
|
|
|
|
|
m_info.latency,
|
|
|
|
|
m_info.hwsize,
|
|
|
|
|
m_info.hwfree,
|
|
|
|
|
m_info.freesam,
|
|
|
|
|
m_info.free3d,
|
|
|
|
|
m_info.minrate,
|
|
|
|
|
m_info.maxrate
|
|
|
|
|
);
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RageSound::~RageSound()
|
|
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "RageSound::~RageSound()" );
|
2002-06-24 22:04:31 +00:00
|
|
|
|
2002-05-28 20:01:22 +00:00
|
|
|
BASS_Stop();
|
2001-11-03 10:52:42 +00:00
|
|
|
BASS_Free();
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-28 20:42:32 +00:00
|
|
|
void RageSound::PlayOnceStreamed( CString sPath )
|
|
|
|
|
{
|
2002-08-28 07:04:52 +00:00
|
|
|
HSTREAM hStream = BASS_StreamCreateFile( FALSE, const_cast<char*>((const char *)sPath), 0, 0, BASS_STREAM_AUTOFREE );
|
2002-04-28 20:42:32 +00:00
|
|
|
if( hStream == NULL )
|
2002-06-14 22:25:22 +00:00
|
|
|
throw RageException( "RageSound: Error creating stream." );
|
2002-04-28 20:42:32 +00:00
|
|
|
|
|
|
|
|
if( FALSE == BASS_StreamPlay( hStream, FALSE, 0 ) )
|
2002-06-14 22:25:22 +00:00
|
|
|
throw RageException( "RageSound: Error playing a sound stream." );
|
2002-04-28 20:42:32 +00:00
|
|
|
|
2002-06-24 22:04:31 +00:00
|
|
|
// this stream will free itself when stopped
|
2002-04-28 20:42:32 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
void RageSound::PlayOnceStreamedFromDir( CString sDir )
|
|
|
|
|
{
|
2002-07-11 19:02:26 +00:00
|
|
|
if( sDir == "" )
|
|
|
|
|
return;
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
// make sure there's a backslash at the end of this path
|
|
|
|
|
if( sDir[sDir.GetLength()-1] != '\\' )
|
|
|
|
|
sDir += "\\";
|
|
|
|
|
|
|
|
|
|
CStringArray arraySoundFiles;
|
|
|
|
|
GetDirListing( sDir + "*.mp3", arraySoundFiles );
|
|
|
|
|
GetDirListing( sDir + "*.wav", arraySoundFiles );
|
|
|
|
|
GetDirListing( sDir + "*.ogg", arraySoundFiles );
|
|
|
|
|
|
2002-10-31 03:16:02 +00:00
|
|
|
if( !arraySoundFiles.empty() )
|
2002-06-14 22:25:22 +00:00
|
|
|
{
|
2002-10-31 03:16:02 +00:00
|
|
|
int index = rand() % arraySoundFiles.size();
|
2002-06-14 22:25:22 +00:00
|
|
|
PlayOnceStreamed( sDir + arraySoundFiles[index] );
|
|
|
|
|
}
|
2002-05-19 01:59:48 +00:00
|
|
|
}
|
2002-10-13 17:30:48 +00:00
|
|
|
#endif
|