简体   繁体   English

Objective-c / IOS:反转NSMutabledata中的字节

[英]Objective-c/IOS: Reversing the bytes in NSMutabledata

In my application I have the bytes of an audio file stored in NSMutableData like so: 在我的应用程序中,我将音频文件的字节存储在NSMutableData中,如下所示:

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: 顺便说一下,音频的byteData是使用以下方法获得的:

    NSMutableData *wave =[NSMutableData dataWithContentsOfURL:url];

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

DaveSmith122 is right. DaveSmith122是正确的。 You cannot just reverse the byte data. 您不能只反转字节数据。 I have achieved the same effect using CoreAudio and AudioUnits. 使用CoreAudio和AudioUnits,可以达到相同的效果。 Use ExtFileReader C API to read the file into lPCM buffers and then you can reverse the buffers as needed. 使用ExtFileReader C API将文件读入lPCM缓冲区,然后您可以根据需要反转缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM