Permalink
Browse files

Initial commit

  • Loading branch information...
hollance committed Aug 14, 2010
0 parents commit 4721f8e5140bc76cdc04732e7afe20da2d4392c4
Showing with 10,179 additions and 0 deletions.
  1. +13 −0 Classes/DemoAppDelegate.h
  2. +24 −0 Classes/DemoAppDelegate.m
  3. +21 −0 Classes/DemoViewController.h
  4. +135 −0 Classes/DemoViewController.m
  5. +159 −0 Classes/OpenALSupport.c
  6. +58 −0 Classes/OpenALSupport.h
  7. +120 −0 Classes/SoundBankPlayer.h
  8. +386 −0 Classes/SoundBankPlayer.m
  9. +30 −0 Demo-Info.plist
  10. +1,394 −0 Demo.xcodeproj/matthijs.mode1v3
  11. +189 −0 Demo.xcodeproj/matthijs.pbxuser
  12. +369 −0 Demo.xcodeproj/project.pbxproj
  13. +547 −0 DemoViewController.xib
  14. +4 −0 Demo_Prefix.pch
  15. +136 −0 Docs/html/_sound_bank_player_8h.html
  16. +127 −0 Docs/html/_sound_bank_player_8h_source.html
  17. +78 −0 Docs/html/annotated.html
  18. BIN Docs/html/bc_s.png
  19. +84 −0 Docs/html/class_sound_bank_player-members.html
  20. +78 −0 Docs/html/classes.html
  21. BIN Docs/html/closed.png
  22. +656 −0 Docs/html/doxygen.css
  23. BIN Docs/html/doxygen.png
  24. +74 −0 Docs/html/files.html
  25. +135 −0 Docs/html/functions.html
  26. +86 −0 Docs/html/functions_func.html
  27. +126 −0 Docs/html/functions_vars.html
  28. +84 −0 Docs/html/globals.html
  29. +84 −0 Docs/html/globals_defs.html
  30. +65 −0 Docs/html/index.html
  31. +117 −0 Docs/html/installdox
  32. +201 −0 Docs/html/interface_sound_bank_player.html
  33. BIN Docs/html/nav_f.png
  34. BIN Docs/html/nav_h.png
  35. BIN Docs/html/open.png
  36. +26 −0 Docs/html/search/all_61.html
  37. +43 −0 Docs/html/search/all_62.html
  38. +26 −0 Docs/html/search/all_63.html
  39. +32 −0 Docs/html/search/all_64.html
  40. +26 −0 Docs/html/search/all_66.html
  41. +26 −0 Docs/html/search/all_69.html
  42. +26 −0 Docs/html/search/all_6d.html
  43. +61 −0 Docs/html/search/all_6e.html
  44. +35 −0 Docs/html/search/all_70.html
  45. +59 −0 Docs/html/search/all_73.html
  46. +25 −0 Docs/html/search/classes_62.html
  47. +25 −0 Docs/html/search/classes_6e.html
  48. +30 −0 Docs/html/search/classes_73.html
  49. BIN Docs/html/search/close.png
  50. +26 −0 Docs/html/search/defines_6d.html
  51. +32 −0 Docs/html/search/defines_6e.html
  52. +25 −0 Docs/html/search/files_73.html
  53. +26 −0 Docs/html/search/functions_61.html
  54. +26 −0 Docs/html/search/functions_6e.html
  55. +26 −0 Docs/html/search/functions_73.html
  56. BIN Docs/html/search/mag_sel.png
  57. +12 −0 Docs/html/search/nomatches.html
  58. +240 −0 Docs/html/search/search.css
  59. +736 −0 Docs/html/search/search.js
  60. BIN Docs/html/search/search_l.png
  61. BIN Docs/html/search/search_m.png
  62. BIN Docs/html/search/search_r.png
  63. +38 −0 Docs/html/search/variables_62.html
  64. +26 −0 Docs/html/search/variables_63.html
  65. +32 −0 Docs/html/search/variables_64.html
  66. +26 −0 Docs/html/search/variables_66.html
  67. +26 −0 Docs/html/search/variables_69.html
  68. +38 −0 Docs/html/search/variables_6e.html
  69. +35 −0 Docs/html/search/variables_70.html
  70. +38 −0 Docs/html/search/variables_73.html
  71. +77 −0 Docs/html/struct_buffer-members.html
  72. +99 −0 Docs/html/struct_buffer.html
  73. +76 −0 Docs/html/struct_note-members.html
  74. +96 −0 Docs/html/struct_note.html
  75. +75 −0 Docs/html/struct_source-members.html
  76. +93 −0 Docs/html/struct_source.html
  77. BIN Docs/html/tab_a.png
  78. BIN Docs/html/tab_b.png
  79. BIN Docs/html/tab_h.png
  80. BIN Docs/html/tab_s.png
  81. +59 −0 Docs/html/tabs.css
  82. +1,630 −0 Doxyfile
  83. +19 −0 LICENSE.txt
  84. +444 −0 MainWindow.xib
  85. +8 −0 README.txt
  86. BIN Sounds/P200 Piano A#2.caf
  87. BIN Sounds/P200 Piano A#3.caf
  88. BIN Sounds/P200 Piano A#4.caf
  89. BIN Sounds/P200 Piano A#5.caf
  90. BIN Sounds/P200 Piano A#7.caf
  91. BIN Sounds/P200 Piano C10.caf
  92. BIN Sounds/P200 Piano C7.caf
  93. BIN Sounds/P200 Piano D#8.caf
  94. BIN Sounds/P200 Piano D2.caf
  95. BIN Sounds/P200 Piano D3.caf
  96. BIN Sounds/P200 Piano D4.caf
  97. BIN Sounds/P200 Piano D5.caf
  98. BIN Sounds/P200 Piano D6.caf
  99. BIN Sounds/P200 Piano F#2.caf
  100. BIN Sounds/P200 Piano F#3.caf
  101. BIN Sounds/P200 Piano F#4.caf
  102. BIN Sounds/P200 Piano F#5.caf
  103. BIN Sounds/P200 Piano F#6.caf
  104. BIN Sounds/P200 Piano F#7.caf
  105. BIN Sounds/P200 Piano G#9.caf
  106. +67 −0 Sounds/Piano.plist
  107. +8 −0 main.m
