Objective-c/IOS: Reversing the bytes in NSMutabledata

醉酒当歌 提交于 2020-01-04 07:26:43

问题


In my application I have the bytes of an audio file stored in NSMutableData like so:

NSMutableData *data = [NSMutableData dataWithBytes:byteData length:len];

I can then later play this using

player = [[AVAudioPlayer alloc] initWithData:data error:&error];

My question is what code would reverse the bytes in the data object, so that when played the sound is backwards?

Any help is very much appreciated.

By the way, the byteData of the audio is obtained using:

    NSMutableData *wave =[NSMutableData dataWithContentsOfURL:url];

NSUInteger len = [wave length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [wave bytes], len);

回答1:


DaveSmith122 is right. You cannot just reverse the byte data. I have achieved the same effect using CoreAudio and AudioUnits. Use ExtFileReader C API to read the file into lPCM buffers and then you can reverse the buffers as needed.



来源:https://stackoverflow.com/questions/7365011/objective-c-ios-reversing-the-bytes-in-nsmutabledata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!