Ho bisogno di convertire un file WAVE in un file M4A codificato AAC su iOS. Sono consapevole che la codifica AAC non è supportata su dispositivi precedenti o nel simulatore. Lo sto testando prima di eseguire il codice. Ma non riesco ancora a farlo funzionare.Come posso ottenere la codifica AAC con ExtAudioFile su iOS per funzionare?
ho guardato in molto proprio iPhoneExtAudioFileConvertTest esempio di Apple e ho pensato ho seguito esattamente, ma ancora senza fortuna!
Attualmente, viene visualizzato un errore -50 (= errore nell'elenco dei parametri utente) durante il tentativo di impostare il formato client sul file di destinazione. Nel file sorgente, funziona.
Di seguito è riportato il mio codice. Qualsiasi aiuto è molto apprezzato, grazie!
UInt32 size;
// Open a source audio file.
ExtAudioFileRef sourceAudioFile;
ExtAudioFileOpenURL((CFURLRef)sourceURL, &sourceAudioFile);
// Get the source data format
AudioStreamBasicDescription sourceFormat;
size = sizeof(sourceFormat);
result = ExtAudioFileGetProperty(sourceAudioFile, kExtAudioFileProperty_FileDataFormat, &size, &sourceFormat);
// Define the output format (AAC).
AudioStreamBasicDescription outputFormat;
outputFormat.mFormatID = kAudioFormatMPEG4AAC;
outputFormat.mSampleRate = 44100;
outputFormat.mChannelsPerFrame = 2;
// Use AudioFormat API to fill out the rest of the description.
size = sizeof(outputFormat);
AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &outputFormat);
// Make a destination audio file with this output format.
ExtAudioFileRef destAudioFile;
ExtAudioFileCreateWithURL((CFURLRef)destURL, kAudioFileM4AType, &outputFormat, NULL, kAudioFileFlags_EraseFile, &destAudioFile);
// Create canonical PCM client format.
AudioStreamBasicDescription clientFormat;
clientFormat.mSampleRate = sourceFormat.mSampleRate;
clientFormat.mFormatID = kAudioFormatLinearPCM;
clientFormat.mFormatFlags = kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
clientFormat.mChannelsPerFrame = 2;
clientFormat.mBitsPerChannel = 16;
clientFormat.mBytesPerFrame = 4;
clientFormat.mBytesPerPacket = 4;
clientFormat.mFramesPerPacket = 1;
// Set the client format in source and destination file.
size = sizeof(clientFormat);
ExtAudioFileSetProperty(sourceAudioFile, kExtAudioFileProperty_ClientDataFormat, size, &clientFormat);
size = sizeof(clientFormat);
ExtAudioFileSetProperty(destAudioFile, kExtAudioFileProperty_ClientDataFormat, size, &clientFormat);
// Make a buffer
int bufferSizeInFrames = 8000;
int bufferSize = (bufferSizeInFrames * sourceFormat.mBytesPerFrame);
UInt8 * buffer = (UInt8 *)malloc(bufferSize);
AudioBufferList bufferList;
bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0].mNumberChannels = clientFormat.mChannelsPerFrame;
bufferList.mBuffers[0].mData = buffer;
bufferList.mBuffers[0].mDataByteSize = (bufferSize);
while(TRUE)
{
// Try to fill the buffer to capacity.
UInt32 framesRead = bufferSizeInFrames;
ExtAudioFileRead(sourceAudioFile, &framesRead, &bufferList);
// 0 frames read means EOF.
if(framesRead == 0)
break;
// Write.
ExtAudioFileWrite(destAudioFile, framesRead, &bufferList);
}
free(buffer);
// Close the files.
ExtAudioFileDispose(sourceAudioFile);
ExtAudioFileDispose(destAudioFile);
Hai mai funzionato? Sto anche cercando di convertire un file .wav in .acc. – RyanG
Hey Ryan, controlla la mia risposta a questo sotto. – Sebastian