mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Revert "Merge pull request #4021 from bollu/master"
This reverts commitc84a9daa40
, reversing changes made toda5b52ce1f
.
This commit is contained in:
parent
f938b95925
commit
367a1e21b2
@ -28,15 +28,12 @@
|
||||
#include "ChunkFile.h"
|
||||
#include "FixedSizeQueue.h"
|
||||
#include "Common/Thread.h"
|
||||
#include "Common/Atomics.h"
|
||||
#include "../../native/base/mutex.h"
|
||||
|
||||
// Should be used to lock anything related to the outAudioQueue.
|
||||
//atomic locks are used on the lock. TODO: make this lock-free
|
||||
atomic_flag audioQueueLock(NATIVE_ATOMIC_FLAG_INIT);
|
||||
recursive_mutex section;
|
||||
|
||||
int eventAudioUpdate = -1;
|
||||
int eventHostAudioUpdate = -1;
|
||||
int eventHostAudioUpdate = -1;
|
||||
int mixFrequency = 44100;
|
||||
|
||||
const int hwSampleRate = 44100;
|
||||
@ -58,9 +55,6 @@ static int chanQueueMinSizeFactor;
|
||||
// is bad mojo.
|
||||
FixedSizeQueue<s16, 512 * 16> outAudioQueue;
|
||||
|
||||
bool __gainAudioQueueLock();
|
||||
void __releaseAcquiredLock();
|
||||
|
||||
static inline s16 clamp_s16(int i) {
|
||||
if (i > 32767)
|
||||
return 32767;
|
||||
@ -114,8 +108,6 @@ void __AudioInit() {
|
||||
|
||||
mixBuffer = new s32[hwBlockSize * 2];
|
||||
memset(mixBuffer, 0, hwBlockSize * 2 * sizeof(s32));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void __AudioDoState(PointerWrap &p) {
|
||||
@ -130,18 +122,9 @@ void __AudioDoState(PointerWrap &p) {
|
||||
|
||||
p.Do(mixFrequency);
|
||||
|
||||
{
|
||||
//block until a lock is achieved. Not a good idea at all, but
|
||||
//can't think of a better one...
|
||||
while(!__gainAudioQueueLock()){
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
lock_guard guard(section);
|
||||
outAudioQueue.DoState(p);
|
||||
|
||||
//release the atomic lock
|
||||
__releaseAcquiredLock();
|
||||
|
||||
}
|
||||
|
||||
int chanCount = ARRAY_SIZE(chans);
|
||||
@ -339,18 +322,11 @@ void __AudioUpdate() {
|
||||
}
|
||||
|
||||
if (g_Config.bEnableSound) {
|
||||
|
||||
//looks like the heavy lifting is done here.
|
||||
//we have to optimize this some more.
|
||||
if(!__gainAudioQueueLock()){
|
||||
return;
|
||||
}
|
||||
|
||||
lock_guard guard(section);
|
||||
if (outAudioQueue.room() >= hwBlockSize * 2) {
|
||||
s16 *buf1 = 0, *buf2 = 0;
|
||||
size_t sz1, sz2;
|
||||
outAudioQueue.pushPointers(hwBlockSize * 2, &buf1, &sz1, &buf2, &sz2);
|
||||
|
||||
for (size_t s = 0; s < sz1; s++)
|
||||
buf1[s] = clamp_s16(mixBuffer[s]);
|
||||
if (buf2) {
|
||||
@ -361,9 +337,6 @@ void __AudioUpdate() {
|
||||
// This happens quite a lot. There's still something slightly off
|
||||
// about the amount of audio we produce.
|
||||
}
|
||||
|
||||
//release the atomic lock
|
||||
__releaseAcquiredLock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,21 +352,12 @@ int __AudioMix(short *outstereo, int numFrames)
|
||||
const s16 *buf1 = 0, *buf2 = 0;
|
||||
size_t sz1, sz2;
|
||||
{
|
||||
|
||||
if(!__gainAudioQueueLock()){
|
||||
return numFrames;
|
||||
}
|
||||
|
||||
|
||||
lock_guard guard(section);
|
||||
outAudioQueue.popPointers(numFrames * 2, &buf1, &sz1, &buf2, &sz2);
|
||||
|
||||
memcpy(outstereo, buf1, sz1 * sizeof(s16));
|
||||
if (buf2) {
|
||||
memcpy(outstereo + sz1, buf2, sz2 * sizeof(s16));
|
||||
}
|
||||
|
||||
//release the atomic lock
|
||||
__releaseAcquiredLock();
|
||||
}
|
||||
|
||||
int remains = (int)(numFrames * 2 - sz1 - sz2);
|
||||
@ -406,21 +370,3 @@ int __AudioMix(short *outstereo, int numFrames)
|
||||
}
|
||||
return underrun >= 0 ? underrun : numFrames;
|
||||
}
|
||||
|
||||
|
||||
/*returns whether the lock was successfully gained or not.
|
||||
i.e - whether the lock belongs to you
|
||||
*/
|
||||
inline bool __gainAudioQueueLock(){
|
||||
/*if the previous state was 0, that means the lock was "unlocked". So,
|
||||
we return !0, which is true thanks to C's int to bool conversion
|
||||
|
||||
One the other hand, if it was locked, then the lock would return 1.
|
||||
so, !1 = 0 = false.
|
||||
*/
|
||||
return !audioQueueLock.test_and_set();
|
||||
};
|
||||
|
||||
inline void __releaseAcquiredLock(){
|
||||
audioQueueLock.clear();
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#pragma once
|
||||
#include "sceAudio.h"
|
||||
|
||||
#include "sceAudio.h"
|
||||
|
||||
// Easy interface for sceAudio to write to, to keep the complexity in check.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user