我在我正在开发的 iOS 应用程序中使用 OpenAL,我们的客户给了我们一堆大端格式的音频文件。我的问题是 OpenAL 只播放 little-endian 格式。
所以我认为我需要做的就是找到音频数据并将其反转,对吗?
我用于提取音频数据的代码(取自 OpenAL 教程):
-(void)addSound:(NSString*)theSound
{
// get the full path of the file
NSString* fileName = [[NSBundle mainBundle] pathForResource:theSound ofType:@"caf"];
// first, open the file
NSLog(@"fileNAme is ===== %@", fileName);
AudioFileID fileID = [self openAudioFile:fileName];
// find out how big the actual audio data is
UInt32 fileSize = [self audioFileSize:fileID];
// this is where the audio data will live for the moment
unsigned char * outData = malloc(fileSize);
// this where we actually get the bytes from the file and put them
// into the data buffer
OSStatus result = noErr;
result = AudioFileReadBytes(fileID, false, 0, &fileSize, outData);
NSLog(@"OUT DATA IS == %d", outData);
AudioFileClose(fileID); //close the file
if (result != 0) NSLog(@"cannot load effect: %@",fileName);
NSUInteger bufferID;
// grab a buffer ID from openAL
alGenBuffers(1, &bufferID);
// jam the audio data into the new buffer
alBufferData(bufferID,AL_FORMAT_STEREO16,outData,fileSize,44100);
// save the buffer so I can release it later
[bufferStorageArray addObject:[NSNumber numberWithUnsignedInteger:bufferID]];
NSUInteger sourceID;
// grab a source ID from openAL
alGenSources(1, &sourceID);
// attach the buffer to the source
alSourcei(sourceID, AL_BUFFER, bufferID);
// set some basic source prefs
alSourcef(sourceID, AL_PITCH, 1.0f);
alSourcef(sourceID, AL_GAIN, 1.0f);
//alSourcei(sourceID, AL_LOOPING, AL_TRUE);
// store this for future use
[soundDictionary setObject:[NSNumber numberWithUnsignedInt:sourceID] forKey:theSound];
// clean up the buffer
if (outData)
{
free(outData);
outData = NULL;
}
}
我想unsigned char * outdata;
这是我需要反转的(当然是在将音频文件数据加载到其中之后),但我不知道该怎么做。任何人都可以帮我解决这个问题吗?