How to record sound in iOS?

I'm currently wondering how you can record audio in iOS. I know that many understand this as recording from a microphone and playing it, but it is not. I am making an audio recording application for iPad. In the GarageBand app that Apple has in the iOS app store, you can record your own sounds and play them from the app. If this does not make sense, think of it as:

All I'm trying to do is make a button that plays a sound. I need to know how to record the sound of this button and be able to play a sound sequence. Therefore, if I pressed “record,” then the “A, F, J” buttons and then “stop”, then press “play” to play back the recorded (AF and J sounds).

I am trying to make it so that you can record and create your own music in this application. Sorry if this is confusing, please help me to the best of my ability. Thank you

+3
source share
1 answer

You can create two NSMutableArrays and delete them when you click the entry. You will also need NSTimer and int. So in the title:

NSTimer *recordTimer;
NSTimer *playTimer;
int incrementation;
NSMutableArray *timeHit;
NSMutableArray *noteHit;

Include in your heading all voids and IBActions and such below.

Your sound buttons have all different unique tags.

and then in the main file:

-(void)viewDidLoad {

    timeHit = [[NSMutableArray alloc] init];
    noteHit = [[NSMutableArray alloc] init];

}

-(IBAction)record {

    recordTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(timerSelector) userInfo:nil repeats:YES];
    [timeHit removeAllObjects];
    [noteHit removeAllObjects];
    incrementation = 0;
}

-(void)timerSelector {

    incrementation += 1;

}

-(IBAction)hitSoundButton:(id)sender {

    int note = [sender tag];
    int time = incrementation;

    [timeHit addObject:[NSNumber numberWithInt:time]];
    [noteHit addObject:[NSNumber numberWithInt:note]];
    [self playNote:note];
}

-(IBAction)stop {

    if ([recordTimer isRunning]) {

        [recordTimer invalidate];
    } else if ([playTimer isRunning]) {

        [playTimer invalidate];
    }

}

-(IBAction)playSounds {

    playTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(playback) userInfo:nil repeats:YES];

    incrementation = 0;



}


-(void)playback {

    incrementation += 1;

    if ([timeHit containsObject:[NSNumber numberWithInt:incrementation]]) {

        int index = [timeHit indexOfObject:[NSNumber numberWithInt:incrementation]];

        int note = [[noteHit objectAtIndex:index] intValue];

        [self playNote:note];
    }
}


-(void)playNote:(int)note {


    //These notes would correspond to the tags of the buttons they are played by.

    if (note == 1) {
        //Play your first note
    } else if (note == 2) {
        //Play second note
    } else if (note == 3) {
       //And so on
    } else if (note == 4) {
            //etc.
    }

}

With a bit of messing around (I doubt this code is perfect), you can make it work. As you probably want the play / record buttons to be disabled after clicking on one of them. Good luck

+1
source

All Articles