Tweaks for a newbie?

28 views
Skip to first unread message

Ian James

unread,
Apr 24, 2015, 2:07:57 PM4/24/15
to objectal-...@googlegroups.com
Hi and thanks for this awesome work! I'm super new to programming and actually got ObjectAL up and running and is really cool!
Working on a drum kit soundboard.
Here is the code below I am using to play the sounds.I plan on sounds being mono for best performance unless i'm thinking wrong?
Do i need to add any special parameters to this code or change anything in the OALSimpleAudio.m file?
I've read some posts but not clear on what to set for lowest latency and such? 
Thanks so much!


#import "BTM_soundView.h"

#import <AudioToolbox/AudioToolbox.h>

#import <AVFoundation/AVFoundation.h>

#import "pandrum_appDelegate.h"

#import "ObjectAL.h"



@implementation BTM_soundView

- (id) init

{

    if(nil != (self = [super init]))

    {

        // We don't want ipod music to keep playing since

        // we have our own bg music.

        [OALSimpleAudio sharedInstance].allowIpod = NO;

        

        // Mute all audio if the silent switch is turned on.

        [OALSimpleAudio sharedInstance].honorSilentSwitch = YES;

        

        // This loads the sound effects into memory so that

        // there's no delay when we tell it to play them.

        [[OALSimpleAudio sharedInstance] preloadEffect:@"ding.caf"];

        [[OALSimpleAudio sharedInstance] preloadEffect:@"templebell.caf"];

        [[OALSimpleAudio sharedInstance] preloadEffect:@"snare.wav"];

         [[OALSimpleAudio sharedInstance] preloadEffect:@"snare.caf"];

    }

    return self;

}






@synthesize viewController = _viewController;




- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.

}


#pragma mark - View lifecycle




- (void)viewDidLoad

{

    [super viewDidLoad];


 

    

    

}


/*

// made .caf file in Terminal for each sound

afconvert -f caff -d LEI16 templebell.wav templebell.caf

*/


// must be wav or caff signed 16-bit little endian


- (IBAction)SSound1{


    

  [[OALSimpleAudio sharedInstance] playEffect:@"snare.wav"];

    

  

 

}

- (IBAction)SSound2{

 

    [[OALSimpleAudio sharedInstance] playEffect:@"templebell.caf"];

}



- (IBAction)SSound3{

   

    

    [[OALSimpleAudio sharedInstance] playEffect:@"ding.caf"];

    

}


- (IBAction)SSound4{

    

    

    [[OALSimpleAudio sharedInstance] playEffect:@"snare.caf"];

    

}




@end


Karl Stenerud

unread,
Apr 24, 2015, 2:49:55 PM4/24/15
to objectal-...@googlegroups.com

Hi Ian,

What you have now will work fine. You're preloading the effects, so they'll play without any delay. Note that you don't necessarily have to convert your sounds to LEI16. That's the internal format used by OpenAL, but ObjectAL will auto convert any sound format supported by iOS. You won't incur any speed penalties when playing them.

--
You received this message because you are subscribed to the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-ip...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ian James Ritter

unread,
Apr 24, 2015, 3:02:34 PM4/24/15
to objectal-...@googlegroups.com
Hi Karl thanks so much for the reply!
So even MP3 will be fine? No latency when playing drum samples?
I'm guessing the         [[OALSimpleAudiosharedInstance] preloadEffect:@"ding.caf"]; 
should go in the ViewDidLoad?
Thank u!!

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/objectal-for-iphone/cKuq7EsDlZA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to objectal-for-ip...@googlegroups.com.

Karl Stenerud

unread,
Apr 24, 2015, 3:16:12 PM4/24/15
to objectal-...@googlegroups.com

Yes, even mp3 is fine. The only limitation of mp3 is that looping doesn't always sound nice (this is a problem with the format itself). Aac doesn't have this problem.

You can preload anywhere you want, just so long as it happens before you start playing the sounds.

Ian James Ritter

unread,
Apr 24, 2015, 3:19:47 PM4/24/15
to objectal-...@googlegroups.com
Thanks a ton!
Ian

Sent from my iPhone

Ian James Ritter

