mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 19:34:39 +01:00
Merge pull request #14998 from unknownbrackets/audio-cleanup
Protect against time skew in background audio
This commit is contained in:
2 files changed
+11
-6
No files matched your search
@@ -118,7 +118,8 @@ inline void ClampBufferToS16(s16 *out, const s32 *in, size_t size, s8 volShift)
|
||||
size -= 8;
|
||||
}
|
||||
#elif PPSSPP_ARCH(ARM_NEON)
|
||||
int16x4_t signedVolShift = vdup_n_s16 (-volShift); // Can only dynamic-shift right, but by a signed integer
|
||||
// Dynamic shifts can only be left, but it's signed - negate to shift right.
|
||||
int16x4_t signedVolShift = vdup_n_s16(-volShift);
|
||||
while (size >= 8) {
|
||||
int32x4_t in1 = vld1q_s32(in);
|
||||
int32x4_t in2 = vld1q_s32(in + 4);
|
||||
@@ -281,10 +282,11 @@ void StereoResampler::PushSamples(const s32 *samples, unsigned int numSamples) {
|
||||
return;
|
||||
}
|
||||
|
||||
int over_bytes = numSamples * 4 - (m_maxBufsize * 2 - (indexW & INDEX_MASK)) * sizeof(short);
|
||||
if (over_bytes > 0) {
|
||||
ClampBufferToS16WithVolume(&m_buffer[indexW & INDEX_MASK], samples, (numSamples * 4 - over_bytes) / 2);
|
||||
ClampBufferToS16WithVolume(&m_buffer[0], samples + (numSamples * 4 - over_bytes) / sizeof(short), over_bytes / 2);
|
||||
// Check if we need to roll over to the start of the buffer during the copy.
|
||||
int indexW_left_samples = m_maxBufsize * 2 - (indexW & INDEX_MASK);
|
||||
if (numSamples * 2 > indexW_left_samples) {
|
||||
ClampBufferToS16WithVolume(&m_buffer[indexW & INDEX_MASK], samples, indexW_left_samples);
|
||||
ClampBufferToS16WithVolume(&m_buffer[0], samples + indexW_left_samples, numSamples * 2 - indexW_left_samples);
|
||||
} else {
|
||||
ClampBufferToS16WithVolume(&m_buffer[indexW & INDEX_MASK], samples, numSamples * 2);
|
||||
}
|
||||
|
||||
@@ -344,7 +344,10 @@ int BackgroundAudio::Play() {
|
||||
}
|
||||
|
||||
double now = time_now_d();
|
||||
int sz = lastPlaybackTime_ <= 0.0 ? 44100 / 60 : (int)((now - lastPlaybackTime_) * 44100);
|
||||
int sz = 44100 / 60;
|
||||
if (lastPlaybackTime_ > 0.0 && lastPlaybackTime_ >= now) {
|
||||
sz = (int)((now - lastPlaybackTime_) * 44100);
|
||||
}
|
||||
sz = std::min(BUFSIZE / 2, sz);
|
||||
if (at3Reader_) {
|
||||
if (at3Reader_->Read(buffer, sz)) {
|
||||
|
||||
Reference in new issue
Block a user