aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/Audio/SoundEngine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.Client/Common/Audio/SoundEngine.cpp')
-rw-r--r--Minecraft.Client/Common/Audio/SoundEngine.cpp161
1 files changed, 79 insertions, 82 deletions
diff --git a/Minecraft.Client/Common/Audio/SoundEngine.cpp b/Minecraft.Client/Common/Audio/SoundEngine.cpp
index 534fc54d..cf140c78 100644
--- a/Minecraft.Client/Common/Audio/SoundEngine.cpp
+++ b/Minecraft.Client/Common/Audio/SoundEngine.cpp
@@ -25,7 +25,7 @@
#include <vector>
#include <memory>
#include <mutex>
-#include "..\Filesystem\Filesystem.h"
+#include <lce_filesystem\lce_filesystem.h>
#ifdef __ORBIS__
#include <audioout.h>
@@ -57,7 +57,7 @@ void SoundEngine::updateSoundEffectVolume(float fVal) {}
void SoundEngine::add(const wstring& name, File *file) {}
void SoundEngine::addMusic(const wstring& name, File *file) {}
void SoundEngine::addStreaming(const wstring& name, File *file) {}
-char *SoundEngine::ConvertSoundPathToName(const wstring& name, bool bConvertSpaces) { return NULL; }
+char *SoundEngine::ConvertSoundPathToName(const wstring& name, bool bConvertSpaces) { return nullptr; }
bool SoundEngine::isStreamingWavebankReady() { return true; }
void SoundEngine::playMusicTick() {};
@@ -103,7 +103,7 @@ char SoundEngine::m_szRedistName[]={"redist"};
#endif
-char *SoundEngine::m_szStreamFileA[eStream_Max]=
+const char *SoundEngine::m_szStreamFileA[eStream_Max]=
{
"calm1",
"calm2",
@@ -187,7 +187,7 @@ void SoundEngine::init(Options* pOptions)
m_bSystemMusicPlaying = false;
app.DebugPrintf("---miniaudio initialized\n");
-
+
return;
}
@@ -260,16 +260,12 @@ void SoundEngine::updateMiniAudio()
continue;
}
- float finalVolume = s->info.volume * m_MasterEffectsVolume;
- if (finalVolume > 1.0f)
- finalVolume = 1.0f;
+ float finalVolume = s->info.volume * m_MasterEffectsVolume * SFX_VOLUME_MULTIPLIER;
+ if (finalVolume > SFX_MAX_GAIN)
+ finalVolume = SFX_MAX_GAIN;
ma_sound_set_volume(&s->sound, finalVolume);
-
- if (!s->info.bUseSoundsPitchVal)
- {
- ma_sound_set_pitch(&s->sound, s->info.pitch);
- }
+ ma_sound_set_pitch(&s->sound, s->info.pitch);
if (s->info.bIs3D)
{
@@ -338,7 +334,7 @@ void SoundEngine::tick(shared_ptr<Mob> *players, float a)
bool bListenerPostionSet = false;
for( size_t i = 0; i < MAX_LOCAL_PLAYERS; i++ )
{
- if( players[i] != NULL )
+ if( players[i] != nullptr )
{
m_ListenerA[i].bValid=true;
F32 x,y,z;
@@ -405,7 +401,7 @@ SoundEngine::SoundEngine()
m_iMusicDelay=0;
m_validListenerCount=0;
- m_bHeardTrackA=NULL;
+ m_bHeardTrackA=nullptr;
// Start the streaming music playing some music from the overworld
SetStreamingSounds(eStream_Overworld_Calm1,eStream_Overworld_piano3,
@@ -474,67 +470,64 @@ void SoundEngine::play(int iSound, float x, float y, float z, float volume, floa
char finalPath[256];
sprintf_s(finalPath, "%s.wav", basePath);
- if (!FileExists(finalPath))
- {
- int count = 0;
-
- for (size_t i = 1; i < 32; i++)
- {
- char numberedFolder[256];
- sprintf_s(numberedFolder, "%s%d", basePath, i);
-
- DWORD attr = GetFileAttributesA(numberedFolder);
-
- if (attr != INVALID_FILE_ATTRIBUTES &&
- (attr & FILE_ATTRIBUTE_DIRECTORY))
- {
- count++;
- }
- else
- {
- break;
- }
- }
-
- char chosenFolder[256];
-
- if (count == 0)
- {
- sprintf_s(chosenFolder, "%s", basePath);
- }
- else
- {
- int chosen = (rand() % count) + 1;
- sprintf_s(chosenFolder, "%s%d", basePath, chosen);
- }
+ const char* extensions[] = { ".ogg", ".wav", ".mp3" };
+ size_t extCount = sizeof(extensions) / sizeof(extensions[0]);
+ bool found = false;
- char searchPattern[256];
- sprintf_s(searchPattern, "%s\\*.wav", chosenFolder);
+ for (size_t extIdx = 0; extIdx < extCount; extIdx++)
+ {
+ char basePlusExt[256];
+ sprintf_s(basePlusExt, "%s%s", basePath, extensions[extIdx]);
+
+ DWORD attr = GetFileAttributesA(basePlusExt);
+ if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ sprintf_s(finalPath, "%s", basePlusExt);
+ found = true;
+ break;
+ }
+ }
- WIN32_FIND_DATAA findData;
- HANDLE hFind = FindFirstFileA(searchPattern, &findData);
+ if (!found)
+ {
+ int count = 0;
- const char* extensions[] = { ".ogg", ".wav", ".mp3" };
- size_t extCount = sizeof(extensions) / sizeof(extensions[0]);
- bool found = false;
- for (size_t i = 0; i < extCount; i++)
+ for (size_t extIdx = 0; extIdx < extCount; extIdx++)
{
- sprintf_s(searchPattern, "%s\\*%s", chosenFolder, extensions[i]);
- hFind = FindFirstFileA(searchPattern, &findData);
- if (hFind != INVALID_HANDLE_VALUE)
+ for (size_t i = 1; i < 32; i++)
{
- found = true;
- break;
+ char numberedPath[256];
+ sprintf_s(numberedPath, "%s%d%s", basePath, i, extensions[extIdx]);
+
+ DWORD attr = GetFileAttributesA(numberedPath);
+ if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ count = i;
+ }
}
}
- if (hFind == INVALID_HANDLE_VALUE)
+
+ if (count > 0)
{
- app.DebugPrintf("No sound files found in %s\n", chosenFolder);
- return;
+ int chosen = (rand() % count) + 1;
+ for (size_t extIdx = 0; extIdx < extCount; extIdx++)
+ {
+ char numberedPath[256];
+ sprintf_s(numberedPath, "%s%d%s", basePath, chosen, extensions[extIdx]);
+
+ DWORD attr = GetFileAttributesA(numberedPath);
+ if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY))
+ {
+ sprintf_s(finalPath, "%s", numberedPath);
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ {
+ sprintf_s(finalPath, "%s%d.wav", basePath, chosen);
+ }
}
-
- sprintf_s(finalPath, "%s\\%s", chosenFolder, findData.cFileName);
- FindClose(hFind);
}
MiniAudioSound* s = new MiniAudioSound();
@@ -554,8 +547,8 @@ void SoundEngine::play(int iSound, float x, float y, float z, float volume, floa
&m_engine,
finalPath,
MA_SOUND_FLAG_ASYNC,
- NULL,
- NULL,
+ nullptr,
+ nullptr,
&s->sound) != MA_SUCCESS)
{
app.DebugPrintf("Failed to initialize sound from file: %s\n", finalPath);
@@ -564,10 +557,13 @@ void SoundEngine::play(int iSound, float x, float y, float z, float volume, floa
}
ma_sound_set_spatialization_enabled(&s->sound, MA_TRUE);
+ ma_sound_set_min_distance(&s->sound, SFX_3D_MIN_DISTANCE);
+ ma_sound_set_max_distance(&s->sound, SFX_3D_MAX_DISTANCE);
+ ma_sound_set_rolloff(&s->sound, SFX_3D_ROLLOFF);
- float finalVolume = volume * m_MasterEffectsVolume;
- if (finalVolume > 1.0f)
- finalVolume = 1.0f;
+ float finalVolume = volume * m_MasterEffectsVolume * SFX_VOLUME_MULTIPLIER;
+ if (finalVolume > SFX_MAX_GAIN)
+ finalVolume = SFX_MAX_GAIN;
ma_sound_set_volume(&s->sound, finalVolume);
ma_sound_set_pitch(&s->sound, pitch);
@@ -638,8 +634,8 @@ void SoundEngine::playUI(int iSound, float volume, float pitch)
&m_engine,
finalPath,
MA_SOUND_FLAG_ASYNC,
- NULL,
- NULL,
+ nullptr,
+ nullptr,
&s->sound) != MA_SUCCESS)
{
delete s;
@@ -652,6 +648,7 @@ void SoundEngine::playUI(int iSound, float volume, float pitch)
float finalVolume = volume * m_MasterEffectsVolume;
if (finalVolume > 1.0f)
finalVolume = 1.0f;
+ printf("UI Sound volume set to %f\nEffects volume: %f\n", finalVolume, m_MasterEffectsVolume);
ma_sound_set_volume(&s->sound, finalVolume);
ma_sound_set_pitch(&s->sound, pitch);
@@ -706,7 +703,7 @@ void SoundEngine::playStreaming(const wstring& name, float x, float y , float z,
for(unsigned int i=0;i<MAX_LOCAL_PLAYERS;i++)
{
- if(pMinecraft->localplayers[i]!=NULL)
+ if(pMinecraft->localplayers[i]!=nullptr)
{
if(pMinecraft->localplayers[i]->dimension==LevelData::DIMENSION_END)
{
@@ -800,7 +797,7 @@ int SoundEngine::getMusicID(int iDomain)
Minecraft *pMinecraft=Minecraft::GetInstance();
// Before the game has started?
- if(pMinecraft==NULL)
+ if(pMinecraft==nullptr)
{
// any track from the overworld
return GetRandomishTrack(m_iStream_Overworld_Min,m_iStream_Overworld_Max);
@@ -933,8 +930,8 @@ int SoundEngine::OpenStreamThreadProc(void* lpParameter)
&soundEngine->m_engine,
soundEngine->m_szStreamName,
MA_SOUND_FLAG_STREAM,
- NULL,
- NULL,
+ nullptr,
+ nullptr,
&soundEngine->m_musicStream);
if (result != MA_SUCCESS)
@@ -1192,7 +1189,7 @@ void SoundEngine::playMusicUpdate()
if( !m_openStreamThread->isRunning() )
{
delete m_openStreamThread;
- m_openStreamThread = NULL;
+ m_openStreamThread = nullptr;
app.DebugPrintf("OpenStreamThreadProc finished. m_musicStreamActive=%d\n", m_musicStreamActive);
@@ -1249,7 +1246,7 @@ void SoundEngine::playMusicUpdate()
if( !m_openStreamThread->isRunning() )
{
delete m_openStreamThread;
- m_openStreamThread = NULL;
+ m_openStreamThread = nullptr;
m_StreamState = eMusicStreamState_Stop;
}
break;
@@ -1285,14 +1282,14 @@ void SoundEngine::playMusicUpdate()
}
if(GetIsPlayingStreamingGameMusic())
{
- //if(m_MusicInfo.pCue!=NULL)
+ //if(m_MusicInfo.pCue!=nullptr)
{
bool playerInEnd = false;
bool playerInNether=false;
Minecraft *pMinecraft = Minecraft::GetInstance();
for(unsigned int i = 0; i < MAX_LOCAL_PLAYERS; ++i)
{
- if(pMinecraft->localplayers[i]!=NULL)
+ if(pMinecraft->localplayers[i]!=nullptr)
{
if(pMinecraft->localplayers[i]->dimension==LevelData::DIMENSION_END)
{
@@ -1423,7 +1420,7 @@ void SoundEngine::playMusicUpdate()
for(unsigned int i=0;i<MAX_LOCAL_PLAYERS;i++)
{
- if(pMinecraft->localplayers[i]!=NULL)
+ if(pMinecraft->localplayers[i]!=nullptr)
{
if(pMinecraft->localplayers[i]->dimension==LevelData::DIMENSION_END)
{