Skip to content

Commit

Permalink
Remove amuse, and compile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote committed Oct 22, 2023
1 parent e9cfa6a commit 137e4c1
Show file tree
Hide file tree
Showing 33 changed files with 634 additions and 652 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
path = extern/nod
url = ../nod.git
branch = master
[submodule "extern/amuse"]
path = extern/amuse
url = ../amuse.git
branch = master
[submodule "extern/kabufuda"]
path = extern/kabufuda
url = ../kabufuda.git
Expand Down
114 changes: 57 additions & 57 deletions NESEmulator/CNESEmulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ void CNESEmulator::InitializeEmulator() {

// double useFreq = 223740;
double useFreq = apuGetFrequency();
m_booVoice = CAudioSys::GetVoiceEngine()->allocateNewStereoVoice(useFreq, this);
m_booVoice->start();
//m_booVoice = CAudioSys::GetVoiceEngine()->allocateNewStereoVoice(useFreq, this);
//m_booVoice->start();
uint32_t apuBufSz = apuGetMaxBufSize();
m_audioBufBlock.reset(new u8[apuBufSz * NUM_AUDIO_BUFFERS]);
memset(m_audioBufBlock.get(), 0, apuBufSz * NUM_AUDIO_BUFFERS);
Expand All @@ -301,8 +301,8 @@ void CNESEmulator::InitializeEmulator() {
void CNESEmulator::DeinitializeEmulator() {
// printf("\n");
emuRenderFrame = false;
m_booVoice->stop();
m_booVoice.reset();
//m_booVoice->stop();
//m_booVoice.reset();
apuDeinitBufs();
if (emuNesROM != NULL) {
if (!nesEmuNSFPlayback && (audioExpansion & EXP_FDS)) {
Expand Down Expand Up @@ -345,63 +345,63 @@ CNESEmulator::~CNESEmulator() {
}

int CNESEmulator::audioUpdate() {
int origProcBufs = m_procBufs;

uint8_t* data = apuGetBuf();
if (data != NULL && m_procBufs) {
uint32_t apuBufSz = apuGetMaxBufSize();
uint32_t remBytes = apuGetBufSize();
while (remBytes != 0) {
size_t thisBytes = std::min(remBytes, apuBufSz - m_posInHeadBuf);
memmove(m_audioBufs[m_headBuf] + m_posInHeadBuf, data, thisBytes);
data += thisBytes;
m_posInHeadBuf += thisBytes;
if (m_posInHeadBuf == apuBufSz) {
m_posInHeadBuf = 0;
--m_procBufs;
++m_headBuf;
if (m_headBuf == NUM_AUDIO_BUFFERS)
m_headBuf = 0;
// printf("PUSH\n");
}
remBytes -= thisBytes;
}
}

// if (!origProcBufs)
// printf("OVERRUN\n");

return origProcBufs;
// int origProcBufs = m_procBufs;
//
// uint8_t* data = apuGetBuf();
// if (data != NULL && m_procBufs) {
// uint32_t apuBufSz = apuGetMaxBufSize();
// uint32_t remBytes = apuGetBufSize();
// while (remBytes != 0) {
// size_t thisBytes = std::min(remBytes, apuBufSz - m_posInHeadBuf);
// memmove(m_audioBufs[m_headBuf] + m_posInHeadBuf, data, thisBytes);
// data += thisBytes;
// m_posInHeadBuf += thisBytes;
// if (m_posInHeadBuf == apuBufSz) {
// m_posInHeadBuf = 0;
// --m_procBufs;
// ++m_headBuf;
// if (m_headBuf == NUM_AUDIO_BUFFERS)
// m_headBuf = 0;
// // printf("PUSH\n");
// }
// remBytes -= thisBytes;
// }
// }
//
// // if (!origProcBufs)
// // printf("OVERRUN\n");
//
// return origProcBufs;
}

static constexpr uint32_t AudioFrameSz = 2 * sizeof(int16_t);

size_t CNESEmulator::supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t* data) {
uint32_t remFrames = uint32_t(frames);
while (remFrames) {
if (m_posInTailBuf == apuGetMaxBufSize()) {
++m_tailBuf;
if (m_tailBuf == NUM_AUDIO_BUFFERS)
m_tailBuf = 0;
m_posInTailBuf = 0;
++m_procBufs;
// printf("POP\n");
}

if (m_procBufs == NUM_AUDIO_BUFFERS) {
memset(data, 0, remFrames * AudioFrameSz);
// printf("UNDERRUN\n");
return frames;
}

size_t copySz = std::min(apuGetMaxBufSize() - m_posInTailBuf, remFrames * AudioFrameSz);
memmove(data, m_audioBufs[m_tailBuf] + m_posInTailBuf, copySz);
data += copySz / sizeof(int16_t);
m_posInTailBuf += copySz;
remFrames -= copySz / AudioFrameSz;
}
return frames;
}
//size_t CNESEmulator::supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t* data) {
// uint32_t remFrames = uint32_t(frames);
// while (remFrames) {
// if (m_posInTailBuf == apuGetMaxBufSize()) {
// ++m_tailBuf;
// if (m_tailBuf == NUM_AUDIO_BUFFERS)
// m_tailBuf = 0;
// m_posInTailBuf = 0;
// ++m_procBufs;
// // printf("POP\n");
// }
//
// if (m_procBufs == NUM_AUDIO_BUFFERS) {
// memset(data, 0, remFrames * AudioFrameSz);
// // printf("UNDERRUN\n");
// return frames;
// }
//
// size_t copySz = std::min(apuGetMaxBufSize() - m_posInTailBuf, remFrames * AudioFrameSz);
// memmove(data, m_audioBufs[m_tailBuf] + m_posInTailBuf, copySz);
// data += copySz / sizeof(int16_t);
// m_posInTailBuf += copySz;
// remFrames -= copySz / AudioFrameSz;
// }
// return frames;
//}

void CNESEmulator::NesEmuMainLoop(bool forceDraw) {
// int start = GetTickCount();
Expand Down
9 changes: 4 additions & 5 deletions NESEmulator/CNESEmulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "RetroTypes.hpp"
#include "zeus/CColor.hpp"
//#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "boo/audiodev/IAudioVoice.hpp"
#include "zeus/CMatrix4f.hpp"
#include "Runtime/Graphics/CGraphics.hpp"

Expand All @@ -15,7 +14,7 @@ namespace MP1 {

#define NUM_AUDIO_BUFFERS 4

class CNESEmulator final : public boo::IAudioVoiceCallback {
class CNESEmulator final {
public:
enum class EPasswordEntryState { NotPasswordScreen, NotEntered, Entered };

Expand Down Expand Up @@ -47,7 +46,7 @@ class CNESEmulator final : public boo::IAudioVoiceCallback {
uint32_t m_procBufs = NUM_AUDIO_BUFFERS;
uint32_t m_posInHeadBuf = 0;
uint32_t m_posInTailBuf = 0;
boo::ObjToken<boo::IAudioVoice> m_booVoice;
//boo::ObjToken<boo::IAudioVoice> m_booVoice;

// void* x4_loadBuf;
// void* x8_rom;
Expand Down Expand Up @@ -82,8 +81,8 @@ class CNESEmulator final : public boo::IAudioVoiceCallback {
EPasswordEntryState GetPasswordEntryState() const { return x34_passwordEntryState; }

int audioUpdate();
void preSupplyAudio(boo::IAudioVoice& voice, double dt) {}
size_t supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t* data);
//void preSupplyAudio(boo::IAudioVoice& voice, double dt) {}
//size_t supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t* data);
};

} // namespace MP1
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Audio/CAudioGroupSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstring>

namespace metaforce {

/*
amuse::AudioGroupData CAudioGroupSet::LoadData() {
const auto readU32 = [](const u8* ptr) {
uint32_t value;
Expand All @@ -30,8 +30,8 @@ amuse::AudioGroupData CAudioGroupSet::LoadData() {
return {proj, projLen, pool, poolLen, sdir, sdirLen, samp, sampLen, amuse::GCNDataTag{}};
}

CAudioGroupSet::CAudioGroupSet(std::unique_ptr<u8[]>&& in) : m_buffer(std::move(in)), m_data(LoadData()) {}
*/
CAudioGroupSet::CAudioGroupSet(std::unique_ptr<u8[]>&& in) : m_buffer(std::move(in)) {}

CFactoryFnReturn FAudioGroupSetDataFactory(const metaforce::SObjectTag& tag, std::unique_ptr<u8[]>&& in, u32 len,
const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) {
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Audio/CAudioGroupSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
#include "Runtime/IObj.hpp"
#include "Runtime/RetroTypes.hpp"

#include <amuse/AudioGroupData.hpp>
//#include <amuse/AudioGroupData.hpp>

namespace metaforce {

class CAudioGroupSet {
std::unique_ptr<u8[]> m_buffer;
std::string x10_baseName;
std::string x20_name;
amuse::AudioGroupData m_data;
amuse::AudioGroupData LoadData();
// amuse::AudioGroupData m_data;
// amuse::AudioGroupData LoadData();

public:
explicit CAudioGroupSet(std::unique_ptr<u8[]>&& in);
const amuse::AudioGroupData& GetAudioGroupData() const { return m_data; }
//const amuse::AudioGroupData& GetAudioGroupData() const { return m_data; }
std::string_view GetName() const { return x20_name; }
};

Expand Down
6 changes: 1 addition & 5 deletions Runtime/Audio/CAudioSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ void CAudioSys::SysUnloadAudioGroupSet(std::string_view name) {
bool CAudioSys::SysIsGroupSetLoaded(std::string_view name) { return FindGroupSet(name).operator bool(); }

void CAudioSys::SysAddGroupIntoAmuse(std::string_view name) {
if (auto set = FindGroupSet(name))
AddAudioGroup(set->GetAudioGroupData());
}

void CAudioSys::SysRemoveGroupFromAmuse(std::string_view name) {
if (auto set = FindGroupSet(name))
RemoveAudioGroup(set->GetAudioGroupData());
}

void CAudioSys::_UpdateVolume() { GetAmuseEngine().setVolume(s_MasterVol * s_SfxVol); }
void CAudioSys::_UpdateVolume() { }

void CAudioSys::SysSetVolume(u8 volume) {
s_MasterVol = volume / 127.f;
Expand Down
13 changes: 3 additions & 10 deletions Runtime/Audio/CAudioSys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "Runtime/GCNTypes.hpp"
#include "Runtime/RetroTypes.hpp"

#include <amuse/amuse.hpp>
#include <boo/audiodev/IAudioVoiceEngine.hpp>
//#include <amuse/amuse.hpp>
//#include <boo/audiodev/IAudioVoiceEngine.hpp>
#include <zeus/CVector3f.hpp>

namespace metaforce {
Expand All @@ -21,8 +21,6 @@ class CAudioSys {

private:
static CAudioSys* g_SharedSys;
boo::IAudioVoiceEngine* m_voiceEngine;
amuse::Engine m_engine;
static void _UpdateVolume();

public:
Expand All @@ -38,16 +36,11 @@ class CAudioSys {
bool x28_important; // Can't be allocated over, regardless of priority
u8 x29_prio;
};
CAudioSys(boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend, u8, u8, u8, u8, u32)
: m_voiceEngine(voiceEngine), m_engine(backend) {
CAudioSys(u8, u8, u8, u8, u32) {
g_SharedSys = this;
}
~CAudioSys() { g_SharedSys = nullptr; }

static void AddAudioGroup(const amuse::AudioGroupData& data) { g_SharedSys->m_engine.addAudioGroup(data); }
static void RemoveAudioGroup(const amuse::AudioGroupData& data) { g_SharedSys->m_engine.removeAudioGroup(data); }
static boo::IAudioVoiceEngine* GetVoiceEngine() { return g_SharedSys->m_voiceEngine; }
static amuse::Engine& GetAmuseEngine() { return g_SharedSys->m_engine; }
static void SetSurroundMode(ESurroundModes mode) {}
static TLockedToken<CAudioGroupSet> FindGroupSet(std::string_view name);
static std::string_view SysGetGroupSetName(CAssetId id);
Expand Down
16 changes: 8 additions & 8 deletions Runtime/Audio/CMidiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ void CMidiManager::StopAll() {
}

void CMidiManager::Stop(const CMidiHandle& handle, float fadeTime) {
handle->GetAudioSysHandle()->stopSong(fadeTime);
m_MidiWrappers.erase(handle);
// handle->GetAudioSysHandle()->stopSong(fadeTime);
// m_MidiWrappers.erase(handle);
}

std::unordered_set<CMidiHandle>::iterator CMidiManager::Stop(std::unordered_set<CMidiHandle>::iterator handle,
float fadeTime) {
const CMidiHandle& h = *handle;
h->GetAudioSysHandle()->stopSong(fadeTime);
// const CMidiHandle& h = *handle;
// h->GetAudioSysHandle()->stopSong(fadeTime);
return m_MidiWrappers.erase(handle);
}

Expand All @@ -29,10 +29,10 @@ CMidiHandle CMidiManager::Play(const CMidiData& data, float fadeTime, bool stopE
it = Stop(it, fadeTime);

CMidiHandle handle = *m_MidiWrappers.insert(std::make_shared<CMidiWrapper>()).first;
handle->SetAudioSysHandle(
CAudioSys::GetAmuseEngine().seqPlay(data.GetGroupId(), data.GetSetupId(), data.GetArrData()));
handle->GetAudioSysHandle()->setVolume(volume, fadeTime);
handle->SetSongId(data.GetSetupId());
// handle->SetAudioSysHandle(
// CAudioSys::GetAmuseEngine().seqPlay(data.GetGroupId(), data.GetSetupId(), data.GetArrData()));
// handle->GetAudioSysHandle()->setVolume(volume, fadeTime);
// handle->SetSongId(data.GetSetupId());
return handle;
}

Expand Down
6 changes: 3 additions & 3 deletions Runtime/Audio/CMidiManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class CMidiManager {
};

class CMidiWrapper {
amuse::ObjToken<amuse::Sequencer> x0_sequencer;
//amuse::ObjToken<amuse::Sequencer> x0_sequencer;
// CSfxHandle x4_handle;
u16 x8_songId;
bool xa_available = true;

public:
amuse::ObjToken<amuse::Sequencer> GetAudioSysHandle() const { return x0_sequencer; }
void SetAudioSysHandle(amuse::ObjToken<amuse::Sequencer> sequencer) { x0_sequencer = std::move(sequencer); }
//amuse::ObjToken<amuse::Sequencer> GetAudioSysHandle() const { return x0_sequencer; }
//void SetAudioSysHandle(amuse::ObjToken<amuse::Sequencer> sequencer) { x0_sequencer = std::move(sequencer); }
// const CSfxHandle& GetManagerHandle() const { return x4_handle; }
// void SetMidiHandle(const CSfxHandle& handle) { x4_handle = handle; }
bool IsAvailable() const { return xa_available; }
Expand Down
Loading

0 comments on commit 137e4c1

Please sign in to comment.