@@ -0,0 +1,13 @@
+
+@class DemoViewController;
+
+@interface DemoAppDelegate : NSObject <UIApplicationDelegate>
+{
+ UIWindow* window;
+ DemoViewController* viewController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow* window;
+@property (nonatomic, retain) IBOutlet DemoViewController* viewController;
+
+@end
@@ -0,0 +1,24 @@
+
+#import "DemoAppDelegate.h"
+#import "DemoViewController.h"
+
+@implementation DemoAppDelegate
+
+@synthesize window;
+@synthesize viewController;
+
+- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
+{
+ [window addSubview:viewController.view];
+ [window makeKeyAndVisible];
+ return YES;
+}
+
+- (void)dealloc
+{
+ [viewController release];
+ [window release];
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,21 @@
+
+#import "SoundBankPlayer.h"
+
+@interface DemoViewController : UIViewController
+{
+ SoundBankPlayer* player;
+ NSTimer* timer;
+ BOOL playingArpeggio;
+ NSArray* arpeggioNotes;
+ int arpeggioIndex;
+ double arpeggioStartTime;
+ double arpeggioDelay;
+}
+
+- (IBAction)strumCMajorChord;
+- (IBAction)arpeggiateCMajorChord;
+
+- (IBAction)strumAMinorChord;
+- (IBAction)arpeggiateAMinorChord;
+
+@end
@@ -0,0 +1,135 @@
+
+// The sounds in this demo project were taken from Fluid R3 by Frank Wen,
+// a freely distributable SoundFont.
+
+#import <QuartzCore/CABase.h>
+#import "DemoViewController.h"
+
+@interface DemoViewController (Private)
+- (void)playArpeggioWithNotes:(NSArray*)notes delay:(double)delay;
+- (void)startTimer;
+- (void)stopTimer;
+@end
+
+@implementation DemoViewController
+
+- (id)initWithCoder:(NSCoder*)decoder
+{
+ if ((self = [super initWithCoder:decoder]))
+ {
+ playingArpeggio = NO;
+
+ // Create the player and tell it which sound bank to use.
+ player = [[SoundBankPlayer alloc] init];
+ [player setSoundBank:@"Piano"];
+
+ // We use a timer to play arpeggios.
+ [self startTimer];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [self stopTimer];
+ [player release];
+
+ [super dealloc];
+}
+
+- (IBAction)strumCMajorChord
+{
+ [player noteOn:48 gain:0.4f];
+ [player noteOn:55 gain:0.4f];
+ [player noteOn:64 gain:0.4f];
+}
+
+- (IBAction)arpeggiateCMajorChord
+{
+ NSArray* notes = [NSArray arrayWithObjects:
+ [NSNumber numberWithInt:48],
+ [NSNumber numberWithInt:55],
+ [NSNumber numberWithInt:64],
+ nil];
+
+ [self playArpeggioWithNotes:notes delay:0.05];
+}
+
+- (IBAction)strumAMinorChord
+{
+ [player noteOn:45 gain:0.4f];
+ [player noteOn:52 gain:0.4f];
+ [player noteOn:60 gain:0.4f];
+ [player noteOn:67 gain:0.4f];
+}
+
+- (IBAction)arpeggiateAMinorChord
+{
+ NSArray* notes = [NSArray arrayWithObjects:
+ [NSNumber numberWithInt:33],
+ [NSNumber numberWithInt:45],
+ [NSNumber numberWithInt:52],
+ [NSNumber numberWithInt:60],
+ [NSNumber numberWithInt:67],
+ nil];
+
+ [self playArpeggioWithNotes:notes delay:0.1];
+}
+
+- (void)playArpeggioWithNotes:(NSArray*)notes delay:(double)delay
+{
+ if (!playingArpeggio)
+ {
+ playingArpeggio = YES;
+ arpeggioNotes = [notes retain];
+ arpeggioIndex = 0;
+ arpeggioDelay = delay;
+ arpeggioStartTime = CACurrentMediaTime();
+ }
+}
+
+- (void)startTimer
+{
+ timer = [NSTimer scheduledTimerWithTimeInterval: 0.05 // 50 ms
+ target: self
+ selector: @selector(handleTimer:)
+ userInfo: nil
+ repeats: YES];
+}
+
+- (void)stopTimer
+{
+ if (timer != nil && [timer isValid])
+ {
+ [timer invalidate];
+ timer = nil;
+ }
+}
+
+- (void)handleTimer:(NSTimer*)timer
+{
+ if (playingArpeggio)
+ {
+ // Play each note of the arpeggio after "arpeggioDelay" seconds.
+ double now = CACurrentMediaTime();
+ if (now - arpeggioStartTime >= arpeggioDelay)
+ {
+ NSNumber* number = (NSNumber*)[arpeggioNotes objectAtIndex:arpeggioIndex];
+ [player noteOn:[number intValue] gain:0.4f];
+
+ ++arpeggioIndex;
+ if (arpeggioIndex == [arpeggioNotes count])
+ {
+ playingArpeggio = NO;
+ [arpeggioNotes release];
+ arpeggioNotes = nil;
+ }
+ else // schedule next note
+ {
+ arpeggioStartTime = now;
+ }
+ }
+ }
+}
+
+@end
@@ -0,0 +1,159 @@
+/*
+
+(Modified from Apple's oalTouch sample code.)
+
+Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
+Inc. ("Apple") in consideration of your agreement to the following
+terms, and your use, installation, modification or redistribution of
+this Apple software constitutes acceptance of these terms. If you do
+not agree with these terms, please do not use, install, modify or
+redistribute this Apple software.
+
+In consideration of your agreement to abide by the following terms, and
+subject to these terms, Apple grants you a personal, non-exclusive
+license, under Apple's copyrights in this original Apple software (the
+"Apple Software"), to use, reproduce, modify and redistribute the Apple
+Software, with or without modifications, in source and/or binary forms;
+provided that if you redistribute the Apple Software in its entirety and
+without modifications, you must retain this notice and the following
+text and disclaimers in all such redistributions of the Apple Software.
+Neither the name, trademarks, service marks or logos of Apple Inc. may
+be used to endorse or promote products derived from the Apple Software
+without specific prior written permission from Apple. Except as
+expressly stated in this notice, no other rights or licenses, express or
+implied, are granted by Apple herein, including but not limited to any
+patent rights that may be infringed by your derivative works or by other
+works in which the Apple Software may be incorporated.
+
+The Apple Software is provided by Apple on an "AS IS" basis. APPLE
+MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+Copyright (C) 2010 Apple Inc. All Rights Reserved.
+
+*/
+
+#include "OpenALSupport.h"
+
+ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq)
+{
+ static alBufferDataStaticProcPtr proc = NULL;
+
+ if (proc == NULL)
+ proc = (alBufferDataStaticProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alBufferDataStatic");
+
+ if (proc != NULL)
+ proc(bid, format, data, size, freq);
+}
+
+ALvoid alcMacOSXMixerOutputRateProc(const ALdouble value)
+{
+ static alcMacOSXMixerOutputRateProcPtr proc = NULL;
+
+ if (proc == NULL)
+ proc = (alcMacOSXMixerOutputRateProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alcMacOSXMixerOutputRate");
+
+ if (proc != NULL)
+ proc(value);
+}
+
+void* GetOpenALAudioData(CFURLRef inFileURL, ALsizei* outDataSize, ALenum* outDataFormat, ALsizei* outSampleRate)
+{
+ OSStatus err = noErr;
+ void* theData = NULL;
+
+ ExtAudioFileRef extRef = NULL;
+ err = ExtAudioFileOpenURL(inFileURL, &extRef);
+ if (err != noErr)
+ {
+ printf("GetOpenALAudioData: ExtAudioFileOpenURL FAILED, Error = %ld\n", err);
+ goto Exit;
+ }
+
+ AudioStreamBasicDescription theFileFormat;
+ UInt32 thePropertySize = sizeof(theFileFormat);
+ err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_FileDataFormat, &thePropertySize, &theFileFormat);
+ if (err != noErr)
+ {
+ printf("GetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_FileDataFormat) FAILED, Error = %ld\n", err);
+ goto Exit;
+ }
+
+ if (theFileFormat.mChannelsPerFrame > 2)
+ {
+ printf("GetOpenALAudioData: Unsupported format, channel count is greater than stereo\n");
+ goto Exit;
+ }
+
+ // Set the output format to 16 bit signed integer (native-endian) data
+ // Maintain the channel count and sample rate of the original source format
+ AudioStreamBasicDescription theOutputFormat;
+ theOutputFormat.mSampleRate = theFileFormat.mSampleRate;
+ theOutputFormat.mChannelsPerFrame = theFileFormat.mChannelsPerFrame;
+ theOutputFormat.mFormatID = kAudioFormatLinearPCM;
+ theOutputFormat.mBytesPerPacket = 2 * theOutputFormat.mChannelsPerFrame;
+ theOutputFormat.mFramesPerPacket = 1;
+ theOutputFormat.mBytesPerFrame = 2 * theOutputFormat.mChannelsPerFrame;
+ theOutputFormat.mBitsPerChannel = 16;
+ theOutputFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
+
+ err = ExtAudioFileSetProperty(extRef, kExtAudioFileProperty_ClientDataFormat, sizeof(theOutputFormat), &theOutputFormat);
+ if (err != noErr)
+ {
+ printf("GetOpenALAudioData: ExtAudioFileSetProperty(kExtAudioFileProperty_ClientDataFormat) FAILED, Error = %ld\n", err);
+ goto Exit;
+ }
+
+ SInt64 theFileLengthInFrames = 0;
+ thePropertySize = sizeof(theFileLengthInFrames);
+ err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_FileLengthFrames, &thePropertySize, &theFileLengthInFrames);
+ if (err != noErr)
+ {
+ printf("GetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_FileLengthFrames) FAILED, Error = %ld\n", err);
+ goto Exit;
+ }
+
+ UInt32 dataSize = theFileLengthInFrames * theOutputFormat.mBytesPerFrame;
+ theData = malloc(dataSize);
+ if (theData == NULL)
+ {
+ printf("GetOpenALAudioData: malloc FAILED\n");
+ goto Exit;
+ }
+
+ AudioBufferList theDataBuffer;
+ theDataBuffer.mNumberBuffers = 1;
+ theDataBuffer.mBuffers[0].mDataByteSize = dataSize;
+ theDataBuffer.mBuffers[0].mNumberChannels = theOutputFormat.mChannelsPerFrame;
+ theDataBuffer.mBuffers[0].mData = theData;
+
+ err = ExtAudioFileRead(extRef, (UInt32*)&theFileLengthInFrames, &theDataBuffer);
+ if (err != noErr)
+ {
+ free(theData);
+ theData = NULL; // make sure to return NULL
+ printf("GetOpenALAudioData: ExtAudioFileRead FAILED, Error = %ld\n", err);
+ goto Exit;
+ }
+
+ *outDataSize = (ALsizei)dataSize;
+ *outDataFormat = (theOutputFormat.mChannelsPerFrame > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
+ *outSampleRate = (ALsizei)theOutputFormat.mSampleRate;
+
+Exit:
+ if (extRef != NULL)
+ ExtAudioFileDispose(extRef);
+
+ return theData;
+}
Oops, something went wrong.

0 comments on commit 4721f8e

Please sign in to comment.