Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting/starting/adjusting looping segments of C4Sample

Tags:

ios

c4

I'd like to be able to loop certain sections of a sample using c4. I'd also like to skip between loops without waiting for the current loop to end. So for example if I have the last bar looping and I'm halfway through and I want to skip to the first bar, it would do so without waiting for the last bar to end.

I was using "currentTime" and "touchesBegan" to try to set it up but I can't get it to work like I want it. I was reading around on stack overflow about it and it looks like I'm supposed to NSTimer? or some sort of callback or something? How can I do this?

Here's what I've got:

@implementation C4WorkSpace {
        C4Sample *audioSample;
    }

    -(void)setup {
        audioSample = [C4Sample sampleNamed:@"C4Loop.aif"];
        [audioSample play];
    }

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        audioSample.currentTime = 1.0f;
       //NSTimer? wait some time and then ?
       //callback? I don't know how to do that, but is that what I would do here?
    }
@end
like image 427
Greg Debicki Avatar asked Nov 13 '22 06:11

Greg Debicki


1 Answers

The C4Sample class doesn't have any ability to loop right now. If you want to do this you'll have to construct the looping mechanism yourself. Off the top of my your first question about using an NSTimer would be pretty straightforward.

You could:

  1. set a loop start time
  2. set a loop duration time
  3. trigger the loop to start playing and start the timer

... then the timer triggers a method that sets audioSample.currentTime = loopStartTimer; similar to how you're doing this in the touchesBegan: method.

like image 53
C4 - Travis Avatar answered Jan 05 '23 07:01

C4 - Travis