Skip to content

Commit

Permalink
Testing changes to audio buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
z2442 committed Jan 9, 2025
1 parent 6d4afed commit 96558a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
7 changes: 2 additions & 5 deletions Source/HLEAudio/AudioBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ asm("sync");
if (write_ptr >= mBufferEnd)
write_ptr = mBufferBegin;

#ifdef DAEDALUS_PSP

#else
while (write_ptr == read_ptr) {
// The buffer is full - spin until the read pointer advances.
// Note - spends a lot of time here if program is running
Expand All @@ -147,11 +144,11 @@ asm("sync");
// ToDo: Adjust Audio Frequency/ Look at Turok in this regard.
// We might want to put a Sleep in when executing on the SC?
// Give time to other threads when using SYNC mode.
// ThreadYield();
sceKernelDelayThread(50);

read_ptr = mReadPtr;
}
#endif


*write_ptr = out;
}
Expand Down
32 changes: 3 additions & 29 deletions Source/HLEAudio/Plugin/PSP/AudioPluginPSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,9 @@ static int audioOutput(SceSize args, void *argp)

sceKernelWaitSema( mSemaphoretwo, 1, nullptr );


sceKernelDcacheInvalidateRange((void *)mei, sizeof(me_struct));
asm("sync");

BeginME( mei, (int)&Audio_Ucode, (int)NULL, -1, NULL, -1, NULL);

asm("sync");

while (CheckME(mei) != 1) {
sceKernelDcacheInvalidateRange((void *)mei, sizeof(me_struct));
asm("sync");
sceKernelDelayThread(50); // Yield to other threads to avoid 100% CPU usage
}

Expand All @@ -185,20 +177,14 @@ static int audiobuffer(SceSize args, void *argp)

sceKernelWaitSema( mSemaphorethree, 1, nullptr );

sceKernelDcacheInvalidateRange((void *)mei, sizeof(me_struct));
asm("sync");

while (CheckME(mei) != 1) {
sceKernelDcacheInvalidateRange((void *)mei, sizeof(me_struct));
asm("sync");
sceKernelDelayThread(50); // Yield to other threads to avoid 100% CPU usage
}

sceKernelWaitSema( mSemaphore, 1, nullptr );


gAudioPlugin->LenChangedME();

sceKernelSignalSema( mSemaphore, 1 );

}

Expand All @@ -214,19 +200,8 @@ int BufferThid = sceKernelCreateThread("audiobuffer", audiobuffer, 0x15, 0x1800,
void AudioPluginPSP::FillBuffer(Sample * buffer, u32 num_samples)
{

sceKernelWaitSema( mSemaphore, 1, nullptr );

dcache_inv_range( mAudioBuffer, sizeof( CAudioBuffer ) );
asm("sync");

mAudioBufferUncached->Drain( buffer, num_samples );

dcache_wbinv_range_unaligned( mAudioBuffer, mAudioBuffer+sizeof( CAudioBuffer ) );
asm("sync");

sceKernelSignalSema( mSemaphore, 1 );


}


Expand All @@ -246,7 +221,8 @@ AudioPluginPSP::AudioPluginPSP()
mAudioBuffer = new( mem ) CAudioBuffer( kAudioBufferSize );
mAudioBufferUncached = (CAudioBuffer*)make_uncached_ptr(mem);
// Ideally we could just invalidate this range?
dcache_wbinv_range_unaligned( mAudioBuffer, mAudioBuffer+sizeof( CAudioBuffer ) );
sceKernelDcacheWritebackAll();
asm("sync");

#ifdef DAEDALUS_PSP_USE_ME
InitialiseMediaEngine();
Expand Down Expand Up @@ -345,8 +321,6 @@ EProcessResult AudioPluginPSP::ProcessAList()
case APM_ENABLED_ASYNC:
{
//signal the audio thread to kick off a audioucode HLE task.
sceKernelDcacheWritebackAll();
asm("sync");
sceKernelSignalSema( mSemaphoretwo, 1 );
if(audiothreadactive == false){
audiothreadactive = true;
Expand Down
6 changes: 5 additions & 1 deletion Source/SysPSP/PRX/MediaEngine/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ static void me_loop(volatile struct me_struct *mei)

while (1); // loop forever until ME reset
}

#define vrp volatile u32*
#define vrg(addr) (*((vrp)(addr)))

int InitME(volatile struct me_struct *mei)
{
unsigned int k1;

vrg(0xbc100004) = 0xffffffff;


k1 = pspSdkSetK1(0);

if (mei == 0)
Expand Down

0 comments on commit 96558a8

Please sign in to comment.