From e89b2055a69356c285728a53e30dd1b57bce2940 Mon Sep 17 00:00:00 2001 From: Jake Traynham Date: Thu, 20 Jun 2013 11:44:59 -0500 Subject: [PATCH 1/4] Reenabled armv7s for iOS with JIT fixes --- CMakeLists.txt | 3 +- Common/ArmCPUDetect.cpp | 5 +++- Core/MIPS/ARM/ArmCompFPU.cpp | 24 ++++++++++++++++ Core/MIPS/ARM/ArmCompVFPU.cpp | 54 +++++++++++++++++++++++++++++++++++ ffmpeg | 2 +- ios/README.md | 7 +++-- lang | 2 +- 7 files changed, 91 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3da63391c4..163b2b59d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,7 +161,8 @@ if(NOT MSVC) if(IOS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") - set(CMAKE_OSX_ARCHITECTURES "armv7") + # jtraynham: re-enabling default/"standard" architectures (which is a fat armv7/armv7s binary) + #set(CMAKE_OSX_ARCHITECTURES "armv7") elseif(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -U__STRICT_ANSI__") # Karen/angelXwind: --macosx-version-min=10.7 is needed in order to produce binaries that OS X 10.7 Lion can execute. However, it seems that PPSSPP won't support 10.6 or lower without getting rid of -stdlib=libc++ ...which probably won't end well. So I guess PPSSPP will strictly be a 10.7+ app. diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index 50ed3228bd..bceff9d370 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -132,7 +132,10 @@ void CPUInfo::Detect() bool isVFP4 = false; #ifdef IOS isVFP3 = true; - // TODO: Check for swift arch (VFP4) + // Check for swift arch (VFP4`) + #ifdef __ARM_ARCH_7S__ + isVFP4 = true; + #endif // #ifdef __ARM_ARCH_7S__ #elif defined(BLACKBERRY) isVFP3 = true; const char cpuInfoPath[] = "/pps/services/hw_info/inventory"; diff --git a/Core/MIPS/ARM/ArmCompFPU.cpp b/Core/MIPS/ARM/ArmCompFPU.cpp index 320c157f13..a116c715d6 100644 --- a/Core/MIPS/ARM/ArmCompFPU.cpp +++ b/Core/MIPS/ARM/ArmCompFPU.cpp @@ -105,6 +105,17 @@ void Jit::Comp_FPULS(u32 op) } ADD(R0, R0, R11); } +#ifdef __ARM_ARCH_7S__ + FixupBranch skip; + if (doCheck) { + skip = B_CC(CC_EQ); + } + VLDR(fpr.R(ft), R0, 0); + if (doCheck) { + SetJumpTarget(skip); + SetCC(CC_AL); + } +#else VLDR(fpr.R(ft), R0, 0); if (doCheck) { SetCC(CC_EQ); @@ -112,6 +123,7 @@ void Jit::Comp_FPULS(u32 op) VMOV(fpr.R(ft), R0); SetCC(CC_AL); } +#endif break; case 57: //Memory::Write_U32(FI(ft), addr); break; //swc1 @@ -129,10 +141,22 @@ void Jit::Comp_FPULS(u32 op) } ADD(R0, R0, R11); } +#ifdef __ARM_ARCH_7S__ + FixupBranch skip2; + if (doCheck) { + skip2 = B_CC(CC_EQ); + } + VSTR(fpr.R(ft), R0, 0); + if (doCheck) { + SetJumpTarget(skip2); + SetCC(CC_AL); + } +#else VSTR(fpr.R(ft), R0, 0); if (doCheck) { SetCC(CC_AL); } +#endif break; default: diff --git a/Core/MIPS/ARM/ArmCompVFPU.cpp b/Core/MIPS/ARM/ArmCompVFPU.cpp index d61cb61298..8731a7422f 100644 --- a/Core/MIPS/ARM/ArmCompVFPU.cpp +++ b/Core/MIPS/ARM/ArmCompVFPU.cpp @@ -216,12 +216,24 @@ namespace MIPSComp } ADD(R0, R0, R11); } +#ifdef __ARM_ARCH_7S__ + FixupBranch skip; + if (doCheck) { + skip = B_CC(CC_EQ); + } + VLDR(fpr.V(vt), R0, 0); + if (doCheck) { + SetJumpTarget(skip); + SetCC(CC_AL); + } +#else VLDR(fpr.V(vt), R0, 0); if (doCheck) { SetCC(CC_EQ); MOVI2F(fpr.V(vt), 0.0f, R0); SetCC(CC_AL); } +#endif } break; @@ -243,10 +255,22 @@ namespace MIPSComp } ADD(R0, R0, R11); } +#ifdef __ARM_ARCH_7S__ + FixupBranch skip; + if (doCheck) { + skip = B_CC(CC_EQ); + } + VSTR(fpr.V(vt), R0, 0); + if (doCheck) { + SetJumpTarget(skip); + SetCC(CC_AL); + } +#else VSTR(fpr.V(vt), R0, 0); if (doCheck) { SetCC(CC_AL); } +#endif } break; @@ -289,6 +313,20 @@ namespace MIPSComp ADD(R0, R0, R11); } +#ifdef __ARM_ARCH_7S__ + FixupBranch skip; + if (doCheck) { + skip = B_CC(CC_EQ); + } + + for (int i = 0; i < 4; i++) + VLDR(fpr.V(vregs[i]), R0, i * 4); + + if (doCheck) { + SetJumpTarget(skip); + SetCC(CC_AL); + } +#else for (int i = 0; i < 4; i++) VLDR(fpr.V(vregs[i]), R0, i * 4); @@ -299,6 +337,7 @@ namespace MIPSComp VMOV(fpr.V(vregs[i]), R0); SetCC(CC_AL); } +#endif } break; @@ -324,12 +363,27 @@ namespace MIPSComp ADD(R0, R0, R11); } +#ifdef __ARM_ARCH_7S__ + FixupBranch skip; + if (doCheck) { + skip = B_CC(CC_EQ); + } + + for (int i = 0; i < 4; i++) + VSTR(fpr.V(vregs[i]), R0, i * 4); + + if (doCheck) { + SetJumpTarget(skip); + SetCC(CC_AL); + } +#else for (int i = 0; i < 4; i++) VSTR(fpr.V(vregs[i]), R0, i * 4); if (doCheck) { SetCC(CC_AL); } +#endif } break; diff --git a/ffmpeg b/ffmpeg index e8ef410aac..dafc67817b 160000 --- a/ffmpeg +++ b/ffmpeg @@ -1 +1 @@ -Subproject commit e8ef410aac458a35064e67582fb80103c29e6474 +Subproject commit dafc67817b7f8006e5065f1a4fbb2070e1dda56a diff --git a/ios/README.md b/ios/README.md index 77f49b0875..672587ae2f 100644 --- a/ios/README.md +++ b/ios/README.md @@ -7,7 +7,10 @@ Prerequisites: * Xcode (from the Mac App Store) with command line tools installed * MacPorts (from macports.org); easiest to install with their package installers * cmake build system (from MacPorts); run "sudo port install cmake" from the command line -* gas-preprocessor (to compile ffmpeg libs); download the zip from https://github.com/mansr/gas-preprocessor, unzip and from the command line run: + +If you need to build ffmpeg yourself too, then you'll also need: + +* gas-preprocessor; download the zip from https://github.com/mansr/gas-preprocessor, unzip and from the command line run: sudo cp gas-preprocessor.pl /usr/bin/ sudo chmod +rw /usr/bin/gas-preprocessor.pl @@ -25,7 +28,7 @@ Change directory to the newly created ppsspp directory and run: git submodule update --init -Change directory into ffmpeg and run (this will take a while): +The above command will pull in the submodules required by PPSSPP, including the native, ffmpeg, and lang directories. Included in the ffmpeg directory should be the necessary libs and includes for ffmpeg, so most people can skip the next command. However, if you need to recompile ffmpeg for some reason, change directory into ffmpeg and run (this will take a while): ./ios-build.sh diff --git a/lang b/lang index cf710f2017..8be7cbb255 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit cf710f2017db93c4019ce53a03764edf3136fa84 +Subproject commit 8be7cbb2555239b88c26c8e02904c83ccc449c9b From ffff60c73cf940a34b0500efeb24c2a916b85791 Mon Sep 17 00:00:00 2001 From: Jake Traynham Date: Mon, 24 Jun 2013 17:49:17 -0500 Subject: [PATCH 2/4] pulled down submodule updates --- lang | 2 +- native | 2 +- pspautotests | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lang b/lang index 81dc0b9141..8be7cbb255 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 81dc0b9141e7d1445efc7b152b88ab16ff75c737 +Subproject commit 8be7cbb2555239b88c26c8e02904c83ccc449c9b diff --git a/native b/native index 80c85b1c60..deb4ba8323 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 80c85b1c604ccead734d595dd7f67656f3fd9d85 +Subproject commit deb4ba83235a86491d073db73a1e5bab2a5ce523 diff --git a/pspautotests b/pspautotests index e07589caa3..d1038e00bd 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit e07589caa30222a8878930d909c5b3970d6b0f74 +Subproject commit d1038e00bdcf48e2ab057616bb2ec973980a7b3f From 24961e28ef3e033c889e1c949ac5b0a3763639aa Mon Sep 17 00:00:00 2001 From: Jake Traynham Date: Tue, 25 Jun 2013 16:18:16 -0500 Subject: [PATCH 3/4] iOS Audio fixes --- CMakeLists.txt | 12 ++-- UI/NativeApp.cpp | 14 +++- ios/ViewController.mm | 2 - ios/iOSCoreAudio.cpp | 148 ++++++++++++++++++++++++++++++++++++++++++ ios/iOSCoreAudio.h | 22 +++++++ native | 2 +- 6 files changed, 192 insertions(+), 8 deletions(-) create mode 100644 ios/iOSCoreAudio.cpp create mode 100644 ios/iOSCoreAudio.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ac592c71e0..e4d7dc7157 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,8 +173,9 @@ if(NOT MSVC) if(IOS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") - # jtraynham: re-enabling default/"standard" architectures (which is a fat armv7/armv7s binary) - #set(CMAKE_OSX_ARCHITECTURES "armv7") + # armv7s (without resorting to FastMemory) is still a work in progress + # comment out the next line to enable default/"standard" architectures (which is a fat armv7/armv7s binary) + set(CMAKE_OSX_ARCHITECTURES "armv7") elseif(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -U__STRICT_ANSI__") # Karen/angelXwind: --macosx-version-min=10.7 is needed in order to produce binaries that OS X 10.7 Lion can execute. However, it seems that PPSSPP won't support 10.6 or lower without getting rid of -stdlib=libc++ ...which probably won't end well. So I guess PPSSPP will strictly be a 10.7+ app. @@ -1144,9 +1145,12 @@ if(USE_FFMPEG) endif() if(APPLE) - set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} bz2 "-framework VideoDecodeAcceleration" "-framework CoreVideo") + set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} bz2 "-framework CoreVideo") + if (NOT IOS) + set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} "-framework VideoDecodeAcceleration") + endif() endif(APPLE) - + set(LinkCommon ${LinkCommon} ${FFMPEG_LIBRARIES}) add_definitions(-DUSE_FFMPEG) endif(USE_FFMPEG) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 26d3bb0760..190127d972 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -34,7 +34,7 @@ #include "base/NativeApp.h" #include "file/vfs.h" #include "file/zip_read.h" -#include "ext/jpge/jpge.h" +#include "native/ext/jpge/jpge.h" #include "gfx_es2/gl_state.h" #include "gfx/gl_lost_manager.h" #include "gfx/texture.h" @@ -79,6 +79,10 @@ static UI::Theme ui_theme; #include #endif +#ifdef IOS +#include "ios/iOSCoreAudio.h" +#endif + Texture *uiTexture; ScreenManager *screenManager; @@ -171,9 +175,17 @@ std::string boot_filename = ""; void NativeHost::InitSound(PMixer *mixer) { g_mixer = mixer; + +#ifdef IOS + iOSCoreAudioInit(); +#endif } void NativeHost::ShutdownSound() { +#ifdef IOS + iOSCoreAudioShutdown(); +#endif + g_mixer = 0; } diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 65c864b7ef..d80f955385 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -131,8 +131,6 @@ ViewController* sharedViewController; dp_xscale = (float)dp_xres / (float)pixel_xres; dp_yscale = (float)dp_yres / (float)pixel_yres; - if (g_Config.bEnableSound) - self.audioEngine = [[[AudioEngine alloc] init] autorelease]; /* UISwipeGestureRecognizer* gesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)] autorelease]; [self.view addGestureRecognizer:gesture]; diff --git a/ios/iOSCoreAudio.cpp b/ios/iOSCoreAudio.cpp new file mode 100644 index 0000000000..507b1d320e --- /dev/null +++ b/ios/iOSCoreAudio.cpp @@ -0,0 +1,148 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +// This code implements the emulated audio using CoreAudio for iOS +// Originally written by jtraynham + +#include "iOSCoreAudio.h" +#include + +#define SAMPLE_RATE 44100 + +#define STREAM_MAX_FRAME_COUNT 2048 +static short stream[STREAM_MAX_FRAME_COUNT * 2 * 2]; // frames * sample size * number of channels + +AudioComponentInstance audioInstance = nil; + +int NativeMix(short *audio, int num_samples); + +OSStatus iOSCoreAudioCallback(void *inRefCon, + AudioUnitRenderActionFlags *ioActionFlags, + const AudioTimeStamp *inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList *ioData) +{ + // see if we have any sound to play + UInt32 frames = (inNumberFrames > STREAM_MAX_FRAME_COUNT ? STREAM_MAX_FRAME_COUNT : inNumberFrames); + UInt32 framesReady = NativeMix(stream, frames); + if (framesReady == 0) { + // oops, we don't currently have any sound, so return silence + *ioActionFlags |= kAudioUnitRenderAction_OutputIsSilence; + return noErr; + } + + // grab the output buffer and copy data into it + AudioSampleType *output = (AudioSampleType *)ioData->mBuffers[0].mData; + UInt32 bytesReady = framesReady * sizeof(short) * 2; + memcpy(output, stream, bytesReady); + // make sure and tell it how much audio data is there + ioData->mBuffers[0].mDataByteSize = bytesReady; + + return noErr; +} + +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(AudioSampleType) * 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() +{ + if (audioInstance) { + AudioOutputUnitStop(audioInstance); + AudioUnitUninitialize(audioInstance); + AudioComponentInstanceDispose(audioInstance); + audioInstance = nil; + } +} diff --git a/ios/iOSCoreAudio.h b/ios/iOSCoreAudio.h new file mode 100644 index 0000000000..a3c70ccbfc --- /dev/null +++ b/ios/iOSCoreAudio.h @@ -0,0 +1,22 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +// This code implements the emulated audio using CoreAudio for iOS +// Originally written by jtraynham + +void iOSCoreAudioInit(); +void iOSCoreAudioShutdown(); \ No newline at end of file diff --git a/native b/native index deb4ba8323..80c85b1c60 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit deb4ba83235a86491d073db73a1e5bab2a5ce523 +Subproject commit 80c85b1c604ccead734d595dd7f67656f3fd9d85 From e052a2d8dabd575e13e121853cb2fbddc958beb5 Mon Sep 17 00:00:00 2001 From: Jake Traynham Date: Tue, 25 Jun 2013 16:38:30 -0500 Subject: [PATCH 4/4] Updated CMakeLists to include new iOS Audio files --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4d7dc7157..f02876b35c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,8 +462,8 @@ elseif(IOS) ios/AppDelegate.h ios/ViewController.mm ios/ViewController.h - ios/AudioEngine.mm - ios/AudioEngine.h + ios/iOSCoreAudio.cpp + ios/iOSCoreAudio.h ios/iCade/iCadeReaderView.h ios/iCade/iCadeReaderView.m ios/iCade/iCadeState.h)