Using RemoteIO audio unit
来源:互联网 发布:淘宝首页搜索 编辑:程序博客网 时间:2024/05/16 00:43
转自:http://atastypixel.com/blog/using-remoteio-audio-unit/
I’ve had nasty old time trying to get some audio stuff going on the iPhone, no thanks to Apple’s lack of documentation. If you’re an iPhone developer interested in getting RemoteIO/IO Remote/whatever it’s called working on the iPhone… Do I have good news for you. Read on.
Wanna skip the Core Audio learning curve and start writing code straight away? Check out my new project:
Update: Thanks to Joel Reymont, we now have an explanation for the “CrashIfClientProvidedBogusAudioBufferList” iPhone simulator bug: The simulator doesn’t like mono audio. Thanks, Joel!
Update: Happily, Apple have now created some excellent documentation on Remote IO, with some good sample projects. I recommend using that as a resource, now that it’s there, as that will continue to be updated.
Update: Tom Zicarelli has created a very extensive sample app that demonstrates the use of AUGraph, with all sorts of goodies.
So, we need to obtain an instance of the RemoteIO audio unit, configure it, and hook it up to a recording callback, which is used to notify you that there is data ready to be grabbed, and where you pull the data from the audio unit.
Overview
- Identify the audio component (kAudioUnitType_Output/ kAudioUnitSubType_RemoteIO/ kAudioUnitManufacturerApple)
- Use AudioComponentFindNext(NULL, &descriptionOfAudioComponent) to obtain the AudioComponent, which is like the factory with which you obtain the audio unit
- Use AudioComponentInstanceNew(ourComponent, &audioUnit) to make an instance of the audio unit
- Enable IO for recording and possibly playback with AudioUnitSetProperty
- Describe the audio format in an AudioStreamBasicDescription structure, and apply the format using AudioUnitSetProperty
- Provide a callback for recording, and possibly playback, again using AudioUnitSetProperty
- Allocate some buffers
- Initialise the audio unit
- Start the audio unit
- Rejoice
Here’s my code: I’m using both recording and playback. Use what applies to you!
Initialisation
Initialisation looks like this. We have a member variable of type AudioComponentInstance which will contain our audio unit.
The audio format described below uses SInt16 for samples (i.e. signed, 16 bits per sample)
Then, when you’re ready to start:
And to stop:
Then, when we’re finished:
And now for our callbacks.
RECORDING
PLAYBACK
Finally, rejoice with me in this discovery ;)
Resources that helped
- http://pastie.org/pastes/219616
- http://developer.apple.com/samplecode/CAPlayThrough/listing8.html
- http://listas.apesol.org/pipermail/svn-libsdl.org/2008-July/000797.html
No thanks at all to Apple for their lack of accessible documentation on this topic – They really have a long way to go here! Also boo to them with their lack of search engine, and refusal to open up their docs to Google. It’s a jungle out there!
Update: You can adjust the latency of RemoteIO (and, in fact, any other audio framework) by setting the kAudioSessionProperty_PreferredHardwareIOBufferDuration
property:
This adjusts the length of buffers that’re passed to you – if buffer length was originally, say, 1024 samples, then halving the number of samples halves the amount of time taken to process them.
RELATED POSTS
- Error -12986 and you A customer recently got in touch with me with an...
- Core Audio and freakin’ error -66632 This will only be of interest to a very small...
- A simple, fast circular buffer implementation for audio processing Circular buffers are pretty much what they sound like –...
- Easy AAC compressed audio conversion on iOS From the iPhone 3Gs up, it’s possible to encode compressed...
- Playing audio in time using Remote IO I got an email today with a question about how...
- Using RemoteIO audio unit
- Using RemoteIO audio unit
- ios audio unit remoteIO playback record
- Audio unit 详解
- iOS Audio Unit 的简介
- Using TestContext in Unit Tests
- iPhone/iPad Audio Unit声音播放
- iPhone/iPad Audio Unit 2012/05/19
- IOS音频架构之Audio Unit
- iOS Audio Unit 录音 AudioStreamBasicDescription 详解
- iOS ijkplayer Audio Unit 播放音频
- iOS Audio unit(音频单元)详解
- audio unit 和audio queue实现音频流的采集
- Using MVC improve UI Unit Test
- Unit Testing (using ReSharper 3.1)
- Using Mockito to Unit Test Java Applications
- Introduction on Using Hamcrest Unit Test Framework
- iPhone/iPad开发札记2012/03/12 Audio Unit
- thinkphp 多表查询
- Java对象序列化
- Tab
- AOP实现--JDK中的动态代理和cglib代理
- Nhibernate3.3.1使用
- Using RemoteIO audio unit
- SET IDENTITY_INSERT
- MFC之代码跟踪
- LINQ学习(一)
- ROS中rosrun和roslaunch命令的对比
- AOP实现(二)---Spring框架中的AOP应用
- 莽撞记者弄哭何姿 我没有妈妈她在天上看我
- CString详解以及CString转换成char*
- JDK环境变量配置(Linux and Windows)