summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authormagumagu <magumagu9@gmail.com>2014-06-15 15:08:47 -0700
committermagumagu <magumagu9@gmail.com>2014-06-15 15:08:47 -0700
commita282f181cd596c309acd10e9c96ba247a43f0c2b (patch)
treeaa9605fe0cd61ce4c287f3d3adc6c83e83aa1a6d /Source/Core
parentaffb7c17fc17e6c28a190f7a854533af4b44a980 (diff)
Streaming/DTK audio: fix pausing playback.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/HW/AudioInterface.cpp8
-rw-r--r--Source/Core/Core/HW/AudioInterface.h2
-rw-r--r--Source/Core/Core/HW/DVDInterface.cpp35
-rw-r--r--Source/Core/Core/HW/DVDInterface.h1
4 files changed, 35 insertions, 11 deletions
diff --git a/Source/Core/Core/HW/AudioInterface.cpp b/Source/Core/Core/HW/AudioInterface.cpp
index 517af05742..9600390c9c 100644
--- a/Source/Core/Core/HW/AudioInterface.cpp
+++ b/Source/Core/Core/HW/AudioInterface.cpp
@@ -143,8 +143,7 @@ void DoState(PointerWrap &p)
static void GenerateAudioInterrupt();
static void UpdateInterrupts();
static void IncreaseSampleCount(const u32 _uAmount);
-void ReadStreamBlock(s16* _pPCM);
-u64 GetAIPeriod();
+static u64 GetAIPeriod();
int et_AI;
void Init()
@@ -307,4 +306,9 @@ u64 GetAIPeriod()
return period;
}
+bool IsAISPlaying()
+{
+ return m_Control.PSTAT;
+}
+
} // end of namespace AudioInterface
diff --git a/Source/Core/Core/HW/AudioInterface.h b/Source/Core/Core/HW/AudioInterface.h
index 0b36692083..40df02fe24 100644
--- a/Source/Core/Core/HW/AudioInterface.h
+++ b/Source/Core/Core/HW/AudioInterface.h
@@ -27,4 +27,6 @@ unsigned int GetAIDSampleRate();
void GenerateAISInterrupt();
+bool IsAISPlaying();
+
} // namespace
diff --git a/Source/Core/Core/HW/DVDInterface.cpp b/Source/Core/Core/HW/DVDInterface.cpp
index 4e4e24ac4c..46f3e86e93 100644
--- a/Source/Core/Core/HW/DVDInterface.cpp
+++ b/Source/Core/Core/HW/DVDInterface.cpp
@@ -261,11 +261,9 @@ void TransferComplete(u64 userdata, int cyclesLate)
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
- short tempPCM[NUM_SAMPLES * 2];
- unsigned samples_processed = 0;
+ u32 samples_processed = 0;
do
{
if (AudioPos >= CurrentStart + CurrentLength)
@@ -280,9 +278,7 @@ void ReadDTKSamples(u64 userdata, int cyclesLate)
if (AudioPos >= CurrentStart + CurrentLength)
{
g_bStream = false;
- return;
}
-
break;
}
@@ -292,13 +288,36 @@ void ReadDTKSamples(u64 userdata, int cyclesLate)
AudioPos += sizeof(tempADPCM);
NGCADPCM::DecodeBlock(tempPCM + samples_processed * 2, tempADPCM);
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)
{
// TODO: Fix the mixer so it can accept non-byte-swapped samples.
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);
+
+ // If we reached the end of the audio, stop.
+ if (!g_bStream)
+ return;
+
int ticks_to_dtk = int(SystemTimers::GetTicksPerSecond() * u64(samples_processed) / 48000);
CoreTiming::ScheduleEvent(ticks_to_dtk - cyclesLate, dtk);
}
@@ -344,7 +363,7 @@ void Init()
insertDisc = CoreTiming::RegisterEvent("InsertDisc", InsertDiscCallback);
tc = CoreTiming::RegisterEvent("TransferComplete", TransferComplete);
- dtk = CoreTiming::RegisterEvent("StreamingTimer", ReadDTKSamples);
+ dtk = CoreTiming::RegisterEvent("StreamingTimer", DTKStreamingCallback);
}
void Shutdown()
diff --git a/Source/Core/Core/HW/DVDInterface.h b/Source/Core/Core/HW/DVDInterface.h
index 6b03c7f123..8f53d824fc 100644
--- a/Source/Core/Core/HW/DVDInterface.h
+++ b/Source/Core/Core/HW/DVDInterface.h
@@ -35,7 +35,6 @@ void ClearCoverInterrupt();
bool DVDRead(u32 _iDVDOffset, u32 _iRamAddress, u32 _iLength);
// For AudioInterface
bool DVDReadADPCM(u8* _pDestBuffer, u32 _iNumSamples);
-extern bool g_bStream;
// Not sure about endianness here. I'll just name them like this...