From 05bdc2cd2f70c929fbf221862e893657feaa74c5 Mon Sep 17 00:00:00 2001 From: rock88 Date: Sat, 16 Mar 2013 22:08:32 +0700 Subject: [PATCH 1/3] IOS: iPhone/iPod 5 screen support --- ios/PPSSPP-Info.plist | 2 ++ ios/assets/Default-568h@2x.png | Bin 0 -> 18594 bytes 2 files changed, 2 insertions(+) create mode 100644 ios/assets/Default-568h@2x.png diff --git a/ios/PPSSPP-Info.plist b/ios/PPSSPP-Info.plist index 0f42d9ca8a..3fa62a8d8f 100644 --- a/ios/PPSSPP-Info.plist +++ b/ios/PPSSPP-Info.plist @@ -47,5 +47,7 @@ assets/Icon.png assets/Icon@2x.png + UILaunchImageFile + assets/Default.png diff --git a/ios/assets/Default-568h@2x.png b/ios/assets/Default-568h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..0891b7aabfcf3422423b109c8beed2bab838c607 GIT binary patch literal 18594 zcmeI4X;f257Jx&9fS`ixvS;&$x8J@slQFSel)6zJN=?13FB7H(lQjRkSy8x_-S~tvu2gzn1oS+dLcF#eqtq$ z%tf9TTvX?`)R@}3uBI;jzS-=ZR-Td&MHaS&;!0?Ni*#$#`n*~CcQK)Q9vAQ~TUpnI!j)a2biYK^R)M~A5wUDZhx?ULMX z3x1P&qt=trOY6P2U67L=m=U?F|5#Uj(eCueNTZaHs_ceWiHeET+j+tp3Jt9g(ekqP z2WOvfR{qV+9r+o4J5?qK>7;;^+I7tGv-i)es$X_D=EoKF+S?zsyj^oRFElP}c}JT< zd8SUs-?O?}2YD#ngKbnHgzHBcboxK_2r9l(?eNCl-pEzkJm}fY?WC*jnS?VBE4EpY zO$fEejz6fU;W2Kl>JeQBZBl-%Irg`obSlg*@4QB;Dd1H7^Oi5wvt4d{RZ!8Og?^aE z)k0$1g+V3fd(gdQ3d&q2q-FL*uy#}|bc^=VhFsl0jBgUGJ+-s3U8MK9A!YJJMxpci z5hJ%|{DwV48fZn0{n5l$N_KcSb#NKE4plB`9I6Zt=Z!~-zw0{9tg$L&Ju1F0X)Cy8 zKF;(&lJ>x)Jw(=;p~sF(Sd9VWGwFE2rnyS9!f^DZ8+aCLq zQ};>lcJ1GDLqjm6Hd>|Eabno@P`~Bn(~6^aD_#yoEH(a?Nm1S<;S+hSxI5d16^<1lEM3NPFi zkqPrpL)+ zgnseFikg`gJVBha1&7C4;O6>h=dt~`ND+;Zd?W(4v2JIb7Pt>Td42%M-Ju-XAH#Pns762L}K3 zDhvsRqN0Ni(1UrishD2YvV?4*h2iFj$+&N||Fn$4n|^NSU+o?~jq`0jVQt8T9l{7b zXiwwODFh2V!Q6sqP9S>WH$oOf$N~=d0-bqTlD61!=`&0eAP-F>XN?*|gtOXX{ zQVTWyYo4ZK0GAw!GHf|pz9`D;-bbb*5LBX*{bnz|+)$@&P9|ORM2o?95{;ejvo&r- zq8cBhTN6nn)7~W>54U)%-F_-b?YKdfk5I8MHcuzBD5)!;yv#Z&R&^y=@=>VTIMy#r zX&U<=BsPkdqcMe<_}2+>H%XKyrr5ZR8_KVe>ZqYN z^=^~TFD};;rHJ$U;{~w^hYojl4hRI@SH$^K{YEo=sg)WY87r!*7blQK&qnpDo0`Vn zkl)9u9g=mCh&ZCJS(L4yN3k0kQ zuvg$h2KEEk51T+O0JQ+r0`R>g{jvqM0Mr6d3qUOZwE!?PI7HY@CE|dr sfw?Q;rAv?G4&^^8-z_>&sWXMxvD*gPOU4CBe-*@OtE+wfmVJNyHv)PfH~;_u literal 0 HcmV?d00001 From 947f8381652da0f973d0bc430e98c91fe194a000 Mon Sep 17 00:00:00 2001 From: rock88 Date: Sat, 16 Mar 2013 21:50:55 +0700 Subject: [PATCH 2/3] IOS: added audio output --- CMakeLists.txt | 6 +- ios/AudioEngine.h | 13 ++++ ios/AudioEngine.mm | 138 ++++++++++++++++++++++++++++++++++++++++++ ios/ViewController.mm | 11 +++- 4 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 ios/AudioEngine.h create mode 100644 ios/AudioEngine.mm diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f76ac54a2..cf7550ccca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -428,8 +428,10 @@ elseif(IOS) ios/AppDelegate.m ios/AppDelegate.h ios/ViewController.mm - ios/ViewController.h) - set(nativeExtraLibs ${nativeExtraLibs} "-framework Foundation -framework AudioToolbox -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework UIKit -framework GLKit") + ios/ViewController.h + ios/AudioEngine.mm + ios/AudioEngine.h) + set(nativeExtraLibs ${nativeExtraLibs} "-framework Foundation -framework AudioToolbox -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework UIKit -framework GLKit -framework AudioToolbox -framework OpenAL") set(TargetBin PPSSPP) elseif(USING_QT_UI) # Currently unused diff --git a/ios/AudioEngine.h b/ios/AudioEngine.h new file mode 100644 index 0000000000..6613513b27 --- /dev/null +++ b/ios/AudioEngine.h @@ -0,0 +1,13 @@ +// +// AudioEngine.h +// PPSSPP +// +// Created by rock88 on 15/03/2013. +// Copyright (c) 2013 Homebrew. All rights reserved. +// + +#import + +@interface AudioEngine : NSObject + +@end diff --git a/ios/AudioEngine.mm b/ios/AudioEngine.mm new file mode 100644 index 0000000000..e484b7cf1f --- /dev/null +++ b/ios/AudioEngine.mm @@ -0,0 +1,138 @@ +// +// AudioEngine.mm +// PPSSPP +// +// Created by rock88 on 15/03/2013. +// Copyright (c) 2013 Homebrew. All rights reserved. +// + +#import "AudioEngine.h" +#import +#import +#import +#import + +#import + +static volatile BOOL done = 0; + +#define SAMPLE_SIZE 44100/6 +static short stream[SAMPLE_SIZE]; + +void NativeMix(short *audio, int num_samples); + +@interface AudioEngine () + +@property (nonatomic,assign) ALCdevice *alcDevice; +@property (nonatomic,assign) ALCcontext *alContext; +@property (nonatomic,assign) ALuint buffer; +@property (nonatomic,assign) ALuint source; + +@end + +@implementation AudioEngine +@synthesize alcDevice,alContext,buffer,source; + +- (id)init +{ + self = [super init]; + if (self) + { + [self audioInit]; + [self audioLoop]; + } + return self; +} + +- (void)dealloc +{ + [self audioShutdown]; + [super dealloc]; +} + +- (void)checkALError +{ + ALenum ErrCode; + std::string Err = "OpenAL error: "; + if ((ErrCode = alGetError()) != AL_NO_ERROR) + { + Err += (char *)alGetString(ErrCode); + printf("%s\n",Err.c_str()); + } +} + +- (void)audioInit +{ + done = 0; + alcDevice = alcOpenDevice(NULL); + + if (alcDevice) + { + NSLog(@"OpenAL device opened: %s",alcGetString(alcDevice, ALC_DEVICE_SPECIFIER)); + } + else + { + NSLog(@"WARNING: could not open OpenAL device"); + return; + } + + alContext = alcCreateContext(alcDevice, NULL); + + if (alContext) + { + alcMakeContextCurrent(alContext); + } + else + { + NSLog(@"ERROR: no OpenAL context"); + return; + } + + alGenSources(1, &source); + alGenBuffers(1, &buffer); +} + +- (void)audioShutdown +{ + done = 1; + alcMakeContextCurrent(NULL); + + if (alContext) + { + alcDestroyContext(alContext); + alContext = NULL; + } + + if (alcDevice) + { + alcCloseDevice(alcDevice); + alcDevice = NULL; + } +} + +- (bool)playing +{ + ALenum state; + alGetSourcei(source, AL_SOURCE_STATE, &state); + return (state == AL_PLAYING); +} + +- (void)audioLoop +{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ + while (!done) + { + if (![self playing]) + { + NativeMix(stream, SAMPLE_SIZE/2); + + alSourcei(source, AL_BUFFER, 0); + alBufferData(buffer, AL_FORMAT_STEREO16, stream, SAMPLE_SIZE, 44100); + alSourcei(source, AL_BUFFER, buffer); + alSourcePlay(source); + } + } + }); +} + +@end diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 2f154fafec..6841b6aae2 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -6,6 +6,7 @@ // #import "ViewController.h" +#import "AudioEngine.h" #import #include "base/display.h" @@ -41,11 +42,12 @@ ViewController* sharedViewController; @property (nonatomic,retain) NSString* documentsPath; @property (nonatomic,retain) NSString* bundlePath; @property (nonatomic,retain) NSMutableArray* touches; +@property (nonatomic,retain) AudioEngine* audioEngine; @end @implementation ViewController -@synthesize documentsPath,bundlePath,touches; +@synthesize documentsPath,bundlePath,touches,audioEngine; - (id)init { @@ -104,7 +106,9 @@ 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]; @@ -129,7 +133,8 @@ ViewController* sharedViewController; - (void)dealloc { [self viewDidUnload]; - + + self.audioEngine = nil; self.touches = nil; self.documentsPath = nil; self.bundlePath = nil; From e8ac8d49b659585a292f38a99b9bf4efa3887d53 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Mar 2013 14:00:41 -0700 Subject: [PATCH 3/3] iOS: Reduce CPU consumption for audio, adjust sync. Still is clicking... --- Core/HLE/__sceAudio.cpp | 2 +- android/jni/NativeApp.cpp | 7 +++++++ ios/AudioEngine.mm | 21 ++++++++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index 3b7c885812..8f5a9e3ca3 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -273,5 +273,5 @@ int __AudioMix(short *outstereo, int numFrames) // DEBUG_LOG(HLE, "No underrun, mixed %i samples fine", numFrames); } section.unlock(); - return numFrames; + return underrun; } diff --git a/android/jni/NativeApp.cpp b/android/jni/NativeApp.cpp index 31f4cbb87b..fd4fc1e02f 100644 --- a/android/jni/NativeApp.cpp +++ b/android/jni/NativeApp.cpp @@ -149,6 +149,13 @@ void NativeMix(short *audio, int num_samples) } } +int NativeMixCount(short *audio, int num_samples) +{ + if (g_mixer) + return g_mixer->Mix(audio, num_samples); + return 0; +} + void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, bool *landscape) { *app_nice_name = "PPSSPP"; diff --git a/ios/AudioEngine.mm b/ios/AudioEngine.mm index e484b7cf1f..aeb187cbe5 100644 --- a/ios/AudioEngine.mm +++ b/ios/AudioEngine.mm @@ -16,10 +16,10 @@ static volatile BOOL done = 0; -#define SAMPLE_SIZE 44100/6 +#define SAMPLE_SIZE 44100 static short stream[SAMPLE_SIZE]; -void NativeMix(short *audio, int num_samples); +int NativeMixCount(short *audio, int num_samples); @interface AudioEngine () @@ -122,15 +122,26 @@ void NativeMix(short *audio, int num_samples); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ while (!done) { + size_t frames_ready; if (![self playing]) + frames_ready = NativeMixCount(stream, SAMPLE_SIZE / 2); + else + frames_ready = 0; + + if (frames_ready > 0) { - NativeMix(stream, SAMPLE_SIZE/2); - + const size_t bytes_ready = frames_ready * sizeof(short) * 2; alSourcei(source, AL_BUFFER, 0); - alBufferData(buffer, AL_FORMAT_STEREO16, stream, SAMPLE_SIZE, 44100); + alBufferData(buffer, AL_FORMAT_STEREO16, stream, bytes_ready, 44100); alSourcei(source, AL_BUFFER, buffer); alSourcePlay(source); + + // TODO: Maybe this could get behind? + usleep((1000000 * frames_ready) / 44100); } + else + usleep(100); + pthread_yield_np(); } }); }