unread,
Apr 24, 2015, 3:23:19 PM4/24/15
to objectal-...@googlegroups.com
Quick question.
MP3 being triggered by a button a bunch of times like a snare drum hit would be considered looping?
Thanks again. That should do it!
I

Sent from my iPhone

Karl Stenerud

unread,
Apr 24, 2015, 4:05:21 PM4/24/15
to objectal-...@googlegroups.com
No, the looping issue would only happen if you tell OpenAL to loop it (automatic looping).
With MP3 files, there can sometimes end up being a gap while it tries to loop because of how the mp3 format works.

Ian James

unread,
Apr 29, 2015, 9:57:39 AM4/29/15
to objectal-...@googlegroups.com
Thanks so much! I have the files playing nicely the response time is great. From the code i  posted how would i stop the sound so i don't get a build up of the sound repeating when tapping the same button over and over?
Also, is there paypal to contribute here?
Thanks!!
Ian

Karl Stenerud

unread,
Apr 29, 2015, 5:37:18 PM4/29/15
to objectal-...@googlegroups.com
Umm… I don’t have any contribution thing. I have paypal attached to my email address (kstenerud at gmail). Not sure if that works?

If you want to be able to stop sounds or limit the number of repeated concurrent sounds, you’ll need to move away from OALSimpleAudio and move into channels (ALChannelSource).

There are examples in the demo app, but basically you want to limit the number of sources OALSimpleAudio takes (there are 32 total), and then create channels with the max number of simultaneous sounds they should support (reserved sources).

- (void) initAudio
{
    [OALSimpleAudio sharedInstance].reservedSources = 10; // Leave 10 sources in OALSimpleAudio so that we can use it for trivial sounds.
    self.snareDrumChannel = [[ALChannelSource alloc] initWithSources:4]; // Allow 4 simultaneous sounds (sources) for snare drum.
    self.snareSound = [[OALSimpleAudio sharedInstance] preloadEffect:@"snare.aac"]; // Load the sound effect and keep a reference.
}

- (void) onPlaySnare
{
    [self.snareDrumChannel play:self.snareSound];
}


Ian James Ritter

unread,
Apr 30, 2015, 7:22:54 AM4/30/15
to objectal-...@googlegroups.com
Cool thanks! I will check the code out soon. excited to make this work!.
I sent a paypal “donation” for your time and talent. It’s not a ton but maybe can at least get u some coding coffee and snacks:)
Thanks
Ian
You received this message because you are subscribed to a topic in the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/objectal-for-iphone/cKuq7EsDlZA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to objectal-for-ip...@googlegroups.com.

Ian James Ritter

unread,
Apr 30, 2015, 7:23:01 AM4/30/15
to objectal-...@googlegroups.com
Cool thanks!
I sen a paypal “contribution” for your time and talents. Hopefully it can at least get u some coding coffee and snacks:)
Excited to see if I can get your example working.
Thanks!
Ian
On Apr 29, 2015, at 5:37 PM, Karl Stenerud <kste...@gmail.com> wrote:

You received this message because you are subscribed to a topic in the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/objectal-for-iphone/cKuq7EsDlZA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to objectal-for-ip...@googlegroups.com.

Karl Stenerud

unread,
Apr 30, 2015, 9:33:47 AM4/30/15
to objectal-...@googlegroups.com
Cool, thanks! I shall use it on “relaxation” (aka beer!)

Ian James

unread,
May 14, 2015, 3:07:20 PM5/14/15
to objectal-...@googlegroups.com
Hi Karl!
Finally got back to working on this. I think I'm doing the channels right? I'm super new to programming so not sure how bad my approach is.
There will be 9 buttons total each with 3 samples. Again thanks for your time! 

