@@ -430,7 +430,9 @@ - (void)setAudioStreamBasicDescription:(AudioStreamBasicDescription)asbd
430
430
numberOfChannels: self .info->streamFormat.mChannelsPerFrame];
431
431
}
432
432
433
- // set new stream format
433
+ //
434
+ // Set new stream format
435
+ //
434
436
self.info ->streamFormat = asbd;
435
437
[EZAudioUtilities checkResult: AudioUnitSetProperty (self .info->audioUnit,
436
438
kAudioUnitProperty_StreamFormat ,
@@ -447,18 +449,21 @@ - (void)setAudioStreamBasicDescription:(AudioStreamBasicDescription)asbd
447
449
sizeof (asbd))
448
450
operation: " Failed to set stream format on output scope" ];
449
451
450
- // allocate float buffers
452
+ //
453
+ // Allocate scratch buffers
454
+ //
451
455
UInt32 maximumBufferSize = [self maximumBufferSize ];
452
456
BOOL isInterleaved = [EZAudioUtilities isInterleaved: asbd];
453
457
UInt32 channels = asbd.mChannelsPerFrame ;
454
458
self.floatConverter = [[EZAudioFloatConverter alloc ] initWithInputFormat: asbd];
455
459
self.info ->floatData = [EZAudioUtilities floatBuffersWithNumberOfFrames: maximumBufferSize
456
460
numberOfChannels: channels];
457
461
self.info ->audioBufferList = [EZAudioUtilities audioBufferListWithNumberOfFrames: maximumBufferSize
458
- numberOfChannels: channels
459
- interleaved: isInterleaved];
460
-
461
- // notify delegate
462
+ numberOfChannels: channels
463
+ interleaved: isInterleaved];
464
+ //
465
+ // Notify delegate
466
+ //
462
467
if ([self .delegate respondsToSelector: @selector (microphone:hasAudioStreamBasicDescription: )])
463
468
{
464
469
[self .delegate microphone: self hasAudioStreamBasicDescription: asbd];
@@ -528,10 +533,14 @@ - (void)setDevice:(EZAudioDevice *)device
528
533
operation: " Couldn't set default device on I/O unit" ];
529
534
#endif
530
535
531
- // store device
536
+ //
537
+ // Store device
538
+ //
532
539
_device = device;
533
540
534
- // notify delegate
541
+ //
542
+ // Notify delegate
543
+ //
535
544
if ([self .delegate respondsToSelector: @selector (microphone:changedDevice: )])
536
545
{
537
546
[self .delegate microphone: self changedDevice: device];
@@ -603,15 +612,27 @@ static OSStatus EZAudioMicrophoneCallback(void *inRefCon,
603
612
EZMicrophone *microphone = (__bridge EZMicrophone *)inRefCon;
604
613
EZMicrophoneInfo *info = (EZMicrophoneInfo *)microphone.info ;
605
614
606
- // render audio into buffer
615
+ //
616
+ // Make sure the size of each buffer in the stored buffer array
617
+ // is properly set using the actual number of frames coming in!
618
+ //
619
+ for (int i = 0 ; i < info->audioBufferList ->mNumberBuffers ; i++) {
620
+ info->audioBufferList ->mBuffers [i].mDataByteSize = inNumberFrames * info->streamFormat .mBytesPerFrame ;
621
+ }
622
+
623
+ //
624
+ // Render audio into buffer
625
+ //
607
626
OSStatus result = AudioUnitRender (info->audioUnit ,
608
627
ioActionFlags,
609
628
inTimeStamp,
610
629
inBusNumber,
611
630
inNumberFrames,
612
631
info->audioBufferList );
613
632
614
- // notify delegate of new buffer list to process
633
+ //
634
+ // Notify delegate of new buffer list to process
635
+ //
615
636
if ([microphone.delegate respondsToSelector: @selector (microphone:hasBufferList:withBufferSize:withNumberOfChannels: )])
616
637
{
617
638
[microphone.delegate microphone: microphone
@@ -620,10 +641,14 @@ static OSStatus EZAudioMicrophoneCallback(void *inRefCon,
620
641
withNumberOfChannels: info->streamFormat.mChannelsPerFrame];
621
642
}
622
643
623
- // notify delegate of new float data processed
644
+ //
645
+ // Notify delegate of new float data processed
646
+ //
624
647
if ([microphone.delegate respondsToSelector: @selector (microphone:hasAudioReceived:withBufferSize:withNumberOfChannels: )])
625
648
{
626
- // convert to float
649
+ //
650
+ // Convert to float
651
+ //
627
652
[microphone.floatConverter convertDataFromAudioBufferList: info->audioBufferList
628
653
withNumberOfFrames: inNumberFrames
629
654
toFloatBuffers: info->floatData];
0 commit comments