Guest User

Playthrough class

a guest
Apr 21st, 2012
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  AEAudioPlaythroughChannel.m
  3. //
  4. //  Created by Michael Tyson on 21/04/2012.
  5. //  Copyright (c) 2012 A Tasty Pixel. All rights reserved.
  6. //
  7.  
  8. #import "AEAudioPlaythroughChannel.h"
  9. #import "TPCircularBuffer.h"
  10. #import "TPCircularBuffer+AudioBufferList.h"
  11.  
  12. static const int kAudioBufferLength = 16384;
  13.  
  14. @interface AEAudioPlaythroughChannel () {
  15.     TPCircularBuffer _buffer;
  16. }
  17. @property (nonatomic, retain) AEAudioController *audioController;
  18. @end
  19.  
  20. @implementation AEAudioPlaythroughChannel
  21. @synthesize audioController=_audioController;
  22.  
  23. - (id)initWithAudioController:(AEAudioController*)audioController {
  24.     if ( !(self = [super init]) ) return nil;
  25.     TPCircularBufferInit(&_buffer, kAudioBufferLength);
  26.     self.audioController = audioController;
  27.     return self;
  28. }
  29.  
  30. - (void)dealloc {
  31.     TPCircularBufferCleanup(&_buffer);
  32.     self.audioController = nil;
  33.     [super dealloc];
  34. }
  35.  
  36. static void inputCallback(id                        receiver,
  37.                           AEAudioController        *audioController,
  38.                           void                     *source,
  39.                           const AudioTimeStamp     *time,
  40.                           UInt32                    frames,
  41.                           AudioBufferList          *audio) {
  42.    
  43.     TPCircularBufferCopyAudioBufferList(&((AEAudioPlaythroughChannel*)receiver)->_buffer,
  44.                                         audio,
  45.                                         time);
  46. }
  47.  
  48. -(AEAudioControllerAudioCallback)receiverCallback {
  49.     return inputCallback;
  50. }
  51.  
  52. static OSStatus renderCallback(id                        channel,
  53.                                AEAudioController        *audioController,
  54.                                const AudioTimeStamp     *time,
  55.                                UInt32                    frames,
  56.                                AudioBufferList          *audio) {
  57.    
  58.     TPCircularBufferConsumeBufferListFrames(&((AEAudioPlaythroughChannel*)channel)->_buffer,
  59.                                             &frames,
  60.                                             audio,
  61.                                             NULL,
  62.                                             AEAudioControllerAudioDescription(audioController));
  63.     return noErr;
  64. }
  65.  
  66. -(AEAudioControllerRenderCallback)renderCallback {
  67.     return renderCallback;
  68. }
  69.  
  70. @end
Advertisement
Add Comment
Please, Sign In to add comment