- (IBAction)D1{

    

    int randomSoundNumber = arc4random() % 3; //random number from 0 to 2

    

    NSLog(@"random sound number = %i", randomSoundNumber);

    

    NSString *effectTitle;

    

    switch (randomSoundNumber) {

        case 0:

            effectTitle = @"D1a";

            break;

        case 1:

            effectTitle = @"D1b";

            break;

        case 2:

            effectTitle = @"D1c";

            break;

            

        default:

            NSLog (@"Integer out of range");

            break;

    }

    NSString *soundPath = [[NSBundle mainBundle] pathForResource:effectTitle ofType:@"wav"];

    

    [OALSimpleAudio sharedInstance].reservedSources = 0; // Leave  sources in OALSimpleAudio so that we can use it for trivial sounds.

    D1 = [[ALChannelSource alloc]initWithSources:3]; // Allow  simultaneous sounds (sources) for  drum.

    D1a = [[OpenALManager sharedInstance] bufferFromFile:soundPath]; // Load the sound effect and keep a reference.

   

    

    [D1 play:D1a loop:NO];

  

 

}


- (IBAction)A2 {


    

    int randomSoundNumber = arc4random() % 3; //random number from 0 to 2

    

    NSLog(@"random sound number = %i", randomSoundNumber);

    

    NSString *effectTitle;

    

    switch (randomSoundNumber) {

        case 0:

            effectTitle = @"A2a";

            break;

        case 1:

            effectTitle = @"A2b";

            break;

        case 2:

            effectTitle = @"A2c";

            break;

            

        default:

            NSLog (@"Integer out of range");

            break;

    }

    NSString *soundPath = [[NSBundle mainBundle] pathForResource:effectTitle ofType:@"wav"];

    

    [OALSimpleAudio sharedInstance].reservedSources = 0; // Leave sources in OALSimpleAudio so that we can use it for trivial sounds.

    A2 = [[ALChannelSource alloc]initWithSources:3]; // Allow  simultaneous sounds (sources) for  drum.

    A2a = [[OpenALManager sharedInstance] bufferFromFile:soundPath]; // Load the sound effect and keep a reference.

    

    

    [A2 play:A2a loop:NO];

Ian
To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-iphone+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to a topic in the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/objectal-for-iphone/cKuq7EsDlZA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to objectal-for-iphone+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "ObjectAL-for-iPhone" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-iphone+unsub...@googlegroups.com.

Karl Stenerud

unread,
May 14, 2015, 3:18:38 PM5/14/15
to objectal-...@googlegroups.com
Hi Ian,

You should leave at least some sources for OALSimpleAudio (like maybe 5 or so?). I imagine you’ll eventually want button sounds and other UI sound effects, which will be run off OALSimpleAudio, and if you give it 0 sources it won’t be able to play them.

Also, you should create your channels and buffers at app initialization time and save them as properties rather than re-creating them on every touch.


To unsubscribe from this group and stop receiving emails from it, send an email to objectal-for-ip...@googlegroups.com.

Ian James Ritter

unread,
May 14, 2015, 3:51:02 PM5/14/15
to objectal-...@googlegroups.com, Karl Stenerud
Thanks Karl,
I’m trying to go off the ChannelsDemo.m file. 
Would this still be re-creating the channels on every touch? Love to buy you a beer again:)
-(void)playD1{

    

   

        

        int randomSoundNumber = arc4random() % 3; //random number from 0 to 2

        

        NSLog(@"random sound number = %i", randomSoundNumber);

        

        NSString *effectTitle;

        

        switch (randomSoundNumber) {
            case 0:
                effectTitle = @"D1a";
                break;
            case 1:
                effectTitle = @"D1b";
                break;
            case 2:
                effectTitle = @"D1c";
                break;

                

            default:
                NSLog (@"Integer out of range");
                break;
        }
        NSString *soundPath = [[NSBundle mainBundle] pathForResource:effectTitle ofType:@"wav"];

        

        [OALSimpleAudio sharedInstance].reservedSources = 4; // Leave  sources in OALSimpleAudio so that we can use it for trivial sounds.
        D1 = [[ALChannelSource alloc]initWithSources:3]; // Allow  simultaneous sounds (sources) for  drum.
        D1a = [[OpenALManager sharedInstance] bufferFromFile:soundPath]; // Load the sound effect and keep a reference.
        [D1 play:D1a loop:NO];

    

    }


- (IBAction)D1{

    

    [self playD1];

}
To unsubscribe from this group and all its topics, send an email to objectal-for-ip...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages