Core MIDI and Friends

31 of 31
Core MIDI and Friends
- Share
- Like

Published on Nov 7, 2011
CocoaHeads Ann Arbor presentation on handling MIDI events in Mac OS X and iOS
- Ben SmileyI've written a series of compreshensive CoreMidi tutorials at: http://www.deluge.co/?q=all-things-midi
4 years ago
Core MIDI and Friends
- 1. CoreMIDI and FriendsChris Adamson, CocoaHeads Ann Arbor Sept. 8, 2011
- 2.Road Map• MIDI basics• MIDI APIs on OSX• MIDI APIs on iOS
- 3.MIDI Basics• MIDI = Musical Instrument Digital Interface • Circa 1982!• Sends messages between devices, not sounds • Notes to play (pitch, impact, vibrato), patch selection, timing synchronization, etc.
- 4.MIDI Terms• Device — participant in a MIDI network• Endpoint — one connection into or out of a device• Source — endpoint that sends data• Destination — endpoint that receives data
- 5.MIDI MessagesSTATUS DATA 1 DATA 2
- 6.MIDI Messages• Channel Voice Messages — Note On, Note Off, After-touch, Pitch wheel • High nybble of status is command, low nybble is channel number• Channel Mode, System Messages• Various extensions to the spec over the yearshttp://www.midi.org/techspecs/midimessages.php
- 7.MIDI APIs on OSX• CoreMIDI — Implementation of MIDI messaging• Instrument Units — Audio Units that generate sound in response to MIDI events• Music Device — Sends commands to Instrument Units• Music Sequence / Music Player — Plays MIDI (.mid) files
- 8.Core MIDI• C-based API in Audio Toolbox • Largely similar to other Core Audio APIs • Uses Core Foundation opaque types, memory management, etc.
- 9.Core MIDI Types• MIDIClientRef — Holds state for your MIDI session• MIDIDeviceRef — A device (real or virtual) with “entities” (MIDIEntityRef), which are logical sub-systems• MIDIEndPointRef — Source or destination• MIDIPortRef — An input or output port
- 10.Creating client & input port!MIDIClientRef client = NULL;!MIDIClientCreate(CFSTR("Core MIDI to System Sounds Demo"), MyMIDINotifyProc, self, &client);!!MIDIPortRef inPort = NULL;!MIDIInputPortCreate(client, CFSTR("Input port"), MyMIDIReadProc, self, &inPort);
- 11.Discovering and connecting sources!unsigned long sourceCount = MIDIGetNumberOfSources();!for (int i = 0; i < sourceCount; ++i) {!! MIDIEndpointRef src = MIDIGetSource(i);!! CFStringRef endpointName = NULL;!! OSStatus nameErr = MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endpointName);!! if (noErr == nameErr) {!! ! NSLog (@" source %d: %@n", i, endpointName);!! }!! MIDIPortConnectSource(inPort, src, NULL);!}
- 12.Read Proc• Callback function indicated by MIDIInputPortCreate() • Receives MIDIPacketList • numPackets and MIDIPacket[] • Receives user-info/context pointers that you set up in MIDIInputPortCreate() and MIDIPortConnectSource()
- 13.MIDIPacket• Contains timeStamp, length, and Byte[]• Byte[] data is the MIDI message • data[0]: status • data[1]: MIDI Data 1 • data[2] (if present): MIDI Data 2
- 14.Parsing a NOTE ON message!MIDIPacket *packet = (MIDIPacket *)pktlist->packet;!!Byte midiCommand = packet->data[0] >> 4;!// is it a note-on?!if (midiCommand == 0x09) {!! Byte note = packet->data[1] & 0x7F;!! Byte velocity = packet->data[2] & 0x7F;
- 15.Now What?
- 16.Instrument Units• Audio Units that generate sound in response to MIDI events • kAudioUnitType_MusicDevice• Do not currently exist on iOS
- 17.Instrument to audio H/W I/O Unit Unit AU Graph
- 18.Instrument to audio H/W Effect Unit I/O Unit Unit AU Graph
- 19.Instrument to audio H/W I/O Unit Unit AU Graph
- 20.Mu si cD ev ic eM ID IE ve nt () Instrument to audio H/W I/O Unit Unit AU Graph
- 21.MusicDevice.h• Small API to deliver MIDI events to instrument units• Not in Xcode documentation. Check out the header file • Only 4 functions • MusicDeviceMIDIEvent() sends status, data1, data2 to a MusicDeviceComponent (i.e., an instrument Audio Unit)
- 22.Demo
- 23.MIDI on iOS• Core MIDI added in iOS 4.2• Device connectivity is via dock port • Custom hardware • iPad Camera Connection Kit
- 24.MIDI via the CCK• MIDI-to-USB adapters semi-officially blessed by Apple • Adapter must be USB MIDI Class- compliant (i.e., doesn’t need drivers) • Bus-powered devices may not work, due to low power supplied by iPad. Powered USB devices generally work.• http://iosmidi.com/devices/
- 25.Playing sounds on iOS• No instrument units on iOS. Options: • Synthesize your own with a render callback • Play sampled sounds with Audio Queue, AV Player, System Sounds, etc.
- 26.Demo
- 27.Demo
- 28.AUSampler• New instrument audio unit in Lion… and… … • Takes a sampled waveform and pitch-shifts it to make it into an instrument • Call with MusicDeviceMIDIEvent(), just like other instrument units
- 29.AUSampler• Configuration is a huge hassle • Huge and tota!y undocumented hassle • Build an .aupreset with AU Lab utility, or load DLS bank or SoundFont 2 files, or provide your own files • See WWDC Session 411 (“Music in iOS and MacOSX”), then file documentation bugs against absence of sample code
- 30.In Summary• Musicians love MIDI. Devices are cheap and plentiful• OSX and iOS love media, MIDI included • By comparison, Android has crap MIDI support (no javax.sound.midi, just .mid file support in android.media.JetPlayer)• If you’re doing Mac or iOS media apps, you should consider supporting MIDI device I/O
- 31.Also, you should buy my bookhttp://www.mypearsonstore.com/bookstore/product.asp?isbn=9780321636843 http://my.safaribooksonline.com/9780321636973 http://www.informit.com/promotions/promotion.aspx?promo=137039
Core MIDI and Friends的更多相关文章
- 使用Core Audio实现VoIP通用音频模块
最近一直在做iOS音频技术相关的项目,由于单项直播SDK,互动直播SDK(iOS/Mac),短视频SDK,都会用到音频技术,因此在这里收集三个SDK的音频技术需求,开发一个通用的音频模块用于三个SDK ...
- iOS开发:iOS的整体架构以及API介绍
iOS的整体架构分为4层——Cocoa Touch层.Media层.Core Services层和Core OS层,下面概要介绍一下这4层. Cocoa Touch:构建iOS应用的一些基本系统服务, ...
- 音频 API 一览
iOS 和 OS X 平台都有一系列操作音频的 API,其中涵盖了从低到高的全部层级.随着时间的推移.平台的增长以及改变,不同 API 的数量可以说有着非常巨大的变化.本文对当前可以使用的 API 以 ...
- Windows 10 的音频和 MIDI API将统一
微软一统 Windows 10 的音频和 MIDI API 微软在夏季NAMM上的A3E大会上做了主题演讲,他们对Windows 10的音频和MIDI API都做了新的规划,开发者针对Windows ...
- 【Win 10 应用开发】MIDI 音乐合成——更改乐器音色
在开始今天的吹 BB 博文之前,说点题外话. 首先,上次老周给大伙伴们介绍完发送 MIDI 音符,本来说好的接着说一下如何更改乐器音色,为啥这么久都没更新呢.特特来解释一下,最近老周接了一个 ASP. ...
- 用 Lua 控制 MIDI 合成器来播放自定义格式乐谱
用 Lua 控制 MIDI 合成器来播放自定义格式乐谱 作者: FreeBlues 最新: https://www.cnblogs.com/freeblues/p/9936844.html 说明: 本 ...
- ASP.NET Core 之 Identity 入门(一)
前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...
- .NET Core中的认证管理解析
.NET Core中的认证管理解析 0x00 问题来源 在新建.NET Core的Web项目时选择“使用个人用户账户”就可以创建一个带有用户和权限管理的项目,已经准备好了用户注册.登录等很多页面,也可 ...
- ASP.NET Core 中的那些认证中间件及一些重要知识点
前言 在读这篇文章之间,建议先看一下我的 ASP.NET Core 之 Identity 入门系列(一,二,三)奠定一下基础. 有关于 Authentication 的知识太广,所以本篇介绍几个在 A ...
随机推荐
- Jaxb annotation使用
JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实例文档反向 ...
- RMAN 命令-删除过期
手动删除日志文件后的处理,不然rman备份会出错 rman target / crosscheck archivelog all; delete expried archivelog all; 删除所 ...
- The type String cannot be constructed. You must configure the container to supply this value.
利用 Enterprise Library 5.0 Microsoft.Practices.EnterpriseLibrary.Common Microsoft.Practices.Enterpris ...
- 打造最高效的科研环境之Emacs插件们
0 盲人摸象 作为初学者,迫切的需求就是直接上手Emacs并打造包含自动补全命令在内的科研环境. 和网上众多的插件安装的教程相比,我认为找到一个与自己需求匹配的Emacs配置环境来得更方便. 本例中, ...
- Oracle查询
1.普通查询 select * from 表格 查询所有内容 select 列名,列名 from 表格查询某几列 2.条件查询 select * from 表格 where 条件 条件查询 selec ...
- ECMAScript6 面向对象 时钟效果
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- AJAX格式
var xmlHttp;function getXmlHttp(){ if(window.ActiveXObject){ xmlHttp = new ActiveXObject("MICRO ...
- 【 2013 Multi-University Training Contest 1 】
HDU 4602 Partition f[i]表示和为i的方案数.已知f[i]=2i-1. dp[i]表示和为i,k有多少个.那么dp[i]=dp[1]+dp[2]+...+dp[i-1]+f[i-k ...
- python时间格式化
import timeprint time.time()输出的结果是:1279578704.6725271 但是这样是一连串的数字不是我们想要的结果,我们可以利用time模块的格式化时间的方法来处理: ...
- Visual Basic 2012 借助DataGridView控件将SQL server2012 数据导入到Excel 2010
摘 要: SQL Server 2012 数据和Excel 2010之间的连接和数据的传输,本篇文章主要针对的是SQL Server 2012 数据导入到Excel 2010文件中.Excel软件对 ...