Make SPU wait for boot up sound to finish

This commit is contained in:
Jaby 2022-09-08 20:36:54 +02:00 committed by Jaby
parent 51f99194b2
commit f65d075db6
4 changed files with 41 additions and 19 deletions

View File

@ -25,6 +25,8 @@ namespace SPU {
//0..3 = +7, +6, +5, +4 or -6, -7, -6, -5 //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5
typedef uint8_t Step; typedef uint8_t Step;
typedef int16_t SimpleVolume;
struct __no_align SampleRate : public ComplexBitMap<uint16_t> { struct __no_align SampleRate : public ComplexBitMap<uint16_t> {
__io_port_inherit_complex_bit_map(SampleRate); __io_port_inherit_complex_bit_map(SampleRate);
@ -74,14 +76,14 @@ namespace SPU {
}; };
struct __no_align Voice { struct __no_align Voice {
IOPort<SweepVolume> volumeLeft; //Offset: 0x0 IOPort<SweepVolume> volumeLeft; //Offset: 0x0
IOPort<SweepVolume> volumeRight; //Offset: 0x2 IOPort<SweepVolume> volumeRight; //Offset: 0x2
IOPort<SampleRate> sampleRate; //Offset: 0x4; IOPort<SampleRate> sampleRate; //Offset: 0x4;
IOPort<uint16_t> adr; //Offset: 0x6 IOPort<uint16_t> adr; //Offset: 0x6
IOPort<AD> ad; //Offset: 0x8 IOPort<AD> ad; //Offset: 0x8
IOPort<SR> sr; //Offset: 0xA IOPort<SR> sr; //Offset: 0xA
IOPort<SweepVolume> currentVolume; //Offset: 0xC IOPort<SimpleVolume> currentVolume; //Offset: 0xC
IOPort<uint16_t> repeatAdr; //Offset: 0xE IOPort<uint16_t> repeatAdr; //Offset: 0xE
}; };
struct __no_align ControlRegister : public ComplexBitMap<uint16_t> { struct __no_align ControlRegister : public ComplexBitMap<uint16_t> {
@ -139,19 +141,19 @@ namespace SPU {
} }
namespace CDVolume { namespace CDVolume {
__declare_io_port_global(int16_t, left, 0x1F801DB0); __declare_io_port_global(SimpleVolume, left, 0x1F801DB0);
__declare_io_port_global(int16_t, right, 0x1F801DB2); __declare_io_port_global(SimpleVolume, right, 0x1F801DB2);
} }
namespace ExternalAudioInputVolume { namespace ExternalAudioInputVolume {
__declare_io_port_global(int16_t, left, 0x1F801DB4); __declare_io_port_global(SimpleVolume, left, 0x1F801DB4);
__declare_io_port_global(int16_t, right, 0x1F801DB6); __declare_io_port_global(SimpleVolume, right, 0x1F801DB6);
} }
namespace Reverb { namespace Reverb {
namespace Volume { namespace Volume {
__declare_io_port_global(int16_t, left, 0x1F801D84); __declare_io_port_global(SimpleVolume, left, 0x1F801D84);
__declare_io_port_global(int16_t, right, 0x1F801D86); __declare_io_port_global(SimpleVolume, right, 0x1F801D86);
} }
__declare_io_port_global(uint16_t, work_area_adr, 0x1F801DA2); __declare_io_port_global(uint16_t, work_area_adr, 0x1F801DA2);
} }

View File

@ -6,6 +6,7 @@ namespace GPU {
} }
namespace SPU { namespace SPU {
void stop_voices();
void setup(); void setup();
} }

View File

@ -1,15 +1,12 @@
#include <PSX/System/IOPorts/SPU_IO.hpp> #include <PSX/System/IOPorts/SPU_IO.hpp>
#include <PSX/System/IOPorts/DMA_IO.hpp> #include <PSX/System/IOPorts/DMA_IO.hpp>
#include <stdio.h>
#include <limits.h> #include <limits.h>
namespace SPU { namespace SPU {
using namespace Port; using namespace Port;
using namespace DMA::Port; using namespace DMA::Port;
static void clear_key() {
Key::off.write(UI32_MAX);
}
static void clear_main_volume() { static void clear_main_volume() {
static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2)); static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2));
@ -70,8 +67,24 @@ namespace SPU {
DataTransferControl.write(RequiredValue); DataTransferControl.write(RequiredValue);
} }
static void wait_voices() {
static constexpr int16_t Treshhold = (I16_MAX*0.03);
try_again:
for(const auto& voice : Voices) {
if(voice.currentVolume.read() > Treshhold) {
goto try_again;
}
}
}
void stop_voices() {
Key::off.write(UI32_MAX);
}
void setup() { void setup() {
clear_key(); wait_voices();
clear_main_volume(); clear_main_volume();
clear_cd_and_ext_audio_volume(); clear_cd_and_ext_audio_volume();
clear_control_register(); clear_control_register();

View File

@ -4,7 +4,13 @@
namespace JabyEngine { namespace JabyEngine {
void start() { void start() {
printf("Hello Planschbecken\n"); printf("Hello Planschbecken\n");
//We key off the voices
SPU::stop_voices();
//Load picture here
//Pause??
//Do the real setup
GPU::setup(); GPU::setup();
SPU::setup(); SPU::setup();
printf("Setup done!\n"); printf("Setup done!\n");