Skip to content

Instantly share code, notes, and snippets.

@nevyn
Created March 14, 2016 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nevyn/bb8f1870e7ed6198496a to your computer and use it in GitHub Desktop.
Save nevyn/bb8f1870e7ed6198496a to your computer and use it in GitHub Desktop.
For @sethwillits
- (void)appendEncodedSampleBuffer:(CMSampleBufferRef)encodedSampleBuffer addTrimAtStart:(int)trimDuration fromSource:(id)source
{
if(!_hasWrittenTrim) {
GFLog(GFDebug, @"Adding trim to sample buffer from %@", source);
const AudioStreamBasicDescription *asbd = CMAudioFormatDescriptionGetStreamBasicDescription(CMSampleBufferGetFormatDescription(encodedSampleBuffer));
CMSetAttachment(encodedSampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, (id)CFAutorelease(
CMTimeCopyAsDictionary(
CMTimeMake(trimDuration, asbd->mSampleRate),
kCFAllocatorDefault
)
), kCMAttachmentMode_ShouldNotPropagate);
_hasWrittenTrim = YES;
}
NSError *error;
if(![_writer writeSampleBuffer:encodedSampleBuffer error:&error]) {
[_delegate audioRecorder:self encounteredPermanentError:error];
[self stop];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment