Cocoa Port:
- Make sound processing thread-safe. Fixes bug #3538263. < http://sourceforge.net/tracker/?func=detail&aid=3538263&group_id=164579&atid=832291 >
This commit is contained in:
parent
3f320792e5
commit
d9f13c57c0
|
@ -20,6 +20,7 @@
|
||||||
#import "cocoa_globals.h"
|
#import "cocoa_globals.h"
|
||||||
#import "cocoa_videofilter.h"
|
#import "cocoa_videofilter.h"
|
||||||
#import "cocoa_util.h"
|
#import "cocoa_util.h"
|
||||||
|
#include "sndOSX.h"
|
||||||
|
|
||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
|
|
||||||
|
@ -214,6 +215,8 @@ GPU3DInterface *core3DList[] = {
|
||||||
SPU_ChangeSoundCore(SNDCORE_DUMMY, 0);
|
SPU_ChangeSoundCore(SNDCORE_DUMMY, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutexAudioEmulateCore = self.mutexProducer;
|
||||||
|
|
||||||
pthread_mutex_unlock(self.mutexProducer);
|
pthread_mutex_unlock(self.mutexProducer);
|
||||||
|
|
||||||
// Force the volume back to it's original setting.
|
// Force the volume back to it's original setting.
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
// Global sound playback manager
|
// Global sound playback manager
|
||||||
static CoreAudioSound *coreAudioPlaybackManager = NULL;
|
static CoreAudioSound *coreAudioPlaybackManager = NULL;
|
||||||
|
static pthread_mutex_t *mutexAudioSampleReadWrite = NULL;
|
||||||
|
pthread_mutex_t *mutexAudioEmulateCore = NULL;
|
||||||
|
|
||||||
// Sound interface to the SPU
|
// Sound interface to the SPU
|
||||||
SoundInterface_struct SNDOSX = {
|
SoundInterface_struct SNDOSX = {
|
||||||
|
@ -36,7 +38,9 @@ SoundInterface_struct SNDOSX = {
|
||||||
SNDOSXMuteAudio,
|
SNDOSXMuteAudio,
|
||||||
SNDOSXUnMuteAudio,
|
SNDOSXUnMuteAudio,
|
||||||
SNDOSXSetVolume,
|
SNDOSXSetVolume,
|
||||||
SNDOSXClearBuffer
|
SNDOSXClearBuffer,
|
||||||
|
SNDOSXFetchSamples,
|
||||||
|
SNDOSXPostProcessSamples
|
||||||
};
|
};
|
||||||
|
|
||||||
SoundInterface_struct *SNDCoreList[] = {
|
SoundInterface_struct *SNDCoreList[] = {
|
||||||
|
@ -58,6 +62,12 @@ int SNDOSXInit(int buffer_size)
|
||||||
coreAudioPlaybackManager = new CoreAudioSound(buffer_size / SPU_SAMPLE_SIZE, SPU_SAMPLE_SIZE);
|
coreAudioPlaybackManager = new CoreAudioSound(buffer_size / SPU_SAMPLE_SIZE, SPU_SAMPLE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mutexAudioSampleReadWrite == NULL)
|
||||||
|
{
|
||||||
|
mutexAudioSampleReadWrite = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
|
||||||
|
pthread_mutex_init(mutexAudioSampleReadWrite, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
coreAudioPlaybackManager->start();
|
coreAudioPlaybackManager->start();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -67,6 +77,13 @@ void SNDOSXDeInit()
|
||||||
{
|
{
|
||||||
delete coreAudioPlaybackManager;
|
delete coreAudioPlaybackManager;
|
||||||
coreAudioPlaybackManager = NULL;
|
coreAudioPlaybackManager = NULL;
|
||||||
|
|
||||||
|
if (mutexAudioSampleReadWrite != NULL)
|
||||||
|
{
|
||||||
|
pthread_mutex_destroy(mutexAudioSampleReadWrite);
|
||||||
|
free(mutexAudioSampleReadWrite);
|
||||||
|
mutexAudioSampleReadWrite = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int SNDOSXReset()
|
int SNDOSXReset()
|
||||||
|
@ -138,3 +155,46 @@ void SNDOSXClearBuffer()
|
||||||
coreAudioPlaybackManager->clearBuffer();
|
coreAudioPlaybackManager->clearBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SNDOSXFetchSamples(s16 *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer)
|
||||||
|
{
|
||||||
|
if (mutexAudioSampleReadWrite == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(mutexAudioSampleReadWrite);
|
||||||
|
SPU_DefaultFetchSamples(sampleBuffer, sampleCount, synchMode, theSynchronizer);
|
||||||
|
pthread_mutex_unlock(mutexAudioSampleReadWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SNDOSXPostProcessSamples(s16 *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer)
|
||||||
|
{
|
||||||
|
size_t processedSampleCount = 0;
|
||||||
|
|
||||||
|
switch (synchMode)
|
||||||
|
{
|
||||||
|
case ESynchMode_DualSynchAsynch:
|
||||||
|
if (mutexAudioEmulateCore != NULL)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(mutexAudioEmulateCore);
|
||||||
|
processedSampleCount = SPU_DefaultPostProcessSamples(postProcessBuffer, requestedSampleCount, synchMode, theSynchronizer);
|
||||||
|
pthread_mutex_unlock(mutexAudioEmulateCore);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ESynchMode_Synchronous:
|
||||||
|
if (mutexAudioSampleReadWrite != NULL)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(mutexAudioSampleReadWrite);
|
||||||
|
processedSampleCount = SPU_DefaultPostProcessSamples(postProcessBuffer, requestedSampleCount, synchMode, theSynchronizer);
|
||||||
|
pthread_mutex_unlock(mutexAudioSampleReadWrite);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return processedSampleCount;
|
||||||
|
}
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
#ifndef _OSXSOUNDINTERFACE_
|
#ifndef _OSXSOUNDINTERFACE_
|
||||||
#define _OSXSOUNDINTERFACE_
|
#define _OSXSOUNDINTERFACE_
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
#include "../SPU.h"
|
#include "../SPU.h"
|
||||||
|
|
||||||
#define SNDCORE_OSX 58325 //hopefully this is unique number
|
#define SNDCORE_OSX 58325 //hopefully this is unique number
|
||||||
|
|
||||||
// Sound interface to the SPU
|
extern SoundInterface_struct SNDOSX; // Sound interface to the SPU
|
||||||
extern SoundInterface_struct SNDOSX;
|
extern pthread_mutex_t *mutexAudioEmulateCore; // Mutex for the emulation core - used when mixing audio in Dual Synch/Asynch mode in post-process
|
||||||
|
|
||||||
// Core Audio functions for the sound interface
|
// Core Audio functions for the sound interface
|
||||||
int SNDOSXInit(int buffer_size);
|
int SNDOSXInit(int buffer_size);
|
||||||
|
@ -36,5 +37,7 @@ void SNDOSXMuteAudio();
|
||||||
void SNDOSXUnMuteAudio();
|
void SNDOSXUnMuteAudio();
|
||||||
void SNDOSXSetVolume(int volume);
|
void SNDOSXSetVolume(int volume);
|
||||||
void SNDOSXClearBuffer();
|
void SNDOSXClearBuffer();
|
||||||
|
void SNDOSXFetchSamples(s16 *sampleBuffer, size_t sampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
|
||||||
|
size_t SNDOSXPostProcessSamples(s16 *postProcessBuffer, size_t requestedSampleCount, ESynchMode synchMode, ISynchronizingAudioBuffer *theSynchronizer);
|
||||||
|
|
||||||
#endif // _OSXSOUNDINTERFACE_
|
#endif // _OSXSOUNDINTERFACE_
|
||||||
|
|
Loading…
Reference in New Issue