This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 11th, 2013  |  syntax: None  |  size: 4.46 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. AudioStreamBasicDescription audioFormat;
  2. audioFormat.mSampleRate         = 44100.00;
  3. audioFormat.mFormatID           = kAudioFormatLinearPCM;
  4. audioFormat.mFormatFlags        = kAudioFormatFlagsCanonical;
  5. audioFormat.mBytesPerPacket     = 2;
  6. audioFormat.mFramesPerPacket    = 1;
  7. audioFormat.mBytesPerFrame      = 2;
  8. audioFormat.mChannelsPerFrame   = 1;
  9. audioFormat.mBitsPerChannel     = 16;
  10. audioFormat.mReserved           = 0;
  11. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  12. NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  13. if(![[NSFileManager defaultManager] fileExistsAtPath:documentsDirectory])
  14.     [[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];
  15. NSString *path = [documentsDirectory stringByAppendingPathComponent:@"audio.caf"];
  16. if(![[NSFileManager defaultManager] fileExistsAtPath:path])
  17.     NSLog(@"file not exist.");
  18. NSLog(@"Path : %@", path);
  19. THIS->url = [NSURL fileURLWithPath:[path retain]];
  20. err = ExtAudioFileCreateWithURL((CFURLRef)THIS->url, kAudioFileCAFType, &audioFormat, NULL, kAudioFileFlags_EraseFile, &THIS->fOutputAudioFile);
  21. if(err != noErr){
  22.     printf("create with url: error %dn", (int)err);
  23. }
  24. THIS->state = 2;
  25. err = ExtAudioFileSetProperty(THIS->fOutputAudioFile, kExtAudioFileProperty_ClientDataFormat, (UInt32)sizeof(audioFormat), &audioFormat);
  26. if(err != noErr){
  27.     printf("file set property: error %dn", (int)err);
  28. }
  29. err = ExtAudioFileWriteAsync(THIS->fOutputAudioFile, 0, NULL);
  30. if(err != noErr){
  31.     printf("write async: error %dn", (int)err);
  32.     return err;
  33. }
  34. [pool release];
  35.  
  36. err = ExtAudioFileWriteAsync(THIS->fOutputAudioFile, ioData->mNumberBuffers, ioData);
  37. if(err != noErr){
  38.     printf("file write async: error %dn", (int)err);
  39.     return err;
  40. }
  41.        
  42. Program received signal:  “EXC_BAD_ACCESS”.
  43. #0  0x30d04bb2 in memmove ()
  44. #1  0x33ba1d1e in AudioRingBuffer::Store ()
  45. #2  0x33c2269e in ExtAudioFile::WriteFramesAsync ()
  46. #3  0x33c278c8 in ExtAudioFileWriteAsync ()
  47. #4  0x00002e74 in PerformThru (inRefCon=0x14d9f0, ioActionFlags=0x2ffe77d4, inTimeStamp=0xa896fc, inBusNumber=0, inNumberFrames=256, ioData=0x14f680) at /Alex/project/ProStudio/TestAudioUnit/Classes/TestAudioUnitAppDelegate.mm:399
  48. #5  0x33b70896 in AUInputElement::PullInput ()
  49. #6  0x33b794a0 in AUInputFormatConverter2::InputProc ()
  50. #7  0x33b5560e in AudioConverterChain::CallInputProc ()
  51. #8  0x33b5555e in AudioConverterChain::FillBufferFromInputProc ()
  52. #9  0x33b5537c in BufferedAudioConverter::GetInputBytes ()
  53. #10 0x33b79390 in CBRConverter::RenderOutput ()
  54. #11 0x33b5505a in BufferedAudioConverter::FillBuffer ()
  55. #12 0x33b55362 in BufferedAudioConverter::GetInputBytes ()
  56. #13 0x33b79390 in CBRConverter::RenderOutput ()
  57. #14 0x33b5505a in BufferedAudioConverter::FillBuffer ()
  58. #15 0x33b551ae in AudioConverterChain::RenderOutput ()
  59. #16 0x33b5505a in BufferedAudioConverter::FillBuffer ()
  60. #17 0x33b54e2a in AudioConverterFillComplexBuffer ()
  61. #18 0x33b78f58 in AUConverterBase::RenderBus ()
  62. #19 0x33c08eea in AURemoteIO::RenderBus ()
  63. #20 0x33b5666e in AUBase::DoRender ()
  64. #21 0x33c09698 in AURemoteIO::PerformIO ()
  65. #22 0x33c09962 in AURIOCallbackReceiver_PerformIO ()
  66. #23 0x33c02448 in _XPerformIO ()
  67. #24 0x33b71bea in mshMIGPerform ()
  68. #25 0x33bd7de0 in MSHMIGDispatchMessage ()
  69. #26 0x33c0ebae in AURemoteIO::IOThread::Entry ()
  70. #27 0x33b4a1d8 in CAPThread::Entry ()
  71. #28 0x30d7d88c in _pthread_start ()
  72. #29 0x30d72a90 in thread_start ()
  73.        
  74. audioFormat.mSampleRate        = 44100.00;
  75. audioFormat.mFormatID          = kAudioFormatLinearPCM;
  76. audioFormat.mFormatFlags       = kAudioFormatFlagsCanonical | (kAudioUnitSampleFractionBits << kLinearPCMFormatFlagsSampleFractionShift) | kAudioFormatFlagIsNonInterleaved;
  77. audioFormat.mChannelsPerFrame  = 2;
  78. audioFormat.mFramesPerPacket   = 1;
  79. audioFormat.mBitsPerChannel    = 8 * sizeof(AudioUnitSampleType);
  80. audioFormat.mBytesPerPacket    = sizeof(AudioUnitSampleType);
  81. audioFormat.mBytesPerFrame     = sizeof(AudioUnitSampleType);;
  82. audioFormat.mReserved          = 0;
  83.        
  84. AudioStreamBasicDescription audioFormat;
  85. audioFormat.mSampleRate         = 44100.00;
  86. audioFormat.mFormatID           = kAudioFormatLinearPCM;
  87. audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
  88. audioFormat.mFramesPerPacket    = 1;
  89. audioFormat.mChannelsPerFrame   = 1;
  90. audioFormat.mBitsPerChannel     = 16;
  91. audioFormat.mBytesPerPacket     = 2;
  92. audioFormat.mBytesPerFrame      = 2;
  93. audioFormat.mReserved           = 0;
clone this paste RAW Paste Data