Updated audio

This commit is contained in:
KiritoDv 2024-11-09 20:45:31 -06:00
parent 4acc13fb36
commit cd48d2cefa
10 changed files with 73 additions and 64 deletions

View File

@ -144,91 +144,91 @@ ReverbSettings D_800C76A8[] = {
{ 1, 0x30, 0x4FFF, 0, 0 }, { 1, 0x30, 0x4FFF, 0, 0 },
}; };
AudioSpec gAudioSpecs[] = { AudioSpec gAudioSpecs[] = {
/* 0 */ { 32000, 2, 22, ARRAY_COUNT(D_800C74D0), D_800C74D0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, /* 0 */ { 44100, 2, 22, ARRAY_COUNT(D_800C74D0), D_800C74D0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 1 */ /* 1 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C74E0), D_800C74E0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C74E0), D_800C74E0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 2 */ /* 2 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C74F0), D_800C74F0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C74F0), D_800C74F0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 3 */ /* 3 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7500), D_800C7500, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7500), D_800C7500, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 4 */ /* 4 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7510), D_800C7510, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7510), D_800C7510, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 5 */ /* 5 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7520), D_800C7520, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7520), D_800C7520, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 6 */ /* 6 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7530), D_800C7530, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7530), D_800C7530, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 7 */ /* 7 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7540), D_800C7540, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7540), D_800C7540, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 8 */ /* 8 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7550), D_800C7550, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7550), D_800C7550, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 9 */ /* 9 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7560), D_800C7560, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7560), D_800C7560, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 10 */ /* 10 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7570), D_800C7570, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7570), D_800C7570, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 11 */ /* 11 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7580), D_800C7580, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7580), D_800C7580, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 12 */ /* 12 */
{ 32000, 1, 22, ARRAY_COUNT(D_800C7590), D_800C7590, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x2B000, { 44100, 1, 22, ARRAY_COUNT(D_800C7590), D_800C7590, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x2B000,
0x35000 }, 0x35000 },
/* 13 */ /* 13 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C75A0), D_800C75A0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C75A0), D_800C75A0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 14 */ /* 14 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C75B0), D_800C75B0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C75B0), D_800C75B0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 15 */ /* 15 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C75C0), D_800C75C0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C75C0), D_800C75C0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x34000 }, 0x34000 },
/* 16 */ /* 16 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C75D8), D_800C75D8, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C75D8), D_800C75D8, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 17 */ /* 17 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C75E8), D_800C75E8, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C75E8), D_800C75E8, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 18 */ /* 18 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C75F8), D_800C75F8, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C75F8), D_800C75F8, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 19 */ /* 19 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7608), D_800C7608, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7608), D_800C7608, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 20 */ /* 20 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7618), D_800C7618, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7618), D_800C7618, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
/* 21 */ /* 21 */
{ 32000, 2, 32, ARRAY_COUNT(D_800C7628), D_800C7628, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 32, ARRAY_COUNT(D_800C7628), D_800C7628, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x00000 }, 0x00000 },
/* 22 */ /* 22 */
{ 32000, 1, 32, ARRAY_COUNT(D_800C7638), D_800C7638, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 1, 32, ARRAY_COUNT(D_800C7638), D_800C7638, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x00000 }, 0x00000 },
/* 23 */ /* 23 */
{ 32000, 1, 32, ARRAY_COUNT(D_800C7648), D_800C7648, 0x7FFF, 0x1200, 0xA000, 0, 0x5B00, 0x1D00, 0, 0x00000, { 44100, 1, 32, ARRAY_COUNT(D_800C7648), D_800C7648, 0x7FFF, 0x1200, 0xA000, 0, 0x5B00, 0x1D00, 0, 0x00000,
0x00000 }, 0x00000 },
/* 24 */ /* 24 */
{ 32000, 1, 22, ARRAY_COUNT(D_800C7658), D_800C7658, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x00000, { 44100, 1, 22, ARRAY_COUNT(D_800C7658), D_800C7658, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x00000,
0x60000 }, 0x60000 },
/* 25 */ /* 25 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7668), D_800C7668, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7668), D_800C7668, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x00000 }, 0x00000 },
/* 26 */ /* 26 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C7678), D_800C7678, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C7678), D_800C7678, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x00000 }, 0x00000 },
/* 27 */ /* 27 */
{ 32000, 2, 32, ARRAY_COUNT(D_800C7688), D_800C7688, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 32, ARRAY_COUNT(D_800C7688), D_800C7688, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x00000 }, 0x00000 },
/* 28 */ /* 28 */
{ 32000, 2, 22, ARRAY_COUNT(D_800C74D0), D_800C74D0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000, { 44100, 2, 22, ARRAY_COUNT(D_800C74D0), D_800C74D0, 0x7FFF, 0x1200, 0x1100, 0, 0x5000, 0x2400, 0, 0x1B000,
0x35000 }, 0x35000 },
}; };
s32 D_800C7C28 = 0x20000000; // unused? s32 D_800C7C28 = 0x20000000; // unused?

