2011-07-25 9 views
0

ピッチを変更するために、サンプルをCMSampleBufferRefから取り出し、フロートの配列に入れようとしています。私はマニュアルでメソッドCMSampleBufferCallForEachSampleを見つけましたが、それを使用する方法は分かりませんし、例や説明はありません。私はこの事をしばらくの間、周りを走り回っています。だれでも助けてくれますか?ピッチシフトのサンプルをCMSampleBufferRefから取得するにはどうすればよいですか?

答えて

0

私は同様の問題を解決していました。 1つのSampleBufferからAACサンプルを分割する必要がありました。

... 
    CMSampleBufferCallForEachSample(sampleBuffer, &sampler, NULL); 
    ... 

static OSStatus sampler(CMSampleBufferRef sampleBuffer, CMItemCount index, void *refcon) { 
    CMTime presentationTimeStamp = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer); 
    CMBlockBufferRef buff = CMSampleBufferGetDataBuffer(sampleBuffer); 
    UInt32 timeStamp = (1000*presentationTimeStamp.value)/presentationTimeStamp.timescale; 
    size_t size = CMBlockBufferGetDataLength(buff); 

    void *sampleData = malloc(size); 
    CMBlockBufferCopyDataBytes(buff, 0, size, sampleData); 
    NSData * data = [NSData dataWithBytes:sampleData length:size]; 
    NSLog(@"Audio %ldx samples of size %lu has been transfered at time %ld", CMSampleBufferGetNumSamples(sampleBuffer), size, timeStamp); 
} 

が、コールバックが各sampleBufferにおける最初のサンプルに対して一度だけ呼び出されるが、偶数

この数値を返す76のサンプルとCMSampleBufferGetNumSamplesのアレイがある私は、優れた溶液here(方法fillMovieSampleBuffer行283)を発見しましたCoreMediaフレームワークの文書化のための

check this URL

@function CMSampleBufferCallForEachSample 
@abstract Calls a function for every individual sample in a sample buffer. 
@discussion Temporary sample buffers will be created for individual samples, 
referring to the sample data and containing its timing, size and attachments. 
The callback function may retain these sample buffers if desired. 
If the callback function returns an error, iteration will stop immediately 
and the error will be returned. 

If there are no sample sizes in the provided sample buffer, kCMSampleBufferError_CannotSubdivide will be returned. 
This will happen, for example, if the samples in the buffer are non-contiguous (eg. non-interleaved audio, where 
the channel values for a single sample are scattered through the buffer). 
関連する問題