diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 1775023be8..36ad2c4263 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -190,7 +190,6 @@ bool DrawEngineCommon::TestBoundingBox(void* control_points, int vertexCount, u3 // Try to skip NormalizeVertices if it's pure positions. No need to bother with a vertex decoder // and a large vertex format. if ((vertType & 0xFFFFFF) == GE_VTYPE_POS_FLOAT) { - // memcpy(verts, control_points, 12 * vertexCount); verts = (float *)control_points; } else if ((vertType & 0xFFFFFF) == GE_VTYPE_POS_8BIT) { const s8 *vtx = (const s8 *)control_points; @@ -440,8 +439,8 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, if (vertType & GE_VTYPE_TC_MASK) { reader.ReadUV(sv.uv); } else { - sv.uv[0] = 0; // This will get filled in during tesselation - sv.uv[1] = 0; + sv.uv[0] = 0.0f; // This will get filled in during tesselation + sv.uv[1] = 0.0f; } if (vertType & GE_VTYPE_COL_MASK) { reader.ReadColor0_8888(sv.color); @@ -452,8 +451,8 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, // Normals are generated during tesselation anyway, not sure if any need to supply reader.ReadNrm((float *)&sv.nrm); } else { - sv.nrm.x = 0; - sv.nrm.y = 0; + sv.nrm.x = 0.0f; + sv.nrm.y = 0.0f; sv.nrm.z = 1.0f; } reader.ReadPos((float *)&sv.pos); diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index 58351d85de..7093ba984d 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -169,15 +169,22 @@ static AT3PlusReader *at3Reader; static double gameLastChanged; static double lastPlaybackTime; static int buffer[44100]; +static bool fadingOut = true; +static float volume; +static float delta = -0.0001f; -static void ClearBackgroundAudio() { +static void ClearBackgroundAudio(bool hard) { + if (!hard) { + fadingOut = true; + volume = 1.0f; + return; + } if (at3Reader) { at3Reader->Shutdown(); delete at3Reader; - at3Reader = 0; + at3Reader = nullptr; } playbackOffset = 0; - gameLastChanged = 0; } void SetBackgroundAudioGame(const std::string &path) { @@ -189,8 +196,15 @@ void SetBackgroundAudioGame(const std::string &path) { return; } - ClearBackgroundAudio(); - gameLastChanged = time_now_d(); + if (path.size() == 0) { + ClearBackgroundAudio(false); + fadingOut = true; + } else { + ClearBackgroundAudio(true); + gameLastChanged = time_now_d(); + fadingOut = false; + } + volume = 1.0f; bgGamePath = path; } @@ -201,7 +215,7 @@ int PlayBackgroundAudio() { // Immediately stop the sound if it is turned off while playing. if (!g_Config.bEnableSound) { - ClearBackgroundAudio(); + ClearBackgroundAudio(true); __PushExternalAudio(0, 0); return 0; } @@ -234,8 +248,23 @@ int PlayBackgroundAudio() { int sz = lastPlaybackTime <= 0.0 ? 44100 / 60 : (int)((now - lastPlaybackTime) * 44100); sz = std::min((int)ARRAY_SIZE(buffer) / 2, sz); if (sz >= 16) { - if (at3Reader->Read(buffer, sz)) - __PushExternalAudio(buffer, sz); + if (at3Reader->Read(buffer, sz)) { + if (!fadingOut) { + __PushExternalAudio(buffer, sz); + } else { + for (int i = 0; i < sz*2; i += 2) { + buffer[i] *= volume; + buffer[i + 1] *= volume; + volume += delta; + } + __PushExternalAudio(buffer, sz); + if (volume <= 0.0f) { + ClearBackgroundAudio(true); + fadingOut = false; + gameLastChanged = 0; + } + } + } lastPlaybackTime = now; } } else {