2012-05-21 3 views
1

Я работал над этой задачей в течение 12 дней, и я не могу найти какое-либо решение pleaaaaase помочьАУДИОБЛОК игральных файлов m4a

я должен загрузить около 80 m4a файлов и играть в некоторых из них с augraph, который содержит смеситель и блоки remoteIO вот как я загрузить файлы

OSStatus result; 
for (int i = 0; i < [filePaths count]; i++) { 
    NSMutableArray *linearr=[[NSMutableArray alloc] init]; 
    for (int j = 0; j < [[filePaths objectAtIndex:i] count]; j++) { 
     NSString *str=[[filePaths objectAtIndex:i] objectAtIndex:j]; 

     CFURLRef audioFileURL = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *)[str cStringUsingEncoding:[NSString defaultCStringEncoding]] , strlen([str cStringUsingEncoding:[NSString defaultCStringEncoding]]), false); 
     ExtAudioFileRef audiofile; 
     ExtAudioFileOpenURL(audioFileURL, &audiofile); 
     assert(audiofile); 
     OSStatus err; 
     AudioStreamBasicDescription fileFormat; 
     UInt32 size = sizeof(fileFormat); 
     err = ExtAudioFileGetProperty(audiofile, kExtAudioFileProperty_FileDataFormat, &size, &fileFormat); 

     AudioFileID aFile; 
     //size = sizeof(aFile); 
     PropertySize =sizeof(PacketsToRead); 
     err = ExtAudioFileGetProperty(audiofile, kExtAudioFileProperty_AudioFile, &PropertySize, &aFile); 
     AudioFileTypeID fileType; 
     PropertySize = sizeof(fileType); 
     err = AudioFileGetProperty(aFile, kAudioFilePropertyFileFormat, &PropertySize, &fileType); 
     AudioStreamBasicDescription clientFormat; 
     bzero(&clientFormat, sizeof(clientFormat)); 
     clientFormat.mChannelsPerFrame = 2; 
     clientFormat.mBytesPerFrame = 4; 
     clientFormat.mBytesPerPacket = clientFormat.mBytesPerFrame; 
     clientFormat.mFramesPerPacket = 1; 
     clientFormat.mBitsPerChannel = 32; 
     clientFormat.mFormatID = kAudioFormatLinearPCM; 
     clientFormat.mSampleRate = 44100.00; 
     clientFormat.mFormatFlags =kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsNonInterleaved; //kLinearPCMFormatFlagIsFloat | kAudioFormatFlagIsNonInterleaved; 

     err = ExtAudioFileSetProperty(audiofile, kExtAudioFileProperty_ClientDataFormat, sizeof(clientFormat), &clientFormat); 

     SInt64 numFrames = 0; 
     PropertySize = sizeof(numFrames); 
     err = ExtAudioFileGetProperty(audiofile, kExtAudioFileProperty_FileLengthFrames, &PropertySize, &numFrames); 
     NSNumber *pc = [NSNumber numberWithLongLong:numFrames]; 
     [[packetCount objectAtIndex:i] replaceObjectAtIndex:j withObject:pc]; 
     // create the buffers for reading in data 
     bufferList = malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer) * (clientFormat.mChannelsPerFrame - 1)); 
     bufferList->mNumberBuffers = clientFormat.mChannelsPerFrame; 
     for (int ii=0; ii < bufferList->mNumberBuffers; ++ii) { 
      bufferList->mBuffers[ii].mDataByteSize = sizeof(float) * numFrames; 
      bufferList->mBuffers[ii].mNumberChannels = 2; 
      bufferList->mBuffers[ii].mData = malloc(bufferList->mBuffers[ii].mDataByteSize); 
     } 

     UInt32 rFrames = 0; 
     rFrames =(UInt32)numFrames; 
     err = ExtAudioFileRead(audiofile, &rFrames, bufferList); 
     [linearr addObject:[NSData dataWithBytes:bufferList->mBuffers[1].mData length:numFrames]]; 
     err = ExtAudioFileDispose(audiofile); 

} 
    [audioData addObject:linearr]; 
} 

, и вот как я играть:

UInt32 *buslist; 
buslist=(UInt32*)[[[audioData objectAtIndex:0] objectAtIndex:4]bytes ]; 

в rendercallback FUNC:

for (int i = 0 ; i < ioData->mNumberBuffers; i++){ 
    UInt32 *au3=au->mBuffers[0].mData; 
    AudioBuffer buffer = ioData->mBuffers[i]; 
    UInt32 *frameBuffer = buffer.mData; 
    for (int j = 0; j < inNumberFrames; j++) 
    { 
     frameBuffer[j] = buflist[counter]; 
     if(counter>=529200) 
      counter=0; 
     else 
      counter++; 
    }}} 

Теперь, когда я воспроизвожу звук, я получаю первую часть с двойной скоростью, а затем вторую часть только искажения.

ответ

1

У меня была такая же проблема, я думаю;

Входящий звук был с меньшей частотой дискретизации, поэтому выделенный мной массив был недостаточно большим для более высокой частоты дискретизации auGraph и был слишком быстрым и коротким.

убедитесь, что вы выделяете массив прочитать файл что-то вроде этого:

sarray-> рамки = totalFramesInFile * graphSampleRate/fileAudioFormat.mSampleRate;

+0

thnx Я думаю, я решил это так же :) –