├── KaraokeDemo ├── bg.m4a ├── snapshot.jpg ├── ViewController.h ├── AppDelegate.h ├── main.m ├── DEKaraokeController.h ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── AppDelegate.m ├── ViewController.m └── DEKaraokeController.m ├── KaraokeDemo.xcodeproj ├── project.xcworkspace │ └── contents.xcworkspacedata ├── xcuserdata │ └── chenwanfei.xcuserdatad │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── KaraokeDemo.xcscheme └── project.pbxproj └── README.md /KaraokeDemo/bg.m4a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heilum/KaraokeDemo/HEAD/KaraokeDemo/bg.m4a -------------------------------------------------------------------------------- /KaraokeDemo/snapshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Heilum/KaraokeDemo/HEAD/KaraokeDemo/snapshot.jpg -------------------------------------------------------------------------------- /KaraokeDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /KaraokeDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 04/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /KaraokeDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 04/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /KaraokeDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 04/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /KaraokeDemo/DEKaraokeController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DEKaraokeController.h 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 05/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DEKaraokeController : NSObject 12 | -(instancetype)initWithBgMusic:(NSURL *)bgMusicURL outputURL:(NSURL *)outputURL; 13 | @property(nonatomic) BOOL isRunning; 14 | -(void)startWithPowerLevelChangeCallback:(void (^)(float))powerLevelChangedCallback musicFinishCallback:(void (^)(void))musicFinishCallback; 15 | -(void)stop; 16 | @end 17 | -------------------------------------------------------------------------------- /KaraokeDemo.xcodeproj/xcuserdata/chenwanfei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | KaraokeDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 7B129ACC1EE42477004E0372 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /KaraokeDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /KaraokeDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | NSMicrophoneUsageDescription 38 | 11111111111 39 | 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![ScreenShot](https://raw.github.com/JagieChen/KaraokeDemo/master/KaraokeDemo/snapshot.jpg) 3 | 4 | ## Features 5 | 6 | * Using Accelerate framework to meter input power level 7 | 8 | ## How to use 9 |

10 | 
11 | self.karaoke = [[DEKaraokeController alloc] initWithBgMusic:[self bgMp3FileURL] outputURL:[self recordFileURL]];
12 |  
13 | ....
14 | 
15 | - (IBAction)onStart:(id)sender {
16 |     UIButton *btn = sender;
17 |     if(self.karaoke.isRunning == NO){
18 |         __weak ViewController *weakSelf = self;
19 | 
20 |         [self.karaoke startWithPowerLevelChangeCallback:^(float p)  {
21 |             weakSelf.meterLabel.text = [NSString stringWithFormat:@"%f",p];
22 |         } musicFinishCallback:^{
23 |             weakSelf.recordBtn.selected = NO;
24 |             weakSelf.replayBtn.enabled = YES;
25 |         }];
26 | 
27 |         btn.selected = YES;
28 |         self.replayBtn.enabled = NO;
29 | 
30 | }else{
31 |       //stop
32 |       [self.karaoke stop];
33 |       self.recordBtn.selected = NO;
34 |       self.replayBtn.enabled = YES;
35 | 
36 |    }
37 | 
38 | }
39 | 
40 | 
41 | 
42 | 
43 | 
44 | 45 | ## References 46 | https://blog.metova.com/audio-manipulation-using-avaudioengine 47 | 48 | https://stackoverflow.com/questions/30641439/level-metering-with-avaudioengine 49 | 50 | ## License 51 | 52 | This code is distributed under the terms and conditions of the [MIT license](LICENSE). 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /KaraokeDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /KaraokeDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 04/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /KaraokeDemo.xcodeproj/xcuserdata/chenwanfei.xcuserdatad/xcschemes/KaraokeDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /KaraokeDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 04/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import 11 | #import 12 | #import "DEKaraokeController.h" 13 | @interface ViewController () 14 | 15 | 16 | @property(nonatomic,strong) AVAudioPlayer *previewPlayer; 17 | 18 | @property (weak, nonatomic) IBOutlet UIButton *replayBtn; 19 | 20 | @property (weak, nonatomic) IBOutlet UILabel *meterLabel; 21 | 22 | @property (weak, nonatomic) IBOutlet UIButton *recordBtn; 23 | 24 | 25 | 26 | 27 | @property(nonatomic,strong) DEKaraokeController *karaoke; 28 | 29 | @end 30 | 31 | @implementation ViewController 32 | 33 | -(void)alertSth:(NSString *)alert{ 34 | UIAlertController *ac = [UIAlertController alertControllerWithTitle:nil message:alert preferredStyle:(UIAlertControllerStyleAlert)]; 35 | [ac addAction:[UIAlertAction actionWithTitle:@"Ok" style:(UIAlertActionStyleDefault) handler:nil]]; 36 | [self presentViewController:ac animated:YES completion:nil]; 37 | } 38 | 39 | 40 | 41 | - (void)viewDidLoad { 42 | [super viewDidLoad]; 43 | self.karaoke = [[DEKaraokeController alloc] initWithBgMusic:[self bgMp3FileURL] outputURL:[self recordFileURL]]; 44 | 45 | 46 | // Do any additional setup after loading the view, typically from a nib. 47 | } 48 | 49 | -(void)viewDidAppear:(BOOL)animated{ 50 | [super viewDidAppear:animated]; 51 | __weak ViewController *weakSelf = self; 52 | [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) { 53 | if(!granted){ 54 | [weakSelf alertSth:@"Pleast let the App access your micphone"]; 55 | } 56 | }]; 57 | } 58 | - (IBAction)onReplay:(id)sender { 59 | 60 | 61 | 62 | if(self.previewPlayer == nil){ 63 | 64 | [[AVAudioSession sharedInstance] 65 | setCategory:AVAudioSessionCategoryPlayback 66 | error:NULL]; 67 | 68 | self.previewPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[self recordFileURL] error:NULL]; 69 | self.previewPlayer.delegate = self; 70 | [self.previewPlayer play]; 71 | self.replayBtn.selected = YES; 72 | 73 | self.recordBtn.enabled = NO; 74 | 75 | }else{ 76 | [self audioPlayerDidFinishPlaying:self.previewPlayer successfully:YES]; 77 | } 78 | 79 | } 80 | 81 | 82 | -(NSURL *)recordFileURL{ 83 | NSString *tmpFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Jagie.wav"]; 84 | NSLog(@"%@",tmpFilePath); 85 | return [NSURL fileURLWithPath:tmpFilePath]; 86 | } 87 | -(NSURL *)bgMp3FileURL{ 88 | 89 | return [[NSBundle mainBundle] URLForResource:@"bg" withExtension:@"m4a"]; 90 | } 91 | 92 | 93 | - (IBAction)onStart:(id)sender { 94 | UIButton *btn = sender; 95 | if(self.karaoke.isRunning == NO){ 96 | __weak ViewController *weakSelf = self; 97 | [self.karaoke startWithPowerLevelChangeCallback:^(float p) { 98 | weakSelf.meterLabel.text = [NSString stringWithFormat:@"%f",p]; 99 | } musicFinishCallback:^{ 100 | weakSelf.recordBtn.selected = NO; 101 | weakSelf.replayBtn.enabled = YES; 102 | }]; 103 | btn.selected = YES; 104 | self.replayBtn.enabled = NO; 105 | 106 | }else{ 107 | //stop 108 | [self.karaoke stop]; 109 | self.recordBtn.selected = NO; 110 | self.replayBtn.enabled = YES; 111 | 112 | } 113 | 114 | } 115 | 116 | 117 | #pragma AVAudioPlayerDelegate 118 | - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{ 119 | self.previewPlayer.delegate = nil; 120 | self.previewPlayer = nil; 121 | self.replayBtn.selected = NO; 122 | self.recordBtn.enabled = YES; 123 | } 124 | 125 | - (void)didReceiveMemoryWarning { 126 | [super didReceiveMemoryWarning]; 127 | // Dispose of any resources that can be recreated. 128 | } 129 | 130 | 131 | @end 132 | -------------------------------------------------------------------------------- /KaraokeDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 32 | 40 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /KaraokeDemo/DEKaraokeController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DEKaraokeController.m 3 | // KaraokeDemo 4 | // 5 | // Created by CHENWANFEI on 05/06/2017. 6 | // Copyright © 2017 SwordFish. All rights reserved. 7 | // 8 | 9 | #import "DEKaraokeController.h" 10 | #import 11 | #import 12 | @interface DEKaraokeController() 13 | 14 | 15 | @property (nonatomic) float averagePowerForChannel1; 16 | @property (nonatomic) float averagePowerForChannel0; 17 | 18 | 19 | 20 | @property(nonatomic,strong) AVAudioEngine *audioEngine; 21 | 22 | @property(nonatomic,copy) NSURL *bgMusicURL; 23 | @property(nonatomic,copy) NSURL *outputURL; 24 | 25 | @property(nonatomic,weak) AVAudioNode *audioMixer; 26 | 27 | @end 28 | @implementation DEKaraokeController 29 | -(instancetype)initWithBgMusic:(NSURL *)bgMusicURL outputURL:(NSURL *)outputURL{ 30 | if(self = [super init]){ 31 | 32 | _bgMusicURL = bgMusicURL; 33 | _outputURL = outputURL; 34 | _audioEngine = [[AVAudioEngine alloc] init]; 35 | 36 | } 37 | return self; 38 | } 39 | -(void)startWithPowerLevelChangeCallback:(void (^)(float))powerLevelChangedCallback musicFinishCallback:(void (^)(void))musicFinishCallback{ 40 | 41 | [[NSFileManager defaultManager] removeItemAtURL:self.outputURL error:NULL]; 42 | 43 | 44 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:(AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionDefaultToSpeaker) error:NULL]; 45 | [[AVAudioSession sharedInstance] setActive:YES error:NULL]; 46 | 47 | 48 | 49 | 50 | AVAudioEngine *engine = _audioEngine; 51 | AVAudioMixerNode *mainMixer = engine.mainMixerNode; 52 | AVAudioFormat *mixerOutputFormat = [mainMixer outputFormatForBus:0]; 53 | 54 | 55 | 56 | AVAudioPlayerNode *playerNodeForMixer = [[AVAudioPlayerNode alloc] init]; 57 | [engine attachNode:playerNodeForMixer]; 58 | 59 | AVAudioMixerNode *audioMixer = [[AVAudioMixerNode alloc] init]; 60 | [engine attachNode:audioMixer]; 61 | 62 | AVAudioPlayerNode *playerNodeForOutput = [[AVAudioPlayerNode alloc] init]; 63 | [engine attachNode:playerNodeForOutput]; 64 | 65 | AVAudioMixerNode *micMixer = [[AVAudioMixerNode alloc] init]; 66 | [engine attachNode:micMixer]; 67 | 68 | 69 | AVAudioInputNode *mic = [engine inputNode]; 70 | [engine connect:mic to:micMixer format:[mic inputFormatForBus:0]]; 71 | [engine connect:micMixer to:audioMixer format:mixerOutputFormat]; 72 | [engine connect:playerNodeForMixer to:audioMixer format:mixerOutputFormat]; 73 | 74 | 75 | 76 | [engine connect:playerNodeForOutput to:mainMixer format:mixerOutputFormat]; 77 | 78 | 79 | AVAudioFile *bgAudioFile = [[AVAudioFile alloc] initForReading:self.bgMusicURL error:NULL]; 80 | 81 | __weak DEKaraokeController *weakSelf = self; 82 | [playerNodeForMixer scheduleFile:bgAudioFile atTime:nil completionHandler:^{ 83 | [playerNodeForOutput stop]; 84 | [weakSelf stop]; 85 | if (musicFinishCallback != nil){ 86 | dispatch_async(dispatch_get_main_queue(), ^{ 87 | musicFinishCallback(); 88 | }); 89 | 90 | } 91 | }]; 92 | 93 | [playerNodeForOutput scheduleFile:bgAudioFile atTime:nil completionHandler:nil]; 94 | 95 | 96 | 97 | 98 | 99 | 100 | AVAudioFormat *tapFormat = [audioMixer outputFormatForBus:0]; 101 | 102 | AVAudioFile *outputFile = [[AVAudioFile alloc] initForWriting:self.outputURL settings: 103 | [tapFormat settings] error:NULL]; 104 | 105 | [audioMixer installTapOnBus:0 bufferSize:4096 format:tapFormat 106 | block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) { 107 | NSError *error; 108 | BOOL success = NO; 109 | 110 | success = [outputFile writeFromBuffer:buffer error:&error]; 111 | NSAssert(success, @"error writing buffer data to file, %@", [error localizedDescription]); 112 | }]; 113 | 114 | self.audioMixer = audioMixer; 115 | 116 | [micMixer installTapOnBus:0 bufferSize:4096 format:tapFormat 117 | block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) { 118 | [weakSelf meterLevel:buffer callback:powerLevelChangedCallback]; 119 | 120 | }]; 121 | 122 | 123 | 124 | NSError *error; 125 | [engine reset]; 126 | [engine prepare]; 127 | [engine startAndReturnError:&error]; 128 | 129 | [playerNodeForMixer play]; 130 | [playerNodeForOutput play]; 131 | 132 | self.isRunning = YES; 133 | 134 | 135 | 136 | } 137 | 138 | 139 | 140 | -(void)meterLevel:(AVAudioPCMBuffer *)buffer callback:(void (^)(float))callback{ 141 | // [buffer setFrameLength:[buffer frameLength]]; 142 | UInt32 inNumberFrames = buffer.frameLength; 143 | 144 | float LEVEL_LOWPASS_TRIG = 0.2; 145 | 146 | if(buffer.format.channelCount > 0) 147 | { 148 | Float32* samples = (Float32*)buffer.floatChannelData[0]; 149 | Float32 avgValue = 0; 150 | 151 | vDSP_meamgv((Float32*)samples, 1, &avgValue, inNumberFrames); 152 | self.averagePowerForChannel0 = (LEVEL_LOWPASS_TRIG*((avgValue==0)?-100:20.0*log10f(avgValue))) + ((1-LEVEL_LOWPASS_TRIG)*self.averagePowerForChannel0) ; 153 | self.averagePowerForChannel1 = self.averagePowerForChannel0; 154 | } 155 | 156 | if(buffer.format.channelCount > 1) 157 | { 158 | Float32* samples = (Float32*)buffer.floatChannelData[1]; 159 | Float32 avgValue = 0; 160 | 161 | vDSP_meamgv((Float32*)samples, 1, &avgValue, inNumberFrames); 162 | self.averagePowerForChannel1 = (LEVEL_LOWPASS_TRIG*((avgValue==0)?-100:20.0*log10f(avgValue))) + ((1-LEVEL_LOWPASS_TRIG)*self.averagePowerForChannel1) ; 163 | } 164 | 165 | float power = (self.averagePowerForChannel0 + self.averagePowerForChannel1) / 2; 166 | 167 | dispatch_async(dispatch_get_main_queue(), ^{ 168 | if(callback != nil){ 169 | callback(power); 170 | } 171 | //self.meterLabel.text = [NSString stringWithFormat:@"%f",self.averagePower]; 172 | }); 173 | 174 | } 175 | 176 | 177 | -(void)stop{ 178 | 179 | [self.audioMixer removeTapOnBus:0]; 180 | [self.audioEngine stop]; 181 | 182 | 183 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL]; 184 | [[AVAudioSession sharedInstance] setActive:YES error:NULL]; 185 | 186 | self.isRunning = NO; 187 | } 188 | @end 189 | -------------------------------------------------------------------------------- /KaraokeDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7B129AD21EE42477004E0372 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B129AD11EE42477004E0372 /* main.m */; }; 11 | 7B129AD51EE42477004E0372 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B129AD41EE42477004E0372 /* AppDelegate.m */; }; 12 | 7B129AD81EE42477004E0372 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B129AD71EE42477004E0372 /* ViewController.m */; }; 13 | 7B129ADB1EE42477004E0372 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7B129AD91EE42477004E0372 /* Main.storyboard */; }; 14 | 7B129ADD1EE42477004E0372 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B129ADC1EE42477004E0372 /* Assets.xcassets */; }; 15 | 7B129AE01EE42477004E0372 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7B129ADE1EE42477004E0372 /* LaunchScreen.storyboard */; }; 16 | 7B4083131EE5694E0061A3EF /* DEKaraokeController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B4083121EE5694E0061A3EF /* DEKaraokeController.m */; }; 17 | 7B4083151EE5932B0061A3EF /* bg.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 7B4083141EE5932B0061A3EF /* bg.m4a */; }; 18 | 7BE5D1F21EE559E8000B5503 /* snapshot.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 7BE5D1F11EE559E8000B5503 /* snapshot.jpg */; }; 19 | 7BE5D1F61EE563FE000B5503 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 7BE5D1F51EE563FE000B5503 /* README.md */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 7B129ACD1EE42477004E0372 /* KaraokeDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KaraokeDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 7B129AD11EE42477004E0372 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 25 | 7B129AD31EE42477004E0372 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 26 | 7B129AD41EE42477004E0372 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 27 | 7B129AD61EE42477004E0372 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 28 | 7B129AD71EE42477004E0372 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 29 | 7B129ADA1EE42477004E0372 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 7B129ADC1EE42477004E0372 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 7B129ADF1EE42477004E0372 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 32 | 7B129AE11EE42477004E0372 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 7B4083111EE5694E0061A3EF /* DEKaraokeController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DEKaraokeController.h; sourceTree = ""; }; 34 | 7B4083121EE5694E0061A3EF /* DEKaraokeController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DEKaraokeController.m; sourceTree = ""; }; 35 | 7B4083141EE5932B0061A3EF /* bg.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = bg.m4a; sourceTree = ""; }; 36 | 7BE5D1F11EE559E8000B5503 /* snapshot.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = snapshot.jpg; sourceTree = ""; }; 37 | 7BE5D1F51EE563FE000B5503 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | 7B129ACA1EE42477004E0372 /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | 7B129AC41EE42477004E0372 = { 52 | isa = PBXGroup; 53 | children = ( 54 | 7BE5D1F51EE563FE000B5503 /* README.md */, 55 | 7B129ACF1EE42477004E0372 /* KaraokeDemo */, 56 | 7B129ACE1EE42477004E0372 /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 7B129ACE1EE42477004E0372 /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 7B129ACD1EE42477004E0372 /* KaraokeDemo.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 7B129ACF1EE42477004E0372 /* KaraokeDemo */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 7B4083141EE5932B0061A3EF /* bg.m4a */, 72 | 7BE5D1F11EE559E8000B5503 /* snapshot.jpg */, 73 | 7B129AD31EE42477004E0372 /* AppDelegate.h */, 74 | 7B129AD41EE42477004E0372 /* AppDelegate.m */, 75 | 7B129AD61EE42477004E0372 /* ViewController.h */, 76 | 7B129AD71EE42477004E0372 /* ViewController.m */, 77 | 7B129AD91EE42477004E0372 /* Main.storyboard */, 78 | 7B129ADC1EE42477004E0372 /* Assets.xcassets */, 79 | 7B129ADE1EE42477004E0372 /* LaunchScreen.storyboard */, 80 | 7B129AE11EE42477004E0372 /* Info.plist */, 81 | 7B129AD01EE42477004E0372 /* Supporting Files */, 82 | 7B4083111EE5694E0061A3EF /* DEKaraokeController.h */, 83 | 7B4083121EE5694E0061A3EF /* DEKaraokeController.m */, 84 | ); 85 | path = KaraokeDemo; 86 | sourceTree = ""; 87 | }; 88 | 7B129AD01EE42477004E0372 /* Supporting Files */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 7B129AD11EE42477004E0372 /* main.m */, 92 | ); 93 | name = "Supporting Files"; 94 | sourceTree = ""; 95 | }; 96 | /* End PBXGroup section */ 97 | 98 | /* Begin PBXNativeTarget section */ 99 | 7B129ACC1EE42477004E0372 /* KaraokeDemo */ = { 100 | isa = PBXNativeTarget; 101 | buildConfigurationList = 7B129AE41EE42477004E0372 /* Build configuration list for PBXNativeTarget "KaraokeDemo" */; 102 | buildPhases = ( 103 | 7B129AC91EE42477004E0372 /* Sources */, 104 | 7B129ACA1EE42477004E0372 /* Frameworks */, 105 | 7B129ACB1EE42477004E0372 /* Resources */, 106 | ); 107 | buildRules = ( 108 | ); 109 | dependencies = ( 110 | ); 111 | name = KaraokeDemo; 112 | productName = KaraokeDemo; 113 | productReference = 7B129ACD1EE42477004E0372 /* KaraokeDemo.app */; 114 | productType = "com.apple.product-type.application"; 115 | }; 116 | /* End PBXNativeTarget section */ 117 | 118 | /* Begin PBXProject section */ 119 | 7B129AC51EE42477004E0372 /* Project object */ = { 120 | isa = PBXProject; 121 | attributes = { 122 | LastUpgradeCheck = 0830; 123 | ORGANIZATIONNAME = SwordFish; 124 | TargetAttributes = { 125 | 7B129ACC1EE42477004E0372 = { 126 | CreatedOnToolsVersion = 8.3.2; 127 | DevelopmentTeam = ZP39L9XLVC; 128 | ProvisioningStyle = Automatic; 129 | }; 130 | }; 131 | }; 132 | buildConfigurationList = 7B129AC81EE42477004E0372 /* Build configuration list for PBXProject "KaraokeDemo" */; 133 | compatibilityVersion = "Xcode 3.2"; 134 | developmentRegion = English; 135 | hasScannedForEncodings = 0; 136 | knownRegions = ( 137 | en, 138 | Base, 139 | ); 140 | mainGroup = 7B129AC41EE42477004E0372; 141 | productRefGroup = 7B129ACE1EE42477004E0372 /* Products */; 142 | projectDirPath = ""; 143 | projectRoot = ""; 144 | targets = ( 145 | 7B129ACC1EE42477004E0372 /* KaraokeDemo */, 146 | ); 147 | }; 148 | /* End PBXProject section */ 149 | 150 | /* Begin PBXResourcesBuildPhase section */ 151 | 7B129ACB1EE42477004E0372 /* Resources */ = { 152 | isa = PBXResourcesBuildPhase; 153 | buildActionMask = 2147483647; 154 | files = ( 155 | 7B129AE01EE42477004E0372 /* LaunchScreen.storyboard in Resources */, 156 | 7B4083151EE5932B0061A3EF /* bg.m4a in Resources */, 157 | 7BE5D1F21EE559E8000B5503 /* snapshot.jpg in Resources */, 158 | 7B129ADD1EE42477004E0372 /* Assets.xcassets in Resources */, 159 | 7B129ADB1EE42477004E0372 /* Main.storyboard in Resources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXResourcesBuildPhase section */ 164 | 165 | /* Begin PBXSourcesBuildPhase section */ 166 | 7B129AC91EE42477004E0372 /* Sources */ = { 167 | isa = PBXSourcesBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | 7B129AD81EE42477004E0372 /* ViewController.m in Sources */, 171 | 7B129AD51EE42477004E0372 /* AppDelegate.m in Sources */, 172 | 7BE5D1F61EE563FE000B5503 /* README.md in Sources */, 173 | 7B4083131EE5694E0061A3EF /* DEKaraokeController.m in Sources */, 174 | 7B129AD21EE42477004E0372 /* main.m in Sources */, 175 | ); 176 | runOnlyForDeploymentPostprocessing = 0; 177 | }; 178 | /* End PBXSourcesBuildPhase section */ 179 | 180 | /* Begin PBXVariantGroup section */ 181 | 7B129AD91EE42477004E0372 /* Main.storyboard */ = { 182 | isa = PBXVariantGroup; 183 | children = ( 184 | 7B129ADA1EE42477004E0372 /* Base */, 185 | ); 186 | name = Main.storyboard; 187 | sourceTree = ""; 188 | }; 189 | 7B129ADE1EE42477004E0372 /* LaunchScreen.storyboard */ = { 190 | isa = PBXVariantGroup; 191 | children = ( 192 | 7B129ADF1EE42477004E0372 /* Base */, 193 | ); 194 | name = LaunchScreen.storyboard; 195 | sourceTree = ""; 196 | }; 197 | /* End PBXVariantGroup section */ 198 | 199 | /* Begin XCBuildConfiguration section */ 200 | 7B129AE21EE42477004E0372 /* Debug */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | ALWAYS_SEARCH_USER_PATHS = NO; 204 | CLANG_ANALYZER_NONNULL = YES; 205 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 206 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 207 | CLANG_CXX_LIBRARY = "libc++"; 208 | CLANG_ENABLE_MODULES = YES; 209 | CLANG_ENABLE_OBJC_ARC = YES; 210 | CLANG_WARN_BOOL_CONVERSION = YES; 211 | CLANG_WARN_CONSTANT_CONVERSION = YES; 212 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 213 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 214 | CLANG_WARN_EMPTY_BODY = YES; 215 | CLANG_WARN_ENUM_CONVERSION = YES; 216 | CLANG_WARN_INFINITE_RECURSION = YES; 217 | CLANG_WARN_INT_CONVERSION = YES; 218 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 219 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 220 | CLANG_WARN_UNREACHABLE_CODE = YES; 221 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 222 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 223 | COPY_PHASE_STRIP = NO; 224 | DEBUG_INFORMATION_FORMAT = dwarf; 225 | ENABLE_STRICT_OBJC_MSGSEND = YES; 226 | ENABLE_TESTABILITY = YES; 227 | GCC_C_LANGUAGE_STANDARD = gnu99; 228 | GCC_DYNAMIC_NO_PIC = NO; 229 | GCC_NO_COMMON_BLOCKS = YES; 230 | GCC_OPTIMIZATION_LEVEL = 0; 231 | GCC_PREPROCESSOR_DEFINITIONS = ( 232 | "DEBUG=1", 233 | "$(inherited)", 234 | ); 235 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 236 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 237 | GCC_WARN_UNDECLARED_SELECTOR = YES; 238 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 239 | GCC_WARN_UNUSED_FUNCTION = YES; 240 | GCC_WARN_UNUSED_VARIABLE = YES; 241 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 242 | MTL_ENABLE_DEBUG_INFO = YES; 243 | ONLY_ACTIVE_ARCH = YES; 244 | SDKROOT = iphoneos; 245 | }; 246 | name = Debug; 247 | }; 248 | 7B129AE31EE42477004E0372 /* Release */ = { 249 | isa = XCBuildConfiguration; 250 | buildSettings = { 251 | ALWAYS_SEARCH_USER_PATHS = NO; 252 | CLANG_ANALYZER_NONNULL = YES; 253 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 254 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 255 | CLANG_CXX_LIBRARY = "libc++"; 256 | CLANG_ENABLE_MODULES = YES; 257 | CLANG_ENABLE_OBJC_ARC = YES; 258 | CLANG_WARN_BOOL_CONVERSION = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 261 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INFINITE_RECURSION = YES; 265 | CLANG_WARN_INT_CONVERSION = YES; 266 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 267 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 268 | CLANG_WARN_UNREACHABLE_CODE = YES; 269 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 270 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 271 | COPY_PHASE_STRIP = NO; 272 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 273 | ENABLE_NS_ASSERTIONS = NO; 274 | ENABLE_STRICT_OBJC_MSGSEND = YES; 275 | GCC_C_LANGUAGE_STANDARD = gnu99; 276 | GCC_NO_COMMON_BLOCKS = YES; 277 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 278 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 279 | GCC_WARN_UNDECLARED_SELECTOR = YES; 280 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 281 | GCC_WARN_UNUSED_FUNCTION = YES; 282 | GCC_WARN_UNUSED_VARIABLE = YES; 283 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 284 | MTL_ENABLE_DEBUG_INFO = NO; 285 | SDKROOT = iphoneos; 286 | VALIDATE_PRODUCT = YES; 287 | }; 288 | name = Release; 289 | }; 290 | 7B129AE51EE42477004E0372 /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 294 | DEVELOPMENT_TEAM = ZP39L9XLVC; 295 | INFOPLIST_FILE = KaraokeDemo/Info.plist; 296 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 297 | PRODUCT_BUNDLE_IDENTIFIER = com.swordfish.ios.KaraokeDemo; 298 | PRODUCT_NAME = "$(TARGET_NAME)"; 299 | }; 300 | name = Debug; 301 | }; 302 | 7B129AE61EE42477004E0372 /* Release */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 306 | DEVELOPMENT_TEAM = ZP39L9XLVC; 307 | INFOPLIST_FILE = KaraokeDemo/Info.plist; 308 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 309 | PRODUCT_BUNDLE_IDENTIFIER = com.swordfish.ios.KaraokeDemo; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | }; 312 | name = Release; 313 | }; 314 | /* End XCBuildConfiguration section */ 315 | 316 | /* Begin XCConfigurationList section */ 317 | 7B129AC81EE42477004E0372 /* Build configuration list for PBXProject "KaraokeDemo" */ = { 318 | isa = XCConfigurationList; 319 | buildConfigurations = ( 320 | 7B129AE21EE42477004E0372 /* Debug */, 321 | 7B129AE31EE42477004E0372 /* Release */, 322 | ); 323 | defaultConfigurationIsVisible = 0; 324 | defaultConfigurationName = Release; 325 | }; 326 | 7B129AE41EE42477004E0372 /* Build configuration list for PBXNativeTarget "KaraokeDemo" */ = { 327 | isa = XCConfigurationList; 328 | buildConfigurations = ( 329 | 7B129AE51EE42477004E0372 /* Debug */, 330 | 7B129AE61EE42477004E0372 /* Release */, 331 | ); 332 | defaultConfigurationIsVisible = 0; 333 | defaultConfigurationName = Release; 334 | }; 335 | /* End XCConfigurationList section */ 336 | }; 337 | rootObject = 7B129AC51EE42477004E0372 /* Project object */; 338 | } 339 | --------------------------------------------------------------------------------