View File

@ -647,7 +647,7 @@ void AudioHeap_Init(void) {
gSampleDmaCount = 0; gSampleDmaCount = 0;
gAudioBufferParams.samplingFrequency = spec->samplingFrequency; gAudioBufferParams.samplingFrequency = spec->samplingFrequency;
gAudioBufferParams.aiSamplingFrequency = 32000; gAudioBufferParams.aiSamplingFrequency = osAiSetFrequency(gAudioBufferParams.samplingFrequency);
gAudioBufferParams.samplesPerFrameTarget = ALIGN16(gAudioBufferParams.samplingFrequency / gRefreshRate); gAudioBufferParams.samplesPerFrameTarget = ALIGN16(gAudioBufferParams.samplingFrequency / gRefreshRate);
printf("aiSamplingFrequency %d\n", gAudioBufferParams.aiSamplingFrequency); printf("aiSamplingFrequency %d\n", gAudioBufferParams.aiSamplingFrequency);

View File

@ -311,10 +311,8 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) {
} }
void AudioLoad_AsyncLoadSampleBank(s32 sampleBankId, s32 nChunks, s32 retData, OSMesgQueue* retQueue) { void AudioLoad_AsyncLoadSampleBank(s32 sampleBankId, s32 nChunks, s32 retData, OSMesgQueue* retQueue) {
if (AudioLoad_AsyncLoadInner(SAMPLE_TABLE, AudioLoad_GetLoadTableIndex(SAMPLE_TABLE, sampleBankId), nChunks, AudioLoad_AsyncLoadInner(SAMPLE_TABLE, AudioLoad_GetLoadTableIndex(SAMPLE_TABLE, sampleBankId), nChunks, retData, retQueue);
retData, retQueue) == NULL) {
osSendMesg(retQueue, OS_MESG_PTR(NULL), OS_MESG_NOBLOCK); osSendMesg(retQueue, OS_MESG_PTR(NULL), OS_MESG_NOBLOCK);
}
} }
void AudioLoad_AsyncLoadSeq(s32 seqId, s32 nChunks, s32 retData, OSMesgQueue* retQueue) { void AudioLoad_AsyncLoadSeq(s32 seqId, s32 nChunks, s32 retData, OSMesgQueue* retQueue) {
@ -430,6 +428,10 @@ void* AudioLoad_SyncLoadSampleBank(u32 sampleBankId, s32* outMedium) {
s32 noLoad; s32 noLoad;
sampleBankId = AudioLoad_GetLoadTableIndex(SAMPLE_TABLE, sampleBankId); sampleBankId = AudioLoad_GetLoadTableIndex(SAMPLE_TABLE, sampleBankId);
gSampleFontLoadStatus[sampleBankId] = 2;
return Audio_LoadBlob(gAudioTable, sampleBankTable->entries[sampleBankId].romAddr);
ramAddr = AudioLoad_SearchCaches(2, sampleBankId); ramAddr = AudioLoad_SearchCaches(2, sampleBankId);
if (ramAddr != NULL) { if (ramAddr != NULL) {
if (gSampleFontLoadStatus[sampleBankId] != 5) { if (gSampleFontLoadStatus[sampleBankId] != 5) {
@ -520,7 +522,6 @@ void* AudioLoad_SyncLoad(u32 tableType, u32 id, s32* didAllocate) {
return Audio_LoadBlob(gAudioSeq, table->entries[id].romAddr); return Audio_LoadBlob(gAudioSeq, table->entries[id].romAddr);
case FONT_TABLE: case FONT_TABLE:
gFontLoadStatus[id] = LOAD_STATUS_COMPLETE; gFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
printf("fontId: %d\n", id);
return Audio_LoadFont(table->entries[id]); return Audio_LoadFont(table->entries[id]);
case SAMPLE_TABLE: case SAMPLE_TABLE:
loadStatus = 0; loadStatus = 0;
@ -705,10 +706,12 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData,
switch (tableType) { switch (tableType) {
case SEQUENCE_TABLE: case SEQUENCE_TABLE:
gFontLoadStatus[id] = LOAD_STATUS_COMPLETE; gFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
osSendMesg(retQueue, OS_MESG_32(retData << 0x18), OS_MESG_NOBLOCK);
return Audio_LoadBlob(gAudioSeq, table->entries[id].romAddr); return Audio_LoadBlob(gAudioSeq, table->entries[id].romAddr);
case FONT_TABLE: case FONT_TABLE:
gFontLoadStatus[id] = LOAD_STATUS_COMPLETE; gFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
printf("fontId: %d\n", id); printf("fontId: %d\n", id);
osSendMesg(retQueue, OS_MESG_32(retData << 0x18), OS_MESG_NOBLOCK);
return Audio_LoadFont(table->entries[id]); return Audio_LoadFont(table->entries[id]);
case SAMPLE_TABLE: case SAMPLE_TABLE:
gSampleFontLoadStatus[id] = LOAD_STATUS_COMPLETE; gSampleFontLoadStatus[id] = LOAD_STATUS_COMPLETE;
@ -790,7 +793,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData,
} }
void AudioLoad_ProcessLoads(s32 resetStatus) { void AudioLoad_ProcessLoads(s32 resetStatus) {
AudioLoad_ProcessSlowLoads(resetStatus); // AudioLoad_ProcessSlowLoads(resetStatus);
// AudioLoad_ProcessSamplePreloads(resetStatus); // AudioLoad_ProcessSamplePreloads(resetStatus);
// AudioLoad_ProcessAsyncLoads(resetStatus); // AudioLoad_ProcessAsyncLoads(resetStatus);
} }
@ -903,6 +906,8 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, u8 instId, s8* status) {
AudioSlowLoad* slowLoad; AudioSlowLoad* slowLoad;
sample = AudioLoad_GetFontSample(fontId, instId); sample = AudioLoad_GetFontSample(fontId, instId);
return 0;
if (sample == NULL) { if (sample == NULL) {
*status = SLOW_LOAD_STATUS_0; *status = SLOW_LOAD_STATUS_0;
return -1; return -1;

View File

@ -644,7 +644,7 @@ Acmd* func_80009B64(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLen) {
} }
aiBufPtr = (s32*) aiBufStart; aiBufPtr = (s32*) aiBufStart;
for (i = gAudioBufferParams.ticksPerUpdate; i > 0; i--) { for (i = gAudioBufferParams.ticksPerUpdate - 1; i > 0; i--) {
if (i == 1) { if (i == 1) {
chunkLen = aiBufLen; chunkLen = aiBufLen;
} else if ((aiBufLen / i) >= gAudioBufferParams.samplesPerTickMax) { } else if ((aiBufLen / i) >= gAudioBufferParams.samplesPerTickMax) {
@ -1000,18 +1000,18 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth
skipBytes = 0; skipBytes = 0;
goto skip; goto skip;
} }
aligned = ALIGN16(nFramesToDecode * frameSize + SAMPLES_PER_FRAME); aligned = ALIGN16(nFramesToDecode * frameSize + 0x10);
addr = 0x990 - aligned; addr = 0x990 - aligned;
if (nFramesToDecode != 0) { if (nFramesToDecode != 0) {
// LTODO: Validate this // LTODO: Validate this
// bookSample->medium = 0; // bookSample->medium = 0;
frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / SAMPLES_PER_FRAME; frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16;
sampleDataOffset = frameIndex * frameSize; sampleDataOffset = frameIndex * frameSize;
if (bookSample->medium == 0) { if (bookSample->medium == 0) {
sampleData = sampleDataOffset + sampleAddr; sampleData = sampleDmaStart + sampleDataOffset + sampleAddr;
} else { } else {
sampleData = sampleDataOffset + sampleAddr; sampleData = sampleDmaStart + sampleDataOffset + sampleAddr;
} }
// if (1){} // if (1){}
sampleDataStartPad = (uintptr_t) sampleData & 0xF; sampleDataStartPad = (uintptr_t) sampleData & 0xF;

View File

@ -48,7 +48,7 @@ void AudioThread_CreateNextAudioBuffer(s16 *samples, u32 num_samples) {
gCurAudioFrameDmaCount = 0; gCurAudioFrameDmaCount = 0;
AudioLoad_DecreaseSampleDmaTtls(); AudioLoad_DecreaseSampleDmaTtls();
// AudioLoad_ProcessLoads(gAudioResetStep); AudioLoad_ProcessLoads(gAudioResetStep);
if (MQ_GET_MESG(gAudioSpecQueue, &specId)) { if (MQ_GET_MESG(gAudioSpecQueue, &specId)) {
if (gAudioResetStep == 0) { if (gAudioResetStep == 0) {
@ -80,6 +80,7 @@ void AudioThread_CreateNextAudioBuffer(s16 *samples, u32 num_samples) {
} }
gCurAbiCmdBuffer = func_80009B64(gCurAbiCmdBuffer, &abiCmdCount, samples, num_samples); gCurAbiCmdBuffer = func_80009B64(gCurAbiCmdBuffer, &abiCmdCount, samples, num_samples);
memcpy(gAiBuffers[gCurAiBuffIndex], samples, num_samples);
gAudioRandom = osGetCount() * (gAudioRandom + gAudioTaskCountQ); gAudioRandom = osGetCount() * (gAudioRandom + gAudioTaskCountQ);
gAudioCurTask->msg = OS_MESG_PTR(NULL); gAudioCurTask->msg = OS_MESG_PTR(NULL);
@ -347,7 +348,7 @@ void AudioThread_ScheduleProcessCmds(void) {
D_800C7C70 = (u8) (gThreadCmdWritePos - gThreadCmdReadPos + 0x100); D_800C7C70 = (u8) (gThreadCmdWritePos - gThreadCmdReadPos + 0x100);
} }
msg = (((gThreadCmdReadPos & 0xFF) << 8) | (gThreadCmdWritePos & 0xFF)); msg = (((gThreadCmdReadPos & 0xFF) << 8) | (gThreadCmdWritePos & 0xFF));
osSendMesg32(gThreadCmdProcQueue, msg, OS_MESG_NOBLOCK); osSendMesg(gThreadCmdProcQueue, OS_MESG_32(msg), OS_MESG_NOBLOCK);
gThreadCmdReadPos = gThreadCmdWritePos; gThreadCmdReadPos = gThreadCmdWritePos;
} }
@ -364,11 +365,10 @@ void AudioThread_ProcessCmds(u32 msg) {
u8 writePos; u8 writePos;
if (!gThreadCmdQueueFinished) { if (!gThreadCmdQueueFinished) {
gCurCmdReadPos = msg >> 8; gCurCmdReadPos = (msg >> 8) & 0xFF;
} }
while (true) {
writePos = msg & 0xFF; writePos = msg & 0xFF;
while (true) {
if (gCurCmdReadPos == writePos) { if (gCurCmdReadPos == writePos) {
gThreadCmdQueueFinished = 0; gThreadCmdQueueFinished = 0;

View File

@ -126,10 +126,16 @@ void aSetBufferImpl(uint8_t flags, uint16_t in, uint16_t out, uint16_t nbytes) {
} }
void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c) { void aInterleaveImpl(uint16_t dest, uint16_t left, uint16_t right, uint16_t c) {
int count = ROUND_UP_8(c) / sizeof(int16_t) / 4; if(rspa.nbytes == 0){
return;
}
int count = ROUND_UP_32(rspa.nbytes) >> 3;
int16_t *l = BUF_S16(left); int16_t *l = BUF_S16(left);
int16_t *r = BUF_S16(right); int16_t *r = BUF_S16(right);
int16_t *d = BUF_S16(dest); int16_t *d = BUF_S16(rspa.out);
while (count > 0) { while (count > 0) {
int16_t l0 = *l++; int16_t l0 = *l++;
int16_t l1 = *l++; int16_t l1 = *l++;
@ -277,7 +283,7 @@ void aEnvSetup2Impl(uint16_t initial_vol_left, uint16_t initial_vol_right) {
void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb, void aEnvMixerImpl(uint16_t in_addr, uint16_t n_samples, bool swap_reverb,
bool neg_3, bool neg_2, bool neg_3, bool neg_2,
bool neg_left, bool neg_right, bool neg_left, bool neg_right,
int32_t wet_dry_addr, u32 unk) int32_t wet_dry_addr, uint32_t unk)
{ {
int16_t *in = BUF_S16(in_addr); int16_t *in = BUF_S16(in_addr);
int16_t *dry[2] = {BUF_S16(((wet_dry_addr >> 24) & 0xFF) << 4), BUF_S16(((wet_dry_addr >> 16) & 0xFF) << 4)}; int16_t *dry[2] = {BUF_S16(((wet_dry_addr >> 24) & 0xFF) << 4), BUF_S16(((wet_dry_addr >> 16) & 0xFF) << 4)};

View File

@ -4,6 +4,7 @@ s32 osViClock2 = 0x02E6D354;
s32 osAiSetFrequency(u32 freq) { s32 osAiSetFrequency(u32 freq) {
return 1; return 1;
register u32 a1; register u32 a1;
register s32 a2; register s32 a2;
register float ftmp; register float ftmp;

View File

@ -66,7 +66,7 @@ GameEngine::GameEngine() {
} }
} }
this->context = Ship::Context::CreateInstance("Starship", "ship", "starship.cfg.json", OTRFiles, {}, 3, { 32000, 512, 1100 }); this->context = Ship::Context::CreateInstance("Starship", "ship", "starship.cfg.json", OTRFiles, {}, 3, { 44100, 1024, 2480 });
auto loader = context->GetResourceManager()->GetResourceLoader(); auto loader = context->GetResourceManager()->GetResourceLoader();
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAnimV0>(), RESOURCE_FORMAT_BINARY, "Animation", static_cast<uint32_t>(SF64::ResourceType::AnimData), 0); loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryAnimV0>(), RESOURCE_FORMAT_BINARY, "Animation", static_cast<uint32_t>(SF64::ResourceType::AnimData), 0);
@ -134,12 +134,15 @@ void GameEngine::HandleAudioThread(){
break; break;
} }
} }
#define AUDIO_FRAMES_PER_UPDATE (gVIsPerFrame > 0 ? gVIsPerFrame : 1 )
std::unique_lock<std::mutex> Lock(audio.mutex); std::unique_lock<std::mutex> Lock(audio.mutex);
int samples_left = AudioPlayerBuffered(); int samples_left = AudioPlayerBuffered();
u32 num_audio_samples = samples_left < AudioPlayerGetDesiredBuffered() ? SAMPLES_HIGH : SAMPLES_LOW; u32 num_audio_samples = samples_left < AudioPlayerGetDesiredBuffered() ? SAMPLES_HIGH : SAMPLES_LOW;
s16 audio_buffer[SAMPLES_PER_FRAME]; s16 audio_buffer[SAMPLES_PER_FRAME];
for (int i = 0; i < NUM_AUDIO_CHANNELS; i++) { for (int i = 0; i < AUDIO_FRAMES_PER_UPDATE; i++) {
AudioThread_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * 2), num_audio_samples); AudioThread_CreateNextAudioBuffer(audio_buffer + i * (num_audio_samples * NUM_AUDIO_CHANNELS), num_audio_samples);
} }
AudioPlayerPlayFrame((u8 *) audio_buffer, num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE)); AudioPlayerPlayFrame((u8 *) audio_buffer, num_audio_samples * (sizeof(int16_t) * NUM_AUDIO_CHANNELS * AUDIO_FRAMES_PER_UPDATE));
audio.processing = false; audio.processing = false;

View File

@ -15,11 +15,10 @@ struct GamePool {
#include <Fast3D/gfx_pc.h> #include <Fast3D/gfx_pc.h>
#include "libultraship/src/Context.h" #include "libultraship/src/Context.h"
#define SAMPLES_HIGH 544 #define SAMPLES_HIGH 752
#define SAMPLES_LOW 528 #define SAMPLES_LOW 720
#define AUDIO_FRAMES_PER_UPDATE 2
#define NUM_AUDIO_CHANNELS 2 #define NUM_AUDIO_CHANNELS 2
#define SAMPLES_PER_FRAME (SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 2) #define SAMPLES_PER_FRAME (SAMPLES_HIGH * NUM_AUDIO_CHANNELS * 3)
class GameEngine { class GameEngine {
public: public:

View File

@ -139,11 +139,6 @@ Sample* Audio_LoadSample(uint32_t sampleAddr, AudioTableEntry entry, uint32_t sa
sample->isRelocated = 1; sample->isRelocated = 1;
sample->medium = MEDIUM_RAM; sample->medium = MEDIUM_RAM;
std::filesystem::path path{ "dumps/" + std::to_string(addr) + ".raw" };
std::ofstream ofs(path);
ofs.write(reinterpret_cast<const char*>(sample->sampleAddr), sample->size);
ofs.close();
gUsedSamples[gNumUsedSamples++] = sample; gUsedSamples[gNumUsedSamples++] = sample;
return sample; return sample;
} }