Potrzebuję przekonwertować plik WAVE do pliku M4A zakodowanego AAC na iOS. Mam świadomość, że kodowanie AAC nie jest obsługiwane na starszych urządzeniach ani w symulatorze. Testuję to zanim uruchomię kod. Ale nadal nie mogę zmusić go do działania.Jak mogę uzyskać kodowanie AAC za pomocą ExtAudioFile na iOS, aby działał?
Spojrzałem na własny przykład Apple iPhoneExtAudioFileConvertTest i pomyślałem, że poszedłem dokładnie, ale wciąż nie ma szczęścia!
Obecnie otrzymuję -50 (= błąd na liście parametrów użytkownika) podczas próby ustawienia formatu klienta w pliku docelowym. W pliku źródłowym działa.
Poniżej znajduje się mój kod. Każda pomoc jest bardzo doceniana, dzięki!
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);
Czy to działa? Chciałbym również przekonwertować plik .wav na .acc. – RyanG
Hej Ryan, sprawdź moją własną odpowiedź na to poniżej. – Sebastian