ios - AudioFileWriteBytes 的工作时间太长了
<p><p>这个问题对于这个空间来说可能有点过于庞大和模糊,但我会试一试。</p>
<p>我有一系列样本,我正试图将它们写入我的 iOS 上的 .wav 文件,这需要长达一分半钟的时间。这是发生拖动的循环:</p>
<pre><code>for (int i=0; i< 1430529; i++)// 1430529 is the length of the array of samples
{
SInt16 sample;
sample = sample_array;
audioErr = AudioFileWriteBytes(audioFile, false, sampleCount*2, &bytesToWrite, &sample);
sampleCount++;
}
</code></pre>
<p>有什么想法吗?</p>
<hr/>
<p><strong>编辑 1</strong></p>
<p>如果有帮助,这是它前面的代码:</p>
<pre><code>NSAutoreleasePool *pool = [ init];
// THIS IS MY BIT TO CONVERT THE LOCATION TO NSSTRING
NSString *filePath = [init];
filePath = ;
// HERE I WANT TO REMOVE THE FILE NAME FROM THE LOCATION.
NSString *truncatedFilePath = filePath;
truncatedFilePath = [truncatedFilePath stringByReplacingOccurrencesOfString:@"/recordedFile.wav"
// withString:@"/newFile.caf"];
withString:@"/recordedFile.wav"];
NSLog(truncatedFilePath);
NSURL *fileURL = ;
AudioStreamBasicDescription asbd;
memset(&asbd,0, sizeof(asbd));
asbd.mSampleRate = SAMPLE_RATE;
asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
asbd.mBitsPerChannel = 16;
asbd.mChannelsPerFrame = 1;
asbd.mFramesPerPacket = 1;
asbd.mBytesPerFrame = 2;
asbd.mBytesPerPacket = 2;
AudioFileID audioFile;
OSStatus audioErr = noErr;
audioErr = AudioFileCreateWithURL((CFURLRef)fileURL, kAudioFileWAVEType, &asbd, kAudioFileFlags_EraseFile, &audioFile);
assert (audioErr == noErr);
long sampleCount = 0;
UInt32 bytesToWrite = 2;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>为什么需要循环?你不能一口气写完所有的样本吗,例如</p>
<pre><code> numSamples = 1430529;
bytesToWrite = numSamples * 2;
audioErr = AudioFileWriteBytes(audioFile, false, 0, &bytesToWrite, sample_array);
</code></pre>
<p>?</p></p>
<p style="font-size: 20px;">关于ios - AudioFileWriteBytes 的工作时间太长了,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/5179418/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/5179418/
</a>
</p>
页:
[1]