Permalink
Browse files

- Converted to ARC.

- You now need to specify the filename extension of the sound files (.caf, .m4a, etc) in the plist file for the sound bank.
  • Loading branch information...
1 parent 2539045 commit 5c42e18e60567481a62b0f9784be8182f44a466c @hollance committed Jun 23, 2012
@@ -288,11 +288,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Demo/Demo_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Demo/Demo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = Demo;
@@ -309,9 +311,11 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Demo/Demo_Prefix.pch;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "Demo/Demo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = Demo;
View
@@ -3,7 +3,7 @@
@interface DemoAppDelegate : UIResponder <UIApplicationDelegate>
-@property (nonatomic, retain) IBOutlet UIWindow *window;
-@property (nonatomic, retain) IBOutlet DemoViewController *viewController;
+@property (nonatomic, strong) UIWindow *window;
+@property (nonatomic, strong) DemoViewController *viewController;
@end
View
@@ -9,18 +9,11 @@ @implementation DemoAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- self.viewController = [[[DemoViewController alloc] initWithNibName:@"DemoViewController" bundle:nil] autorelease];
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.viewController = [[DemoViewController alloc] initWithNibName:@"DemoViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
-- (void)dealloc
-{
- [_viewController release];
- [_window release];
- [super dealloc];
-}
-
@end
@@ -36,8 +36,6 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)dealloc
{
[self stopTimer];
- [_soundBankPlayer release];
- [super dealloc];
}
- (IBAction)strumCMajorChord
@@ -126,7 +124,6 @@ - (void)handleTimer:(NSTimer *)timer
if (_arpeggioIndex == [_arpeggioNotes count])
{
_playingArpeggio = NO;
- [_arpeggioNotes release];
_arpeggioNotes = nil;
}
else // schedule next note
@@ -25,8 +25,8 @@
* It's like SoundFonts but simpler.
*
* The SoundBankPlayer takes care of setting up the Audio Session. You only
- * have to provide the sound samples (in CAF format) and a PLIST file that
- * describes how the samples map to MIDI notes.
+ * have to provide the sound samples (in CAF, M4A, or any other supported audio
+ * format) and a PLIST file that describes how the samples map to MIDI notes.
*
* The sound samples must always be mono. SoundBankPlayer pans the notes to
* achieve a stereo effect.
@@ -13,10 +13,10 @@
// Describes a sound sample and connects it to an OpenAL buffer.
typedef struct
{
- float pitch; // pitch of the note in the sound sample
- NSString *filename; // name of the sound sample file
- ALuint bufferId; // OpenAL buffer name
- void *data; // the buffer sample data
+ float pitch; // pitch of the note in the sound sample
+ CFStringRef filename; // name of the sound sample file
+ ALuint bufferId; // OpenAL buffer name
+ void *data; // the buffer sample data
}
Buffer;
@@ -80,15 +80,12 @@ - (void)dealloc
{
[self tearDownAudio];
[self tearDownAudioSession];
- [_soundBankName release];
- [super dealloc];
}
- (void)setSoundBank:(NSString *)newSoundBankName
{
if (![newSoundBankName isEqualToString:_soundBankName])
{
- [_soundBankName release];
_soundBankName = [newSoundBankName copy];
[self tearDownAudio];
@@ -144,20 +141,20 @@ - (void)loadSoundBank:(NSString *)filename
NSArray *array = [NSArray arrayWithContentsOfFile:path];
if (array == nil)
{
- NSLog(@"Could not load soundbank '%@'", path);
+ NSLog(@"Could not load sound bank '%@'", path);
return;
}
_sampleRate = [(NSString *)[array objectAtIndex:0] intValue];
- _numBuffers = (array.count - 1) / 3;
+ _numBuffers = ([array count] - 1) / 3;
if (_numBuffers > MAX_BUFFERS)
_numBuffers = MAX_BUFFERS;
int midiStart = 0;
for (int t = 0; t < _numBuffers; ++t)
{
- _buffers[t].filename = [array objectAtIndex:1 + t*3];
+ _buffers[t].filename = CFBridgingRetain([array objectAtIndex:1 + t*3]);
int midiEnd = [(NSString *)[array objectAtIndex:1 + t*3 + 1] intValue];
int rootKey = [(NSString *)[array objectAtIndex:1 + t*3 + 2] intValue];
_buffers[t].pitch = _notes[rootKey].pitch;
@@ -176,7 +173,7 @@ - (void)loadSoundBank:(NSString *)filename
static void interruptionListener(void *inClientData, UInt32 inInterruptionState)
{
- SoundBankPlayer *player = (SoundBankPlayer *)inClientData;
+ SoundBankPlayer *player = (__bridge SoundBankPlayer *)inClientData;
if (inInterruptionState == kAudioSessionBeginInterruption)
[player audioSessionBeginInterruption];
else if (inInterruptionState == kAudioSessionEndInterruption)
@@ -191,7 +188,7 @@ - (void)registerAudioSessionCategory
- (void)setUpAudioSession
{
- AudioSessionInitialize(NULL, NULL, interruptionListener, self);
+ AudioSessionInitialize(NULL, NULL, interruptionListener, (__bridge void *)self);
[self registerAudioSessionCategory];
AudioSessionSetActive(true);
}
@@ -255,35 +252,34 @@ - (void)initBuffers
if ((error = alGetError()) != AL_NO_ERROR)
{
NSLog(@"Error generating OpenAL buffer: %x", error);
- exit(1);
+ return;
}
- NSString *path = [[NSBundle mainBundle] pathForResource:_buffers[t].filename ofType:@"caf"];
- CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:path] retain];
- if (fileURL == NULL)
+ NSString *filename = (__bridge NSString *)_buffers[t].filename;
+ NSURL *url = [[NSBundle mainBundle] URLForResource:filename withExtension:nil];
+ if (url == nil)
{
- NSLog(@"Could not find file '%@'", path);
- exit(1);
+ NSLog(@"Could not find file '%@'", filename);
+ return;
}
ALenum format;
ALsizei size;
ALsizei freq;
- _buffers[t].data = GetOpenALAudioData(fileURL, &size, &format, &freq);
- CFRelease(fileURL);
+ _buffers[t].data = GetOpenALAudioData((__bridge CFURLRef)url, &size, &format, &freq);
if (_buffers[t].data == NULL)
{
NSLog(@"Error loading sound");
- exit(1);
+ return;
}
alBufferDataStaticProc(_buffers[t].bufferId, format, _buffers[t].data, size, freq);
if ((error = alGetError()) != AL_NO_ERROR)
{
NSLog(@"Error attaching audio to buffer: %x", error);
- exit(1);
+ return;
}
}
}
@@ -294,6 +290,7 @@ - (void)freeBuffers
{
alDeleteBuffers(1, &_buffers[t].bufferId);
free(_buffers[t].data);
+ CFRelease(_buffers[t].filename);
_buffers[t].bufferId = 0;
_buffers[t].data = NULL;
}
@@ -310,7 +307,7 @@ - (void)initSources
if ((error = alGetError()) != AL_NO_ERROR)
{
NSLog(@"Error generating OpenAL source: %x", error);
- exit(1);
+ return;
}
_sources[t].noteIndex = -1;
View
@@ -2,66 +2,66 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
-<string>32000</string>
-<string>P200 Piano D2</string>
-<string>26</string>
-<string>26</string>
-<string>P200 Piano F#2</string>
-<string>30</string>
-<string>30</string>
-<string>P200 Piano A#2</string>
-<string>34</string>
-<string>34</string>
-<string>P200 Piano D3</string>
-<string>38</string>
-<string>38</string>
-<string>P200 Piano F#3</string>
-<string>42</string>
-<string>42</string>
-<string>P200 Piano A#3</string>
-<string>46</string>
-<string>46</string>
-<string>P200 Piano D4</string>
-<string>50</string>
-<string>50</string>
-<string>P200 Piano F#4</string>
-<string>54</string>
-<string>54</string>
-<string>P200 Piano A#4</string>
-<string>58</string>
-<string>58</string>
-<string>P200 Piano D5</string>
-<string>62</string>
-<string>62</string>
-<string>P200 Piano F#5</string>
-<string>66</string>
-<string>66</string>
-<string>P200 Piano A#5</string>
-<string>70</string>
-<string>70</string>
-<string>P200 Piano D6</string>
-<string>74</string>
-<string>74</string>
-<string>P200 Piano F#6</string>
-<string>78</string>
-<string>78</string>
-<string>P200 Piano C7</string>
-<string>84</string>
-<string>84</string>
-<string>P200 Piano F#7</string>
-<string>90</string>
-<string>90</string>
-<string>P200 Piano A#7</string>
-<string>94</string>
-<string>94</string>
-<string>P200 Piano D#8</string>
-<string>99</string>
-<string>99</string>
-<string>P200 Piano G#9</string>
-<string>104</string>
-<string>104</string>
-<string>P200 Piano C10</string>
-<string>108</string>
-<string>108</string>
+ <string>32000</string>
+ <string>P200 Piano D2.caf</string>
+ <string>26</string>
+ <string>26</string>
+ <string>P200 Piano F#2.caf</string>
+ <string>30</string>
+ <string>30</string>
+ <string>P200 Piano A#2.caf</string>
+ <string>34</string>
+ <string>34</string>
+ <string>P200 Piano D3.caf</string>
+ <string>38</string>
+ <string>38</string>
+ <string>P200 Piano F#3.caf</string>
+ <string>42</string>
+ <string>42</string>
+ <string>P200 Piano A#3.caf</string>
+ <string>46</string>
+ <string>46</string>
+ <string>P200 Piano D4.caf</string>
+ <string>50</string>
+ <string>50</string>
+ <string>P200 Piano F#4.caf</string>
+ <string>54</string>
+ <string>54</string>
+ <string>P200 Piano A#4.caf</string>
+ <string>58</string>
+ <string>58</string>
+ <string>P200 Piano D5.caf</string>
+ <string>62</string>
+ <string>62</string>
+ <string>P200 Piano F#5.caf</string>
+ <string>66</string>
+ <string>66</string>
+ <string>P200 Piano A#5.caf</string>
+ <string>70</string>
+ <string>70</string>
+ <string>P200 Piano D6.caf</string>
+ <string>74</string>
+ <string>74</string>
+ <string>P200 Piano F#6.caf</string>
+ <string>78</string>
+ <string>78</string>
+ <string>P200 Piano C7.caf</string>
+ <string>84</string>
+ <string>84</string>
+ <string>P200 Piano F#7.caf</string>
+ <string>90</string>
+ <string>90</string>
+ <string>P200 Piano A#7.caf</string>
+ <string>94</string>
+ <string>94</string>
+ <string>P200 Piano D#8.caf</string>
+ <string>99</string>
+ <string>99</string>
+ <string>P200 Piano G#9.caf</string>
+ <string>104</string>
+ <string>104</string>
+ <string>P200 Piano C10.caf</string>
+ <string>108</string>
+ <string>108</string>
</array>
</plist>

0 comments on commit 5c42e18

Please sign in to comment.