mirror of
https://github.com/isledecomp/isle.git
synced 2024-11-22 15:48:09 -05:00
finish MusicManager (#453)
* finish MusicManager * Fixes/improvements --------- Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
parent
909c44b679
commit
30b35981d3
7 changed files with 168 additions and 23 deletions
|
@ -8,7 +8,7 @@ DECOMP_SIZE_ASSERT(LegoMeterPresenter, 0x94)
|
||||||
|
|
||||||
// GLOBAL: LEGO1 0x1010207c
|
// GLOBAL: LEGO1 0x1010207c
|
||||||
// STRING: LEGO1 0x10101fb4
|
// STRING: LEGO1 0x10101fb4
|
||||||
const char* g_filterIndex = "FILTER_INDEX";
|
const char* g_filterIndex = "FILLER_INDEX";
|
||||||
|
|
||||||
// GLOBAL: LEGO1 0x10102094
|
// GLOBAL: LEGO1 0x10102094
|
||||||
// STRING: LEGO1 0x10101f70
|
// STRING: LEGO1 0x10101f70
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include "decomp.h"
|
#include "decomp.h"
|
||||||
#include "mxaudiomanager.h"
|
#include "mxaudiomanager.h"
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
// VTABLE: LEGO1 0x100dc930
|
// VTABLE: LEGO1 0x100dc930
|
||||||
// SIZE 0x58
|
// SIZE 0x58
|
||||||
class MxMusicManager : public MxAudioManager {
|
class MxMusicManager : public MxAudioManager {
|
||||||
|
@ -16,9 +18,17 @@ class MxMusicManager : public MxAudioManager {
|
||||||
virtual MxResult Create(MxU32 p_frequencyMS, MxBool p_createThread); // vtable+30
|
virtual MxResult Create(MxU32 p_frequencyMS, MxBool p_createThread); // vtable+30
|
||||||
|
|
||||||
inline MxBool GetMIDIInitialized() { return m_midiInitialized; }
|
inline MxBool GetMIDIInitialized() { return m_midiInitialized; }
|
||||||
|
inline void GetMIDIVolume(DWORD& p_volume)
|
||||||
|
{
|
||||||
|
if (midiOutGetVolume((HMIDIOUT) m_midiStreamH, &p_volume)) {
|
||||||
|
p_volume = CalculateVolume(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MxResult ResetStream();
|
||||||
|
void ResetBuffer();
|
||||||
|
undefined4 InitializeMIDI(MxU8* p_data, MxS32 p_loopCount);
|
||||||
void DeinitializeMIDI();
|
void DeinitializeMIDI();
|
||||||
undefined4 FUN_100c09c0(MxU8* p_data, MxS32 p_loopCount);
|
|
||||||
void SetMultiplier(MxS32 p_multiplier);
|
void SetMultiplier(MxS32 p_multiplier);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -27,13 +37,16 @@ class MxMusicManager : public MxAudioManager {
|
||||||
MxS32 CalculateVolume(MxS32 p_volume);
|
MxS32 CalculateVolume(MxS32 p_volume);
|
||||||
void SetMIDIVolume();
|
void SetMIDIVolume();
|
||||||
|
|
||||||
|
static void CALLBACK
|
||||||
|
MidiCallbackProc(HMIDIOUT p_hmo, UINT p_wMsg, DWORD_PTR p_dwInstance, DWORD_PTR p_dwParam1, DWORD_PTR p_dwParam2);
|
||||||
|
|
||||||
HMIDISTRM m_midiStreamH; // 0x30
|
HMIDISTRM m_midiStreamH; // 0x30
|
||||||
MxBool m_midiInitialized; // 0x34
|
MxBool m_midiInitialized; // 0x34
|
||||||
undefined4 m_unk0x38; // 0x38
|
MxU32 m_bufferSize; // 0x38
|
||||||
undefined4 m_unk0x3c; // 0x3c
|
MxU32 m_bufferCurrentSize; // 0x3c
|
||||||
undefined4 m_unk0x40; // 0x40
|
MxU8* m_bufferOffset; // 0x40
|
||||||
undefined4 m_unk0x44; // 0x44
|
MxU8* m_bufferCurrentOffset; // 0x44
|
||||||
undefined4 m_unk0x48; // 0x48
|
MxU32 m_loopCount; // 0x48
|
||||||
MIDIHDR* m_midiHdrP; // 0x4c
|
MIDIHDR* m_midiHdrP; // 0x4c
|
||||||
MxS32 m_multiplier; // 0x50
|
MxS32 m_multiplier; // 0x50
|
||||||
DWORD m_midiVolume; // 0x54
|
DWORD m_midiVolume; // 0x54
|
||||||
|
|
|
@ -118,4 +118,7 @@ class MxStreamController : public MxCore {
|
||||||
// TEMPLATE: LEGO1 0x100c1240
|
// TEMPLATE: LEGO1 0x100c1240
|
||||||
// List<MxNextActionDataStart *>::~List<MxNextActionDataStart *>
|
// List<MxNextActionDataStart *>::~List<MxNextActionDataStart *>
|
||||||
|
|
||||||
|
// TEMPLATE: LEGO1 0x100c1bc0
|
||||||
|
// list<MxDSAction *,allocator<MxDSAction *> >::insert
|
||||||
|
|
||||||
#endif // MXSTREAMCONTROLLER_H
|
#endif // MXSTREAMCONTROLLER_H
|
||||||
|
|
|
@ -40,7 +40,7 @@ MxResult MxLoopingMIDIPresenter::PutData()
|
||||||
|
|
||||||
if (m_currentTickleState == e_streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) {
|
if (m_currentTickleState == e_streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) {
|
||||||
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
||||||
MusicManager()->FUN_100c09c0(m_chunk->GetData(), !m_action->GetLoopCount() ? -1 : m_action->GetLoopCount());
|
MusicManager()->InitializeMIDI(m_chunk->GetData(), !m_action->GetLoopCount() ? -1 : m_action->GetLoopCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_criticalSection.Leave();
|
m_criticalSection.Leave();
|
||||||
|
|
|
@ -95,7 +95,7 @@ MxResult MxMIDIPresenter::PutData()
|
||||||
if (m_currentTickleState == e_streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) {
|
if (m_currentTickleState == e_streaming && m_chunk && !MusicManager()->GetMIDIInitialized()) {
|
||||||
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
SetVolume(((MxDSSound*) m_action)->GetVolume());
|
||||||
|
|
||||||
if (MusicManager()->FUN_100c09c0(m_chunk->GetData(), 1))
|
if (MusicManager()->InitializeMIDI(m_chunk->GetData(), 1))
|
||||||
EndAction();
|
EndAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,11 @@ void MxMusicManager::InitData()
|
||||||
{
|
{
|
||||||
m_midiStreamH = 0;
|
m_midiStreamH = 0;
|
||||||
m_midiInitialized = FALSE;
|
m_midiInitialized = FALSE;
|
||||||
m_unk0x38 = 0;
|
m_bufferSize = 0;
|
||||||
m_unk0x3c = 0;
|
m_bufferCurrentSize = 0;
|
||||||
m_unk0x40 = 0;
|
m_bufferOffset = 0;
|
||||||
m_unk0x44 = 0;
|
m_bufferCurrentOffset = 0;
|
||||||
m_unk0x48 = 0;
|
m_loopCount = 0;
|
||||||
m_midiHdrP = NULL;
|
m_midiHdrP = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,60 @@ void MxMusicManager::Destroy(MxBool p_fromDestructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FUNCTION: LEGO1 0x100c0720
|
||||||
|
MxResult MxMusicManager::ResetStream()
|
||||||
|
{
|
||||||
|
MxResult result = FAILURE;
|
||||||
|
|
||||||
|
if (m_midiInitialized) {
|
||||||
|
if (m_bufferCurrentSize == 0) {
|
||||||
|
if (m_loopCount != -1) {
|
||||||
|
m_loopCount += -1;
|
||||||
|
|
||||||
|
if (!m_loopCount) {
|
||||||
|
DeinitializeMIDI();
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ResetBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_midiHdrP->dwFlags & (MHDR_DONE | MHDR_PREPARED)) {
|
||||||
|
if (midiOutUnprepareHeader((HMIDIOUT) m_midiStreamH, m_midiHdrP, sizeof(MIDIHDR)) != MMSYSERR_NOERROR)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
memset(m_midiHdrP, 0, sizeof(MIDIHDR));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_bufferCurrentOffset += 4;
|
||||||
|
DWORD length = *((DWORD*) m_bufferCurrentOffset);
|
||||||
|
m_bufferCurrentOffset += sizeof(DWORD);
|
||||||
|
|
||||||
|
m_midiHdrP->lpData = (LPSTR) m_bufferCurrentOffset;
|
||||||
|
m_midiHdrP->dwBufferLength = length;
|
||||||
|
m_midiHdrP->dwBytesRecorded = length;
|
||||||
|
|
||||||
|
if (!midiOutPrepareHeader((HMIDIOUT) m_midiStreamH, m_midiHdrP, sizeof(MIDIHDR))) {
|
||||||
|
if (!midiStreamOut(m_midiStreamH, m_midiHdrP, sizeof(MIDIHDR))) {
|
||||||
|
result = SUCCESS;
|
||||||
|
m_bufferCurrentOffset += length;
|
||||||
|
m_bufferCurrentSize--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUNCTION: LEGO1 0x100c07e0
|
||||||
|
void MxMusicManager::ResetBuffer()
|
||||||
|
{
|
||||||
|
m_bufferCurrentOffset = m_bufferOffset;
|
||||||
|
m_bufferCurrentSize = m_bufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100c07f0
|
// FUNCTION: LEGO1 0x100c07f0
|
||||||
void MxMusicManager::SetMIDIVolume()
|
void MxMusicManager::SetMIDIVolume()
|
||||||
{
|
{
|
||||||
|
@ -74,6 +128,19 @@ void MxMusicManager::SetMIDIVolume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FUNCTION: LEGO1 0x100c0820
|
||||||
|
void CALLBACK MxMusicManager::MidiCallbackProc(
|
||||||
|
HMIDIOUT p_hmo,
|
||||||
|
UINT p_wMsg,
|
||||||
|
DWORD_PTR p_dwInstance,
|
||||||
|
DWORD_PTR p_dwParam1,
|
||||||
|
DWORD_PTR p_dwParam2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (p_wMsg == MOM_DONE)
|
||||||
|
((MxMusicManager*) p_dwInstance)->ResetStream();
|
||||||
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100c0840
|
// FUNCTION: LEGO1 0x100c0840
|
||||||
MxResult MxMusicManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
|
MxResult MxMusicManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
|
||||||
{
|
{
|
||||||
|
@ -136,11 +203,68 @@ MxS32 MxMusicManager::CalculateVolume(MxS32 p_volume)
|
||||||
return (result << 0x10) | result;
|
return (result << 0x10) | result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// STUB: LEGO1 0x100c09c0
|
// FUNCTION: LEGO1 0x100c09c0
|
||||||
undefined4 MxMusicManager::FUN_100c09c0(MxU8* p_data, MxS32 p_loopCount)
|
undefined4 MxMusicManager::InitializeMIDI(MxU8* p_data, MxS32 p_loopCount)
|
||||||
{
|
{
|
||||||
// TODO
|
MxResult result = FAILURE;
|
||||||
return 0;
|
|
||||||
|
m_criticalSection.Enter();
|
||||||
|
|
||||||
|
if (!m_midiInitialized) {
|
||||||
|
MxU32 total = midiOutGetNumDevs();
|
||||||
|
MxU32 device = 0;
|
||||||
|
|
||||||
|
for (; device < total; device++) {
|
||||||
|
MIDIOUTCAPSA caps;
|
||||||
|
midiOutGetDevCapsA(device, &caps, sizeof(MIDIOUTCAPSA));
|
||||||
|
if (caps.wTechnology == MOD_FMSYNTH)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device >= total)
|
||||||
|
device = -1;
|
||||||
|
|
||||||
|
if (midiStreamOpen(&m_midiStreamH, &device, 1, (DWORD) MidiCallbackProc, (DWORD) this, CALLBACK_FUNCTION) !=
|
||||||
|
MMSYSERR_NOERROR)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
GetMIDIVolume(m_midiVolume);
|
||||||
|
|
||||||
|
m_midiHdrP = new MIDIHDR();
|
||||||
|
if (!m_midiHdrP)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
memset(m_midiHdrP, 0, sizeof(MIDIHDR));
|
||||||
|
|
||||||
|
MIDIPROPTIMEDIV timediv;
|
||||||
|
timediv.cbStruct = 8;
|
||||||
|
m_bufferOffset = p_data;
|
||||||
|
m_bufferOffset += 0x14;
|
||||||
|
timediv.dwTimeDiv = *((DWORD*) m_bufferOffset);
|
||||||
|
|
||||||
|
if (midiStreamProperty(m_midiStreamH, (LPBYTE) &timediv, MIDIPROP_SET | MIDIPROP_TIMEDIV) != MMSYSERR_NOERROR)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
m_bufferOffset += 0x14;
|
||||||
|
m_bufferSize = *((MxU32*) m_bufferOffset);
|
||||||
|
m_bufferOffset += sizeof(MxU32);
|
||||||
|
m_loopCount = p_loopCount;
|
||||||
|
m_midiInitialized = TRUE;
|
||||||
|
|
||||||
|
ResetBuffer();
|
||||||
|
if (ResetStream() != SUCCESS)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
SetMIDIVolume();
|
||||||
|
if (midiStreamRestart(m_midiStreamH) != MMSYSERR_NOERROR)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
result = SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
m_criticalSection.Leave();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100c0b20
|
// FUNCTION: LEGO1 0x100c0b20
|
||||||
|
|
|
@ -15,6 +15,11 @@
|
||||||
#define COMPAT_CONST
|
#define COMPAT_CONST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// DWORD_PTR didn't exist in older Windows SDKs
|
||||||
|
#if (defined(_MSC_VER) && _MSC_VER < 1100)
|
||||||
|
typedef unsigned long DWORD_PTR, *PDWORD_PTR;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Disable "identifier was truncated to '255' characters" warning.
|
// Disable "identifier was truncated to '255' characters" warning.
|
||||||
// Impossible to avoid this if using STL map or set.
|
// Impossible to avoid this if using STL map or set.
|
||||||
// This removes most (but not all) occurrences of the warning.
|
// This removes most (but not all) occurrences of the warning.
|
||||||
|
|
Loading…
Reference in a new issue