2012-07-19 2 views
1

메신저 OpenAL 프레임 워크에 어려움을 겪고 있습니다 ... 단지 재생 동작의 피치를 변경하고 싶습니다 ... 내 프로젝트에서 어떤 코드가 누락 되었습니까? im 객관적인 c, iOS 개발. , 당신의 친절한 배려에 미리 감사를 기대하는 것은 ... 여기에 세 개의 버튼에 대한 내 코드 (녹화, 정지, 재생) ..목표 C : OpenAL 변경 피치 문제

-(void)startRecording:(UIButton *)sender 
{ //for recording 

    recStopBtn.hidden = NO; 
    recStopBtn.enabled =YES; 
    playRecBtn.enabled = NO; 
    loading.hidden = NO; 
    [loading startAnimating]; 

    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
    NSError *err = nil; 
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err]; 
    if(err) 
    { 
     NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]); 
     return; 
    } 
    [audioSession setActive:YES error:&err]; 
    err = nil; 
    if(err) 
    { 
     NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]); 
     return; 
    } 

    recordSetting = [[NSMutableDictionary alloc] init]; 

    // We can use kAudioFormatAppleIMA4 (4:1 compression) or kAudioFormatLinearPCM for nocompression 
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey]; 

    // We can use 44100, 32000, 24000, 16000 or 12000 depending on sound quality 
    [recordSetting setValue:[NSNumber numberWithFloat:16000.0] forKey:AVSampleRateKey]; 

    // We can use 2(if using additional h/w) or 1 (iPhone only has one microphone) 
    [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey]; 

    // These settings are used if we are using kAudioFormatLinearPCM format 
    //[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey]; 
    //[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey]; 
    //[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey]; 

    recorderFilePath = [NSString stringWithFormat:@"%@/MySound.caf", DOCUMENTS_FOLDER]; 



    NSLog(@"recorderFilePath: %@",recorderFilePath); 

    NSURL *url = [NSURL fileURLWithPath:recorderFilePath]; 

    err = nil; 

    NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err]; 
    if(audioData) 
    { 
     NSFileManager *fm = [NSFileManager defaultManager]; 
     [fm removeItemAtPath:[url path] error:&err]; 
    } 

    err = nil; 
    recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err]; 
    if(!recorder){ 
     NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]); 
     UIAlertView *alert = 
     [[UIAlertView alloc] initWithTitle: @"Warning" 
            message: [err localizedDescription] 
            delegate: nil 
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil]; 
     [alert show]; 

     return; 
    } 

    //prepare to record 
    [recorder setDelegate:self]; 
    [recorder prepareToRecord]; 
    recorder.meteringEnabled = YES; 

    BOOL audioHWAvailable = audioSession.inputIsAvailable; 
    if (! audioHWAvailable) { 
     UIAlertView *cantRecordAlert = 
     [[UIAlertView alloc] initWithTitle: @"Warning" 
            message: @"Audio input hardware not available" 
            delegate: nil 
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil]; 
     [cantRecordAlert show]; 

     return; 
    } 

    // start recording 
    [recorder record]; 

    lblStatusMsg.text = @"Recording..."; 
    //recIcon.image = [UIImage imageNamed:@"rec_icon.png"]; 
    //progressView.progress = 0.0; 
    //timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES]; 
} 

-(void)stopRecord:(UIButton *)sender 
{ 
    loading.hidden = YES; 
    [loading stopAnimating]; 

    recStartBtn.enabled = YES; 
    recStartBtn.hidden = NO; 
    playRecBtn.hidden = NO; 

    playRecBtn.enabled = YES; 
    recStopBtn.enabled = NO; 
    recStopBtn.hidden = YES; 
    [recorder stop]; 

    [timer invalidate]; 
    lblStatusMsg.text = @"Stopped"; 
    // recIcon.image = [UIImage imageNamed:@"rec_icon2.png"]; 

} 

-(void)playRecord:(UIButton *)sender 
{ 
    recorderFilePath = [NSString stringWithFormat:@"%@/MySound.caf", DOCUMENTS_FOLDER]; 
    NSURL *urlRecord = [NSURL fileURLWithPath:recorderFilePath isDirectory:NO]; 
    NSError *errorRecord; 
    soundRecord = [[AVAudioPlayer alloc] initWithContentsOfURL:urlRecord error:&errorRecord]; 
    [soundRecord play]; 
} 


-(void)changePitch:(UIButton *)sender 
{ 


    alSourcef(recorderFilePath, AL_PITCH, 1.2f);//this kinda troubles me,the source. =(
    [soundRecord play];//this one also... 

} 

답변

0

alSourcef 방법의 첫 번째 인수가없는있는 NSString 파일 경로입니다, 오디오 소스를 나타내는 ALuint입니다.

URL에서 OpenAL 소스를 설정하는 방법에 대한 예제는 oalTouch (특히 oalPlayback 클래스)을 참조하십시오.

+0

링크 선생님 덕분에. –