diff --git a/CMakeLists.txt b/CMakeLists.txt index 749f788478..e0d117728b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1290,6 +1290,8 @@ elseif(IOS AND NOT LIBRETRO) ios/AppDelegate.h ios/DisplayManager.h ios/DisplayManager.mm + ios/Controls.h + ios/Controls.mm ios/ViewController.mm ios/ViewController.h ios/iOSCoreAudio.mm diff --git a/ios/Controls.h b/ios/Controls.h new file mode 100644 index 0000000000..2f5ed182a1 --- /dev/null +++ b/ios/Controls.h @@ -0,0 +1,3 @@ +// Code extracted from ViewController.mm, in order to modularize +// and share it between multiple view controllers. + diff --git a/ios/Controls.mm b/ios/Controls.mm new file mode 100644 index 0000000000..0ddf13417b --- /dev/null +++ b/ios/Controls.mm @@ -0,0 +1,3 @@ +#include "Controls.h" + +#include "Common/Log.h" diff --git a/ios/ViewController.h b/ios/ViewController.h index 0e91161453..1e1678685d 100644 --- a/ios/ViewController.h +++ b/ios/ViewController.h @@ -2,9 +2,7 @@ #import #import -#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 #import -#endif #import "iCade/iCadeReaderView.h" #import "CameraHelper.h" #import "LocationHelper.h" diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 6a0232b62d..cb7547efcf 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -110,9 +110,7 @@ static LocationHelper *locationHelper; @property (nonatomic, strong) EAGLContext* context; //@property (nonatomic) iCadeReaderView* iCadeView; -#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 @property (nonatomic) GCController *gameController __attribute__((weak_import)); -#endif @end @@ -139,13 +137,11 @@ static LocationHelper *locationHelper; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate:) name:UIApplicationWillTerminateNotification object:nil]; -#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 if ([GCController class]) // Checking the availability of a GameController framework { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidDisconnect:) name:GCControllerDidDisconnectNotification object:nil]; } -#endif } return self; } @@ -170,7 +166,6 @@ extern float g_safeInsetBottom; - (void)viewSafeAreaInsetsDidChange { if (@available(iOS 11.0, *)) { [super viewSafeAreaInsetsDidChange]; - char safeArea[100]; // we use 0.0f instead of safeAreaInsets.bottom because the bottom overlay isn't disturbing (for now) g_safeInsetLeft = self.view.safeAreaInsets.left; g_safeInsetRight = self.view.safeAreaInsets.right; @@ -225,13 +220,11 @@ extern float g_safeInsetBottom; self.iCadeView.delegate = self; self.iCadeView.active = YES;*/ -#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 if ([GCController class]) { if ([[GCController controllers] count] > 0) { [self setupController:[[GCController controllers] firstObject]]; } } -#endif cameraHelper = [[CameraHelper alloc] init]; [cameraHelper setDelegate:self]; @@ -305,11 +298,9 @@ extern float g_safeInsetBottom; [[NSNotificationCenter defaultCenter] removeObserver:self]; -#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 if ([GCController class]) { self.gameController = nil; } -#endif if (graphicsContext) { graphicsContext->Shutdown(); @@ -553,10 +544,8 @@ int ToTouchID(UITouch *uiTouch, bool allowAllocate) { key.deviceId = DEVICE_ID_PAD_0; NativeKey(key); } - } -#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 - (void)controllerDidConnect:(NSNotification *)note { if (![[GCController controllers] containsObject:self.gameController]) self.gameController = nil; diff --git a/ios/iOSCoreAudio.mm b/ios/iOSCoreAudio.mm index 8743ab7953..8129cc9afc 100644 --- a/ios/iOSCoreAudio.mm +++ b/ios/iOSCoreAudio.mm @@ -25,10 +25,9 @@ #include #import - #define SAMPLE_RATE 44100 -AudioComponentInstance audioInstance = nil; +static AudioComponentInstance audioInstance = nil; int NativeMix(short *audio, int numSamples, int sampleRate); @@ -77,83 +76,85 @@ void iOSCoreAudioInit() } } - if (!audioInstance) { - OSErr err; - - // first, grab the default output - AudioComponentDescription defaultOutputDescription; - defaultOutputDescription.componentType = kAudioUnitType_Output; - defaultOutputDescription.componentSubType = kAudioUnitSubType_RemoteIO; - defaultOutputDescription.componentManufacturer = kAudioUnitManufacturer_Apple; - defaultOutputDescription.componentFlags = 0; - defaultOutputDescription.componentFlagsMask = 0; - AudioComponent defaultOutput = AudioComponentFindNext(NULL, &defaultOutputDescription); - - // create our instance - err = AudioComponentInstanceNew(defaultOutput, &audioInstance); - if (err != noErr) { - audioInstance = nil; - return; - } - - // create our callback so we can give it the audio data - AURenderCallbackStruct input; - input.inputProc = iOSCoreAudioCallback; - input.inputProcRefCon = NULL; - err = AudioUnitSetProperty(audioInstance, - kAudioUnitProperty_SetRenderCallback, - kAudioUnitScope_Input, - 0, - &input, - sizeof(input)); - if (err != noErr) { - AudioComponentInstanceDispose(audioInstance); - audioInstance = nil; - return; - } - - // setup the audio format we'll be using (stereo pcm) - AudioStreamBasicDescription streamFormat; - memset(&streamFormat, 0, sizeof(streamFormat)); - streamFormat.mSampleRate = SAMPLE_RATE; - streamFormat.mFormatID = kAudioFormatLinearPCM; - streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; - streamFormat.mBitsPerChannel = sizeof(short) * 8; - streamFormat.mChannelsPerFrame = 2; - streamFormat.mFramesPerPacket = 1; - streamFormat.mBytesPerFrame = (streamFormat.mBitsPerChannel / 8) * streamFormat.mChannelsPerFrame; - streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame * streamFormat.mFramesPerPacket; - err = AudioUnitSetProperty(audioInstance, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &streamFormat, - sizeof(AudioStreamBasicDescription)); - if (err != noErr) { - AudioComponentInstanceDispose(audioInstance); - audioInstance = nil; - return; - } - - // k, all setup, so init - err = AudioUnitInitialize(audioInstance); - if (err != noErr) { - AudioComponentInstanceDispose(audioInstance); - audioInstance = nil; - return; - } - - // finally start playback - err = AudioOutputUnitStart(audioInstance); - if (err != noErr) { - AudioUnitUninitialize(audioInstance); - AudioComponentInstanceDispose(audioInstance); - audioInstance = nil; - return; - } - - // we're good to go + if (audioInstance) { + // Already running + return; } + OSErr err; + + // first, grab the default output + AudioComponentDescription defaultOutputDescription; + defaultOutputDescription.componentType = kAudioUnitType_Output; + defaultOutputDescription.componentSubType = kAudioUnitSubType_RemoteIO; + defaultOutputDescription.componentManufacturer = kAudioUnitManufacturer_Apple; + defaultOutputDescription.componentFlags = 0; + defaultOutputDescription.componentFlagsMask = 0; + AudioComponent defaultOutput = AudioComponentFindNext(NULL, &defaultOutputDescription); + + // create our instance + err = AudioComponentInstanceNew(defaultOutput, &audioInstance); + if (err != noErr) { + audioInstance = nil; + return; + } + + // create our callback so we can give it the audio data + AURenderCallbackStruct input; + input.inputProc = iOSCoreAudioCallback; + input.inputProcRefCon = NULL; + err = AudioUnitSetProperty(audioInstance, + kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Input, + 0, + &input, + sizeof(input)); + if (err != noErr) { + AudioComponentInstanceDispose(audioInstance); + audioInstance = nil; + return; + } + + // setup the audio format we'll be using (stereo pcm) + AudioStreamBasicDescription streamFormat; + memset(&streamFormat, 0, sizeof(streamFormat)); + streamFormat.mSampleRate = SAMPLE_RATE; + streamFormat.mFormatID = kAudioFormatLinearPCM; + streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; + streamFormat.mBitsPerChannel = sizeof(short) * 8; + streamFormat.mChannelsPerFrame = 2; + streamFormat.mFramesPerPacket = 1; + streamFormat.mBytesPerFrame = (streamFormat.mBitsPerChannel / 8) * streamFormat.mChannelsPerFrame; + streamFormat.mBytesPerPacket = streamFormat.mBytesPerFrame * streamFormat.mFramesPerPacket; + err = AudioUnitSetProperty(audioInstance, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &streamFormat, + sizeof(AudioStreamBasicDescription)); + if (err != noErr) { + AudioComponentInstanceDispose(audioInstance); + audioInstance = nil; + return; + } + + // k, all setup, so init + err = AudioUnitInitialize(audioInstance); + if (err != noErr) { + AudioComponentInstanceDispose(audioInstance); + audioInstance = nil; + return; + } + + // finally start playback + err = AudioOutputUnitStart(audioInstance); + if (err != noErr) { + AudioUnitUninitialize(audioInstance); + AudioComponentInstanceDispose(audioInstance); + audioInstance = nil; + return; + } + + // we're good to go } void iOSCoreAudioShutdown()