###前提・実現したいこと
Objective-Cで楽曲再生アプリを作っています。
CoreAudioを使用して楽曲再生したいのですが下記コードにて
「All Exceptions Breakpoint」を設定して実行すると * 箇所にて停止します。
(「All Exceptions Breakpoint」を設定しないと停止しません。)
どなたか、解決方法をご存知の方がいましたらアドバイスをお願いします。
###発生している問題・エラーメッセージ
Thread 1: breakpoint 1.2
###ソースコード
Objective
1 2#import <CoreAudio/CoreAudioTypes.h> 3#import <AudioToolbox/MusicPlayer.h> 4#import <AVFoundation/AVFoundation.h> 5#import "ViewController.h" 6 7#define MAXBUFS 2 8 9typedef struct { 10 AudioStreamBasicDescription asbd; 11 SInt32 *data; 12 UInt32 numFrames; 13} SoundBuffer, *SoundBufferPtr; 14 15typedef struct { 16 UInt32 frameNum; 17 UInt32 maxNumFrames; 18 SoundBuffer soundBuffer[MAXBUFS]; 19} SourceAudioBufferData, *SourceAudioBufferDataPtr; 20 21@interface ViewController () 22 23@end 24 25@implementation ViewController 26 27- (void)viewDidLoad { 28 [super viewDidLoad]; 29 30 AUGraph _AUGraph; 31 AUNode audioPlayerNode, remoteOutputNode; 32 AudioUnit remoteIOUnit, audioPlayerUnit; 33 AudioFileID audioFileID; 34 AudioComponentDescription acd; 35 AudioStreamBasicDescription asbd; 36 37 [self XThrowIfError:NewAUGraph(&_AUGraph) msg:@"NewAUGraph"]; 38 [self XThrowIfError:AUGraphOpen(_AUGraph) msg:@"AUGraphOpen"]; 39 40 acd.componentManufacturer = kAudioUnitManufacturer_Apple; 41 acd.componentFlags = acd.componentFlagsMask = 0; 42 43 acd.componentType = kAudioUnitType_Generator; 44 acd.componentSubType = kAudioUnitSubType_AudioFilePlayer; 45 [self XThrowIfError:AUGraphAddNode(_AUGraph, &acd, &audioPlayerNode) msg:@"audioPlayerNode"]; 46 [self XThrowIfError:AUGraphNodeInfo(_AUGraph, audioPlayerNode, NULL, &audioPlayerUnit) msg:@"audioPlayerNode"]; 47 48 acd.componentType = kAudioUnitType_Output; 49 acd.componentSubType = kAudioUnitSubType_RemoteIO; 50 [self XThrowIfError:AUGraphAddNode(_AUGraph, &acd, &remoteOutputNode) msg:@"remoteOutputNode"]; 51 [self XThrowIfError:AUGraphNodeInfo(_AUGraph, remoteOutputNode, NULL, &remoteIOUnit) msg:@"remoteOutputNode"]; 52 53 [self XThrowIfError:AUGraphConnectNodeInput(_AUGraph, audioPlayerNode, 0, remoteOutputNode, 0) 54 msg:@"audioPlayerNode converterNode1"]; 55 56 [self XThrowIfError:AUGraphInitialize(_AUGraph) msg:@"AUGraphInitialize"]; 57 58 CAShow(_AUGraph); 59 60 61 62 NSURL *url = [[NSBundle mainBundle] URLForResource:@"DemoSong" withExtension:@"m4a"]; 63 64 [self XThrowIfError:AudioFileOpenURL((__bridge CFURLRef)(url) 65 , kAudioFileReadPermission 66 , 0, &audioFileID) 67 msg:@"kAudioFileReadPermission"]; 68 69 UInt32 propSize = sizeof(asbd); 70 [self XThrowIfError:AudioFileGetProperty(audioFileID 71 , kAudioFilePropertyDataFormat 72 , &propSize 73 , &asbd) 74 msg:@"kAudioFilePropertyDataFormat"]; 75 76 [self XThrowIfError:AudioUnitReset(audioPlayerUnit, kAudioUnitScope_Global, 0) msg:@"Reset file audio unit"]; 77 78 // * ここでプログラムが停止します。 79 [self XThrowIfError:AudioUnitSetProperty(audioPlayerUnit 80 , kAudioUnitProperty_ScheduledFileIDs 81 , kAudioUnitScope_Global 82 , 0 83 , &audioFileID 84 , sizeof(audioFileID)) 85 msg:@"kAudioUnitProperty_ScheduledFileIDs"]; 86 87 UInt64 nPackets; 88 propSize = sizeof(nPackets); 89 [self XThrowIfError:AudioFileGetProperty(audioFileID 90 , kAudioFilePropertyAudioDataPacketCount 91 , &propSize 92 , &nPackets) 93 msg:@"kAudioUnitProperty_ScheduledFileRegion"]; 94 95 ScheduledAudioFileRegion rgn; 96 memset(&rgn.mTimeStamp, 0, sizeof(rgn.mTimeStamp)); 97 rgn.mTimeStamp.mFlags = kAudioTimeStampSampleHostTimeValid; 98 rgn.mTimeStamp.mSampleTime = 0; 99 rgn.mCompletionProc = NULL; 100 rgn.mCompletionProcUserData = NULL; 101 rgn.mAudioFile = audioFileID; 102 rgn.mLoopCount = 0; 103 rgn.mStartFrame = 0; 104 rgn.mFramesToPlay = (unsigned int)nPackets * asbd.mFramesPerPacket; 105 106 [self XThrowIfError:AudioUnitSetProperty(audioPlayerUnit 107 , kAudioUnitProperty_ScheduledFileRegion 108 , kAudioUnitScope_Global 109 , 0 110 , &rgn, sizeof(rgn)) 111 msg:@"kAudioUnitProperty_ScheduledFileRegion"]; 112 113 UInt32 primeFrames = 0; 114 [self XThrowIfError:AudioUnitSetProperty(audioPlayerUnit 115 , kAudioUnitProperty_ScheduledFilePrime 116 , kAudioUnitScope_Global 117 , 0 118 , &primeFrames 119 , sizeof(primeFrames)) 120 msg:@"kAudioUnitProperty_ScheduledFilePrime"]; 121 122 AudioTimeStamp startTime; 123 startTime.mFlags = kAudioTimeStampSampleTimeValid; 124 startTime.mSampleTime = -1; 125 [self XThrowIfError:AudioUnitSetProperty(audioPlayerUnit 126 , kAudioUnitProperty_ScheduleStartTimeStamp 127 , kAudioUnitScope_Global 128 , 0 129 , &startTime 130 , sizeof(startTime)) 131 msg:@"kAudioUnitProperty_ScheduleStartTimeStamp"]; 132 133 AUGraphStart(_AUGraph); 134 135} 136 137- (void) XThrowIfError:(OSStatus)isBool msg:(NSString *)msg { 138 if (isBool < 0) { 139 NSLog(@"%@:", msg); 140 } 141} 142 143 144- (void)didReceiveMemoryWarning { 145 [super didReceiveMemoryWarning]; 146 // Dispose of any resources that can be recreated. 147} 148 149@end 150 151
###補足情報(言語/FW/ツール等のバージョンなど)
- Xcode Version 6.4
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/09/28 01:51 編集