Seems to be working on 44100

This commit is contained in:
KiritoDv 2024-11-15 14:48:47 -06:00
parent 8da3a6e866
commit d589fc4606
4 changed files with 30 additions and 24 deletions

View File

@ -558,8 +558,6 @@ void AudioHeap_ClearCurrentAiBuffer(void) {
}
}
extern s16 audio_buffer[];
s32 AudioHeap_ResetStep(void) {
s32 i;
s32 j;
@ -599,7 +597,7 @@ s32 AudioHeap_ResetStep(void) {
gResetFadeoutFramesLeft--;
AudioHeap_UpdateReverbs();
} else {
memset(audio_buffer, 0, (1056 * 2 * 3) * 2 * 2);
// memset(audio_buffer, 0, (1056 * 2 * 3) * 2 * 2);
gResetFadeoutFramesLeft = 4 / sp24;
gAudioResetStep--;
break; // needed to match
@ -617,7 +615,7 @@ s32 AudioHeap_ResetStep(void) {
case 1:
AudioHeap_Init();
gAudioResetStep = 0;
memset(audio_buffer, 0, (1056 * 2 * 3) * 2 * 2);
// memset(audio_buffer, 0, (1056 * 2 * 3) * 2 * 2);
break;
}
if (gAudioResetStep < 3) {
@ -643,15 +641,12 @@ void AudioHeap_Init(void) {
gAudioBufferParams.aiSamplingFrequency = osAiSetFrequency(gAudioBufferParams.samplingFrequency);
gAudioBufferParams.samplesPerFrameTarget = ALIGN16(gAudioBufferParams.samplingFrequency / gRefreshRate);
printf("aiSamplingFrequency %d\n", gAudioBufferParams.aiSamplingFrequency);
printf("samplesPerFrameTarget %d\n", gAudioBufferParams.samplesPerFrameTarget);
gAudioBufferParams.minAiBufferLength = gAudioBufferParams.samplesPerFrameTarget - 0x10;
gAudioBufferParams.maxAiBufferLength = gAudioBufferParams.samplesPerFrameTarget + 0x10;
gAudioBufferParams.ticksPerUpdate = ((gAudioBufferParams.samplesPerFrameTarget + 0x10) / 192);
gAudioBufferParams.ticksPerUpdate = ((gAudioBufferParams.samplesPerFrameTarget + 0x10) / 192) + 1;
gAudioBufferParams.samplesPerTick =
(gAudioBufferParams.samplesPerFrameTarget / (gAudioBufferParams.ticksPerUpdate + 1)) & ~7;
(gAudioBufferParams.samplesPerFrameTarget / gAudioBufferParams.ticksPerUpdate) & ~7;
gAudioBufferParams.samplesPerTickMax = gAudioBufferParams.samplesPerTick + 8;
gAudioBufferParams.samplesPerTickMin = gAudioBufferParams.samplesPerTick - 8;
gAudioBufferParams.resampleRate = 32000.0f / (s32) gAudioBufferParams.samplingFrequency;
@ -665,11 +660,11 @@ void AudioHeap_Init(void) {
// Using 1 buffer has caused issues, so we hardcoded it to 2.
// To prevent sequences from going too fast, we added a * 2 here.
// This is not an optimal fix but it works. We may wish to find something better in the future.
gMaxTempo = (u16) ((gAudioBufferParams.ticksPerUpdate * 2 * 2880000.0f / gSeqTicksPerBeat) / gMaxTempoTvTypeFactors);
//gMaxTempo = (u16) ((gAudioBufferParams.ticksPerUpdate * 2880000.0f / gSeqTicksPerBeat) / gMaxTempoTvTypeFactors);
// gMaxTempo = (u16) ((gAudioBufferParams.ticksPerUpdate * 2880000.0f / gSeqTicksPerBeat) / gMaxTempoTvTypeFactors);
gMaxTempo = (u16) ((gAudioBufferParams.ticksPerUpdate * 2880000.0f / gSeqTicksPerBeat) / gMaxTempoTvTypeFactors);
gAudioBufferParams.numBuffers = spec->numBuffers;
gAudioBufferParams.numBuffers = 2;
gAudioBufferParams.numBuffers = 1;
gAudioBufferParams.samplesPerFrameTarget *= gAudioBufferParams.numBuffers;
gAudioBufferParams.maxAiBufferLength *= gAudioBufferParams.numBuffers;

View File

@ -701,7 +701,7 @@ Acmd* AudioSynth_Update(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLe
AudioSynth_DoOneAudioUpdate((s16*) aiBufPtr, chunkLen, aCmdPtr, gAudioBufferParams.ticksPerUpdate - i);
aiBufLen -= chunkLen;
// if (aiBufLen < 0) aiBufLen = 0;
aiBufPtr += chunkLen*2;
aiBufPtr += chunkLen * 2;
}
for (j = 0; j < gNumSynthReverbs; j++) {

View File

@ -132,7 +132,7 @@ void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c) {
return;
}
int count = ROUND_UP_16(rspa.nbytes) >> 2;
int count = ROUND_UP_16(rspa.nbytes) >> 3;
int16_t *l = BUF_S16(left);
int16_t *r = BUF_S16(right);

View File

@ -30,6 +30,10 @@
#include <Fast3D/gfx_pc.h>
#include <Fast3D/gfx_rendering_api.h>
#include <SDL2/SDL.h>
#include <fstream>
#include <filesystem>
namespace fs = std::filesystem;
//extern "C" AudioBufferParameters gAudioBufferParams;
@ -68,7 +72,7 @@ GameEngine::GameEngine() {
}
this->context =
Ship::Context::CreateInstance("Starship", "ship", "starship.cfg.json", OTRFiles, {}, 3, { 44100, 1056, 1056 * 2 });
Ship::Context::CreateInstance("Starship", "ship", "starship.cfg.json", OTRFiles, {}, 3, { 44100, 1024, 2480 });
auto loader = context->GetResourceManager()->GetResourceLoader();
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAnimV0>(), RESOURCE_FORMAT_BINARY,
@ -126,6 +130,7 @@ void GameEngine::Create() {
}
void GameEngine::Destroy() {
AudioExit();
free(MemoryPool.memory);
}
@ -149,13 +154,9 @@ void GameEngine::StartFrame() const {
this->context->GetWindow()->StartFrame();
}
#define SAMPLES_HIGH 1056
#define SAMPLES_LOW 880
#define SAMPLES_HIGH 752
#define SAMPLES_LOW 720
#define NUM_AUDIO_CHANNELS 2
#define SAMPLES_PER_FRAME (SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 3)
extern "C"
s16 audio_buffer[SAMPLES_PER_FRAME * 2 * 2] = { 0 };
extern "C" s32 audBuffer = 0;
#include <sf64audio_provisional.h>
@ -164,6 +165,9 @@ extern "C" volatile s32 gAudioTaskCountQ;
int frames = 0;
extern "C" int countermin = 0;
void GameEngine::HandleAudioThread() {
#ifdef PIPE_DEBUG
std::ofstream outfile("audio.bin", std::ios::binary | std::ios::app);
#endif
while (audio.running) {
{
std::unique_lock<std::mutex> Lock(audio.mutex);
@ -177,8 +181,7 @@ void GameEngine::HandleAudioThread() {
//gVIsPerFrame = 2;
//#define AUDIO_FRAMES_PER_UPDATE (gVIsPerFrame > 0 ? gVIsPerFrame : 1)
#define AUDIO_FRAMES_PER_UPDATE 2
#define AUDIO_FRAMES_PER_UPDATE (gVIsPerFrame > 0 ? gVIsPerFrame : 1)
std::unique_lock<std::mutex> Lock(audio.mutex);
int samples_left = AudioPlayerBuffered();
@ -190,16 +193,24 @@ void GameEngine::HandleAudioThread() {
countermin++;
}
s16 audio_buffer[SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 3] = { 0 };
for (int i = 0; i < AUDIO_FRAMES_PER_UPDATE; i++) {
AudioThread_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS),
num_audio_samples);
}
#ifdef PIPE_DEBUG
if(outfile.is_open()){
outfile.write(reinterpret_cast<char*>(audio_buffer), num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
}
#endif
AudioPlayerPlayFrame((u8*) audio_buffer,
num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
audio.processing = false;
audio.cv_from_thread.notify_one();
}
#ifdef PIPE_DEBUG
outfile.close();
#endif
}
void GameEngine::StartAudioFrame() {