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 ...
随机推荐
- NXOPEN环境配置
1.找到NX中的vc文件夹 D:\study software\NX\NX9.0\UGOPEN\vs_files
- MVC5+EF6 入门完整教程六
本篇我们谈谈分部视图(Partial View). 上篇文章提到过Partial和Action这两个helper, 本篇文章主要就结合这两个helper来讲解分部视图(Partial View)的应用 ...
- laravel cookie写入
$cookie = cookie('cookie_name', 'value', 5); $data = ['title'=>'hello world']; ...
- Thrift入门及Java实例演示<转载备用>
Thrift入门及Java实例演示 作者: Michael 日期: 年 月 日 •概述 •下载配置 •基本概念 .数据类型 .服务端编码基本步骤 .客户端编码基本步骤 .数据传输协议 •实例演示(ja ...
- [并查集] POJ 2236 Wireless Network
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25022 Accepted: 103 ...
- bzoj 3504: [Cqoi2014]危桥
#include<cstdio> #include<iostream> #include<cstring> #define M 100009 #define inf ...
- easyui-validatebox 验证
required: "必选字段", remote: "请修正该字段", email: "请输入正确格式的电子邮件" ...
- jquery tab 插件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- sublime_markdown
sublime text 下实现markdown实时预览 这个文档是网上比较流行的教程,你可以按照这个教程来,如果你幸运的话,也许一次性成功.那就到此为止,可以不用看了-- ---------–华丽的 ...
- uboot环境变量实现分析
u-boot的环境变量用来存储一些经常使用的参数变量,uboot希望将环境变量存储在静态存储器中(如nand nor eeprom mmc). 其中有一些也是大家经常使用,有一些是使用人员自己定义的, ...