mirror of https://github.com/axmolengine/axmol.git
fix-157
This commit is contained in:
parent
a3b208075b
commit
a09253c7a2
|
@ -24,7 +24,7 @@ set(COCOS_AUDIO_SRC
|
||||||
# stupid, clang always compie .mm as objc/cpp mix obj
|
# stupid, clang always compie .mm as objc/cpp mix obj
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
|
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
|
||||||
audio/src/AudioEngineImpl.cpp
|
audio/src/alink.cpp
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
|
set(COCOS_AUDIO_SRC ${COCOS_AUDIO_SRC}
|
||||||
|
|
|
@ -35,13 +35,10 @@
|
||||||
#define MAX_AUDIOINSTANCES 24
|
#define MAX_AUDIOINSTANCES 24
|
||||||
#define CC_USE_ALSOFT 0
|
#define CC_USE_ALSOFT 0
|
||||||
#else
|
#else
|
||||||
#ifdef OPENAL_PLAIN_INCLUDES
|
#define AL_ALEXT_PROTOTYPES 1
|
||||||
#include <al.h>
|
#include "AL/al.h"
|
||||||
#include <alext.h>
|
#include "AL/alc.h"
|
||||||
#else
|
#include "AL/alext.h"
|
||||||
#include <AL/al.h>
|
|
||||||
#include <AL/alext.h>
|
|
||||||
#endif
|
|
||||||
#define MAX_AUDIOINSTANCES 32
|
#define MAX_AUDIOINSTANCES 32
|
||||||
#define CC_USE_ALSOFT 1
|
#define CC_USE_ALSOFT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
/* Android clang link workaround for unrefenreced "gnu_objc_personality_v0" */
|
|
||||||
#include "AudioEngineImpl.mm"
|
|
|
@ -50,6 +50,27 @@ static ALCdevice* s_ALDevice = nullptr;
|
||||||
static ALCcontext* s_ALContext = nullptr;
|
static ALCcontext* s_ALContext = nullptr;
|
||||||
static AudioEngineImpl* s_instance = nullptr;
|
static AudioEngineImpl* s_instance = nullptr;
|
||||||
|
|
||||||
|
static void ccALPauseDevice() {
|
||||||
|
ALOGD("%s", "===> ccALPauseDevice");
|
||||||
|
#if CC_USE_ALSOFT
|
||||||
|
alcDevicePauseSOFT(s_ALDevice);
|
||||||
|
#else
|
||||||
|
if(alcGetCurrentContext())
|
||||||
|
alcMakeContextCurrent(nullptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ccALResumeDevice() {
|
||||||
|
ALOGD("%s", "===> ccALResumeDevice");
|
||||||
|
#if CC_USE_ALSOFT
|
||||||
|
alcDeviceResumeSOFT(s_ALDevice);
|
||||||
|
#else
|
||||||
|
if(alcGetCurrentContext())
|
||||||
|
alcMakeContextCurrent(nullptr);
|
||||||
|
alcMakeContextCurrent(s_ALContext);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
|
||||||
typedef ALvoid (*alSourceNotificationProc)(ALuint sid, ALuint notificationID, ALvoid* userData);
|
typedef ALvoid (*alSourceNotificationProc)(ALuint sid, ALuint notificationID, ALvoid* userData);
|
||||||
|
@ -88,14 +109,14 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
||||||
{
|
{
|
||||||
if (kAudioSessionBeginInterruption == interruption_state)
|
if (kAudioSessionBeginInterruption == interruption_state)
|
||||||
{
|
{
|
||||||
alcMakeContextCurrent(nullptr);
|
ccALPauseDevice();
|
||||||
}
|
}
|
||||||
else if (kAudioSessionEndInterruption == interruption_state)
|
else if (kAudioSessionEndInterruption == interruption_state)
|
||||||
{
|
{
|
||||||
OSStatus result = AudioSessionSetActive(true);
|
OSStatus result = AudioSessionSetActive(true);
|
||||||
if (result) NSLog(@"Error setting audio session active! %d\n", static_cast<int>(result));
|
if (result) NSLog(@"Error setting audio session active! %d\n", static_cast<int>(result));
|
||||||
|
|
||||||
alcMakeContextCurrent(s_ALContext);
|
ccALResumeDevice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -142,16 +163,16 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
||||||
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive)
|
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive)
|
||||||
{
|
{
|
||||||
ALOGD("AVAudioSessionInterruptionTypeBegan, application != UIApplicationStateActive, alcMakeContextCurrent(nullptr)");
|
ALOGD("AVAudioSessionInterruptionTypeBegan, application != UIApplicationStateActive, alcMakeContextCurrent(nullptr)");
|
||||||
alcMakeContextCurrent(nullptr);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ALOGD("AVAudioSessionInterruptionTypeBegan, application == UIApplicationStateActive, pauseOnResignActive = true");
|
ALOGD("AVAudioSessionInterruptionTypeBegan, application == UIApplicationStateActive, pauseOnResignActive = true");
|
||||||
pauseOnResignActive = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reason == AVAudioSessionInterruptionTypeEnded)
|
// We always pause device when interruption began
|
||||||
|
ccALPauseDevice();
|
||||||
|
}
|
||||||
|
else if (reason == AVAudioSessionInterruptionTypeEnded)
|
||||||
{
|
{
|
||||||
isAudioSessionInterrupted = false;
|
isAudioSessionInterrupted = false;
|
||||||
|
|
||||||
|
@ -160,9 +181,7 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
||||||
ALOGD("AVAudioSessionInterruptionTypeEnded, application == UIApplicationStateActive, alcMakeContextCurrent(s_ALContext)");
|
ALOGD("AVAudioSessionInterruptionTypeEnded, application == UIApplicationStateActive, alcMakeContextCurrent(s_ALContext)");
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
[[AVAudioSession sharedInstance] setActive:YES error:&error];
|
[[AVAudioSession sharedInstance] setActive:YES error:&error];
|
||||||
if (alcGetCurrentContext() != nullptr)
|
ccALResumeDevice();
|
||||||
alcMakeContextCurrent(nullptr);
|
|
||||||
alcMakeContextCurrent(s_ALContext);
|
|
||||||
if (Director::getInstance()->isPaused())
|
if (Director::getInstance()->isPaused())
|
||||||
{
|
{
|
||||||
ALOGD("AVAudioSessionInterruptionTypeEnded, director was paused, try to resume it.");
|
ALOGD("AVAudioSessionInterruptionTypeEnded, director was paused, try to resume it.");
|
||||||
|
@ -183,7 +202,7 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
||||||
{
|
{
|
||||||
pauseOnResignActive = false;
|
pauseOnResignActive = false;
|
||||||
ALOGD("UIApplicationWillResignActiveNotification, alcMakeContextCurrent(nullptr)");
|
ALOGD("UIApplicationWillResignActiveNotification, alcMakeContextCurrent(nullptr)");
|
||||||
alcMakeContextCurrent(nullptr);
|
ccALPauseDevice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ([notification.name isEqualToString:UIApplicationDidBecomeActiveNotification])
|
else if ([notification.name isEqualToString:UIApplicationDidBecomeActiveNotification])
|
||||||
|
@ -201,14 +220,11 @@ void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruptio
|
||||||
}
|
}
|
||||||
[[AVAudioSession sharedInstance] setActive:YES error:&error];
|
[[AVAudioSession sharedInstance] setActive:YES error:&error];
|
||||||
|
|
||||||
if (alcGetCurrentContext() != nullptr)
|
ccALResumeDevice();
|
||||||
alcMakeContextCurrent(nullptr);
|
|
||||||
alcMakeContextCurrent(s_ALContext);
|
|
||||||
}
|
}
|
||||||
else if (isAudioSessionInterrupted)
|
else if (isAudioSessionInterrupted)
|
||||||
{
|
{
|
||||||
ALOGD("Audio session is still interrupted, pause director!");
|
ALOGD("Audio session is still interrupted!");
|
||||||
// Director::getInstance()->pause();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
/* alink.cpp: only a workaround for solving clang link issue, said: unrefenreced "gnu_objc_personality_v0" */
|
||||||
|
#include "AudioEngineImpl.mm"
|
Loading…
Reference in New Issue