mikeash.com pyblog/why-coreaudio-is-hard.html commentshttp://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsmikeash.com Recent CommentsFri, 29 Mar 2024 05:51:22 GMTPyRSS2Gen-1.0.0http://blogs.law.harvard.edu/tech/rssMark Aufflick - 2013-11-20 23:11:05http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsFWIW with the current run-time optimisations, I happily use (very small) Objective-C method calls inside realtime audio stages on multi-track audio on an iPad (inside an MTAudioProcessingTap). <br /> <br />As @gvdl points out you do really need to avoid memory allocation, but if your method calls nothing but your own code you can easily check this. Also as @gvdl points out there are various ways to turn ObjC calls into simpler function calls if need be. <br /> <br />Premature optimisation begone!ae02690b46ec319145099fb7338d7c8aWed, 20 Nov 2013 23:11:05 GMTHari Karam Singh - 2012-02-04 17:53:23http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsWith regards to efficiency in the audio callback, do c++ method calls have low enough overhead to be acceptable? I'm thinking about a C++ class with a method which gets used as the callback and with properties which the callback can access...6b033ccf23ae57770a36de3ad43055caSat, 04 Feb 2012 17:53:23 GMTiluvcapra - 2011-07-02 05:59:24http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsI don't find the latency argument particularly compelling when were talking about things like offline or non synchronous file operations, or merely constructing AUGraphs of AudioUnits, something that only happens occasionally and can't happen while the graph is rendering, anyways. GStreamer, for example, has Ruby and Python bindings for constructing graphs and they work great. Same thing with Max or PureData. <br /> <br />Also, I second the comment that CoreAudio is atrociously documented. I was looking up AUMIxer documentation and I found a developer on the listserv mentioning that they were working on some,. This message was from 2006. <br />3a5231a3e585491698f3b96cc898fb11Sat, 02 Jul 2011 05:59:24 GMTgvdl - 2011-03-03 17:59:42http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsNeXTStep did indeed support Obj-C, BUT it did not allow Obj-C on the interrupt path. The problem is that it is possible for the method cache to perform an allocation, a big interrupt time no-no. For MacOSX we developed an interrupt safe message mechanism by tweaking the objc runtime. However, in 1997 Apple was de-emphasising ObjC and as a result we decided to switch to Embedded-C++. <br /> <br />The audio priority band is the user-land equivalent to interrupt threads and has the same issues with ObjC. One possible low-latency solution is to ask ObjC's introspection to give you a C function pointer using -[NSObject methodForSelector:] and the function must be standalone, i.e. no method calls. <br />c8babbc5353d0f9edc2c17a50760f36cThu, 03 Mar 2011 17:59:42 GMTRuben Perez - 2009-03-26 20:07:08http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsCore Audio isn't hard. You just need to understand the underlying digital audio concepts. If you'd like I can send you my C++ wrapper for CA, four lines, asynchronous playback, skip the technicalities. Audio Fajita. You can contact me through <a href="http://www.bitjelly.com">www.bitjelly.com</a> contact info link. <br /> <br />Salut, <br /> <br />Ruben8e55ee5e97990d283f52cec2b98eea5cThu, 26 Mar 2009 20:07:08 GMTTony Million - 2007-09-14 13:20:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsA quick note: Port Audio &amp;#8211; &lt;a href="<a href="http://www.portaudio.com/">http://www.portaudio.com/</a>" rel="nofollow"&gt;<a href="http://www.portaudio.com/&amp;lt">http://www.portaudio.com/&lt;</a>;/a&gt;&lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;its cross platform, works in a similar way to Core Audio (its a pull model) however it adds buffering (and thus a little more latency). But makes up for it in ease of use. Its especially useful if all you need is to stream some audio to the speakers (i.e. background music for your game/app) and dont mind about sub 40ms latentcy! <br />dd7e6bbd556910570b2e7ea65ea4a8a6Fri, 14 Sep 2007 13:20:00 GMTUli Kusterer - 2006-10-31 08:45:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsI think the biggest problem is that, although CA is gaining layers (e.g. the File Player, and I&amp;#8217;m hoping that e.g. NSSound uses CA under the hood), there&amp;#8217;s almost no mobility between layers. Why is it not possible to create an NSSound and then get at its AudioUnit to tell it to only play on the left channel? There&amp;#8217;s no way to bridge the various APIs, so you can use the simple ones and only drop lower when you actually need more control.&lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;RANT=ON&lt;br /&gt; <br />In addition, I think the engineers are too much in love with the technical aspects&amp;#8230; I was in a presentation by one where &amp;#8220;pause/resume&amp;#8221; were listed among the &amp;#8220;advanced features&amp;#8221; (!). Now, if I had the sources to CA, it wouldn&amp;#8217;t be so advanced, but from the outside I had to jump through hoops to get that working&amp;#8230;&lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;Elementary stuff that half of the users of a sound playing framework would use, that took two sndCommands with Sound Manager takes pages upon pages of code and requires polling and other inefficient approaches&amp;#8230;&lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;And don&amp;#8217;t get me started on the sample code &amp;#8230; most sample code only replicates what Sound Manager would do. I&amp;#8217;m not switching to CA to get my sound reduced to two channels&amp;#8230; I want 5.1 audio. And the header comments are almost useless and don&amp;#8217;t even document the type of the value you pass into a SetParameter or SetProperty call&amp;#8230; &lt;strong&gt;that&lt;/strong&gt; is why CoreAudio is hard.&lt;br /&gt; <br />RANT=OFF <br />06fb71e1eb855c3bc61aa9273977fee5Tue, 31 Oct 2006 08:45:00 GMTarne - 2006-10-20 11:17:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsFor a much simpler solution you should look at the output AudioUnits. It&amp;#8217;s very easy to code and if you need to get into the details you can get deep down into CoreAudio with it. <br />033207bde894854020abf8c1c2b1d2baFri, 20 Oct 2006 11:17:00 GMTssp - 2006-10-20 11:00:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsSure, audio glitches are easily noticeable. And I&amp;#8217;m sure you need some tight engineering for the audio engine to work well and for plugins or other things working at its core. &lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;But wanting to do something really simple (like playing a sinewave, say) still seems unnecessarily complicated through CoreAudio&amp;#8230; I always thought it should be sufficient to provide a single callback function for that, but you tend to need plenty of code around that which you need to grab from examples yourself. <br />430eb47b0b3c00b7101cba9505eed31dFri, 20 Oct 2006 11:00:00 GMTMatt Ronge - 2006-10-20 08:10:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsThere is a guy on the QuickTime team who has written a bunch of books on developing audio API and systems. I have the first book in his series, and I’ve had a chance to look at the second one and it’s also very good. I’d recommend checking these books out if you want to learn more about audio systems, I found the first one to be very interesting reading (ringbuffers, totally cool!):&lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;Audio Anecdotes: &lt;a href="<a href="http://www.amazon.com/Audio-Anecdotes-Tools-Techniques-Digital/dp/1568811047/ref=pd_bxgy_b_text_b/002-2490952-4612813?ie=UTF8">http://www.amazon.com/Audio-Anecdotes-Tools-Techniques-Digital/dp/1568811047/ref=pd_bxgy_b_text_b/002-2490952-4612813?ie=UTF8</a>" rel="nofollow"&gt;<a href="http://www.amazon.com/Audio-Anecdotes-To..&amp;lt">http://www.amazon.com/Audio-Anecdotes-To..&lt;</a>;/a&gt;&lt;br /&gt; <br />Audio Anecdotes II: &lt;a href="<a href="http://www.amazon.com/Audio-Anecdotes-II-Techniques-Digital/dp/1568812140/sr=8-2/qid=1161327952/ref=sr_1_2/002-2490952-4612813?ie=UTF8&amp;amp">http://www.amazon.com/Audio-Anecdotes-II-Techniques-Digital/dp/1568812140/sr=8-2/qid=1161327952/ref=sr_1_2/002-2490952-4612813?ie=UTF8&amp;</a>;#38;s=books" rel="nofollow"&gt;<a href="http://www.amazon.com/Audio-Anecdotes-II..&amp;lt">http://www.amazon.com/Audio-Anecdotes-II..&lt;</a>;/a&gt; <br />56c17207cc9df94a7fd3694515dc49baFri, 20 Oct 2006 08:10:00 GMTmikeash - 2006-10-20 05:26:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsChris, I&amp;#8217;m not sure exactly what that means, but it&amp;#8217;s an interesting data point in any case. Device drivers don&amp;#8217;t necessarily have to be realtime, although obviously in the case of audio you&amp;#8217;d run into similar problems. One very large difference between the CoreAudio case and the driver case is that the drivers you cite ran in kernel mode, and ran in a completely separate task. This means that there was no chance of any sort of priority inversion such as what could happen if a CA realtime thread hit a spinlock held by a regular thread. It also means that it may have been able to replace the spinlocks with evil techniques such as simply disabling context switches and interrupts during the critical section. In any case, the changes to the runtime that allowed Driver Kit to run on ObjC may not be appropriate or sufficient to allow safe ObjC use in realtime userland threads. <br />fcccb49039b8f12322b9b4809ec6180dFri, 20 Oct 2006 05:26:00 GMTfoobaz - 2006-10-20 00:28:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsVery enlightening. <br />92fa8d8f05a2be47b754e68b309286ccFri, 20 Oct 2006 00:28:00 GMTSimon - 2006-10-19 21:32:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#commentsFrom the title, I thought you were going to talk about the documentation and C++ sample code&amp;#8230; <br />c4861639a1fd11e8edf5e15d87044af0Thu, 19 Oct 2006 21:32:00 GMTChris - 2006-10-19 20:48:00http://www.mikeash.com/?page=pyblog/why-coreaudio-is-hard.html#comments<div class="blogcommentquote"><div class="blogcommentquoteinner">&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ObjC message dispatch is generally unsuited for realtime tasks.&lt;br /&gt; <br /></div></div>&lt;br /&gt; <br />&lt;br /&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;This is not fundamental to Objective-C message dispatch, it&amp;#8217;s fundamental to Apple&amp;#8217;s current Objective-C runtime implementation.&amp;nbsp;NeXTstep had &lt;em&gt;device drivers&lt;/em&gt; written in&amp;nbsp;Objective-C. (See &lt;a href="<a href="http://www.channelu.com/NeXT/NeXTStep/3.3/nd/OperatingSystem/Part3_DriverKit/Concepts/1_Overview/Overview.htmld/index.html">http://www.channelu.com/NeXT/NeXTStep/3.3/nd/OperatingSystem/Part3_DriverKit/Concepts/1_Overview/Overview.htmld/index.html</a>" rel="nofollow"&gt;<a href="http://www.channelu.com/NeXT/NeXTStep/3...&amp;lt">http://www.channelu.com/NeXT/NeXTStep/3...&lt;</a>;/a&gt;). <br />e995041b62fef4b7cf433e6f439ea8e9Thu, 19 Oct 2006 20:48:00 GMT