自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
MIDI 测试程序
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
以下测试可用于验证 Android 设备上的 MIDI 功能。成功执行这些测试是声明 MIDI 功能的先决条件。
准备
硬件
测试需要使用以下硬件。
- 配备 USB 连接器的 MIDI 键盘
- 支持低功耗蓝牙 (BLE) 的 MIDI 键盘
- USB 线
- 可将 USB-A 母头转换为 micro-USB 或 USB-C 公头的 USB On-The-Go (OTG) 适配器
- 运行 Android 6.0 Marshmallow 或更高版本的 Android 设备
- 可选:桌面设备
多个 MIDI 键盘支持 USB 和 BLE-MIDI,因此您可以只用一个键盘来进行测试。例如 Akai LPK25 Wireless 和 Korg Microkey Air。
应用
该测试程序涉及多个应用。您可以通过点击下表中的链接获取 GitHub 项目 android-midisuite 应用的源代码或通过 Google Play™ 安装应用。
如果您选择从源代码开始构建,而不是通过 Google Play™ 进行安装,请先使用附带的 Android.mk 构建应用。然后使用 Android 调试桥 (ADB) 安装该应用。例如,如需安装 MidiScopeMidiScope 应用,请按以下步骤操作:
- 使用安装了 ADB 的工作站。
- 使用 USB 线将工作站连接到 Android 设备。
- 您可能需要在 Android 设备上允许 USB 连接;请参阅 USB 外设模式。
- 在工作站上,输入以下内容:
cd THIS_FOLDER
adb install -r MidiScope.apk
虚拟合成器测试
请注意,MIDI 输入端口只能建立一个连接。因此,如果另一个应用已经连接到输入端口,则该端口将不可用。如果您无法连接到输入端口,请尝试关闭其他应用。
所需的硬件:受测 Android 设备
简易连接
所需的应用:MidiKeyboard、MidiSynthExample
这个测试用于测试设备枚举、虚拟设备、端口连接和消息发送等功能。
- 将 Android 设备上的音量调节至大约一半的位置。
- 将手机切换为横屏模式。
- 启动 MidiKeyboard 应用。MidiKeyboard
- 从下拉菜单中选择 SynthExample。
- 弹奏琴键。您应该能听到 SynthExample 应用中播放的音符。SynthExample
- 按返回按钮退出应用后,端口将关闭。
USB 测试:主机模式
所需的硬件:USB MIDI 键盘、USB 线、OTG 适配器
这些测试需要重复进行几次。我们发现,如果将设备插入和拔下数次,某些原型设备上会出现 USB 协议栈严重崩溃。
键盘已插入
所需的应用:MidiSynthExample 或 MidiScope
这个测试用于在主机模式下测试 USB MIDI。
- 将 Android 设备上的音量调节至大约一半的位置。
- 使用 OTG 适配器连接 USB 键盘。
- 启动 SynthExample 应用或 MidiScope 应用。
- 从菜单中选择 USB 键盘。界面上会显示键盘的品牌信息。
- 在键盘上弹奏音符。如果运行 SynthExample,您应该能在手机上听到播放的音符。SynthExample如果运行 MidiScope,屏幕上将显示 NoteOn 和 NoteOff 消息。
- 拔下键盘。“合成器的发送器”菜单应该会显示“- - - - -”。
- 按返回按钮退出应用。
热插拔 USB 键盘
所需的应用:MidiSynthExample 或 MidiScope
这个测试用于在主机模式下测试 USB MIDI。
- 将 Android 设备上的音量调节至大约一半的位置。
- 确保没有插入任何 USB MIDI 键盘。
- 启动 SynthExample 应用。SynthExample
- 在中间位置,找到“合成器的发送器”旁边的菜单。应该不会列出 USB 键盘。
- 使用 OTG 适配器连接 USB 键盘。
- 在中间位置,选择“合成器的发送器”旁边的 USB 键盘。将显示键盘的品牌信息。
- 在键盘上弹奏音符。您应该能在手机上听到播放的音符。
- 在中间位置,选择“合成器的发送器”旁边的 - - - - -。
- 在键盘上弹奏音符。您应该不会听到任何声音。
- 在中间位置,选择“合成器的发送器”旁边的 USB 键盘。将显示键盘的品牌信息。
- 在键盘上弹奏音符。您应该能在手机上听到播放的音符。
- 拔下合成器。“合成器的发送器”菜单应该会显示“- - - - -”。
- 按返回按钮退出应用。
USB 测试:外围设备模式
所需的硬件:USB 线、OTG 适配器
Android 设备到 Android 设备
所需的应用:受测 Android 设备上的 MidiKeyboard,另一台 Android 设备上的 MidiScope。
将 Android 设备用作另一台 Android 设备的外围设备控制器。为了帮助测试该模式,请使用另一台在主机模式下运行的 Android 设备。请注意,您可以修改测试,以便用于运行数字音频工作站 (DAW) 软件(如 GarageBand)的桌面设备。
- 将 USB 线连接到受测 Android 设备(Android 设备 A)。
- 使用 OTG 适配器将线的另一端连接到另一台 Android 设备 B(在主机模式下运行)。
- 在 Android 设备 A 上执行以下操作:
- 用手指从屏幕顶部向下滑动。
- 选择正在通过 USB 充电图标。
- 选择 MIDI。
- 启动 MidiKeyboard 应用。MidiKeyboard
- 从顶部的“按键接收器”菜单中选择 Android USB 外设端口。
- 在 Android 设备 B 上执行以下操作:
- 启动 MidiScope 应用。MidiScope
- 选择另一台 Android 设备作为源设备。
- 在 Android 设备 A 上执行以下操作:
- 在键盘上弹奏音符,并在 Android 设备 B 上查找 NoteOn 和 NoteOff。
BLE 测试
所需的硬件:支持 BLE 的 MIDI 键盘
基本配对和弹奏
所需的应用:MidiBtlePairing、MidiSynthExample
测试通过 BLE 连接到 Android 设备的键盘。
- 重新启动 Android 设备。
- 开启 BLE 键盘。
(按下靠近背面的按钮,开启 Miselu C.24 键盘,从而使其弹开。在配对模式下,C.24 上的电源按钮闪烁蓝光。)
- 启动 MidiBtlePairing 应用。该应用具有 MIDI + BTLE 图标。
- 按蓝牙扫描按钮。
- 选择所需的 BLE 外围设备。
- 应用应该会返回到主页面,并且您应该会看到列出的外围设备。如果您使用的是 C.24,那么您会发现 C.24 上的指示灯变绿,表明已配对成功。
- 按主屏幕按钮(而非返回按钮)退出应用。
- 启动 SynthExample 应用。
- 从菜单中选择 BLE 键盘作为发送器。
- 在 BLE 键盘上弹奏琴键后,您能够在 Android 设备上听到播放的音符。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# MIDI test procedure\n\nThese tests may be used to validate the MIDI feature on Android devices.\nSuccessful execution of these tests is a prerequisite to\n[claim the MIDI feature](/docs/core/audio/midi#claim-feature).\n\nPreparation\n-----------\n\n### Hardware\n\n\nThe following hardware is needed for the tests.\n\n- MIDI keyboard with USB connector\n- MIDI keyboard with Bluetooth Low Energy (BLE) support\n- USB cables\n- USB On-The-Go (OTG) adapter to convert a female USB-A to male micro-USB or USB-C\n- Android device running Android 6.0 Marshmallow or later release\n- Optional: desktop computer\n\n\nSeveral MIDI keyboards support both USB and BLE-MIDI, so you can do your testing with\njust one keyboard. Examples are the\n[Akai LPK25 Wireless](http://www.akaipro.com/product/lpk25)\nand the\n[Korg Microkey Air](https://www.korg.com/us/products/computergear/microkey2_air/).\n\n### Apps\n\n\nSeveral apps are used by this test procedure.\nThe apps are available in source code on GitHub project\n[android-midisuite](https://github.com/philburk/android-midisuite),\nand via *Google Play*™ at links in the following table.\n\n| Source code | Google Play™ | Description |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|\n| [MidiScope](https://github.com/philburk/android-midisuite/tree/master/MidiScope) or [MidiScope](https://github.com/googlesamples/android-MidiScope) | [MIDI Scope](https://play.google.com/store/apps/details?id=com.mobileer.example.midiscope) | displays MIDI messages on-screen |\n| [MidiKeyboard](https://github.com/philburk/android-midisuite/tree/master/MidiKeyboard) | [MIDI Keyboard](https://play.google.com/store/apps/details?id=com.mobileer.midikeyboard) | sends MIDI messages by pressing an on-screen music keyboard |\n| [MidiSynthExample](https://github.com/philburk/android-midisuite/tree/master/MidiSynthExample) or [MidiSynth](https://github.com/googlesamples/android-MidiSynth) | [MIDI Synth Ex](https://play.google.com/store/apps/details?id=com.mobileer.midisynthexample) | simple MIDI synthesizer that uses sawtooth oscillators |\n| [MidiBtlePairing](https://github.com/philburk/android-midisuite/tree/master/MidiBtlePairing) | [MIDI BLE Connect](https://play.google.com/store/apps/details?id=com.mobileer.example.midibtlepairing) | pairs an Android device with a BLE peripheral |\n| [MidiTools](https://github.com/philburk/android-midisuite/tree/master/MidiTools) | | library dependency of the above apps |\n\n\nIf you choose to work from source code rather than install via *Google Play* ™,\nfirst build the app using the supplied *Android.mk* .\nThen install the app using\n[Android Debug Bridge](http://developer.android.com/tools/help/adb.html) (ADB).\nFor example, to install the *MidiScope* app:\n\n1. Use a workstation with ADB installed.\n2. Connect a USB cable from the workstation to the Android device.\n3. You may need to allow the USB connection on the Android device; see [USB peripheral mode](/docs/core/audio/midi#usb-peripheral)\n4. On the workstation, enter:\n\n cd \u003cvar translate=\"no\"\u003eTHIS_FOLDER\u003c/var\u003e\n adb install -r MidiScope.apk\n\nVirtual synth tests\n-------------------\n\nNote that a MIDI input port can have only one connection. So if another app is\nalready using an input port, that port will not be available. If you cannot connect to\nan input port then try closing other apps.\n\nHardware needed: Android device under test\n\n### Simple connection\n\nApps needed: *MidiKeyboard* , *MidiSynthExample*\n\nThis tests device enumeration, virtual devices, port connections, and message\nsending.\n\n1. Adjust volume on Android device to about halfway.\n2. Orient phone in landscape mode.\n3. Launch *MidiKeyboard* app.\n4. Select **SynthExample** from the spinner menu.\n5. Play keys. You should hear notes being played in the *SynthExample* app.\n6. Exit the application by pressing the **Back** button so that the port will be closed.\n\nUSB test: host mode\n-------------------\n\nHardware needed: USB MIDI keyboard, USB cable, OTG adapter\n\nRepeat these tests several times. We have seen the USB stack crash hard on some\nprototype devices if devices were plugged in and unplugged a few times.\n\n### Keyboard already plugged in\n\nApps needed: *MidiSynthExample* or *MidiScope*\n\nThis tests USB MIDI in host mode.\n\n1. Adjust volume on Android device to about halfway.\n2. Plug in USB keyboard using the OTG adapter.\n3. Launch *SynthExample* app or the *MidiScope* app.\n4. From the menu select the USB keyboard. It will display the brand.\n5. Play notes on the keyboard. If you ran *SynthExample* then you should hear notes being played on the phone. If you ran *MidiScope* then you should see *NoteOn* and *NoteOff* messages on-screen.\n6. Unplug the keyboard. The *Sender for Synth* menu should display *- - - - -*.\n7. Exit the application by pressing the **Back** button.\n\n### Hot-plug USB keyboard\n\nApps needed: *MidiSynthExample* or *MidiScope*\n\nThis tests USB MIDI in host mode.\n\n1. Adjust volume on Android device to about halfway.\n2. Make sure there is not a USB MIDI keyboard plugged in.\n3. Launch *SynthExample* app.\n4. At middle, next to *Sender for Synth*, look in menu. You should not see the USB keyboard listed.\n5. Plug in USB keyboard using the OTG adapter.\n6. At middle, next to *Sender for Synth*, select the USB keyboard. It will display the brand.\n7. Play notes on the keyboard. You should hear notes being played on the phone.\n8. At middle, next to *Sender for Synth* , select **- - - - -**.\n9. Play notes on the keyboard. You should hear nothing.\n10. At middle, next to *Sender for Synth*, select the USB keyboard. It will display the brand.\n11. Play notes on the keyboard. You should hear notes being played on the phone.\n12. Unplug the synthesizer. The *Sender for Synth* menu should display *- - - - -*.\n13. Exit the application by pressing the **Back** button.\n\nUSB test: peripheral mode\n-------------------------\n\nHardware needed: USB cable, OTG adapter\n\n### Android-to-Android\n\nApps needed: *MidiKeyboard* on Android device under test, *MidiScope* on another\nAndroid device.\n\nUse Android devices as a peripheral controller for another Android device. To help test\nthis mode, use another Android device running in host mode. Note that\nyou could modify the test to work with a desktop computer running Digital Audio Workstation (DAW)\nsoftware such as\nGarageBand.\n\n1. Connect the USB cable to the Android device under test (Android device **A**).\n2. Use an OTG adapter to connect the other end of the cable to a second Android device **B** that operates in host mode.\n3. On Android device A:\n 1. Drag finger down from top of screen.\n 2. Select **USB for Charging** icon.\n 3. Select **MIDI**.\n 4. Launch *MidiKeyboard* app.\n 5. Select **Android USB Peripheral Port** from *Receiver for Keys* menu at top.\n4. On Android device B:\n 1. Launch *MidiScope* app.\n 2. Select the other Android device as the source.\n5. On Android device A:\n 1. Play notes on the keyboard and look for *NoteOn* and *NoteOff* on Android device B.\n\nBLE test\n--------\n\nHardware needed: MIDI keyboard supporting BLE\n\n### Basic pairing and playing\n\nApps needed: *MidiBtlePairing* , *MidiSynthExample*\n\nTest a keyboard connected to Android over BLE.\n\n1. Reboot the Android device.\n2. Power on the BLE keyboard. \n (The Miselu C.24 keyboard is powered on by pushing the button near the back so that it pops open. The power button on the C.24 pulses blue when in pairing mode.)\n3. Launch the *MidiBtlePairing* app. It has a *MIDI+BTLE* icon.\n4. Press the **Bluetooth Scan** button.\n5. Select desired BLE peripheral.\n6. The app should return to the main page, and you should see the peripheral listed. If you are using a C.24, then you will notice that the light should turn green on the C.24 to indicate paired mode.\n7. Exit the app by pressing the **Home** button, not the **Back** button.\n8. Launch the SynthExample app.\n9. Select the BLE keyboard as the sender from the menu.\n10. You should be able to press keys on the BLE keyboard and hear notes on Android."]]