Streaming/DTK audio: fix pausing playback.

This commit is contained in:
magumagu
2014-06-15 15:08:47 -07:00
parent affb7c17fc
commit a282f181cd
4 changed files with 35 additions and 11 deletions

View File

@ -143,8 +143,7 @@ void DoState(PointerWrap &p)
static void GenerateAudioInterrupt(); static void GenerateAudioInterrupt();
static void UpdateInterrupts(); static void UpdateInterrupts();
static void IncreaseSampleCount(const u32 _uAmount); static void IncreaseSampleCount(const u32 _uAmount);
void ReadStreamBlock(s16* _pPCM); static u64 GetAIPeriod();
u64 GetAIPeriod();
int et_AI; int et_AI;
void Init() void Init()
@ -307,4 +306,9 @@ u64 GetAIPeriod()
return period; return period;
} }
bool IsAISPlaying()
{
return m_Control.PSTAT;
}
} // end of namespace AudioInterface } // end of namespace AudioInterface

View File

@ -27,4 +27,6 @@ unsigned int GetAIDSampleRate();
void GenerateAISInterrupt(); void GenerateAISInterrupt();
bool IsAISPlaying();
} // namespace } // namespace

View File

@ -261,11 +261,9 @@ void TransferComplete(u64 userdata, int cyclesLate)
FinishExecuteRead(); FinishExecuteRead();
} }
void ReadDTKSamples(u64 userdata, int cyclesLate) static u32 ProcessDTKSamples(short *tempPCM, u32 num_samples)
{ {
static const int NUM_SAMPLES = 48000 / 1000 * 7; // 7ms of 48kHz samples u32 samples_processed = 0;
short tempPCM[NUM_SAMPLES * 2];
unsigned samples_processed = 0;
do do
{ {
if (AudioPos >= CurrentStart + CurrentLength) if (AudioPos >= CurrentStart + CurrentLength)
@ -280,9 +278,7 @@ void ReadDTKSamples(u64 userdata, int cyclesLate)
if (AudioPos >= CurrentStart + CurrentLength) if (AudioPos >= CurrentStart + CurrentLength)
{ {
g_bStream = false; g_bStream = false;
return;
} }
break; break;
} }
@ -292,13 +288,36 @@ void ReadDTKSamples(u64 userdata, int cyclesLate)
AudioPos += sizeof(tempADPCM); AudioPos += sizeof(tempADPCM);
NGCADPCM::DecodeBlock(tempPCM + samples_processed * 2, tempADPCM); NGCADPCM::DecodeBlock(tempPCM + samples_processed * 2, tempADPCM);
samples_processed += NGCADPCM::SAMPLES_PER_BLOCK; samples_processed += NGCADPCM::SAMPLES_PER_BLOCK;
} while (samples_processed < NUM_SAMPLES); } while (samples_processed < num_samples);
for (unsigned i = 0; i < samples_processed * 2; ++i) for (unsigned i = 0; i < samples_processed * 2; ++i)
{ {
// TODO: Fix the mixer so it can accept non-byte-swapped samples. // TODO: Fix the mixer so it can accept non-byte-swapped samples.
tempPCM[i] = Common::swap16(tempPCM[i]); tempPCM[i] = Common::swap16(tempPCM[i]);
} }
return samples_processed;
}
void DTKStreamingCallback(u64 userdata, int cyclesLate)
{
// Send audio to the mixer.
static const int NUM_SAMPLES = 48000 / 2000 * 7; // 3.5ms of 48kHz samples
short tempPCM[NUM_SAMPLES * 2];
unsigned samples_processed;
if (AudioInterface::IsAISPlaying())
{
samples_processed = ProcessDTKSamples(tempPCM, NUM_SAMPLES);
}
else
{
memset(tempPCM, 0, sizeof(tempPCM));
samples_processed = NUM_SAMPLES;
}
soundStream->GetMixer()->PushStreamingSamples(tempPCM, samples_processed); soundStream->GetMixer()->PushStreamingSamples(tempPCM, samples_processed);
// If we reached the end of the audio, stop.
if (!g_bStream)
return;
int ticks_to_dtk = int(SystemTimers::GetTicksPerSecond() * u64(samples_processed) / 48000); int ticks_to_dtk = int(SystemTimers::GetTicksPerSecond() * u64(samples_processed) / 48000);
CoreTiming::ScheduleEvent(ticks_to_dtk - cyclesLate, dtk); CoreTiming::ScheduleEvent(ticks_to_dtk - cyclesLate, dtk);
} }
@ -344,7 +363,7 @@ void Init()
insertDisc = CoreTiming::RegisterEvent("InsertDisc", InsertDiscCallback); insertDisc = CoreTiming::RegisterEvent("InsertDisc", InsertDiscCallback);
tc = CoreTiming::RegisterEvent("TransferComplete", TransferComplete); tc = CoreTiming::RegisterEvent("TransferComplete", TransferComplete);
dtk = CoreTiming::RegisterEvent("StreamingTimer", ReadDTKSamples); dtk = CoreTiming::RegisterEvent("StreamingTimer", DTKStreamingCallback);
} }
void Shutdown() void Shutdown()

View File

@ -35,7 +35,6 @@ void ClearCoverInterrupt();
bool DVDRead(u32 _iDVDOffset, u32 _iRamAddress, u32 _iLength); bool DVDRead(u32 _iDVDOffset, u32 _iRamAddress, u32 _iLength);
// For AudioInterface // For AudioInterface
bool DVDReadADPCM(u8* _pDestBuffer, u32 _iNumSamples); bool DVDReadADPCM(u8* _pDestBuffer, u32 _iNumSamples);
extern bool g_bStream;
// Not sure about endianness here. I'll just name them like this... // Not sure about endianness here. I'll just name them like this...