Permalink
Browse files

First update pass - remove property ivars, manual synthesize, and add…

… arc support
  • Loading branch information...
ndonald2 committed Jun 10, 2013
1 parent 9f21e3c commit 559739e95ed82817b1a30bf7a0a14f22db595a67
@@ -28,13 +28,12 @@
#import "AudioFileWriter.h"
@interface AppDelegate : NSObject <NSApplicationDelegate>
-{
- RingBuffer *ringBuffer;
- Novocaine *audioManager;
- AudioFileReader *fileReader;
- AudioFileWriter *fileWriter;
-}
-@property (assign) IBOutlet NSWindow *window;
+@property (nonatomic, assign) RingBuffer *ringBuffer;
+@property (nonatomic, strong) Novocaine *audioManager;
+@property (nonatomic, strong) AudioFileReader *fileReader;
+@property (nonatomic, strong) AudioFileWriter *fileWriter;
+
+@property (nonatomic, weak) IBOutlet NSWindow *window;
@end
@@ -26,18 +26,11 @@
@implementation AppDelegate
-@synthesize window = _window;
-
-- (void)dealloc
-{
- [super dealloc];
-}
-
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
- audioManager = [Novocaine audioManager];
+ self.audioManager = [Novocaine audioManager];
// ringBuffer = new RingBuffer(32768, 2);
@@ -73,22 +66,25 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// ========================================
NSURL *inputFileURL = [[NSBundle mainBundle] URLForResource:@"TLC" withExtension:@"mp3"];
- fileReader = [[AudioFileReader alloc]
- initWithAudioFileURL:inputFileURL
- samplingRate:audioManager.samplingRate
- numChannels:audioManager.numOutputChannels];
+ self.fileReader = [[AudioFileReader alloc]
+ initWithAudioFileURL:inputFileURL
+ samplingRate:self.audioManager.samplingRate
+ numChannels:self.audioManager.numOutputChannels];
- fileReader.currentTime = 5;
- [fileReader play];
+ self.fileReader.currentTime = 5;
+ [self.fileReader play];
__block int counter = 0;
- [audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
+
+ __weak AppDelegate * wself = self;
+
+ [self.audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
- [fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
+ [wself.fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
counter++;
if (counter % 80 == 0)
- NSLog(@"Time: %f", fileReader.currentTime);
+ NSLog(@"Time: %f", wself.fileReader.currentTime);
}];
@@ -28,24 +28,14 @@
@implementation AppDelegate
-@synthesize window = _window;
-@synthesize viewController = _viewController;
-
-- (void)dealloc
-{
- [_window release];
- [_viewController release];
- [super dealloc];
-}
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
+ self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
- self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
+ self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
@@ -29,10 +29,10 @@
#import "AudioFileWriter.h"
@interface ViewController : UIViewController
-{
- RingBuffer *ringBuffer;
- Novocaine *audioManager;
- AudioFileReader *fileReader;
- AudioFileWriter *fileWriter;
-}
+
+@property (nonatomic, assign) RingBuffer *ringBuffer;
+@property (nonatomic, strong) Novocaine *audioManager;
+@property (nonatomic, strong) AudioFileReader *fileReader;
+@property (nonatomic, strong) AudioFileWriter *fileWriter;
+
@end
@@ -46,8 +46,8 @@ - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
- ringBuffer = new RingBuffer(32768, 2);
- audioManager = [Novocaine audioManager];
+ self.ringBuffer = new RingBuffer(32768, 2);
+ self.audioManager = [Novocaine audioManager];
// Basic playthru example
@@ -169,18 +169,20 @@ - (void)viewWillAppear:(BOOL)animated
// ========================================
NSURL *inputFileURL = [[NSBundle mainBundle] URLForResource:@"TLC" withExtension:@"mp3"];
- fileReader = [[AudioFileReader alloc]
- initWithAudioFileURL:inputFileURL
- samplingRate:audioManager.samplingRate
- numChannels:audioManager.numOutputChannels];
+ self.fileReader = [[AudioFileReader alloc]
+ initWithAudioFileURL:inputFileURL
+ samplingRate:self.audioManager.samplingRate
+ numChannels:self.audioManager.numOutputChannels];
- [fileReader play];
- fileReader.currentTime = 30.0;
+ [self.fileReader play];
+ self.fileReader.currentTime = 30.0;
- [audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
+
+ __weak ViewController * wself = self;
+ [self.audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
- [fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
- NSLog(@"Time: %f", fileReader.currentTime);
+ [wself.fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
+ NSLog(@"Time: %f", wself.fileReader.currentTime);
}];
@@ -451,6 +451,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
@@ -472,6 +473,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -492,6 +494,7 @@
FA5526E9152A6452003D9601 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Novocaine iOS Example/Novocaine iOS Example-Prefix.pch";
@@ -504,6 +507,7 @@
FA5526EA152A6452003D9601 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Novocaine iOS Example/Novocaine iOS Example-Prefix.pch";
@@ -27,27 +27,15 @@
@interface AudioFileReader : NSObject
-{
- float currentTime;
- float duration;
- float samplingRate;
- float latency;
- UInt32 numChannels;
- NSURL *audioFileURL;
-
- InputBlock readerBlock;
-
- BOOL playing;
-}
-@property (getter=getCurrentTime, setter=setCurrentTime:) float currentTime;
-@property (readonly, getter=getDuration) float duration;
-@property float samplingRate;
-@property UInt32 numChannels;
-@property float latency;
+@property (nonatomic, assign, getter=getCurrentTime, setter=setCurrentTime:) float currentTime;
+@property (nonatomic, assign, readonly, getter=getDuration) float duration;
+@property (nonatomic, assign) float samplingRate;
+@property (nonatomic, assign) UInt32 numChannels;
+@property (nonatomic, assign) float latency;
@property (nonatomic, copy) NSURL *audioFileURL;
@property (nonatomic, copy) InputBlock readerBlock;
-@property BOOL playing;
+@property (nonatomic, assign) BOOL playing;
- (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSamplingRate numChannels:(UInt32)thisNumChannels;
@@ -32,16 +32,15 @@ @interface AudioFileReader ()
RingBuffer *ringBuffer;
}
-@property AudioStreamBasicDescription outputFormat;
-@property ExtAudioFileRef inputFile;
-@property UInt32 outputBufferSize;
-@property float *outputBuffer;
-@property float *holdingBuffer;
-@property UInt32 numSamplesReadPerPacket;
-@property UInt32 desiredPrebufferedSamples;
-@property SInt64 currentFileTime;
-@property dispatch_source_t callbackTimer;
-
+@property (nonatomic, assign) AudioStreamBasicDescription outputFormat;
+@property (nonatomic, assign) ExtAudioFileRef inputFile;
+@property (nonatomic, assign) UInt32 outputBufferSize;
+@property (nonatomic, assign) float *outputBuffer;
+@property (nonatomic, assign) float *holdingBuffer;
+@property (nonatomic, assign) UInt32 numSamplesReadPerPacket;
+@property (nonatomic, assign) UInt32 desiredPrebufferedSamples;
+@property (nonatomic, assign) SInt64 currentFileTime;
+@property (nonatomic, assign) dispatch_source_t callbackTimer;
- (void)bufferNewAudio;
@@ -51,23 +50,6 @@ - (void)bufferNewAudio;
@implementation AudioFileReader
-@synthesize outputFormat = _outputFormat;
-@synthesize inputFile = _inputFile;
-@synthesize outputBuffer = _outputBuffer;
-@synthesize holdingBuffer = _holdingBuffer;
-@synthesize outputBufferSize = _outputBufferSize;
-@synthesize numSamplesReadPerPacket = _numSamplesReadPerPacket;
-@synthesize desiredPrebufferedSamples = _desiredPrebufferedSamples;
-@synthesize currentFileTime = _currentFileTime;
-@synthesize callbackTimer = _callbackTimer;
-@synthesize currentTime = _currentTime;
-@synthesize duration = _duration;
-@synthesize samplingRate = _samplingRate;
-@synthesize latency = _latency;
-@synthesize numChannels = _numChannels;
-@synthesize audioFileURL = _audioFileURL;
-@synthesize readerBlock = _readerBlock;
-@synthesize playing = _playing;
- (void)dealloc
{
@@ -85,7 +67,6 @@ - (void)dealloc
delete ringBuffer;
- [super dealloc];
}
@@ -101,7 +82,7 @@ - (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSampl
// Open a reference to the audio file
self.audioFileURL = urlToAudioFile;
- CFURLRef audioFileRef = (CFURLRef)self.audioFileURL;
+ CFURLRef audioFileRef = (__bridge CFURLRef)self.audioFileURL;
CheckError(ExtAudioFileOpenURL(audioFileRef, &_inputFile), "Opening file URL (ExtAudioFileOpenURL)");
@@ -30,27 +30,15 @@
@interface AudioFileWriter : NSObject
-{
- float currentTime;
- float duration;
- float samplingRate;
- float latency;
- UInt32 numChannels;
- NSURL *audioFileURL;
-
- OutputBlock writerBlock;
-
- BOOL recording;
-}
-@property (getter=getDuration, readonly) float currentTime;
-@property (getter=getDuration) float duration;
-@property float samplingRate;
-@property UInt32 numChannels;
-@property float latency;
+@property (nonatomic, assign, getter=getDuration, readonly) float currentTime;
+@property (nonatomic, assign, getter=getDuration) float duration;
+@property (nonatomic, assign) float samplingRate;
+@property (nonatomic, assign) UInt32 numChannels;
+@property (nonatomic, assign) float latency;
@property (nonatomic, copy) NSURL *audioFileURL;
@property (nonatomic, copy) InputBlock writerBlock;
-@property BOOL recording;
+@property (nonatomic, assign) BOOL recording;
- (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSamplingRate numChannels:(UInt32)thisNumChannels;
@@ -29,48 +29,29 @@
@interface AudioFileWriter()
-@property AudioStreamBasicDescription outputFormat;
-@property ExtAudioFileRef outputFile;
-@property UInt32 outputBufferSize;
-@property float *outputBuffer;
-@property float *holdingBuffer;
-@property SInt64 currentFileTime;
-@property dispatch_source_t callbackTimer;
-@property (readwrite) float currentTime;
+@property (nonatomic, assign) AudioStreamBasicDescription outputFormat;
+@property (nonatomic, assign) ExtAudioFileRef outputFile;
+@property (nonatomic, assign) UInt32 outputBufferSize;
+@property (nonatomic, assign) float *outputBuffer;
+@property (nonatomic, assign) float *holdingBuffer;
+@property (nonatomic, assign) SInt64 currentFileTime;
+@property (nonatomic, assign) dispatch_source_t callbackTimer;
+@property (nonatomic, assign, readwrite) float currentTime;
@end
-
@implementation AudioFileWriter
static pthread_mutex_t outputAudioFileLock;
-@synthesize outputFormat = _outputFormat;
-@synthesize outputFile = _outputFile;
-@synthesize outputBuffer = _outputBuffer;
-@synthesize holdingBuffer = _holdingBuffer;
-@synthesize outputBufferSize = _outputBufferSize;
-@synthesize currentFileTime = _currentFileTime;
-@synthesize callbackTimer = _callbackTimer;
-
-@synthesize currentTime = _currentTime;
-@synthesize duration = _duration;
-@synthesize samplingRate = _samplingRate;
-@synthesize latency = _latency;
-@synthesize numChannels = _numChannels;
-@synthesize audioFileURL = _audioFileURL;
-@synthesize writerBlock = _writerBlock;
-@synthesize recording = _recording;
-
- (void)dealloc
{
[self stop];
free(self.outputBuffer);
free(self.holdingBuffer);
- [super dealloc];
}
- (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSamplingRate numChannels:(UInt32)thisNumChannels
@@ -85,7 +66,7 @@ - (id)initWithAudioFileURL:(NSURL *)urlToAudioFile samplingRate:(float)thisSampl
// Open a reference to the audio file
self.audioFileURL = urlToAudioFile;
- CFURLRef audioFileRef = (CFURLRef)self.audioFileURL;
+ CFURLRef audioFileRef = (__bridge CFURLRef)self.audioFileURL;
AudioStreamBasicDescription outputFileDesc = {44100.0, kAudioFormatMPEG4AAC, 0, 0, 1024, 0, thisNumChannels, 0, 0};
Oops, something went wrong.

0 comments on commit 559739e

Please sign in to comment.