iOS和解码内存缓冲区中的MP3 / AAC数据 [英] iOS and decoding MP3/AAC data from memory buffer
问题描述
请原谅我,我在iOS上非常新 - 并且通常以这种规模进行编程。
Forgive me, I very new at iOS - and programming at this scale in general.
我一直在挖掘iOS文档,我知道有一些功能像ExtAudiofile ...用于解码MP3 / AAC文件,但有没有可以在已经在内存中的Mp3 / aac数据上运行?
I have been digging through iOS documentation, I know there are some functions like ExtAudiofile... for decoding MP3/AAC files, but are there any that will operate on Mp3/aac data that's already in memory?
我可能需要提取来自另一个文件的媒体数据(逐字节; iOS确实允许吗?),所以我不能只给它一个URL。
I will probably have to extract the media data (byte by byte; iOS does allow that right?) from inside another file, so I can't just give it the URL.
编辑:mp3数据将采用非标准文件格式,Apple提供的功能应该无法读取它们。我听说iOS有一个可以在一个音频流上运行的硬件解码器,如果有多个流,操作系统将回退到软件解码。
the mp3 data will be in a non-standard file format, Apple provided function should not be able to read them. I heard iOS has a hardware decoder that works on one audio stream and the OS will fallback to software decoding if there are multiple streams.
我宁愿使用Apple提供的功能,然后将MP3解码器集成到应用程序中。
I would rather use what Apple provides then integrate a MP3 decoder into the app.
推荐答案
您可以使用ExtAudioFileRead读取内存中的文件,但必须使用AudioFileOpenWithCallbacks。我不是我的工作电脑,所以我不能给你确切的代码,但这是一般的过程:
You can use ExtAudioFileRead to read a file that is in memory, but you have to use AudioFileOpenWithCallbacks. I'm not by my work computer so I can't give you exact code, but here's the general process:
- 使用fopen / fread将给定文件读入内存缓冲区数组。使用简单的C数组而不是NSArray或NSData - 您需要速度,并且需要它与下一步兼容。
- 为read / get size创建一些基本的C函数回调。
- 将AudioFileOpenWithCallbacks与您编写的回调一起打开
内存中的音频文件。 - 使用ExtAudioFileWrapAudioFileID开始解码文件记忆。
这取代了ExtAudioFileOpenURL。
- Use fopen/fread to read the given file into a memory buffer array. Use a simple C array and not an NSArray or NSData - you need speed and you need for it to be compatible with the next step.
- Create some basic C function callbacks for read / get size.
- Use AudioFileOpenWithCallbacks with the callbacks you wrote to open the audio file in memory.
- Use ExtAudioFileWrapAudioFileID to start decoding the file in memory. This is in replacement of ExtAudioFileOpenURL.
如果你是Google + AudioFileOpenWithCallbacks + ExtAudioFileWrapAudioFileID,你会发现有些人有已经完成了这个并发布了他们的代码。
If you Google +AudioFileOpenWithCallbacks +ExtAudioFileWrapAudioFileID, you'll find that some folks have already done this and published their code.
我不确定你的非标准mp3数据是什么意思,所以你应该尝试使用另一个应用来播放该文件看它是否兼容。
I'm not sure what you mean by non-standard mp3 data, so you should try to play the file using another app to see if it will be compatible.
这篇关于iOS和解码内存缓冲区中的MP3 / AAC数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!