MIDI

作者: 抹不掉那伤1 | 来源:发表于2018-10-24 13:41 被阅读0次

Handling MIDI Data

原文

When working with MIDI data, an application might need to load track data from a standard MIDI file (SMF). You can invoke a Music Player function (MusicSequenceLoadSMFWithFlags or MusicSequenceLoadSMFDataWithFlags) to read in data in the Standard MIDI Format, as shown in Figure 3-5.


Figure 3-5 Reading a standard MIDI file

Depending on the type of MIDI file and the flags set when loading a file, you can store all the MIDI data in single track, or store each MIDI channel as a separate track in the sequence. By default, each MIDI channel is mapped sequentially to a new track in the sequence. For example, if the MIDI data contains channels 1, 3, and, 4, three new tracks are added to the sequence, containing data for channels 1, 3, and 4 respectively. These tracks are appended to the sequence at the end of any existing tracks. Each track in a sequence is assigned a zero-based index value.

Timing information (that is, tempo events) goes to the tempo track.

Once you have loaded MIDI data into the sequence, you can assign a music player instance to play it, as shown in Figure 3-6.


Figure 3-6 Playing MIDI data

The sequence must be associated with a particular audio processing graph, and the tracks in the sequence can be assigned to one or more instrument units in the graph. (If you don't specify a track mapping, the music player sends all the MIDI data to the first instrument unit it finds in the graph.) The music player assigned to the sequence automatically communicates with the graph's output unit to make sure the outgoing audio data is properly synchronized. The compressor unit, while not required, is useful for ensuring that the dynamic range of the instrument unit’s output stays consistent.

MIDI data in a sequence can also go to external MIDI hardware (or software configured as a virtual MIDI destination), as shown in Figure 3-7.

Tracks destined for MIDI output must be assigned a MIDI endpoint. The music player communicates with Core MIDI to ensure that the data flow to the MIDI device is properly synchronized. Core MIDI then coordinates with the MIDI Server to transmit the data to the MIDI instrument.


Figure 3-7 Sending MIDI data to a MIDI device

A sequence of tracks can be assigned to a combination of instrument units and MIDI devices. For example, you can assign some of the tracks to play through an instrument unit, while other tracks go through Core MIDI to play through external MIDI devices, as shown in Figure 3-8.


Figure 3-8 Playing both MIDI devices and a virtual instrument
The music player automatically coordinates between the audio processing graph's output unit and Core MIDI to ensure that the outputs are synchronized.

Another common scenario is to play back already existing track data while accepting new MIDI input, as shown in Figure 3-9.


Figure 3-9 Accepting new track inpu

The playback of existing data is handled as usual through the audio processing graph, which sends audio data to the output unit. New data from an external MIDI device enters through Core MIDI and is transferred through the assigned endpoint. Your application must iterate through this incoming data and write the MIDI events to a new or existing track. The Music Player API contains functions to add new tracks to a sequence, and to write time-stamped MIDI events or other messages to a track.

For examples of handling and playing MIDI data, see the following examples in the Core Audio SDK:

  • PlaySoftMIDI, which sends MIDI data to a simple processing graph consisting of an instrument unit and an output unit.

  • PlaySequence, which reads in a MIDI file into a sequence and uses a music player to play it.

Handling Audio and MIDI Data Together

Sometimes you want to combine audio data with audio synthesized from MIDI data and play back the result. For example, the audio for many games consists of background music, which is stored as an audio file on disk, along with noises triggered by events (footsteps, gunfire, and so on), which are generated as MIDI data. Figure 3-10 shows how you can use Core Audio to combine the two.


Figure 3-10 Combining audio and MIDI data

The soundtrack audio data is retrieved from disk or memory and converted to linear PCM using the Extended Audio File API. The MIDI data, stored as tracks in a music sequence, is sent to a virtual instrument unit. The output from the virtual instrument unit is in linear PCM format and can then be combined with the soundtrack data. This example uses a 3D mixer unit, which can position audio sources in a three-dimensional space. One of the tracks in the sequence is sending event data to the mixer unit, which alters the positioning parameters, making the sound appear to move over time. The application would have to monitor the player's movements and add events to the special movement track as necessary.

For an example of loading and playing file-based audio data, see SimpleSDK/PlayFile in the Core Audio SDK.

相关文章

  • MIDI

    Handling MIDI Data 原文 When working with MIDI data, an app...

  • 蓝牙BLE MIDI芯片IC方案

    蓝牙BLE MIDI芯片IC方案 一、BLE MIDI简介...

  • MIDI格式

    1. MIDI基础 1.1. 概念 MIDI(Musical Instrument Digital Interfa...

  • MIDI

    那些关于她,关于纹身,关于滑板,关于小种,关于爱好,关于朋友 关于“贴画” 第一次看见时,她笑着说,“这是贴...

  • MIDI

    MIDI 它用音符的数字控制信号来记录音乐。一首完整的MIDI音乐只有几十KB大,而能包含数十条音乐轨道。几乎所有...

  • 啷个哩个啷

    今天开始玩miditrail 网站:midishow此网站MIDI资源较多,并且更新频率较高,MIDI文件比较容易...

  • FL Studio 中启用(打开)MIDI键盘外设 2020-1

      ◆ 1、首先确保外设MIDI键盘可用,并且与计算机连接良好。   ◆ 2、选择OPTIONS,MIDI set...

  • 基于keras的人工作曲代码积累

    utils.py 包含的函数有 def convert_midi_to_mp3():: 将神经网络生成的MIDI文...

  • Processing接收MIDI消息

    直接上代码了 Live里把MIDI消息发送到IAC_BUS1 Processing里选取MIDI IN的port ...

  • C语言实现--计算MIDI音符的频率

    MIDI音符数据 MIDI音符数据的值是无符号 seven-bit 整数,每个整数的取值范围是[0,127]。MI...

网友评论

      本文标题:MIDI

      本文链接:https://www.haomeiwen.com/subject/vhnttqtx.html