shithub: cstory

Download patch

ref: add4e69374f90afc09f7a5e1389b8a372a119713
parent: 8f5370ea81c63e632d2f2b15d0afa55dfca9d2c3
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Aug 13 16:45:50 EDT 2019

Made Sound.cpp more accurate

--- a/msvc2003/devilution/comparer-config.toml
+++ b/msvc2003/devilution/comparer-config.toml
@@ -1067,6 +1067,21 @@
 addr = 0x420640
 
 [[func]]
+name = "ChangeSoundFrequency"
+addr = 0x420720
+size = 0x34
+
+[[func]]
+name = "ChangeSoundVolume"
+addr = 0x420760
+size = 0x35
+
+[[func]]
+name = "ChangeSoundPan"
+addr = 0x4207A0
+size = 0x36
+
+[[func]]
 name = "TransferStage"
 addr = 0x420BE0
 
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -221,7 +221,7 @@
 }
 
 //Sound things
-SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
+SOUNDBUFFER* lpSECONDARYBUFFER[SE_MAX];
 
 BOOL InitDirectSound()
 {
@@ -250,6 +250,9 @@
 	//Unpause audio device
 	SDL_PauseAudioDevice(audioDevice, 0);
 
+	for (unsigned int i = 0; i < SE_MAX; ++i)
+		lpSECONDARYBUFFER[i] = NULL;
+
 	//Start organya
 	StartOrganya();
 	return TRUE;
@@ -257,14 +260,15 @@
 
 void EndDirectSound()
 {
-	//Quit sub-system
+	EndOrganya();
+
+	for (unsigned int i = 0; i < SE_MAX; ++i)
+		lpSECONDARYBUFFER[i]->Release();
+
 	SDL_QuitSubSystem(SDL_INIT_AUDIO);
 
-	//Close audio device
 	SDL_CloseAudioDevice(audioDevice);
 
-	//End organya
-	EndOrganya();
 }
 
 //Sound effects playing
@@ -293,20 +297,17 @@
 
 void ChangeSoundFrequency(int no, unsigned long rate)
 {
-	if (lpSECONDARYBUFFER[no])
-		lpSECONDARYBUFFER[no]->SetFrequency(10 * rate + 100);
+	lpSECONDARYBUFFER[no]->SetFrequency((rate * 10) + 100);
 }
 
 void ChangeSoundVolume(int no, long volume)
 {
-	if (lpSECONDARYBUFFER[no])
-		lpSECONDARYBUFFER[no]->SetVolume(8 * volume - 2400);
+	lpSECONDARYBUFFER[no]->SetVolume((volume - 300) * 8);
 }
 
 void ChangeSoundPan(int no, long pan)
 {
-	if (lpSECONDARYBUFFER[no])
-		lpSECONDARYBUFFER[no]->SetPan(10 * (pan - 256));
+	lpSECONDARYBUFFER[no]->SetPan((pan - 256) * 10);
 }
 
 int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no)
--- a/src/Sound.h
+++ b/src/Sound.h
@@ -90,8 +90,8 @@
 	mus_White = 0x29
 };
 
-#define SOUND_NO 0x100
-extern SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
+#define SE_MAX 160	// According to the Organya source code release, this is the real name for this constant
+extern SOUNDBUFFER* lpSECONDARYBUFFER[SE_MAX];
 
 BOOL InitDirectSound();
 void EndDirectSound();