syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.94k stars 821 forks source link

Skipped frames on recording #317

Open enamodeka opened 8 years ago

enamodeka commented 8 years ago

Hi there,

has anybody got the problem of skipped frames now and then? At times the recording plot freezes for the split second and the frames at that time are missing in the recorded file. I'm recording to AIFF format (with modified flags:

asbd.mFormatFlags = kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; such that the recorded file can open in Ableton Live.)

I'm recording using Soundflower device. The same setup with AudioQueues (instead of EZAudio engine) from the Learning Core Audio book example works fine. Even if the system stutters the recording is unaffected.

Any idea on what could be happening?

designerfuzzi commented 2 years ago

same Issue. Ended up heavily optimising EZAudio.

Things i have done..

and most important after lots testing.. changed

- (void)appendDataFromBufferList:(AudioBufferList *)bufferList withBufferSize:(UInt32)bufferSize
{
    //
    // Make sure the audio file is not closed
    if (self.info->closed) return; //no NSAssert here, return is enoug
   //would be even better without *self*, so it could become an argument.  

    //
    // Perform the write
    // ExtAudioFileWrite() not used here, instead Asynchron writing without Objective-C ErrorHandling Wrapper. I take the risk.
    ExtAudioFileWriteAsync(self.info->extAudioFileRef, bufferSize, bufferList);

    //
    // Notify delegate <-- NOT, we call the delegate!
    //
    //if ([self.delegate respondsToSelector:@selector(recorderUpdatedCurrentTime:)])
    if (delegatedRecorderUpdatedCurrentTimeToString) //ugly name from the delegate optimisation.
    {
        // see the C function naming? and not *self* here, what is not in the block can not be locked!
        [_delegate recorderUpdatedCurrentTimeToString:EZAudioUtilities_displayTimeStringFromSeconds([self currentTime])];
    }
}

this basically made EZAudio work for me.. After hours of hickups, little glitches or skipps, listening for errors in recordings in different formats, it writes much cleaner cause the ExtAudioFileWriteAsync() seems to fit better for EZAudio

Ah and not to forget, EZAudioDisplayLink protocol has a delegate method that takes the displaylink as message, which you never need.

- (void)displayLinkNeedsDisplay;

cheers