2011-08-21 1 views
1

저는 현재 iOS 오디오 프로젝트를 만들고 있는데 XCode의 Extras/CoreAudio/PublicUtility 폴더에서 사용할 수있는 CARingBuffer 클래스를 사용해야합니다. 문제는 내 viewController 헤더에 CARingBuffer.h를 포함시키고 CARingBuffer 개체를 선언 할 때 4 개의 컴파일 오류가 발생합니다.iOS (iPhone, iPad) 프로젝트에서 CARingBuffer 클래스를 사용하는 방법은 무엇입니까?

내 문제를 재현하려면 매우 간단합니다. 새로운 뷰 기반 애플리케이션을 만들고 viewController 헤더에 "CARingBuffer.h"를 # 포함 시키십시오. 여기

#import <UIKit/UIKit.h> 

    #include "CARingBuffer.h" 

    @interface testViewController : UIViewController { 

    } 

    @end 

가 내 testViewController.m의 내용은 다음과 같습니다 : (이상하게)에있는 4 컴파일 오류 벨로

#import "testViewController.h" 

    @implementation testViewController 

    - (void)dealloc 
    { 
     [super dealloc]; 
    } 

    - (void)didReceiveMemoryWarning 
    { 
     // Releases the view if it doesn't have a superview. 
     [super didReceiveMemoryWarning]; 

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

    #pragma mark - View lifecycle 

    /* 
    // Implement viewDidLoad to do additional setup after loading the view, typically               from a nib. 
    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
    } 
    */ 

    - (void)viewDidUnload 
    { 
     [super viewDidUnload]; 
     // Release any retained subviews of the main view. 
     // e.g. self.myOutlet = nil; 
    } 

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
     // Return YES for supported orientations 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 

    @end 

CARingBuffer에 따라 다음

내 testViewController.h의 내용입니다 XCode 4 :

1) 이니셜 라이저 요소가 온라인상의 상수가 아닙니다.

const UInt32 kGeneralRingTimeBoundsQueueMask = kGeneralRingTimeBoundsQueueSize - 1; 

2) 예상되는 ';' 최상위 선언자 후 '='예상 ... 또는 'atribute'CARingBuffer '전 :

class CARingBuffer { 

3) 초기화 소자 라인에 일정하지 않다 :

const UInt32 kGeneralRingTimeBoundsQueueMask = kGeneralRingTimeBoundsQueueSize - 1; 

4) 예상 ';' 당신의 도움에 미리

class CARingBuffer { 

감사 : 최고 수준의 '='예상 선언자, ... 또는 'CARingBuffer'이전 'atribute'후.

답변

0

링 버퍼를 포함 할 클래스의 이름을 .mm 파일로 바꿔야합니다.

이렇게하면 컴파일러에서 객관적인 C++을 사용하도록 지시합니다.

1

또한 CARingBuffer은 C 클래스 ++이기 때문에 testViewController.mm로 testViewController.m을 변경해야 할이 alternative

0

를보십시오. 그것을 사용하는 방법에 대한 , 여기 CARingBuffer의 확장입니다 :

CARingBufferEx*   _musicMixerRingBuffer; 
    _musicMixerRingBuffer = new CARingBufferEx(); 
    _musicMixerRingBuffer->Allocate(2, sizeof(AudioUnitSampleType), 1024 * 50); 
    //1024 is length for one package. and 50 means this buffer contains 50 packages at most. 

    //store 
    //ioData is AudioBufferList ,inTimeStamp is AudioTimeStamp 
    musicMixerRingBuffer->Store(ioData, inNumberFrames, inTimeStamp->mSampleTime); 
    //Fetch 
    musicMixerRingBuffer->Fetch(ioData, inNumberFrames, inTimeStamp->mSampleTime); 
:
//header file 
#include "CARingBuffer.h" 
class CARingBufferEx : public CARingBuffer { 

public: 
    CARingBufferEx(); 
    ~CARingBufferEx(); 
    CARingBufferError Store(const AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber); 

    CARingBufferError Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber); 

private: 
    SInt64 firstInputSampleTime; 
    SInt64 firstOutputSampleTime; 
    SInt64 offset; 

}; 

//Class 
#include "CARingBufferEx.h" 
#include "stdio.h" 

CARingBufferEx::CARingBufferEx():firstInputSampleTime(-1), firstOutputSampleTime(-1), offset(0) { 
} 
CARingBufferEx::~CARingBufferEx() { 

} 

CARingBufferError CARingBufferEx::Store(const AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber) { 
    if (firstInputSampleTime < 0) { 
     firstInputSampleTime = frameNumber; 
     if (firstOutputSampleTime > 0 && offset == 0) { 
      offset = firstInputSampleTime - firstOutputSampleTime; 
     } 
    } 
    return CARingBuffer::Store(abl, nFrames, frameNumber); 
} 

CARingBufferError CARingBufferEx::Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber) { 
    if (firstOutputSampleTime < 0) { 
     firstOutputSampleTime = frameNumber; 
     if (firstInputSampleTime > 0 && offset == 0) { 
      offset = firstInputSampleTime - firstOutputSampleTime; 
     } 
    } 
    return CARingBuffer::Fetch(abl, nFrames, frameNumber + offset); 
} 

사용 CARingBufferEx