2012-05-03 8 views
3

현재 iOS에서 오디오를 녹음하는 방법에 대해 궁금합니다. 많은 사람들이 이것을 마이크에서 녹음하고 다시 재생하는 것으로 이해합니다. 그러나 이것이 사실이 아닙니다. 나는 iPad 용 녹음 응용 프로그램을 만들고 있습니다. Apple이 iOS App Store에 가지고있는 GarageBand 응용 프로그램에서 자신의 소리를 녹음하고 응용 프로그램 내에서 재생할 수 있습니다. 이것이 의미가 없으면 다음과 같이 생각하십시오.iOS에서 소리를 녹음하는 방법은 무엇입니까?

소리를 재생하는 버튼을 만드는 것입니다. 그 버튼 사운드를 녹음하고 사운드 시퀀스를 다시 재생할 수 있어야합니다. 그래서 "녹음"을 누른 다음 "A, F, J"버튼을 누른 다음 "정지"를 누른 다음 "재생"을 누르면 녹음 된 내용이 재생됩니다 (A F 및 J 소리).

나는이 앱 내에서 자신의 음악을 녹음하고 만들 수 있도록 노력 중입니다. 죄송합니다. 혼란 스럽다면 최선을 다해 도와주세요. 감사!

+0

연구를 수행 한 적이 있습니까? –

+0

http://stackoverflow.com/questions/4215180/record-and-play-audio-simultaneously의 가능한 복제본 | Apple의 aurioTouch 샘플 애플리케이션에서 예제 코드를 확인하십시오. –

답변

1

레코드를 기록 할 때 두 개의 NSMutableArrays를 만들고 비울 수 있습니다. 또한 NSTimer와 int가 필요합니다. 그래서 머리글에 :

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

헤더에 공백과 IBActions 등을 모두 포함하십시오.

사운드 버튼의 고유 한 태그가 다르게 설정하십시오.

다음 주 파일에

: (이 코드는 완벽 의심) 하구의 조금으로

-(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. 
    } 

} 

, 당신은이 작업을 얻을 수 있습니다. 당신이 아마 당신이 그 중 하나를 치면 재생/녹음 버튼이 비활성화되기를 원할 것입니다. 행운을 빕니다!

관련 문제