Skip to content

Commit

Permalink
Now correctly detects mute button
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamLCobb committed May 8, 2016
1 parent 9cf2bcb commit a2462b1
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 72 deletions.
2 changes: 1 addition & 1 deletion desmume/src/gfx3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ void gfx3d_execute3D()
for(i=0;i<HACK_FIFO_BATCH_SIZE;i++) {
if(GFX_PIPErecv(&cmd, &param))
{
//if (isSwapBuffers) printf("Executing while swapbuffers is pending: %d:%08X\n",cmd,param);
if (isSwapBuffers) printf("Executing while swapbuffers is pending: %d:%08X\n",cmd,param);

//since we did anything at all, incur a pipeline motion cost.
//also, we can't let gxfifo sequencer stall until the fifo is empty.
Expand Down
18 changes: 14 additions & 4 deletions iNDS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@
CA32245A1CCA86FC00C5BEA7 /* WCEasySettingsCustom.m in Sources */ = {isa = PBXBuildFile; fileRef = CA3224591CCA86FC00C5BEA7 /* WCEasySettingsCustom.m */; };
CA32245D1CCAA0D100C5BEA7 /* iNDSDropboxTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CA32245C1CCAA0D100C5BEA7 /* iNDSDropboxTableViewController.m */; };
CA3224E31CD41D7C00C5BEA7 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D32C39D4178E73B500E6809E /* Security.framework */; };
CA3224E51CD5BB2E00C5BEA7 /* UnrarKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CAB2C42C1CB21D8E00ED22BB /* UnrarKit.framework */; };
CA4258111CADADF200BFD05E /* UIDevice-Hardware.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4258101CADADF200BFD05E /* UIDevice-Hardware.m */; };
CA4258141CADBD4900BFD05E /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = CA4258131CADBD4900BFD05E /* MBProgressHUD.m */; };
CA48465B1CDD7131005030EF /* UnrarKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CAB2C42C1CB21D8E00ED22BB /* UnrarKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
CA48465E1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = CA48465D1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.m */; };
CA4846601CDFA8A1005030EF /* mute.caf in Resources */ = {isa = PBXBuildFile; fileRef = CA48465F1CDFA47D005030EF /* mute.caf */; };
CA570B651C3B8AA300918E3A /* MHWDirectoryWatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = CA570B641C3B8AA300918E3A /* MHWDirectoryWatcher.m */; };
CA68821D1CDC118500B0ED05 /* iNDSBuildStoreTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CA68821C1CDC118500B0ED05 /* iNDSBuildStoreTableViewController.m */; };
CA6882241CDC19A800B0ED05 /* WCBuildStoreAuthenticateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CA6882231CDC19A800B0ED05 /* WCBuildStoreAuthenticateViewController.m */; };
Expand Down Expand Up @@ -279,6 +283,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
CA48465B1CDD7131005030EF /* UnrarKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -609,7 +614,9 @@
CA4258101CADADF200BFD05E /* UIDevice-Hardware.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Hardware.m"; sourceTree = "<group>"; };
CA4258121CADBD4900BFD05E /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBProgressHUD.h; sourceTree = "<group>"; };
CA4258131CADBD4900BFD05E /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBProgressHUD.m; sourceTree = "<group>"; };
CA4846591CDC574D005030EF /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
CA48465C1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharkfoodMuteSwitchDetector.h; sourceTree = "<group>"; };
CA48465D1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharkfoodMuteSwitchDetector.m; sourceTree = "<group>"; };
CA48465F1CDFA47D005030EF /* mute.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = mute.caf; sourceTree = "<group>"; };
CA570B631C3B8AA300918E3A /* MHWDirectoryWatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MHWDirectoryWatcher.h; sourceTree = "<group>"; };
CA570B641C3B8AA300918E3A /* MHWDirectoryWatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MHWDirectoryWatcher.m; sourceTree = "<group>"; };
CA6614AF1BFF7D7800AAD7D4 /* libFlurry_7.0.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libFlurry_7.0.0.a; path = ../ShoutOut/ShoutOut/Flurry/libFlurry_7.0.0.a; sourceTree = "<group>"; };
Expand Down Expand Up @@ -661,7 +668,6 @@
CA908C041C2356F700B2A864 /* SCLTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCLTextView.m; sourceTree = "<group>"; };
CA908C0C1C235A9B00B2A864 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
CA908C0E1C235AA000B2A864 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
CA908C161C239D0000B2A864 /* Fabric.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Fabric.framework; sourceTree = "<group>"; };
CA908C1A1C23B27300B2A864 /* iNDSEmulationProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iNDSEmulationProfile.h; sourceTree = "<group>"; };
CA908C1B1C23B27300B2A864 /* iNDSEmulationProfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iNDSEmulationProfile.m; sourceTree = "<group>"; };
CA908C1D1C23B2BE00B2A864 /* Twitter.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Twitter.png; path = Resources/Twitter.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -813,6 +819,7 @@
4C3F2AED178E017600AE10B8 /* Twitter.framework in Frameworks */,
BFAE6F9B17674D93000911CF /* libz.dylib in Frameworks */,
BFAE6F931767490A000911CF /* OpenGLES.framework in Frameworks */,
CA3224E51CD5BB2E00C5BEA7 /* UnrarKit.framework in Frameworks */,
BFAE6F9117674902000911CF /* GLKit.framework in Frameworks */,
BFCFE0F31764FBD3000A70CF /* UIKit.framework in Frameworks */,
BFCFE0F51764FBD3000A70CF /* Foundation.framework in Frameworks */,
Expand Down Expand Up @@ -1033,11 +1040,9 @@
BFCFE0F11764FBD3000A70CF /* Frameworks */ = {
isa = PBXGroup;
children = (
CA4846591CDC574D005030EF /* WebKit.framework */,
CA6E609B1CB0574B000B269D /* MobileCoreServices.framework */,
CA8EA1411C37C42E0082A3F8 /* MediaPlayer.framework */,
CABE38971C30FA9800BE8857 /* libsqlite3.tbd */,
CA908C161C239D0000B2A864 /* Fabric.framework */,
CA908C0E1C235AA000B2A864 /* Accelerate.framework */,
CA908C0C1C235A9B00B2A864 /* AVFoundation.framework */,
CA6614AF1BFF7D7800AAD7D4 /* libFlurry_7.0.0.a */,
Expand Down Expand Up @@ -1595,6 +1600,9 @@
CABE38421C30BFC600BE8857 /* Utilities */ = {
isa = PBXGroup;
children = (
CA48465C1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.h */,
CA48465D1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.m */,
CA48465F1CDFA47D005030EF /* mute.caf */,
CA8EA13A1C375D860082A3F8 /* UITapticEngine.h */,
CA8EA13B1C375D870082A3F8 /* UIDevice+Private.h */,
CA8EA13C1C375D870082A3F8 /* UIDevice+Private.m */,
Expand Down Expand Up @@ -1785,6 +1793,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CA4846601CDFA8A1005030EF /* mute.caf in Resources */,
CAB2C4301CB2234300ED22BB /* cheats.rar in Resources */,
CAB2C4311CB2234300ED22BB /* cheats.7z in Resources */,
28DA4A481787FD7F002236A4 /* Select.png in Resources */,
Expand Down Expand Up @@ -2040,6 +2049,7 @@
CA6E60951CB056A0000B269D /* AFHTTPSessionManager.m in Sources */,
CA4258111CADADF200BFD05E /* UIDevice-Hardware.m in Sources */,
CAB2C4BE1CB5F2C300ED22BB /* EZAudioUtilities.m in Sources */,
CA48465E1CDF9BF2005030EF /* SharkfoodMuteSwitchDetector.m in Sources */,
CAB2C4B91CB5F2C300ED22BB /* EZAudioFloatConverter.m in Sources */,
D31CC8B217927C3B0098FB9C /* ConciseKit.m in Sources */,
D31CC8B317927C3B0098FB9C /* NSArray+ConciseKit.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion iNDS/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Embedding UnrarKit causes signing issues for the build store.
// To use it, you must uncomment this line and then link and
// embed UnrarKit.framework
//#define UseRarKit
#define UseRarKit

#define kBugUrl @"http://69.167.218.245:6768/iNDS/bugreport"
//#define kBugUrl @"http://www.williamlcobb.com/iNDS/bugreport"
Expand Down
12 changes: 7 additions & 5 deletions iNDS/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,13 @@ - (WCEasySettingsViewController *)getSettingsViewController
// Audio
WCEasySettingsSection *audioSection = [[WCEasySettingsSection alloc] initWithTitle:@"Audio" subTitle:@""];
audioSection.items = @[[[WCEasySettingsSwitch alloc] initWithIdentifier:@"disableSound"
title:@"Disable Sound"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"synchSound"
title:@"Synchronous Audio"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"enableMic"
title:@"Enable Mic"]];
title:@"Disable Sound"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"ignoreMute"
title:@"Ignore Mute Button"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"synchSound"
title:@"Synchronous Audio"],
[[WCEasySettingsSwitch alloc] initWithIdentifier:@"enableMic"
title:@"Enable Mic"]];


//Dropbox
Expand Down
21 changes: 21 additions & 0 deletions iNDS/SharkfoodMuteSwitchDetector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// SharkfoodMuteSwitchDetector.h
//
// Created by Moshe Gottlieb on 6/2/13.
// Copyright (c) 2013 Sharkfood. All rights reserved.
//

#import <Foundation/Foundation.h>


typedef void(^SharkfoodMuteSwitchDetectorBlock)(BOOL silent);

@interface SharkfoodMuteSwitchDetector : NSObject

+(SharkfoodMuteSwitchDetector*)shared;

@property (nonatomic,readonly) BOOL isMute;
@property (nonatomic,copy) SharkfoodMuteSwitchDetectorBlock silentNotify;
@property (nonatomic) BOOL disabled;

@end
154 changes: 154 additions & 0 deletions iNDS/SharkfoodMuteSwitchDetector.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//
// SharkfoodMuteSwitchDetector.m
//
// Created by Moshe Gottlieb on 6/2/13.
// Copyright (c) 2013 Sharkfood. All rights reserved.
//

#import "SharkfoodMuteSwitchDetector.h"
#import <AudioToolbox/AudioToolbox.h>

/**
Sound completion proc - this is the real magic, we simply calculate how long it took for the sound to finish playing
In silent mode, playback will end very fast (but not in zero time)
*/
void SharkfoodSoundMuteNotificationCompletionProc(SystemSoundID ssID,void* clientData);

@interface SharkfoodMuteSwitchDetector()
/**
Find out how fast the completion call is called
*/
@property (nonatomic,assign) NSTimeInterval interval;
/**
Our silent sound (0.5 sec)
*/
@property (nonatomic,assign) SystemSoundID soundId;
/**
Set to true after the block was set or during init.
Otherwise the block is called only when the switch value actually changes
*/
@property (nonatomic,assign) BOOL forceEmit;
/**
Sound completion, objc
*/
-(void)complete;
/**
Our loop, checks sound switch
*/
-(void)loopCheck;
/**
Pause while in the background, if your app supports playing audio in the background, you want this.
Otherwise your app will be rejected.
*/
-(void)didEnterBackground;
/**
Resume when entering foreground
*/
-(void)willReturnToForeground;
/**
Schedule a next check
*/
-(void)scheduleCall;
/**
Is paused?
*/
@property (nonatomic,assign) BOOL isPaused;
/**
Currently playing? used when returning from the background (if went to background and foreground really quickly)
*/
@property (nonatomic,assign) BOOL isPlaying;

@end



void SharkfoodSoundMuteNotificationCompletionProc(SystemSoundID ssID,void* clientData){
SharkfoodMuteSwitchDetector* detecotr = (__bridge SharkfoodMuteSwitchDetector*)clientData;
[detecotr complete];
}


@implementation SharkfoodMuteSwitchDetector

-(id)init{
self = [super init];
if (self){
NSURL* url = [[NSBundle mainBundle] URLForResource:@"mute" withExtension:@"caf"];
if (AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &_soundId) == kAudioServicesNoError){
AudioServicesAddSystemSoundCompletion(self.soundId, CFRunLoopGetMain(), kCFRunLoopDefaultMode, SharkfoodSoundMuteNotificationCompletionProc,(__bridge void *)(self));
UInt32 yes = 1;
AudioServicesSetProperty(kAudioServicesPropertyIsUISound, sizeof(_soundId),&_soundId,sizeof(yes), &yes);
[self performSelector:@selector(loopCheck) withObject:nil afterDelay:1];
self.forceEmit = YES;
} else {
NSLog(@"Sharkfood Error");
self.soundId = -1;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willReturnToForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
}
return self;
}

-(void)didEnterBackground{
self.isPaused = YES;
}
-(void)willReturnToForeground{
self.isPaused = NO;
if (!self.isPlaying){
[self scheduleCall];
}
}

-(void)setSilentNotify:(SharkfoodMuteSwitchDetectorBlock)silentNotify{
_silentNotify = [silentNotify copy];
self.forceEmit = YES;
}

+(SharkfoodMuteSwitchDetector*)shared{
static SharkfoodMuteSwitchDetector* sShared = nil;
if (!sShared)
sShared = [SharkfoodMuteSwitchDetector new];
return sShared;
}

-(void)scheduleCall{
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(loopCheck) object:nil];
[self performSelector:@selector(loopCheck) withObject:nil afterDelay:1];
}



-(void)complete{
self.isPlaying = NO;
NSTimeInterval elapsed = [NSDate timeIntervalSinceReferenceDate] - self.interval;
BOOL isMute = elapsed < 0.1; // Should have been 0.5 sec, but it seems to return much faster (0.3something)
if (self.isMute != isMute || self.forceEmit) {
self.forceEmit = NO;
_isMute = isMute;
if (self.silentNotify)
self.silentNotify(isMute);
}
[self scheduleCall];
}

-(void)loopCheck{
if (!self.isPaused){
self.interval = [NSDate timeIntervalSinceReferenceDate];
self.isPlaying = YES;
AudioServicesPlaySystemSound(self.soundId);
}
}


// For reference only, this DTOR will never be invoked.

-(void)dealloc{
if (self.soundId != -1){
AudioServicesRemoveSystemSoundCompletion(self.soundId);
AudioServicesDisposeSystemSoundID(self.soundId);
}
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
56 changes: 7 additions & 49 deletions iNDS/core/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,53 +353,21 @@ void iNDS_user()
mainLoopData.fpsframecount = 0;
mainLoopData.fpsticks = GetTickCount();
}

//Don't think this does very much
return;
if(nds.idleFrameCounter==0 || oneSecond)
{
//calculate a 16 frame arm9 load average
for(int cpu=0;cpu<2;cpu++)
{
int load = 0;
//printf("%d: ",cpu);
for(int i=0;i<16;i++)
{
//blend together a few frames to keep low-framerate games from having a jittering load average
//(they will tend to work 100% for a frame and then sleep for a while)
//4 frames should handle even the slowest of games
s32 sample =
nds.runCycleCollector[cpu][(i+0+nds.idleFrameCounter)&15]
+ nds.runCycleCollector[cpu][(i+1+nds.idleFrameCounter)&15]
+ nds.runCycleCollector[cpu][(i+2+nds.idleFrameCounter)&15]
+ nds.runCycleCollector[cpu][(i+3+nds.idleFrameCounter)&15];
sample /= 4;
load = load/8 + sample*7/8;
}
//printf("\n");
load = std::min(100,std::max(0,(int)(load*100/1120380)));
//Hud.cpuload[cpu] = load;
}
}

//Hud.cpuloopIterationCount = nds.cpuloopIterationCount;
}

void iNDS_throttle(bool allowSleep, int forceFrameSkip)
void iNDS_throttle()
{
int skipRate = (forceFrameSkip < 0) ? frameskiprate : forceFrameSkip;
int ffSkipRate = (forceFrameSkip < 0) ? 9 : forceFrameSkip;

//Change in skip rate
if(lastskiprate != skipRate)
if(lastskiprate != frameskiprate)
{
lastskiprate = skipRate;
lastskiprate = frameskiprate;
mainLoopData.framestoskip = 0; // otherwise switches to lower frameskip rates will lag behind
}


//Load a frame
if(!mainLoopData.skipnextframe || forceFrameSkip == 0 || frameAdvance || (continuousframeAdvancing && !FastForward))
if(!mainLoopData.skipnextframe)
{
mainLoopData.framesskipped = 0;

Expand All @@ -420,32 +388,22 @@ void iNDS_throttle(bool allowSleep, int forceFrameSkip)
NDS_SkipNextFrame();
}

if ((/*autoframeskipenab && frameskiprate ||*/ FrameLimit) && allowSleep)
{
SpeedThrottle();
}

if (autoframeskipenab && frameskiprate)
{
if(!frameAdvance && !continuousframeAdvancing)
{
AutoFrameSkip_NextFrame();
if (mainLoopData.framestoskip < 1)
mainLoopData.framestoskip += AutoFrameSkip_GetSkipAmount(0,skipRate);
mainLoopData.framestoskip += AutoFrameSkip_GetSkipAmount(0, frameskiprate);
}
}

else
{
if (mainLoopData.framestoskip < 1)
mainLoopData.framestoskip += skipRate;
mainLoopData.framestoskip += frameskiprate;
}

if (frameAdvance && allowSleep)
{
frameAdvance = false;
emu_halt();
SPU_Pause(1);
}
if(execute && emu_paused && !frameAdvance)
{
// safety net against running out of control in case this ever happens.
Expand Down
Loading

0 comments on commit a2462b1

Please sign in to comment.